Skip to content

Commit

Permalink
Resolved review remarks
Browse files Browse the repository at this point in the history
- Changes related to serialization extension
- Refactors RegIntegSMRepo and RegIntegAasRepo to check for descriptor before deletion
- Swaps order of deletion from Repo and Registry

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>
  • Loading branch information
mdanish98 committed Nov 24, 2023
1 parent dbc5a89 commit 12471ab
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint;
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.DefaultAttributeMapperFactory;
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;

/**
Expand All @@ -57,11 +56,11 @@ public class AasDescriptorFactory {

private AttributeMapper attributeMapper;

public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL) {
public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL, AttributeMapper attributeMapper) {
super();
this.shell = shell;
this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL);
this.attributeMapper = new DefaultAttributeMapperFactory().create();
this.attributeMapper = attributeMapper;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi;
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException;
import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException;
Expand All @@ -54,10 +55,12 @@ public class RegistryIntegrationAasRepository implements AasRepository {
private AasRepository decorated;

private AasRepositoryRegistryLink aasRepositoryRegistryLink;
private AttributeMapper attributeMapper;

public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) {
public RegistryIntegrationAasRepository(AasRepository decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink, AttributeMapper attributeMapper) {
this.decorated = decorated;
this.aasRepositoryRegistryLink = aasRepositoryRegistryLink;
this.attributeMapper = attributeMapper;
}

@Override
Expand All @@ -84,10 +87,9 @@ public void updateAas(String shellId, AssetAdministrationShell shell) {

@Override
public void deleteAas(String shellId) {
AssetAdministrationShell shell = decorated.getAas(shellId);
deleteFromRegistry(shellId);

decorated.deleteAas(shellId);

deleteFromRegistry(shell.getId());
}

@Override
Expand Down Expand Up @@ -121,14 +123,14 @@ public AssetInformation getAssetInformation(String shellId) throws ElementDoesNo
}

private void integrateAasWithRegistry(AssetAdministrationShell shell, String aasRepositoryURL) {
AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL).create();
AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURL, attributeMapper).create();

RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi();

try {
registryApi.postAssetAdministrationShellDescriptor(descriptor);

logger.info("Shell {} has been automatically linked with the Registry", shell.getId());
logger.info("Shell '{}' has been automatically linked with the Registry", shell.getId());
} catch (ApiException e) {
e.printStackTrace();

Expand All @@ -138,6 +140,12 @@ private void integrateAasWithRegistry(AssetAdministrationShell shell, String aas

private void deleteFromRegistry(String shellId) {
RegistryAndDiscoveryInterfaceApi registryApi = aasRepositoryRegistryLink.getRegistryApi();

if (!shellExistsOnRegistry(shellId, registryApi)) {
logger.error("Unable to un-link the AAS descriptor '{}' from the Registry because it does not exist on the Registry.", shellId);

return;
}

try {
registryApi.deleteAssetAdministrationShellDescriptorById(shellId);
Expand All @@ -149,5 +157,15 @@ private void deleteFromRegistry(String shellId) {
throw new RepositoryRegistryUnlinkException(shellId);
}
}

private boolean shellExistsOnRegistry(String shellId, RegistryAndDiscoveryInterfaceApi registryApi) {
try {
registryApi.getAssetAdministrationShellDescriptorById(shellId);

return true;
} catch (ApiException e) {
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@

import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Configuration for integrating {@link AasRepository} with AasRegistry
*
Expand All @@ -49,5 +52,12 @@ public AasRepositoryRegistryLink getAasRepositoryRegistryLink(@Value("${basyx.aa

return new AasRepositoryRegistryLink(new RegistryAndDiscoveryInterfaceApi(registryBasePath), aasRepositoryBaseURL);
}

@Bean
@ConditionalOnMissingBean
public AttributeMapper getAasAttributeMapper(ObjectMapper objectMapper) {

return new AttributeMapper(objectMapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper;

/**
* Factory for creating {@link RegistryIntegrationAasRepository}
Expand All @@ -37,15 +38,17 @@ public class RegistryIntegrationAasRepositoryFactory implements AasRepositoryFac

private AasRepositoryFactory decorated;
private AasRepositoryRegistryLink aasRepositoryRegistryLink;
private AttributeMapper attributeMapper;

public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink) {
public RegistryIntegrationAasRepositoryFactory(AasRepositoryFactory decorated, AasRepositoryRegistryLink aasRepositoryRegistryLink, AttributeMapper attributeMapper) {
this.decorated = decorated;
this.aasRepositoryRegistryLink = aasRepositoryRegistryLink;
this.attributeMapper = attributeMapper;
}

@Override
public AasRepository create() {
return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink);
return new RegistryIntegrationAasRepository(decorated.create(), aasRepositoryRegistryLink, attributeMapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
Expand All @@ -51,15 +52,18 @@ public class RegistryIntegrationAasRepositoryFeature implements AasRepositoryFea

@Value("${basyx.externalurl:}")
private String aasRepositoryExternalBaseURL;

private AttributeMapper attributeMapper;

@Autowired
public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink) {
public RegistryIntegrationAasRepositoryFeature(AasRepositoryRegistryLink aasRepositoryRegistryLink, AttributeMapper attributeMapper) {
this.aasRepositoryRegistryLink = aasRepositoryRegistryLink;
this.attributeMapper = attributeMapper;
}

@Override
public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) {
return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink);
return new RegistryIntegrationAasRepositoryFactory(aasRepositoryFactory, aasRepositoryRegistryLink, attributeMapper);
}

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 12471ab

Please sign in to comment.