Skip to content

Commit 471d45f

Browse files
FriedJannikaaronzi
andauthored
Adapts Discovery Integration Feature (#736)
* Fixes possible NPE in DiscoveryIntegration * Update AuthorizedAasRepositoryDiscoveryIntegrationTest.java * Adds missing Test * Update DiscoveryIntegrationAasRepository.java * Update DiscoveryIntegrationAasRepository.java --------- Co-authored-by: Aaron Zielstorff <aaron.zi@web.de>
1 parent 98d8a33 commit 471d45f

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

basyx.aasrepository/basyx.aasrepository-feature-discovery-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/discoveryintegration/DiscoveryIntegrationAasRepository.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class DiscoveryIntegrationAasRepository implements AasRepository {
5858
private AasRepository decorated;
5959

6060
private final AasDiscoveryService discoveryApi;
61-
61+
6262
public DiscoveryIntegrationAasRepository(AasRepository decorated, AasDiscoveryService discoveryApi) {
6363
this.decorated = decorated;
6464
this.discoveryApi = discoveryApi;
@@ -94,6 +94,7 @@ public void deleteAas(String shellId) {
9494
try {
9595
discoveryApi.deleteAllAssetLinksById(shellId);
9696
} catch (Exception e){
97+
logger.error("Failed to unlink asset in discovery service for AAS ID {}", shellId, e);
9798
throw new RepositoryDiscoveryUnlinkException(shellId, e);
9899
}
99100
}
@@ -162,30 +163,52 @@ private void updateAssetLinks(String shellId, AssetAdministrationShell shell) {
162163
}
163164

164165
private static DefaultSpecificAssetId getGlobalAssetIdAsSpecificAssetId(AssetAdministrationShell shell) {
165-
return new DefaultSpecificAssetId.Builder().name("globalAssetId").value(shell.getAssetInformation().getGlobalAssetId()).build();
166+
if (shell.getAssetInformation() == null || shell.getAssetInformation().getGlobalAssetId() == null)
167+
throw new IllegalArgumentException("AssetInformation or GlobalAssetId is null");
168+
169+
return new DefaultSpecificAssetId.Builder()
170+
.name("globalAssetId")
171+
.value(shell.getAssetInformation().getGlobalAssetId())
172+
.build();
166173
}
167174

168175
private void createAssetLinksOnDiscoveryServiceIfNecessary(AssetAdministrationShell shell) {
169-
List<SpecificAssetId> linksToAdd = new ArrayList<>(shell.getAssetInformation().getSpecificAssetIds());
170-
if(shell.getAssetInformation().getGlobalAssetId() != null){
176+
if (shell.getAssetInformation() == null) return;
177+
178+
List<SpecificAssetId> linksToAdd;
179+
if (shell.getAssetInformation().getSpecificAssetIds() != null) {
180+
linksToAdd = new ArrayList<>(shell.getAssetInformation().getSpecificAssetIds());
181+
} else {
182+
linksToAdd = new ArrayList<>();
183+
}
184+
185+
if (shell.getAssetInformation().getGlobalAssetId() != null) {
171186
linksToAdd.add(getGlobalAssetIdAsSpecificAssetId(shell));
172187
}
173-
if(!linksToAdd.isEmpty()){
188+
189+
if(!linksToAdd.isEmpty()) {
174190
try {
175191
discoveryApi.createAllAssetLinksById(shell.getId(), linksToAdd);
176192
} catch (Exception e) {
177193
decorated.deleteAas(shell.getId());
194+
logger.error("Failed to link asset in discovery service for AAS ID {}", shell.getId(), e);
178195
throw new RepositoryDiscoveryLinkException(shell.getId(), e);
179196
}
180197
}
181198
}
182199

183200
private static boolean specificAssetIdsUpdated(AssetAdministrationShell shell, AssetAdministrationShell oldShell) {
184-
return !(oldShell.getAssetInformation().getSpecificAssetIds() != null && oldShell.getAssetInformation().getSpecificAssetIds().equals(shell.getAssetInformation().getSpecificAssetIds()));
201+
return !(oldShell.getAssetInformation() != null &&
202+
oldShell.getAssetInformation().getSpecificAssetIds() != null &&
203+
oldShell.getAssetInformation().getSpecificAssetIds().equals(
204+
shell.getAssetInformation().getSpecificAssetIds()));
185205
}
186206

187207
private static boolean isGlobalAssetIdUpdated(AssetAdministrationShell shell, AssetAdministrationShell oldShell) {
188-
return !(oldShell.getAssetInformation().getGlobalAssetId() != null && oldShell.getAssetInformation().getGlobalAssetId().equals(shell.getAssetInformation().getGlobalAssetId()));
208+
return !(oldShell.getAssetInformation() != null &&
209+
oldShell.getAssetInformation().getGlobalAssetId() != null &&
210+
oldShell.getAssetInformation().getGlobalAssetId().equals(
211+
shell.getAssetInformation().getGlobalAssetId()));
189212
}
190213

191214
}

basyx.aasrepository/basyx.aasrepository-feature-discovery-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/discoveryintegration/AasRepositoryDiscoveryIntegrationTestSuite.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ public void updateAAS_withGlobalAndSpecificAssetId() {
114114
}
115115
}
116116

117+
@Test
118+
public void updateAAS_withoutChange() {
119+
executeCreateTestWithProperties(true, false);
120+
executeUpdateTestWithProperties(true, false);
121+
assertOnlyGlobalAssetIdIsSet(getDemoAAS(true,false));
122+
}
123+
117124
@Test
118125
public void updateAAS() throws IOException {
119126
AssetAdministrationShell aas = getDemoAAS(true, true);
@@ -213,6 +220,13 @@ private void assertNewAssetLinksAreSet(AssetAdministrationShell aas) {
213220
assertEquals("test-specific-asset-id-value-2", assetIds.get(1).getValue());
214221
}
215222

223+
private void assertOnlyGlobalAssetIdIsSet(AssetAdministrationShell aas) {
224+
List<SpecificAssetId> assetIds = getDiscoveryService().getAllAssetLinksById(aas.getId());
225+
assertEquals(1, assetIds.size());
226+
assertEquals("globalAssetId", assetIds.get(0).getName());
227+
assertEquals("test-global-asset-id", assetIds.get(0).getValue());
228+
}
229+
216230
private static void addAssetIdToAAS(AssetAdministrationShell aas) {
217231
AssetInformation info = aas.getAssetInformation();
218232
List<SpecificAssetId> assetIds = info.getSpecificAssetIds();

0 commit comments

Comments
 (0)