use of io.adminshell.aas.v3.model.Identifiable in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemory method get.
@Override
public <T extends Identifiable> T get(Identifier id, QueryModifier modifier) throws ResourceNotFoundException {
if (id == null || modifier == null) {
return null;
}
Identifiable identifiable = identifiablePersistenceManager.getIdentifiableById(id);
QueryModifierHelper.applyQueryModifier(identifiable, modifier);
return (T) identifiable;
}
use of io.adminshell.aas.v3.model.Identifiable in project FAAAST-Service by FraunhoferIOSB.
the class IdentifiablePersistenceManager method remove.
/**
* Remove an identifiable by its identifier.
* Following identifiables are supported:
* <p>
* <ul>
* <li>{@link io.adminshell.aas.v3.model.AssetAdministrationShell}
* <li>{@link io.adminshell.aas.v3.model.Submodel}
* <li>{@link io.adminshell.aas.v3.model.ConceptDescription}
* <li>{@link io.adminshell.aas.v3.model.Asset}
* </ul>
* <p>
*
* @param id of the indetifiable which should be removed
* @throws ResourceNotFoundException if there is no identifiable with such an identifer
*/
public void remove(Identifier id) throws ResourceNotFoundException {
if (id == null || this.aasEnvironment == null) {
return;
}
Predicate<Identifiable> removeFilter = x -> !x.getIdentification().getIdentifier().equalsIgnoreCase(id.getIdentifier());
Identifiable identifiable = getIdentifiableById(id);
if (identifiable == null) {
throw new ResourceNotFoundException("Resource not found with ID " + id.getIdentifier());
}
// TODO: use reflection?
if (AssetAdministrationShell.class.isAssignableFrom(identifiable.getClass())) {
List<AssetAdministrationShell> newAASList;
newAASList = this.aasEnvironment.getAssetAdministrationShells().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setAssetAdministrationShells(newAASList);
} else if (Submodel.class.isAssignableFrom(identifiable.getClass())) {
List<Submodel> newSubmodelList;
newSubmodelList = this.aasEnvironment.getSubmodels().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setSubmodels(newSubmodelList);
Reference referenceOfIdentifiable = AasUtils.toReference(identifiable);
this.aasEnvironment.getAssetAdministrationShells().forEach(x -> x.getSubmodels().remove(referenceOfIdentifiable));
} else if (ConceptDescription.class.isAssignableFrom(identifiable.getClass())) {
List<ConceptDescription> newConceptDescriptionList;
newConceptDescriptionList = this.aasEnvironment.getConceptDescriptions().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setConceptDescriptions(newConceptDescriptionList);
} else if (Asset.class.isAssignableFrom(identifiable.getClass())) {
List<Asset> newAssetList;
newAssetList = this.aasEnvironment.getAssets().stream().filter(removeFilter).collect(Collectors.toList());
this.aasEnvironment.setAssets(newAssetList);
}
}
use of io.adminshell.aas.v3.model.Identifiable in project FAAAST-Service by FraunhoferIOSB.
the class PersistenceInMemoryTest method removeSubmodelTest.
@Test
public void removeSubmodelTest() throws ResourceNotFoundException {
String SUBMODEL_IDENTIFIER = "https://acplt.org/Test_Submodel_Mandatory";
Identifier submodelId = new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier(SUBMODEL_IDENTIFIER).build();
Identifiable submodel = this.persistence.get(submodelId, new QueryModifier());
this.persistence.remove(submodelId);
Assert.assertThrows(ResourceNotFoundException.class, () -> this.persistence.get(submodelId, new QueryModifier()));
}
Aggregations