Skip to content

Commit 93a4f69

Browse files
FaheemBhattifaheem
andauthored
fix(registry): prevent NullPointerException when specificAssetIds is null in DiscoveryIntegrationAasRegistry (#887)
Co-authored-by: faheem <[email protected]>
1 parent dd57b97 commit 93a4f69

File tree

1 file changed

+32
-12
lines changed
  • basyx.aasregistry/basyx.aasregistry-feature-discovery-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/discovery/integration

1 file changed

+32
-12
lines changed

basyx.aasregistry/basyx.aasregistry-feature-discovery-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/discovery/integration/DiscoveryIntegrationAasRegistry.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,49 @@ public AssetAdministrationShellDescriptor getAasDescriptor(@NonNull String aasDe
7070
}
7171

7272
@Override
73-
public void insertAasDescriptor(AssetAdministrationShellDescriptor descr) throws AasDescriptorAlreadyExistsException {
73+
public void insertAasDescriptor(AssetAdministrationShellDescriptor descr)
74+
throws AasDescriptorAlreadyExistsException {
7475
decorated.insertAasDescriptor(descr);
75-
@Valid List<org.eclipse.digitaltwin.basyx.aasregistry.model.@Valid SpecificAssetId> ids = descr.getSpecificAssetIds();
76-
List<SpecificAssetId> specificAssetIds = ids.stream()
77-
.map(rId -> {
78-
SpecificAssetId assetId = new DefaultSpecificAssetId();
79-
assetId.setName(rId.getName());
80-
assetId.setValue(rId.getValue());
81-
return assetId;
82-
}).collect(Collectors.toList());
76+
77+
List<org.eclipse.digitaltwin.basyx.aasregistry.model.SpecificAssetId> ids = descr.getSpecificAssetIds();
78+
if (ids == null || ids.isEmpty()) {
79+
log.debug("No specificAssetIds present for AAS '{}', skipping discovery integration", descr.getId());
80+
return;
81+
}
82+
83+
List<SpecificAssetId> specificAssetIds = ids.stream()
84+
.map(rId -> {
85+
SpecificAssetId assetId = new DefaultSpecificAssetId();
86+
assetId.setName(rId.getName());
87+
assetId.setValue(rId.getValue());
88+
return assetId;
89+
}).collect(Collectors.toList());
90+
8391
discoveryApi.createAllAssetLinksById(descr.getId(), specificAssetIds);
8492
}
8593

8694
@Override
87-
public void replaceAasDescriptor(@NonNull String aasDescriptorId, @NonNull AssetAdministrationShellDescriptor descriptor) throws AasDescriptorNotFoundException {
95+
public void replaceAasDescriptor(@NonNull String aasDescriptorId,
96+
@NonNull AssetAdministrationShellDescriptor descriptor)
97+
throws AasDescriptorNotFoundException {
8898
decorated.replaceAasDescriptor(aasDescriptorId, descriptor);
89-
List<SpecificAssetId> specificAssetIds = descriptor.getSpecificAssetIds().stream()
99+
100+
List<org.eclipse.digitaltwin.basyx.aasregistry.model.SpecificAssetId> ids = descriptor.getSpecificAssetIds();
101+
102+
if (ids == null || ids.isEmpty()) {
103+
log.debug("No specificAssetIds present for AAS '{}', skipping discovery integration update", aasDescriptorId);
104+
discoveryApi.deleteAllAssetLinksById(aasDescriptorId);
105+
return;
106+
}
107+
108+
List<SpecificAssetId> specificAssetIds = ids.stream()
90109
.map(rId -> {
91110
SpecificAssetId assetId = new DefaultSpecificAssetId();
92111
assetId.setName(rId.getName());
93112
assetId.setValue(rId.getValue());
94113
return assetId;
95-
}).collect(Collectors.toList());
114+
})
115+
.collect(Collectors.toList());
96116

97117
discoveryApi.deleteAllAssetLinksById(aasDescriptorId);
98118
discoveryApi.createAllAssetLinksById(aasDescriptorId, specificAssetIds);

0 commit comments

Comments
 (0)