Skip to content

Commit 5851a23

Browse files
authored
Fixes a error in the assetIds Query Parameter of the /shells endpoint (#771)
* Fixes /shells Endpoint Query Param * Intermediate commit * Fixes InMemory Implementation of filtering * Fixes InMemory Implementation of filtering
1 parent 3ad16cc commit 5851a23

5 files changed

Lines changed: 56 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ local.properties
9090
/.env
9191

9292
**.iml
93+
94+
.DS_Store

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.apache.hc.core5.http.ProtocolException;
4444
import org.apache.hc.core5.http.io.entity.EntityUtils;
4545
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.DeserializationException;
46-
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell;
4746
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;
4847
import org.eclipse.digitaltwin.basyx.http.HttpBaSyxHeader;
4948
import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor;
@@ -192,6 +191,26 @@ public void getAllAasWithIdShort() throws IOException, ParseException {
192191
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
193192
}
194193

194+
@Test
195+
public void getAllAasWithMultipleDifferentGlobalAssetIds() throws IOException, ParseException {
196+
createMultipleAasOnServer();
197+
CloseableHttpResponse retrievalResponse = getAllAasMultipleDifferentGlobalAssetIdsParam();
198+
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
199+
200+
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
201+
BaSyxHttpTestUtils.assertSameJSONContent(getEmptyResultJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
202+
}
203+
204+
@Test
205+
public void getAllAasWithMultipleIdenticalGlobalAssetIds() throws IOException, ParseException {
206+
createMultipleAasOnServer();
207+
CloseableHttpResponse retrievalResponse = getAllAasMultipleIdenticalGlobalAssetIdsParam();
208+
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
209+
210+
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
211+
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
212+
}
213+
195214
@Test
196215
public void deleteAas() throws IOException {
197216
createDummyAasOnServer(getAas1JSONString());
@@ -423,6 +442,10 @@ public void deleteNonExistingThumbnail() throws FileNotFoundException, Unsupport
423442
private String getPaginatedAas1JSONString() throws FileNotFoundException, IOException {
424443
return BaSyxHttpTestUtils.readJSONStringFromClasspath("PaginatedAasSimple_1.json");
425444
}
445+
446+
private String getEmptyResultJSONString() throws FileNotFoundException, IOException {
447+
return BaSyxHttpTestUtils.readJSONStringFromClasspath("EmptyResponse.json");
448+
}
426449

427450
private String getJSONWithoutCursorInfo(String response) throws JsonMappingException, JsonProcessingException {
428451
return BaSyxHttpTestUtils.removeCursorFromJSON(response);
@@ -489,6 +512,14 @@ protected CloseableHttpResponse getAllAasGlobalAssetIdsParam() throws IOExceptio
489512
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9");
490513
}
491514

515+
protected CloseableHttpResponse getAllAasMultipleDifferentGlobalAssetIdsParam() throws IOException {
516+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6ImR1bW15QWFzQXNzZXRJZCINCn0");
517+
}
518+
519+
protected CloseableHttpResponse getAllAasMultipleIdenticalGlobalAssetIdsParam() throws IOException {
520+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9");
521+
}
522+
492523
protected CloseableHttpResponse getAllAasIdShortParam() throws IOException {
493524
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?idShort=ExampleMotor");
494525
}
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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3636
import org.springframework.stereotype.Component;
3737

38+
import java.util.ArrayList;
3839
import java.util.List;
3940
import java.util.Optional;
4041
import java.util.TreeMap;
@@ -115,9 +116,9 @@ public AssetInformation getAssetInformation(String aasId) {
115116
public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetIds, String idShort) {
116117
Iterable<AssetAdministrationShell> allAas = findAll();
117118
List<AssetAdministrationShell> filteredAas = new java.util.ArrayList<>();
118-
String globalAssetId = null;
119+
List<SpecificAssetId> globalAssetIds = new ArrayList<>();
119120
try {
120-
globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue();
121+
globalAssetIds = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).toList();
121122
assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList());
122123
} catch (Exception e) {}
123124
for (AssetAdministrationShell aas : allAas){
@@ -129,7 +130,15 @@ public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetI
129130
matchesAssetIds = false;
130131
}
131132
boolean matchesIdShort = (idShort == null || aas.getIdShort().equals(idShort));
132-
boolean matchesGlobalAssetId = (globalAssetId == null || (aas.getAssetInformation() != null && aas.getAssetInformation().getGlobalAssetId() != null && aas.getAssetInformation().getGlobalAssetId().equals(globalAssetId)));
133+
boolean matchesGlobalAssetId = globalAssetIds.isEmpty();
134+
for (SpecificAssetId globalAssetId : globalAssetIds){
135+
String id = globalAssetId.getValue();
136+
if (aas.getAssetInformation() == null || aas.getAssetInformation().getGlobalAssetId() == null || !aas.getAssetInformation().getGlobalAssetId().equals(id)) {
137+
matchesGlobalAssetId = false;
138+
break;
139+
}
140+
matchesGlobalAssetId = true;
141+
}
133142
if (matchesAssetIds && matchesIdShort && matchesGlobalAssetId) {
134143
filteredAas.add(aas);
135144
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,11 @@ private List<Criteria> buildAasFilterCriteria(List<SpecificAssetId> assetIds, St
240240
List<Criteria> criteriaList = new ArrayList<>();
241241

242242
// Extract globalAssetId from assetIds
243-
String globalAssetId = null;
243+
List<SpecificAssetId> globalAssetIds = new ArrayList<>();
244244
try {
245-
globalAssetId = assetIds.stream()
245+
globalAssetIds = assetIds.stream()
246246
.filter(assetId -> "globalAssetId".equals(assetId.getName()))
247-
.findFirst()
248-
.map(SpecificAssetId::getValue)
249-
.orElse(null);
247+
.toList();
250248

251249
assetIds = assetIds.stream()
252250
.filter(assetId -> !"globalAssetId".equals(assetId.getName()))
@@ -267,8 +265,8 @@ private List<Criteria> buildAasFilterCriteria(List<SpecificAssetId> assetIds, St
267265
}
268266

269267
// Match globalAssetId if present
270-
if (globalAssetId != null && !globalAssetId.isEmpty()) {
271-
criteriaList.add(Criteria.where("assetInformation.globalAssetId").is(globalAssetId));
268+
for (SpecificAssetId globalAssetId : globalAssetIds) {
269+
criteriaList.add(Criteria.where("assetInformation.globalAssetId").is(globalAssetId.getValue()));
272270
}
273271

274272
return criteriaList;

0 commit comments

Comments
 (0)