Search in sources :

Example 21 with Submodel

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

the class ReferablePersistenceManager method getSubmodelElements.

/**
 * Get the submodel elements associated to the reference.
 * Supported are two possible parents of submodel elements:
 * <ul>
 * <li>{@link io.adminshell.aas.v3.model.Submodel}
 * <li>{@link io.adminshell.aas.v3.model.SubmodelElementCollection}
 * </ul>
 *
 * @param reference to the submodel or submodel element collection
 * @param semanticId of the submodel elements
 */
public List<SubmodelElement> getSubmodelElements(Reference reference, Reference semanticId) throws ResourceNotFoundException {
    if (reference == null) {
        return null;
    }
    if (reference.getKeys() != null && !reference.getKeys().isEmpty()) {
        List<SubmodelElement> submodelElements = null;
        KeyElements lastKeyElementOfReference = reference.getKeys().get(reference.getKeys().size() - 1).getType();
        if (lastKeyElementOfReference == KeyElements.SUBMODEL) {
            Submodel submodel = AasUtils.resolve(reference, this.aasEnvironment, Submodel.class);
            if (submodel == null) {
                throw new ResourceNotFoundException(String.format(ERROR_MSG_RESOURCE_NOT_FOUND_BY_REF, AasUtils.asString(reference)));
            }
            Submodel deepCopiedSubmodel = DeepCopyHelper.deepCopy(submodel, submodel.getClass());
            submodelElements = deepCopiedSubmodel.getSubmodelElements();
        } else if (lastKeyElementOfReference == KeyElements.SUBMODEL_ELEMENT_COLLECTION) {
            SubmodelElementCollection submodelElementCollection = AasUtils.resolve(reference, this.aasEnvironment, SubmodelElementCollection.class);
            if (submodelElementCollection == null) {
                throw new ResourceNotFoundException(String.format(ERROR_MSG_RESOURCE_NOT_FOUND_BY_REF, AasUtils.asString(reference)));
            }
            SubmodelElementCollection deepCopiedSubmodelElementCollection = DeepCopyHelper.deepCopy(submodelElementCollection, submodelElementCollection.getClass());
            submodelElements = new ArrayList<>(deepCopiedSubmodelElementCollection.getValues());
        }
        if (semanticId != null) {
            assert submodelElements != null;
            submodelElements = submodelElements.stream().filter(x -> x.getSemanticId() != null && x.getSemanticId().equals(semanticId)).collect(Collectors.toList());
        }
        return submodelElements;
    }
    return null;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ArrayList(java.util.ArrayList) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) KeyElements(io.adminshell.aas.v3.model.KeyElements) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 22 with Submodel

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

the class PersistenceInMemoryTest method testQueryModifierLevel.

@Test
public void testQueryModifierLevel() throws ResourceNotFoundException {
    String SUBMODEL_IDENTIFIER = "https://acplt.org/Test_Submodel_Mandatory";
    QueryModifier queryModifier = new QueryModifier.Builder().level(Level.DEEP).build();
    Identifier submodelId = new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier(SUBMODEL_IDENTIFIER).build();
    Submodel expected = this.environment.getSubmodels().stream().filter(x -> x.getIdentification().equals(submodelId)).findFirst().get();
    Submodel actual = (Submodel) this.persistence.get(submodelId, queryModifier);
    Assert.assertEquals(expected, actual);
    queryModifier = new QueryModifier.Builder().level(Level.CORE).build();
    actual = (Submodel) this.persistence.get(submodelId, queryModifier);
    List<SubmodelElement> submodelElementCollections = actual.getSubmodelElements().stream().filter(x -> SubmodelElementCollection.class.isAssignableFrom(x.getClass())).collect(Collectors.toList());
    Assert.assertTrue(submodelElementCollections.stream().allMatch(x -> ((SubmodelElementCollection) x).getValues().isEmpty()));
}
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) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) Test(org.junit.Test)

Example 23 with Submodel

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

the class PersistenceInMemoryTest method putIdentifiableNewTest.

@Test
public void putIdentifiableNewTest() throws ResourceNotFoundException {
    Submodel newSubmodel = DeepCopyHelper.deepCopy(this.environment.getSubmodels().get(0), this.environment.getSubmodels().get(0).getClass());
    String idShort = "NewIdShort";
    newSubmodel.setIdShort(idShort);
    Identifier newIdentifier = new DefaultIdentifier.Builder().identifier("http://newIdentifier.org").idType(IdentifierType.IRI).build();
    newSubmodel.setIdentification(newIdentifier);
    this.persistence.put(newSubmodel);
    Submodel expected = this.environment.getSubmodels().stream().filter(x -> x.getIdentification().equals(newIdentifier)).findFirst().orElse(null);
    Assert.assertEquals(expected, newSubmodel);
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) Identifier(io.adminshell.aas.v3.model.Identifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) Test(org.junit.Test)

Example 24 with Submodel

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

the class HttpEndpointIT method testSubmodelInterfaceCreateSubmodelElement.

@Test
public void testSubmodelInterfaceCreateSubmodelElement() throws InterruptedException, MessageBusException, IOException, URISyntaxException, SerializationException, DeserializationException {
    Submodel submodel = environment.getSubmodels().get(0);
    SubmodelElement expected = new DefaultProperty.Builder().idShort("newProperty").build();
    assertEvent(messageBus, ElementCreateEventMessage.class, expected, LambdaExceptionHelper.wrap(x -> executeAndAssertSingleEntity(HttpMethod.POST, API_PATHS.submodelRepository().submodelInterface(submodel).submodelElements(), StatusCode.SUCCESS_CREATED, expected, expected, SubmodelElement.class)));
    List<SubmodelElement> after = HttpHelper.getWithMultipleResult(API_PATHS.submodelRepository().submodelInterface(submodel).submodelElements(), SubmodelElement.class);
    Assert.assertTrue(after.contains(expected));
}
Also used : DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) Submodel(io.adminshell.aas.v3.model.Submodel) HttpHelper(de.fraunhofer.iosb.ilt.faaast.service.test.util.HttpHelper) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) HttpHelper.toHttpStatusCode(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.util.HttpHelper.toHttpStatusCode) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) URISyntaxException(java.net.URISyntaxException) OutputModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier) Service(de.fraunhofer.iosb.ilt.faaast.service.Service) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) MessageBusInternalConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig) ServerSocket(java.net.ServerSocket) StatusCode(de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode) DeserializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException) DefaultIdentifierKeyValuePair(io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair) Map(java.util.Map) After(org.junit.After) FaaastConstants(de.fraunhofer.iosb.ilt.faaast.service.util.FaaastConstants) DefaultConceptDescription(io.adminshell.aas.v3.model.impl.DefaultConceptDescription) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Level(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level) HttpResponse(java.net.http.HttpResponse) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) MessageBusHelper.assertEvent(de.fraunhofer.iosb.ilt.faaast.service.test.util.MessageBusHelper.assertEvent) EncodingHelper(de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper) ApiPaths(de.fraunhofer.iosb.ilt.faaast.service.test.util.ApiPaths) Reference(io.adminshell.aas.v3.model.Reference) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) SerializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException) Collectors(java.util.stream.Collectors) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) EventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage) List(java.util.List) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) Path(de.fraunhofer.iosb.ilt.faaast.service.serialization.json.util.Path) BeforeClass(org.junit.BeforeClass) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) AssetInformation(io.adminshell.aas.v3.model.AssetInformation) Identifier(io.adminshell.aas.v3.model.Identifier) ArrayList(java.util.ArrayList) DeepCopyHelper(de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper) KeyType(io.adminshell.aas.v3.model.KeyType) LangString(io.adminshell.aas.v3.model.LangString) DefaultAssetAdministrationShell(io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) Before(org.junit.Before) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) HttpMethod(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpMethod) MessageBusException(de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) IOException(java.io.IOException) Test(org.junit.Test) JsonSerializer(de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonSerializer) PersistenceInMemoryConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) LambdaExceptionHelper(de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Assert(org.junit.Assert) Content(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content) Submodel(io.adminshell.aas.v3.model.Submodel) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Test(org.junit.Test)

Example 25 with Submodel

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

the class AasServiceNodeManager method elementCreated.

/**
 * Handles an elementCreated event.
 *
 * @param element Reference to the created element.
 * @param value The element that was added.
 * @throws StatusException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
@SuppressWarnings("java:S2629")
private void elementCreated(Reference element, Referable value) throws StatusException, ServiceResultException, ServiceException, AddressSpaceException {
    if (element == null) {
        throw new IllegalArgumentException(ELEMENT_NULL);
    } else if (value == null) {
        throw new IllegalArgumentException(VALUE_NULL);
    }
    try {
        LOG.debug("elementCreated called. Reference {}", AasUtils.asString(element));
        // The element is the parent object where the value is added
        ObjectData parent = null;
        if (referableMap.containsKey(element)) {
            parent = referableMap.get(element);
        } else {
            LOG.info("elementCreated: element not found in referableMap: {}", AasUtils.asString(element));
        }
        if (value instanceof ConceptDescription) {
            addConceptDescriptions(List.of((ConceptDescription) value));
        } else if (value instanceof Asset) {
            addAsset(aasEnvironmentNode, (Asset) value);
        } else if (value instanceof Submodel) {
            addSubmodel(aasEnvironmentNode, (Submodel) value);
        } else if (value instanceof AssetAdministrationShell) {
            addAssetAdministrationShell((AssetAdministrationShell) value);
        } else if (parent != null) {
            if (value instanceof EmbeddedDataSpecification) {
                if (parent.getNode() instanceof AASAssetAdministrationShellType) {
                    addEmbeddedDataSpecifications((AASAssetAdministrationShellType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
                } else if (parent.getNode() instanceof AASSubmodelType) {
                    addEmbeddedDataSpecifications((AASSubmodelType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
                } else if (parent.getNode() instanceof AASSubmodelElementType) {
                    addEmbeddedDataSpecifications((AASSubmodelElementType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
                } else if (parent.getNode() instanceof AASAssetType) {
                    addEmbeddedDataSpecifications((AASAssetType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
                } else {
                    LOG.warn("elementCreated: EmbeddedDataSpecification parent class not found");
                }
            } else if (value instanceof Constraint) {
                if (parent.getNode() instanceof AASSubmodelType) {
                    addQualifiers(((AASSubmodelType) parent.getNode()).getQualifierNode(), List.of((Constraint) value));
                } else if (parent.getNode() instanceof AASSubmodelElementType) {
                    addQualifiers(((AASSubmodelElementType) parent.getNode()).getQualifierNode(), List.of((Constraint) value));
                } else {
                    LOG.warn("elementCreated: Constraint parent class not found");
                }
            } else if (value instanceof SubmodelElement) {
                if (parent.getNode() instanceof AASSubmodelType) {
                    LOG.info("elementCreated: call addSubmodelElements");
                    addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), (Submodel) parent.getReferable(), element);
                } else if (parent.getNode() instanceof AASSubmodelElementType) {
                    LOG.info("elementCreated: call addSubmodelElements");
                    addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), parent.getSubmodel(), element);
                } else {
                    LOG.warn("elementCreated: SubmodelElement parent class not found: {}; {}", parent.getNode().getNodeId(), parent.getNode());
                }
            }
        } else {
            LOG.warn("elementCreated: element not found: {}", AasUtils.asString(element));
        }
    } catch (Exception ex) {
        LOG.error("elementCreated Exception", ex);
        throw ex;
    }
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) AASAssetType(opc.i4aas.AASAssetType) Constraint(io.adminshell.aas.v3.model.Constraint) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ServiceResultException(com.prosysopc.ua.stack.common.ServiceResultException) StatusException(com.prosysopc.ua.StatusException) MessageBusException(de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException) ServiceException(com.prosysopc.ua.ServiceException) UaNodeFactoryException(com.prosysopc.ua.nodes.UaNodeFactoryException) AddressSpaceException(com.prosysopc.ua.client.AddressSpaceException) EmbeddedDataSpecification(io.adminshell.aas.v3.model.EmbeddedDataSpecification) AASSubmodelType(opc.i4aas.AASSubmodelType) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) AASAssetAdministrationShellType(opc.i4aas.AASAssetAdministrationShellType) AASSubmodelElementType(opc.i4aas.AASSubmodelElementType) Asset(io.adminshell.aas.v3.model.Asset) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription)

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