Search in sources :

Example 76 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class PersistenceInMemoryTest method getSubmodelsWithSemanticIdTest.

@Test
public void getSubmodelsWithSemanticIdTest() {
    Reference semanticId = new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).idType(KeyType.IRI).value("http://acplt.org/SubmodelTemplates/ExampleSubmodel").build()).build();
    List<Submodel> actualSubmodels = persistence.get("", semanticId, new QueryModifier());
    List<Submodel> expectedSubmodels = this.environment.getSubmodels().stream().filter(x -> x.getSemanticId() != null && x.getSemanticId().equals(semanticId)).collect(Collectors.toList());
    Assert.assertEquals(expectedSubmodels, actualSubmodels);
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) KeyElements(io.adminshell.aas.v3.model.KeyElements) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Extend(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extend) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) AssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.AssetIdentification) Identifiable(io.adminshell.aas.v3.model.Identifiable) Message(de.fraunhofer.iosb.ilt.faaast.service.model.api.Message) DeepCopyHelper(de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper) KeyType(io.adminshell.aas.v3.model.KeyType) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Level(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level) Before(org.junit.Before) GlobalAssetIdentification(de.fraunhofer.iosb.ilt.faaast.service.model.asset.GlobalAssetIdentification) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) Reference(io.adminshell.aas.v3.model.Reference) Test(org.junit.Test) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) Collectors(java.util.stream.Collectors) Result(de.fraunhofer.iosb.ilt.faaast.service.model.api.Result) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) List(java.util.List) ExecutionState(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.ExecutionState) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Assert(org.junit.Assert) Submodel(io.adminshell.aas.v3.model.Submodel) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) Test(org.junit.Test)

Example 77 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class PersistenceInMemoryTest method getSubmodelsAllTest.

@Test
public void getSubmodelsAllTest() {
    List<Submodel> actualSubmodelList = persistence.get(null, (Reference) null, new QueryModifier());
    List<Submodel> expectedSubmodelList = this.environment.getSubmodels();
    Assert.assertEquals(expectedSubmodelList, actualSubmodelList);
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) Test(org.junit.Test)

Example 78 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class IdentifiablePersistenceManager method remove.

/**
 * Remove an identifiable by its identifier.
 * Following identifiables are supported:
 * <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>
 *
 * @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(String.format(ERROR_MSG_RESOURCE_NOT_FOUND_BY_ID, IdentifierHelper.asString(id)));
    }
    // 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) IdentifierHelper(de.fraunhofer.iosb.ilt.faaast.service.util.IdentifierHelper) 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 79 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class GetSubmodelByIdRequestHandler method process.

@Override
public GetSubmodelByIdResponse process(GetSubmodelByIdRequest request) throws ResourceNotFoundException, AssetConnectionException, ValueMappingException, MessageBusException {
    GetSubmodelByIdResponse response = new GetSubmodelByIdResponse();
    Submodel submodel = (Submodel) persistence.get(request.getId(), request.getOutputModifier());
    response.setPayload(submodel);
    response.setStatusCode(StatusCode.SUCCESS);
    Reference reference = AasUtils.toReference(submodel);
    syncWithAsset(reference, submodel.getSubmodelElements());
    messageBus.publish(ElementReadEventMessage.builder().element(reference).value(submodel).build());
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) Reference(io.adminshell.aas.v3.model.Reference) GetSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelByIdResponse)

Example 80 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class GetSubmodelRequestHandler method process.

@Override
public GetSubmodelResponse process(GetSubmodelRequest request) throws ResourceNotFoundException, AssetConnectionException, ValueMappingException, MessageBusException {
    GetSubmodelResponse response = new GetSubmodelResponse();
    Submodel submodel = (Submodel) persistence.get(request.getId(), request.getOutputModifier());
    response.setPayload(submodel);
    response.setStatusCode(StatusCode.SUCCESS);
    Reference reference = AasUtils.toReference(submodel);
    syncWithAsset(reference, submodel.getSubmodelElements());
    messageBus.publish(ElementReadEventMessage.builder().element(reference).value(submodel).build());
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) GetSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelResponse) Reference(io.adminshell.aas.v3.model.Reference)

Aggregations

Test (org.junit.Test)60 Submodel (io.adminshell.aas.v3.model.Submodel)58 Reference (io.adminshell.aas.v3.model.Reference)53 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)49 LangString (io.adminshell.aas.v3.model.LangString)47 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)41 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)38 DefaultSubmodel (io.adminshell.aas.v3.model.impl.DefaultSubmodel)34 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)30 ArrayList (java.util.ArrayList)30 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)28 Identifier (io.adminshell.aas.v3.model.Identifier)27 SubmodelElementCollection (io.adminshell.aas.v3.model.SubmodelElementCollection)25 OutputModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier)24 List (java.util.List)24 Collectors (java.util.stream.Collectors)24 StatusException (com.prosysopc.ua.StatusException)23 DeepCopyHelper (de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper)23 AssetAdministrationShell (io.adminshell.aas.v3.model.AssetAdministrationShell)22 ConceptDescription (io.adminshell.aas.v3.model.ConceptDescription)22