Skip to content

Commit 8395bc0

Browse files
committed
Fixes InMemory Implementation of filtering
1 parent 8d64fd8 commit 8395bc0

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

  • basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http
  • basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend

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

Lines changed: 17 additions & 4 deletions
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;
@@ -193,15 +192,25 @@ public void getAllAasWithIdShort() throws IOException, ParseException {
193192
}
194193

195194
@Test
196-
public void getAllAasWithMultipleAssetIds() throws IOException, ParseException {
195+
public void getAllAasWithMultipleDifferentGlobalAssetIds() throws IOException, ParseException {
197196
createMultipleAasOnServer();
198-
CloseableHttpResponse retrievalResponse = getAllAasMultipleGlobalAssetIdsParam();
197+
CloseableHttpResponse retrievalResponse = getAllAasMultipleDifferentGlobalAssetIdsParam();
199198
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
200199

201200
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
202201
BaSyxHttpTestUtils.assertSameJSONContent(getEmptyResultJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
203202
}
204203

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+
205214
@Test
206215
public void deleteAas() throws IOException {
207216
createDummyAasOnServer(getAas1JSONString());
@@ -503,10 +512,14 @@ protected CloseableHttpResponse getAllAasGlobalAssetIdsParam() throws IOExceptio
503512
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9");
504513
}
505514

506-
protected CloseableHttpResponse getAllAasMultipleGlobalAssetIdsParam() throws IOException {
515+
protected CloseableHttpResponse getAllAasMultipleDifferentGlobalAssetIdsParam() throws IOException {
507516
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6ImR1bW15QWFzQXNzZXRJZCINCn0");
508517
}
509518

519+
protected CloseableHttpResponse getAllAasMultipleIdenticalGlobalAssetIdsParam() throws IOException {
520+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9&assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9");
521+
}
522+
510523
protected CloseableHttpResponse getAllAasIdShortParam() throws IOException {
511524
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?idShort=ExampleMotor");
512525
}

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

Lines changed: 13 additions & 6 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,12 +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-
if(assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).count() > 1){
121-
return filteredAas;
122-
}
123-
globalAssetId = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).findFirst().get().getValue();
121+
globalAssetIds = assetIds.stream().filter(assetId -> assetId.getName().equals("globalAssetId")).toList();
124122
assetIds = assetIds.stream().filter(assetId -> !assetId.getName().equals("globalAssetId")).collect(Collectors.toList());
125123
} catch (Exception e) {}
126124
for (AssetAdministrationShell aas : allAas){
@@ -132,7 +130,16 @@ public Iterable<AssetAdministrationShell> getAllAas(List<SpecificAssetId> assetI
132130
matchesAssetIds = false;
133131
}
134132
boolean matchesIdShort = (idShort == null || aas.getIdShort().equals(idShort));
135-
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().getGlobalAssetId().equals(id)){
137+
matchesGlobalAssetId = true;
138+
} else {
139+
matchesGlobalAssetId = false;
140+
break;
141+
}
142+
}
136143
if (matchesAssetIds && matchesIdShort && matchesGlobalAssetId) {
137144
filteredAas.add(aas);
138145
}

0 commit comments

Comments
 (0)