diff --git a/.gitignore b/.gitignore index ecadeccfa..b2ea72595 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,5 @@ local.properties /.env **.iml + +.DS_Store diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java b/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java index 9b589f488..1114eb0e0 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java @@ -43,7 +43,6 @@ import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.DeserializationException; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.HttpBaSyxHeader; import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor; @@ -192,6 +191,26 @@ public void getAllAasWithIdShort() throws IOException, ParseException { BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer)); } + @Test + public void getAllAasWithMultipleDifferentGlobalAssetIds() throws IOException, ParseException { + createMultipleAasOnServer(); + CloseableHttpResponse retrievalResponse = getAllAasMultipleDifferentGlobalAssetIdsParam(); + assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); + + String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse); + BaSyxHttpTestUtils.assertSameJSONContent(getEmptyResultJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer)); + } + + @Test + public void getAllAasWithMultipleIdenticalGlobalAssetIds() throws IOException, ParseException { + createMultipleAasOnServer(); + CloseableHttpResponse retrievalResponse = getAllAasMultipleIdenticalGlobalAssetIdsParam(); + assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); + + String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse); + BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer)); + } + @Test public void deleteAas() throws IOException { createDummyAasOnServer(getAas1JSONString()); @@ -423,6 +442,10 @@ public void deleteNonExistingThumbnail() throws FileNotFoundException, Unsupport private String getPaginatedAas1JSONString() throws FileNotFoundException, IOException { return BaSyxHttpTestUtils.readJSONStringFromClasspath("PaginatedAasSimple_1.json"); } + + private String getEmptyResultJSONString() throws FileNotFoundException, IOException { + return BaSyxHttpTestUtils.readJSONStringFromClasspath("EmptyResponse.json"); + } private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException { return BaSyxHttpTestUtils.removeCursorFromJSON(response); @@ -489,6 +512,14 @@ protected CloseableHttpResponse getAllAasGlobalAssetIdsParam() throws IOExceptio return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9"); } + protected CloseableHttpResponse getAllAasMultipleDifferentGlobalAssetIdsParam() throws IOException { + return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6ImR1bW15QWFzQXNzZXRJZCINCn0"); + } + + protected CloseableHttpResponse getAllAasMultipleIdenticalGlobalAssetIdsParam() throws IOException { + return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9"); + } + protected CloseableHttpResponse getAllAasIdShortParam() throws IOException { return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?idShort=ExampleMotor"); } diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/EmptyResponse.json b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/EmptyResponse.json new file mode 100644 index 000000000..309ebab7e --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/EmptyResponse.json @@ -0,0 +1,5 @@ +{ + "paging_metadata": {}, + "result": [ + ] +} \ No newline at end of file diff --git a/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasBackend.java b/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasBackend.java index 44297394a..3f88f07f3 100644 --- a/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasBackend.java +++ b/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasBackend.java @@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.TreeMap; @@ -115,9 +116,9 @@ public AssetInformation getAssetInformation(String aasId) { public Iterable getAllAas(List assetIds, String idShort) { Iterable allAas = findAll(); List filteredAas = new java.util.ArrayList<>(); - String globalAssetId = null; + List globalAssetIds = new ArrayList<>(); try { - globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue(); + globalAssetIds = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).toList(); assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList()); } catch (Exception e) {} for (AssetAdministrationShell aas : allAas){ @@ -129,7 +130,15 @@ public Iterable getAllAas(List assetI matchesAssetIds = false; } boolean matchesIdShort = (idShort == null || aas.getIdShort().equals(idShort)); - boolean matchesGlobalAssetId = (globalAssetId == null || (aas.getAssetInformation() != null && aas.getAssetInformation().getGlobalAssetId() != null && aas.getAssetInformation().getGlobalAssetId().equals(globalAssetId))); + boolean matchesGlobalAssetId = globalAssetIds.isEmpty(); + for (SpecificAssetId globalAssetId : globalAssetIds){ + String id = globalAssetId.getValue(); + if (aas.getAssetInformation() == null || aas.getAssetInformation().getGlobalAssetId() == null || !aas.getAssetInformation().getGlobalAssetId().equals(id)) { + matchesGlobalAssetId = false; + break; + } + matchesGlobalAssetId = true; + } if (matchesAssetIds && matchesIdShort && matchesGlobalAssetId) { filteredAas.add(aas); } diff --git a/basyx.aasservice/basyx.aasservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/MongoDBAasOperations.java b/basyx.aasservice/basyx.aasservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/MongoDBAasOperations.java index 3fd254845..47b6ef440 100644 --- a/basyx.aasservice/basyx.aasservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/MongoDBAasOperations.java +++ b/basyx.aasservice/basyx.aasservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/MongoDBAasOperations.java @@ -240,13 +240,11 @@ private List buildAasFilterCriteria(List assetIds, St List criteriaList = new ArrayList<>(); // Extract globalAssetId from assetIds - String globalAssetId = null; + List globalAssetIds = new ArrayList<>(); try { - globalAssetId = assetIds.stream() + globalAssetIds = assetIds.stream() .filter(assetId -> "globalAssetId".equals(assetId.getName())) - .findFirst() - .map(SpecificAssetId::getValue) - .orElse(null); + .toList(); assetIds = assetIds.stream() .filter(assetId -> !"globalAssetId".equals(assetId.getName())) @@ -267,8 +265,8 @@ private List buildAasFilterCriteria(List assetIds, St } // Match globalAssetId if present - if (globalAssetId != null && !globalAssetId.isEmpty()) { - criteriaList.add(Criteria.where("assetInformation.globalAssetId").is(globalAssetId)); + for (SpecificAssetId globalAssetId : globalAssetIds) { + criteriaList.add(Criteria.where("assetInformation.globalAssetId").is(globalAssetId.getValue())); } return criteriaList;