Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,49 @@ public AssetAdministrationShellDescriptor getAasDescriptor(@NonNull String aasDe
}

@Override
public void insertAasDescriptor(AssetAdministrationShellDescriptor descr) throws AasDescriptorAlreadyExistsException {
public void insertAasDescriptor(AssetAdministrationShellDescriptor descr)
throws AasDescriptorAlreadyExistsException {
decorated.insertAasDescriptor(descr);
@Valid List<org.eclipse.digitaltwin.basyx.aasregistry.model.@Valid SpecificAssetId> ids = descr.getSpecificAssetIds();
List<SpecificAssetId> specificAssetIds = ids.stream()
.map(rId -> {
SpecificAssetId assetId = new DefaultSpecificAssetId();
assetId.setName(rId.getName());
assetId.setValue(rId.getValue());
return assetId;
}).collect(Collectors.toList());

List<org.eclipse.digitaltwin.basyx.aasregistry.model.SpecificAssetId> ids = descr.getSpecificAssetIds();
if (ids == null || ids.isEmpty()) {
log.debug("No specificAssetIds present for AAS '{}', skipping discovery integration", descr.getId());
return;
}

List<SpecificAssetId> specificAssetIds = ids.stream()
.map(rId -> {
SpecificAssetId assetId = new DefaultSpecificAssetId();
assetId.setName(rId.getName());
assetId.setValue(rId.getValue());
return assetId;
}).collect(Collectors.toList());

discoveryApi.createAllAssetLinksById(descr.getId(), specificAssetIds);
}

@Override
public void replaceAasDescriptor(@NonNull String aasDescriptorId, @NonNull AssetAdministrationShellDescriptor descriptor) throws AasDescriptorNotFoundException {
public void replaceAasDescriptor(@NonNull String aasDescriptorId,
@NonNull AssetAdministrationShellDescriptor descriptor)
throws AasDescriptorNotFoundException {
decorated.replaceAasDescriptor(aasDescriptorId, descriptor);
List<SpecificAssetId> specificAssetIds = descriptor.getSpecificAssetIds().stream()

List<org.eclipse.digitaltwin.basyx.aasregistry.model.SpecificAssetId> ids = descriptor.getSpecificAssetIds();

if (ids == null || ids.isEmpty()) {
log.debug("No specificAssetIds present for AAS '{}', skipping discovery integration update", aasDescriptorId);
discoveryApi.deleteAllAssetLinksById(aasDescriptorId);
return;
}
Comment on lines +102 to +106
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup logic deleteAllAssetLinksById() is only executed in replaceAasDescriptor() when ids are null/empty, but not in insertAasDescriptor(). This asymmetry could lead to inconsistent behavior. Consider documenting why cleanup is needed only during replacement, or ensure both methods handle the absence of identifiers consistently.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup call to deleteAllAssetLinksById() is intentionally omitted in insertAasDescriptor().

When inserting a new AAS descriptor, the registry guarantees that the descriptor ID is unique and does not already exist in the system. Any attempt to insert a duplicate descriptor results in an HTTP 409 Conflict, preventing residual or stale discovery links from ever being created.

As a result, there is no need to perform a cleanup of discovery links during insertion — such links cannot exist yet.

In contrast, replaceAasDescriptor() explicitly handles cleanup to ensure that any previously registered discovery links are removed when an existing descriptor is updated or replaced with one that no longer contains identifiers.

This intentional asymmetry avoids redundant API calls and ensures consistent behavior while maintaining efficiency and clarity in the discovery integration process.

Furthermore, the internal implementation of the discovery service throws a 404 Not Found error if an attempt is made to delete non-existent links.
Including a deletion call during insertion would therefore generate unnecessary 404 responses and misleading log entries, implying a missing or inconsistent discovery state.
By omitting the cleanup step in insertAasDescriptor(), the registry avoids this confusion and keeps the integration behavior semantically correct.


List<SpecificAssetId> specificAssetIds = ids.stream()
.map(rId -> {
SpecificAssetId assetId = new DefaultSpecificAssetId();
assetId.setName(rId.getName());
assetId.setValue(rId.getValue());
return assetId;
}).collect(Collectors.toList());
})
.collect(Collectors.toList());

discoveryApi.deleteAllAssetLinksById(aasDescriptorId);
discoveryApi.createAllAssetLinksById(aasDescriptorId, specificAssetIds);
Expand Down