Skip to content

Commit

Permalink
Merge pull request #24 from bci-oss/feature/release-0.1.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
bs-jokri authored Sep 19, 2022
2 parents 79158c5 + 6de8385 commit 72366ba
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 154 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ The Semantic Hub is a logical and architectural component of Tractus-X.
The source code under this folder contains reference implementations of the SLDT Semantic Hub

## Build Packages
The project requires a private package from https://maven.pkg.github.com/eclipse-dataspaceconnector/DataSpaceConnector.
Add the following configuration to your `.m2/settings.xml`:

```xml
<server>
<id>edc-github</id>
<username>oauth2</username>
<password>$ADD_GITHUB_ACCESS_TOKEN_HERE</password>
</server>
```

You need to add your own GitHub Access Token. Navigate to https://github.com/settings/tokens and create a new token
with the permission `read:packages`.

Run `mvn install` to run unit tests, build and install the package.

Expand Down
13 changes: 7 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

FROM eclipse-temurin:11-jre
FROM eclipse-temurin:11-jre-alpine

RUN apt-get -y upgrade \
&& apt-get -y update \
&& apt-get -y install graphviz \
&& apt-get clean
RUN apk upgrade \
&& apk update \
&& apk add graphviz \
&& rm -rf /var/cache/apk/*

RUN adduser --system --group spring \
RUN addgroup -S spring \
&& adduser -S spring -G spring \
&& mkdir -p /service \
&& chown spring:spring /service

Expand Down
2 changes: 1 addition & 1 deletion backend/deployment/semantic-hub/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ description: Helm Chart for the Catena-X Semantic Hub Application

type: application
version: 0.1.0
appVersion: 1.3.0-SNAPSHOT
appVersion: 0.1.0-M1
6 changes: 3 additions & 3 deletions backend/deployment/semantic-hub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
###############################################################

hub:
image: semantic-hub:latest
image: semantic-hub:0.1.0-M1
imagePullPolicy: IfNotPresent
replicaCount: 1
containerPort: 4242
## Use in-memory triple store that is not persistent
embeddedTripleStore: false
host: minikube
host: host
## If 'authentication' is set to false, no OAuth authentication is enforced
authentication: false
idpIssuerUri: "https://catenaxdev042akssrv.germanywestcentral.cloudapp.azure.com/iamcentralidp/auth/realms/CX-Central"
idpIssuerUri: https://idp-url
## Ignored if 'graphdb.enabled' is set to true
graphdbBaseUrl: http://graphdb:3030
service:
Expand Down
46 changes: 31 additions & 15 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>semantic-hub</artifactId>
<version>0.1.0-M1</version>
<version>0.1.0-M2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -54,22 +54,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Tempory fix for a finding in snakeyaml v1.30, remove once new Spring Boot release contains fix -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
Expand All @@ -78,11 +76,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
Expand All @@ -108,6 +101,17 @@
<groupId>io.openmanufacturing</groupId>
<artifactId>sds-aspect-model-starter</artifactId>
</dependency>
<!--
The AASX generator uses this dependency to generate AASX XML files.
The jackson version provided by Spring Boot has an issue, xml prefixes are not generated correctly.
To mitigate this problem we downgraded to the latest working version.
If there is a newer version you can try out if it works by running the test ModelsApi#testAasxEndpointExpectSuccess.
-->
<dependency>
<artifactId>jackson-dataformat-xml</artifactId>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<version>2.12.7</version>
</dependency>
<dependency>
<groupId>io.openmanufacturing</groupId>
<artifactId>sds-aspect-model-aas-generator</artifactId>
Expand All @@ -116,6 +120,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<artifactId>maven-core</artifactId>
<groupId>org.apache.maven</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down Expand Up @@ -164,7 +172,15 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class OAuthSecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(auth -> auth
.antMatchers(HttpMethod.OPTIONS).permitAll()
.mvcMatchers(HttpMethod.GET,"/**/models/**").access("@authorizationEvaluator.hasRoleViewSemanticModel()")
.mvcMatchers(HttpMethod.POST,"/**/models/**").access("@authorizationEvaluator.hasRoleAddSemanticModel()")
.mvcMatchers(HttpMethod.PUT,"/**/models/**").access("@authorizationEvaluator.hasRoleUpdateSemanticModel()")
.mvcMatchers(HttpMethod.DELETE,"/**/models/**").access("@authorizationEvaluator.hasRoleDeleteSemanticModel()"))
.mvcMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers(HttpMethod.GET,"/**/models/**").access("@authorizationEvaluator.hasRoleViewSemanticModel()")
.antMatchers(HttpMethod.POST,"/**/models/**").access("@authorizationEvaluator.hasRoleAddSemanticModel()")
.antMatchers(HttpMethod.PUT,"/**/models/**").access("@authorizationEvaluator.hasRoleUpdateSemanticModel()")
.antMatchers(HttpMethod.DELETE,"/**/models/**").access("@authorizationEvaluator.hasRoleDeleteSemanticModel()"))
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.oauth2ResourceServer().jwt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;

import org.eclipse.tractusx.semantics.hub.domain.ModelPackageStatus;
import org.eclipse.tractusx.semantics.hub.domain.ModelPackageUrn;
Expand All @@ -20,6 +21,7 @@
import org.springframework.http.ResponseEntity;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;

import io.openmanufacturing.sds.aspectmodel.resolver.services.VersionedModel;
import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn;
Expand Down Expand Up @@ -161,6 +163,19 @@ public ResponseEntity getAasSubmodelTemplate(String urn, AasFormat aasFormat) {
return new ResponseEntity( result.get(), responseHeaders, HttpStatus.OK );
}

@Override
public ResponseEntity<SemanticModelList> getModelListByUrns(Integer pageSize, Integer page, List<String> requestBody) {
List<AspectModelUrn> urnList = Lists.transform(requestBody, (String urn) -> AspectModelUrn.fromUrn(urn));

final SemanticModelList models = persistenceLayer.findModelListByUrns( urnList, page, pageSize );

if ( models == null ) {
return new ResponseEntity<>( HttpStatus.NOT_FOUND );
}

return new ResponseEntity<SemanticModelList>( models, HttpStatus.OK );
}

private Aspect getBamAspect( String urn ) {
final Try<Aspect> aspect = bammHelper.getAspectFromVersionedModel( getVersionedModel( urn ) );
if ( aspect.isFailure() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package org.eclipse.tractusx.semantics.hub.persistence;

import java.util.List;

import javax.annotation.Nullable;

import org.eclipse.tractusx.semantics.hub.domain.ModelPackageStatus;
Expand Down Expand Up @@ -58,4 +60,6 @@ public interface PersistenceLayer {
void deleteModelsPackage( ModelPackageUrn urn );

boolean echo();

public SemanticModelList findModelListByUrns(List<AspectModelUrn> urns, int page, int pageSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@

import org.eclipse.tractusx.semantics.hub.domain.ModelPackageStatus;
import org.eclipse.tractusx.semantics.hub.domain.ModelPackageUrn;

import com.google.common.collect.Lists;

import ch.qos.logback.core.pattern.LiteralConverter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.jena.datatypes.BaseDatatype;
import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.xsd.impl.XSDPlainType;
import org.apache.jena.graph.impl.AdhocDatatype;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.Query;
import org.apache.jena.query.QuerySolutionMap;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.RDFList;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.rdf.model.impl.RDFListImpl;
import org.apache.jena.reasoner.rulesys.FunctorDatatype;
import org.apache.jena.update.UpdateRequest;

import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn;
Expand Down Expand Up @@ -90,6 +110,23 @@ public class SparqlQueries {
+ " && (str(?s) = ?packageUrn) )\n"
+ " }";

private static final String FIND_BY_MULTIPLE_URNS_QUERY =
"SELECT DISTINCT ?aspect (?status as ?statusResult)\n"
+ "WHERE\n"
+ " {\n"
+ " VALUES (?urns) { ?urnParamList } \n"
+ " VALUES (?packageUrns) { ?packageUrnParamList } \n"
+ " bind( $bammAspectUrnParam as ?bammAspectUrn )\n"
+ " ?aspect a ?bammAspect .\n"
+ " ?s aux:status ?status .\n"
+ " FILTER ( regex(str(?bammAspect), ?bammAspectUrn, \"\") \n"
+ " && ( str(?aspect) IN (?urns) ) \n"
+ " && ( str(?s) IN (?packageUrns)) ) \n"
+ " }"
+ "ORDER BY lcase(str(?aspect))\n"
+ "OFFSET $offsetParam\n"
+ "LIMIT $limitParam";

private static final String FIND_BY_PACKAGE_URN_QUERY =
"SELECT (?status as ?statusResult)\n"
+ "WHERE\n"
Expand All @@ -114,6 +151,22 @@ public class SparqlQueries {
+ "FILTER ( !bound(?namespaceFilter) || contains(str(?aspect), ?namespaceFilter ) )\n"
+ "}\n";

private static final String FILTER_QUERY_MINIMAL_WHERE_CLAUSE_SELECTIVE = "WHERE {\n"
+ "BIND($bammAspectUrnRegexParam AS ?bammAspectUrnRegex)\n"
+ "BIND(iri($bammFieldToSearchInParam) AS ?bammFieldToSearchIn)\n"
+ "BIND($bammFieldSearchValueParam AS ?bammFieldSearchValue)\n"
+ "BIND($statusFilterParam AS ?statusFilter)\n"
+ "BIND($namespaceFilterParam AS ?namespaceFilter)\n"
+ "VALUES (?urns) { ?urnParamList } \n"
+ "?aspect a ?bammAspect .\n"
+ "FILTER regex(str(?bammAspect), ?bammAspectUrnRegex, \"\")\n"
+ "BIND(iri(concat(strbefore(str(?aspect ), \"#\"), \"#\")) AS ?package)\n"
+ "?package aux:status ?status\n"
+ "FILTER ( !bound(?statusFilter) || contains(str(?status), ?statusFilter) )\n"
+ "FILTER ( !bound(?namespaceFilter) || contains(str(?aspect), ?namespaceFilter ) )\n"
+ "FILTER ( str(?aspect) IN (?urns) ) "
+ "}\n";

private static final String FIND_ALL_MINIMAL_QUERY =
"SELECT DISTINCT ?aspect (?status as ?statusResult)\n"
+ FILTER_QUERY_MINIMAL_WHERE_CLAUSE
Expand All @@ -125,6 +178,10 @@ public class SparqlQueries {
"SELECT (count(DISTINCT ?aspect) as ?aspectModelCount)\n"
+ FILTER_QUERY_MINIMAL_WHERE_CLAUSE;

private static final String COUNT_ASPECT_MODELS_MINIMAL_QUERY_SELECTIVE =
"SELECT (count(DISTINCT ?aspect) as ?aspectModelCount)\n"
+ FILTER_QUERY_MINIMAL_WHERE_CLAUSE_SELECTIVE;

private SparqlQueries() {
}

Expand All @@ -135,12 +192,50 @@ public static Query buildFindByUrnQuery( final AspectModelUrn urn ) {
pss.setLiteral( "$packageUrnParam", ModelPackageUrn.fromUrn( urn ).getUrn() );
return pss.asQuery();
}

public static Query buildFindListByUrns( final List<AspectModelUrn> urns, int page, int pageSize ) {
final ParameterizedSparqlString pss = create( FIND_BY_MULTIPLE_URNS_QUERY );

List<RDFNode> urnList = new ArrayList<>();
List<RDFNode> modelPackageUrnList = new ArrayList<>();

urns.forEach((AspectModelUrn urn) -> {
urnList.add(ResourceFactory.createStringLiteral(urn.toString()));
modelPackageUrnList.add(ResourceFactory.createStringLiteral(ModelPackageUrn.fromUrn(urn).getUrn()));
});

pss.setValues("urnParamList", urnList);
pss.setLiteral( "$bammAspectUrnParam", BAMM_ASPECT_URN_REGEX );
pss.setValues( "packageUrnParamList", modelPackageUrnList );
pss.setLiteral("offsetParam", getOffset(page, pageSize));
pss.setLiteral("limitParam", pageSize);

return pss.asQuery();
}

public static Query buildCountAspectModelsQuery( String namespaceFilter,
ModelPackageStatus status ) {
return buildMinimalQuery(COUNT_ASPECT_MODELS_MINIMAL_QUERY, namespaceFilter, status).asQuery();
}

public static Query buildCountSelectiveAspectModelsQuery( String namespaceFilter, String nameFilter, String nameType,
ModelPackageStatus status, List<AspectModelUrn> urns ) {
ParameterizedSparqlString pss = buildMinimalQuery(COUNT_ASPECT_MODELS_MINIMAL_QUERY_SELECTIVE, namespaceFilter, status);

List<RDFNode> urnList = new ArrayList<>();
List<RDFNode> modelPackageUrnList = new ArrayList<>();

urns.forEach((AspectModelUrn urn) -> {
urnList.add(ResourceFactory.createStringLiteral(urn.toString()));
modelPackageUrnList.add(ResourceFactory.createStringLiteral(ModelPackageUrn.fromUrn(urn).getUrn()));
});

pss.setValues("urnParamList", urnList);
pss.setValues( "packageUrnParamList", modelPackageUrnList );

return pss.asQuery();
}

public static Query buildFindByPackageQuery( final ModelPackageUrn modelsPackage ) {
final ParameterizedSparqlString pss = create( FIND_BY_PACKAGE_URN_QUERY );
pss.setLiteral( "$urnParam", modelsPackage.getUrn() );
Expand Down
Loading

0 comments on commit 72366ba

Please sign in to comment.