Search in sources :

Example 1 with Identifiable

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;
}
Also used : Identifiable(io.adminshell.aas.v3.model.Identifiable)

Example 2 with 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);
    }
}
Also used : GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) Predicate(java.util.function.Predicate) Reference(io.adminshell.aas.v3.model.Reference) SpecificAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.SpecificAssetIdentification) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AasUtils(io.adminshell.aas.v3.dataformat.core.util.AasUtils) Identifier(io.adminshell.aas.v3.model.Identifier) ArrayList(java.util.ArrayList) ReferenceHelper(de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper) AssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification) Asset(io.adminshell.aas.v3.model.Asset) Identifiable(io.adminshell.aas.v3.model.Identifiable) List(java.util.List) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) DeepCopyHelper(de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper) EnvironmentHelper(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.util.EnvironmentHelper) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Submodel(io.adminshell.aas.v3.model.Submodel) Submodel(io.adminshell.aas.v3.model.Submodel) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Reference(io.adminshell.aas.v3.model.Reference) Asset(io.adminshell.aas.v3.model.Asset) ArrayList(java.util.ArrayList) List(java.util.List) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) Identifiable(io.adminshell.aas.v3.model.Identifiable)

Example 3 with Identifiable

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()));
}
Also used : Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) Identifiable(io.adminshell.aas.v3.model.Identifiable) Test(org.junit.Test)

Aggregations

Identifiable (io.adminshell.aas.v3.model.Identifiable)3 Identifier (io.adminshell.aas.v3.model.Identifier)2 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 QueryModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier)1 AssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification)1 GlobalAssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification)1 SpecificAssetIdentification (de.fraunhofer.iosb.ilt.faaast.service.model.asset.SpecificAssetIdentification)1 EnvironmentHelper (de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.util.EnvironmentHelper)1 DeepCopyHelper (de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper)1 ReferenceHelper (de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper)1 AasUtils (io.adminshell.aas.v3.dataformat.core.util.AasUtils)1 Asset (io.adminshell.aas.v3.model.Asset)1 AssetAdministrationShell (io.adminshell.aas.v3.model.AssetAdministrationShell)1 ConceptDescription (io.adminshell.aas.v3.model.ConceptDescription)1 Reference (io.adminshell.aas.v3.model.Reference)1 Submodel (io.adminshell.aas.v3.model.Submodel)1 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1