diff --git a/README.md b/README.md
index 311ed582..6576c7a9 100644
--- a/README.md
+++ b/README.md
@@ -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
-
- edc-github
- oauth2
- $ADD_GITHUB_ACCESS_TOKEN_HERE
-
-```
-
-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.
diff --git a/backend/Dockerfile b/backend/Dockerfile
index ab32740c..71cd2c3c 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -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
diff --git a/backend/deployment/semantic-hub/Chart.yaml b/backend/deployment/semantic-hub/Chart.yaml
index 8c98f1fb..b2a1cc1c 100644
--- a/backend/deployment/semantic-hub/Chart.yaml
+++ b/backend/deployment/semantic-hub/Chart.yaml
@@ -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
\ No newline at end of file
+appVersion: 0.1.0-M1
\ No newline at end of file
diff --git a/backend/deployment/semantic-hub/values.yaml b/backend/deployment/semantic-hub/values.yaml
index 023e2862..f5737a66 100644
--- a/backend/deployment/semantic-hub/values.yaml
+++ b/backend/deployment/semantic-hub/values.yaml
@@ -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:
diff --git a/backend/pom.xml b/backend/pom.xml
index 6326ca53..17f3416f 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -25,7 +25,7 @@
org.eclipse.tractusx
semantic-hub
- 0.1.0-M1
+ 0.1.0-M2
../pom.xml
@@ -54,22 +54,20 @@
org.springframework.boot
spring-boot-starter-validation
+
- org.springframework.boot
- spring-boot-starter-web
+ org.yaml
+ snakeyaml
org.springframework.boot
- spring-boot-starter-jetty
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
+ spring-boot-starter-web
org.springframework.boot
- spring-boot-starter-test
+ spring-boot-starter-jetty
+
org.springframework.boot
spring-boot-starter-oauth2-resource-server
@@ -78,11 +76,6 @@
org.springframework.boot
spring-boot-starter-actuator
-
- org.springframework.security
- spring-security-test
- test
-
org.mapstruct
mapstruct
@@ -108,6 +101,17 @@
io.openmanufacturing
sds-aspect-model-starter
+
+
+ jackson-dataformat-xml
+ com.fasterxml.jackson.dataformat
+ 2.12.7
+
io.openmanufacturing
sds-aspect-model-aas-generator
@@ -116,6 +120,10 @@
junit
junit
+
+ maven-core
+ org.apache.maven
+
@@ -164,7 +172,15 @@
org.slf4j
slf4j-simple
-
+
+ org.springframework.boot
+ spring-boot-starter-test
+
+
+ org.springframework.security
+ spring-security-test
+ test
+
diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/OAuthSecurityConfig.java b/backend/src/main/java/org/eclipse/tractusx/semantics/OAuthSecurityConfig.java
index be2cd32c..0b163764 100644
--- a/backend/src/main/java/org/eclipse/tractusx/semantics/OAuthSecurityConfig.java
+++ b/backend/src/main/java/org/eclipse/tractusx/semantics/OAuthSecurityConfig.java
@@ -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();
diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/AspectModelService.java b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/AspectModelService.java
index 628e4d5e..db8fecc6 100644
--- a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/AspectModelService.java
+++ b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/AspectModelService.java
@@ -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;
@@ -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;
@@ -161,6 +163,19 @@ public ResponseEntity getAasSubmodelTemplate(String urn, AasFormat aasFormat) {
return new ResponseEntity( result.get(), responseHeaders, HttpStatus.OK );
}
+ @Override
+ public ResponseEntity getModelListByUrns(Integer pageSize, Integer page, List requestBody) {
+ List 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( models, HttpStatus.OK );
+ }
+
private Aspect getBamAspect( String urn ) {
final Try aspect = bammHelper.getAspectFromVersionedModel( getVersionedModel( urn ) );
if ( aspect.isFailure() ) {
diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/PersistenceLayer.java b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/PersistenceLayer.java
index 12078c7a..f85ae296 100644
--- a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/PersistenceLayer.java
+++ b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/PersistenceLayer.java
@@ -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;
@@ -58,4 +60,6 @@ public interface PersistenceLayer {
void deleteModelsPackage( ModelPackageUrn urn );
boolean echo();
+
+ public SemanticModelList findModelListByUrns(List urns, int page, int pageSize);
}
diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/SparqlQueries.java b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/SparqlQueries.java
index c1869f2b..dbb6c8a7 100644
--- a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/SparqlQueries.java
+++ b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/SparqlQueries.java
@@ -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;
@@ -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"
@@ -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
@@ -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() {
}
@@ -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 urns, int page, int pageSize ) {
+ final ParameterizedSparqlString pss = create( FIND_BY_MULTIPLE_URNS_QUERY );
+
+ List urnList = new ArrayList<>();
+ List 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 urns ) {
+ ParameterizedSparqlString pss = buildMinimalQuery(COUNT_ASPECT_MODELS_MINIMAL_QUERY_SELECTIVE, namespaceFilter, status);
+
+ List urnList = new ArrayList<>();
+ List 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() );
diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java
index e18c87bf..5aa9b9b3 100644
--- a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java
+++ b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java
@@ -172,6 +172,28 @@ public void deleteModelsPackage( final ModelPackageUrn urn ) {
deleteByUrn( urn );
}
+ @Override
+ public SemanticModelList findModelListByUrns(List urns, int page, int pageSize) {
+ final Query query = SparqlQueries.buildFindListByUrns( urns, page, pageSize );
+ final AtomicReference> aspectModels = new AtomicReference<>();
+ try ( final RDFConnection rdfConnection = rdfConnectionRemoteBuilder.build() ) {
+ rdfConnection.queryResultSet( query, resultSet -> {
+ final List querySolutions = ResultSetFormatter.toList( resultSet );
+ aspectModels.set( TripleStorePersistence.aspectModelFrom( querySolutions ) );
+ } );
+ }
+ int totalSemanticModelCount = getSelectiveItemsCount( null, null, null, null, urns );
+ int totalPages = getTotalPages(totalSemanticModelCount, pageSize );
+ SemanticModelList modelList = new SemanticModelList();
+ List semanticModels = aspectModels.get();
+ modelList.setCurrentPage( page );
+ modelList.setItemCount( semanticModels.size() );
+ modelList.setTotalPages( totalPages );
+ modelList.setTotalItems( totalSemanticModelCount );
+ modelList.setItems( aspectModels.get() );
+ return modelList;
+ }
+
public boolean echo() {
final RDFConnection rdfConnection = rdfConnectionRemoteBuilder.build();
@@ -213,6 +235,21 @@ private Integer getTotalItemsCount( @Nullable String namespaceFilter,
}
}
+ private Integer getSelectiveItemsCount( @Nullable String namespaceFilter, @Nullable String nameFilter,
+ @Nullable String nameType,
+ @Nullable ModelPackageStatus status, List urns ) {
+ try ( final RDFConnection rdfConnection = rdfConnectionRemoteBuilder.build() ) {
+ AtomicReference count = new AtomicReference<>();
+ rdfConnection.querySelect(
+ SparqlQueries.buildCountSelectiveAspectModelsQuery( namespaceFilter, nameFilter, nameType, status, urns ),
+ querySolution -> {
+ int countResult = querySolution.getLiteral( "aspectModelCount" ).getInt();
+ count.set( countResult );
+ } );
+ return count.get();
+ }
+ }
+
private void deleteByUrn( final ModelPackageUrn modelsPackage ) {
final UpdateRequest deleteByUrn = SparqlQueries.buildDeleteByUrnRequest( modelsPackage );
try ( final RDFConnection rdfConnection = rdfConnectionRemoteBuilder.build() ) {
diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml
index cabe83f2..9f3e5a1e 100644
--- a/backend/src/main/resources/application.yml
+++ b/backend/src/main/resources/application.yml
@@ -55,6 +55,9 @@ http:
spring:
application:
name: semantics-services
+ mvc:
+ pathmatch:
+ matching-strategy: ant-path-matcher
banner:
location: "classpath:banner.txt"
servlet:
@@ -81,7 +84,7 @@ springdoc:
use-pkce-with-authorization-code-grant: true
# the scopes and client id will be prefilled in the swagger ui
scopes: openid profile
- client-id: catenax-portal
+ client-id: ${hub.general.idm.public-client-id}
title: '@project.name@'
project_desc: '@project.description@'
diff --git a/backend/src/main/resources/static/semantic-hub-openapi.yaml b/backend/src/main/resources/static/semantic-hub-openapi.yaml
index 4741d0ca..aea287c0 100644
--- a/backend/src/main/resources/static/semantic-hub-openapi.yaml
+++ b/backend/src/main/resources/static/semantic-hub-openapi.yaml
@@ -2,6 +2,11 @@ openapi: 3.0.3
info:
title: Semantic Hub
version: v1
+
+security:
+ - OpenIdProfile:
+ - profile
+
servers:
- url: ./api/{api-version}
variables:
@@ -116,6 +121,50 @@ paths:
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
+ /models/lookup:
+ post:
+ tags:
+ - SemanticHub
+ operationId: getModelListByUrns
+ description: This endpoint allows to filter for a specific set of URNs. The endpoint returns the metadata, such as the model status. For URNs that are not in the database there is no entry in the result set. Therefore, a search array with 10 URNs can result in a response containing 9 or less result entries.
+ parameters:
+ - in: query
+ name: pageSize
+ required: true
+ schema:
+ default: 10
+ type: integer
+ enum:
+ - 10
+ - 50
+ - 100
+ description: Size of the pages that the results should be partitioned in
+ - in: query
+ name: page
+ required: true
+ schema:
+ default: 0
+ type: integer
+ description: The page to return
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ type: string
+ responses:
+ '200':
+ $ref: '#/components/responses/SemanticModelList'
+ '400':
+ $ref: '#/components/responses/BadRequest'
+ '401':
+ $ref: '#/components/responses/Unauthorized'
+ '404':
+ $ref: '#/components/responses/NotFound'
+ '500':
+ $ref: '#/components/responses/InternalServerError'
'/models/{urn}':
get:
tags:
@@ -533,4 +582,9 @@ components:
NotFound:
description: Not Found
InternalServerError:
- description: Internal Server Error
\ No newline at end of file
+ description: Internal Server Error
+
+ securitySchemes:
+ OpenIdProfile:
+ type: openIdConnect
+ openIdConnectUrl: ../.well-known/openid-configuration
\ No newline at end of file
diff --git a/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java b/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java
index a2b567b9..db65addb 100644
--- a/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java
+++ b/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java
@@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@@ -36,7 +37,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.jena.atlas.json.JSON;
+import org.apache.poi.hpsf.Array;
+import org.json.JSONArray;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@@ -46,8 +52,11 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
+import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.function.text.Length;
+import jakarta.json.JsonArray;
+
@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_CLASS )
public class ModelsApiTest extends AbstractModelsApiTest{
@@ -400,6 +409,69 @@ public void testDependentModelTransition() throws Exception {
}
}
+ @Test
+ public void testGetModelListByMultipleUrns() throws Exception {
+ String urnPrefixPattern = "urn:bamm:org.eclipse.tractusx.test_model_list_by_urns_%s:1.0.0#";
+
+ List urnSearchArrayEvenNumbers = new ArrayList();
+ List urnSearchArrayOddNumbers = new ArrayList();
+ List urnSearchArrayNonExistingEntry = new ArrayList();
+
+ for(int i = 1; i <= 11; i++) {
+ String urnPrefix = String.format(urnPrefixPattern, i);
+ mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"DRAFT") )
+ .andDo( MockMvcResultHandlers.print() )
+ .andExpect( status().isOk() );
+
+ if((i % 2) == 0) {
+ urnSearchArrayEvenNumbers.add(toMovementUrn(urnPrefix));
+ } else {
+ urnSearchArrayOddNumbers.add(toMovementUrn(urnPrefix));
+ }
+ }
+
+ urnSearchArrayNonExistingEntry.add("urn:bamm:org.eclipse.tractusx.test_model_list_by_urns_50:1.0.0#Movement");
+
+ mvc.perform(MockMvcRequestBuilders.post("/api/v1/models/lookup" )
+ .param("pageSize", "2")
+ .param("page", "0")
+ .content(new JSONArray(urnSearchArrayEvenNumbers).toString())
+ .contentType(MediaType.APPLICATION_JSON)
+ .with(jwtTokenFactory.allRoles()))
+ .andDo( MockMvcResultHandlers.print() )
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.currentPage", equalTo(0)))
+ .andExpect(jsonPath("$.totalItems", equalTo(5)))
+ .andExpect(jsonPath("$.totalPages", equalTo(3)))
+ .andExpect(jsonPath("$.items[0].urn", equalTo("urn:bamm:org.eclipse.tractusx.test_model_list_by_urns_10:1.0.0#Movement")))
+ .andExpect(jsonPath("$.items[1].urn", equalTo("urn:bamm:org.eclipse.tractusx.test_model_list_by_urns_2:1.0.0#Movement")))
+ .andExpect(jsonPath("$.items.length()", equalTo(2)));
+
+ mvc.perform(MockMvcRequestBuilders.post("/api/v1/models/lookup")
+ .param("pageSize", "2")
+ .param("page", "1")
+ .content(new JSONArray(urnSearchArrayOddNumbers).toString())
+ .contentType(MediaType.APPLICATION_JSON)
+ .with(jwtTokenFactory.allRoles()))
+ .andDo( MockMvcResultHandlers.print() )
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.currentPage", equalTo(1)))
+ .andExpect(jsonPath("$.totalItems", equalTo(6)))
+ .andExpect(jsonPath("$.totalPages", equalTo(3)))
+ .andExpect(jsonPath("$.items[0].urn", equalTo("urn:bamm:org.eclipse.tractusx.test_model_list_by_urns_3:1.0.0#Movement")))
+ .andExpect(jsonPath("$.items[1].urn", equalTo("urn:bamm:org.eclipse.tractusx.test_model_list_by_urns_5:1.0.0#Movement")))
+ .andExpect(jsonPath("$.items.length()", equalTo(2)));
+
+ mvc.perform(MockMvcRequestBuilders.post("/api/v1/models/lookup")
+ .content(new JSONArray(urnSearchArrayNonExistingEntry).toString())
+ .contentType(MediaType.APPLICATION_JSON)
+ .with(jwtTokenFactory.allRoles()))
+ .andDo( MockMvcResultHandlers.print() )
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.items.length()", equalTo(0)));
+
+ }
+
private static String toMovementUrn(String urn){
return urn + "Movement";
}
diff --git a/pom.xml b/pom.xml
index 458a7193..08d22820 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,13 +25,13 @@
org.springframework.boot
spring-boot-starter-parent
- 2.5.14
+ 2.7.3
org.eclipse.tractusx
semantic-hub
- 0.1.0-M1
+ 0.1.0-M2
Tractus-X Semantic Hub
Root Module of the Tractus-X Semantic Hub
pom
@@ -65,9 +65,7 @@
- 2.5.14
- 2020.0.3
- 5.3.20
+ 2.7.3
3.1.3
1.6.6
2.9.2
@@ -80,26 +78,16 @@
0.10.3
2.11.0
3.0.2
+ 1.31
1.7.32
1.2.11
-
- 4.5.13
- 11.7
- 2.1.0
- 4.0.3
- 0.0.1-SNAPSHOT
- 4.0.1
-
2.13.1
20211205
-
- 1.0.2
-
2.0.0
4.2.0
@@ -108,10 +96,6 @@
1.4.2.Final
0.2.0
- 42.2.25
- 2.1.210
- 4.9.1
-
3.18.1
5.6.3
@@ -154,24 +138,12 @@
commons-io
${commons-io.version}
-
- javax.servlet
- javax.servlet-api
- ${javax.servlet}
-
com.google.code.findbugs
jsr305
${google.findbugs.version}
-
- org.springframework.cloud
- spring-cloud-dependencies
- ${spring.cloud.version}
- pom
- import
-
org.springframework.boot
spring-boot-starter-web
@@ -187,6 +159,23 @@
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+ ${spring.boot.version}
+
+
+ org.yaml
+ snakeyaml
+
+
+
+
+ org.yaml
+ snakeyaml
+ ${snakeyaml.version}
+
org.springframework.boot
spring-boot-starter-test
@@ -213,22 +202,6 @@
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
- ${spring.feign.version}
-
-
- org.springframework.cloud
- spring-cloud-openfeign-core
- ${spring.feign.version}
-
-
- org.springframework
- spring-test
- ${spring.version}
- test
-
org.springframework.boot
spring-boot-starter-data-jpa
@@ -240,12 +213,6 @@
-
- org.springframework
- spring-webmvc
- ${spring.version}
-
-
org.springdoc
@@ -257,12 +224,6 @@
springfox-swagger2
${springfox.version}
-
- io.springfox
- springfox-swagger-ui
- ${springfox.version}
- runtime
-
@@ -280,31 +241,6 @@
jackson-databind-nullable
0.1.0
-
- io.github.openfeign
- feign-core
- ${feign-version}
-
-
- io.github.openfeign
- feign-jackson
- ${feign-version}
-
-
- io.github.openfeign
- feign-slf4j
- ${feign-version}
-
-
- io.github.openfeign.form
- feign-form
- ${feign-form-version}
-
-
- org.apache.httpcomponents
- httpclient
- ${httpcomponents.version}
-
@@ -313,36 +249,12 @@
${jackson.version}
-
-
- org.apache.oltu.oauth2
- org.apache.oltu.oauth2.client
- ${oltu-version}
-
-
org.mapstruct
mapstruct
${mapstruct.version}
-
- org.liquibase
- liquibase-core
- ${liquibase.version}
-
-
-
-
- org.postgresql
- postgresql
- ${postgresql.version}
-
-
- com.h2database
- h2
- ${h2.version}
-