From 4d970ce57231ac75e21000b0b8ba79d48d32026f Mon Sep 17 00:00:00 2001 From: fried Date: Thu, 12 Jun 2025 09:15:13 +0200 Subject: [PATCH] Fixes /shells Endpoint Query Param --- .../http/AasRepositoryHTTPSuite.java | 18 ++++++++++++++++++ .../src/test/resources/EmptyResponse.json | 5 +++++ .../aasservice/backend/InMemoryAasBackend.java | 3 +++ .../backend/MongoDBAasOperations.java | 14 ++++++-------- 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-http/src/test/resources/EmptyResponse.json 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..bd0f063f0 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 @@ -192,6 +192,16 @@ public void getAllAasWithIdShort() throws IOException, ParseException { BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer)); } + @Test + public void getAllAasWithMultipleAssetIds() throws IOException, ParseException { + createMultipleAasOnServer(); + CloseableHttpResponse retrievalResponse = getAllAasMultipleGlobalAssetIdsParam(); + assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); + + String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse); + BaSyxHttpTestUtils.assertSameJSONContent(getEmptyResultJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer)); + } + @Test public void deleteAas() throws IOException { createDummyAasOnServer(getAas1JSONString()); @@ -423,6 +433,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 +503,10 @@ protected CloseableHttpResponse getAllAasGlobalAssetIdsParam() throws IOExceptio return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9"); } + protected CloseableHttpResponse getAllAasMultipleGlobalAssetIdsParam() throws IOException { + return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6ImR1bW15QWFzQXNzZXRJZCINCn0"); + } + 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 69d17998f..f3eac586d 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 @@ -104,6 +104,9 @@ public Iterable getAllAas(List assetI List filteredAas = new java.util.ArrayList<>(); String globalAssetId = null; try { + if(assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1){ + return filteredAas; + } globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue(); assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList()); } catch (Exception e) {} 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 8b8286458..a92a1ec91 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 @@ -176,12 +176,10 @@ public Iterable getAllAas(List assetI Query query = new Query(); Criteria criteria = new Criteria(); - String globalAssetId = null; - try { - globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue(); - assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList()); - } catch (Exception ignored) {} - + List globalAssetId = assetIds.stream() + .filter(assetId -> "globalAssetId".equals(assetId.getName())) + .map(SpecificAssetId::getValue) + .collect(Collectors.toList()); if (assetIds != null && !assetIds.isEmpty()) { List assetIdCriteria = new ArrayList<>(); for (SpecificAssetId assetId : assetIds) { @@ -195,8 +193,8 @@ public Iterable getAllAas(List assetI } query.addCriteria(criteria); - if (globalAssetId != null && !globalAssetId.isEmpty()) { - query.addCriteria(Criteria.where("assetInformation.globalAssetId").is(globalAssetId)); + for (String id : globalAssetId) { + query.addCriteria(Criteria.where("assetInformation.globalAssetId").is(id)); } return mongoOperations.find(query, AssetAdministrationShell.class, collectionName);