Skip to content

Commit 4d970ce

Browse files
committed
Fixes /shells Endpoint Query Param
1 parent 376e3f6 commit 4d970ce

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ public void getAllAasWithIdShort() throws IOException, ParseException {
192192
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
193193
}
194194

195+
@Test
196+
public void getAllAasWithMultipleAssetIds() throws IOException, ParseException {
197+
createMultipleAasOnServer();
198+
CloseableHttpResponse retrievalResponse = getAllAasMultipleGlobalAssetIdsParam();
199+
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
200+
201+
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
202+
BaSyxHttpTestUtils.assertSameJSONContent(getEmptyResultJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
203+
}
204+
195205
@Test
196206
public void deleteAas() throws IOException {
197207
createDummyAasOnServer(getAas1JSONString());
@@ -423,6 +433,10 @@ public void deleteNonExistingThumbnail() throws FileNotFoundException, Unsupport
423433
private String getPaginatedAas1JSONString() throws FileNotFoundException, IOException {
424434
return BaSyxHttpTestUtils.readJSONStringFromClasspath("PaginatedAasSimple_1.json");
425435
}
436+
437+
private String getEmptyResultJSONString() throws FileNotFoundException, IOException {
438+
return BaSyxHttpTestUtils.readJSONStringFromClasspath("EmptyResponse.json");
439+
}
426440

427441
private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException {
428442
return BaSyxHttpTestUtils.removeCursorFromJSON(response);
@@ -489,6 +503,10 @@ protected CloseableHttpResponse getAllAasGlobalAssetIdsParam() throws IOExceptio
489503
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9");
490504
}
491505

506+
protected CloseableHttpResponse getAllAasMultipleGlobalAssetIdsParam() throws IOException {
507+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6ImR1bW15QWFzQXNzZXRJZCINCn0");
508+
}
509+
492510
protected CloseableHttpResponse getAllAasIdShortParam() throws IOException {
493511
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?idShort=ExampleMotor");
494512
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"paging_metadata": {},
3+
"result": [
4+
]
5+
}

basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasBackend.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetI
104104
List<AssetAdministrationShell> filteredAas = new java.util.ArrayList<>();
105105
String globalAssetId = null;
106106
try {
107+
if(assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1){
108+
return filteredAas;
109+
}
107110
globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue();
108111
assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList());
109112
} catch (Exception e) {}

basyx.aasservice/basyx.aasservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/MongoDBAasOperations.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,10 @@ public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetI
176176
Query query = new Query();
177177
Criteria criteria = new Criteria();
178178

179-
String globalAssetId = null;
180-
try {
181-
globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue();
182-
assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList());
183-
} catch (Exception ignored) {}
184-
179+
List<String> globalAssetId = assetIds.stream()
180+
.filter(assetId -> "globalAssetId".equals(assetId.getName()))
181+
.map(SpecificAssetId::getValue)
182+
.collect(Collectors.toList());
185183
if (assetIds != null && !assetIds.isEmpty()) {
186184
List<Criteria> assetIdCriteria = new ArrayList<>();
187185
for (SpecificAssetId assetId : assetIds) {
@@ -195,8 +193,8 @@ public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetI
195193
}
196194
query.addCriteria(criteria);
197195

198-
if (globalAssetId != null && !globalAssetId.isEmpty()) {
199-
query.addCriteria(Criteria.where("assetInformation.globalAssetId").is(globalAssetId));
196+
for (String id : globalAssetId) {
197+
query.addCriteria(Criteria.where("assetInformation.globalAssetId").is(id));
200198
}
201199

202200
return mongoOperations.find(query, AssetAdministrationShell.class, collectionName);

0 commit comments

Comments
 (0)