Search in sources :

Example 1 with AddressSpaceException

use of com.prosysopc.ua.client.AddressSpaceException 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)

Example 2 with AddressSpaceException

use of com.prosysopc.ua.client.AddressSpaceException in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method createAddressSpace.

/**
 * Creates the address space of the OPC UA Server.
 */
private void createAddressSpace() throws StatusException, ServiceResultException, ServiceException, AddressSpaceException, MessageBusException {
    try {
        LOG.info("createAddressSpace");
        aasMethodManagerListener = new AasServiceMethodManagerListener(endpoint, this);
        createAasNodes();
        subscribeMessageBus();
    } catch (Exception ex) {
        LOG.error("createAddressSpace Exception", ex);
        throw ex;
    }
}
Also used : AasServiceMethodManagerListener(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.listener.AasServiceMethodManagerListener) 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)

Example 3 with AddressSpaceException

use of com.prosysopc.ua.client.AddressSpaceException in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addAasEntity.

/**
 * Adds an AAS entity to the given node.
 *
 * @param node The desired UA node
 * @param aasEntity The AAS entity to add
 * @param submodel The corresponding Submodel
 * @param parentRef The AAS reference to the parent object
 * @param ordered Specifies whether the entity should be added ordered
 *            (true) or unordered (false)
 * @throws StatusException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private void addAasEntity(UaNode node, Entity aasEntity, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasEntity != null)) {
            String name = aasEntity.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEntityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASEntityType entityNode = createInstance(AASEntityType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(entityNode, aasEntity);
            Reference entityRef = AasUtils.toReference(parentRef, aasEntity);
            // EntityType
            entityNode.setEntityType(ValueConverter.getAasEntityType(aasEntity.getEntityType()));
            submodelElementAasMap.put(entityNode.getEntityTypeNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_TYPE, entityRef));
            // GlobalAssetId
            if (aasEntity.getGlobalAssetId() != null) {
                if (entityNode.getGlobalAssetIdNode() == null) {
                    addAasReferenceAasNS(entityNode, aasEntity.getGlobalAssetId(), AASEntityType.GLOBAL_ASSET_ID, false);
                } else {
                    setAasReferenceData(aasEntity.getGlobalAssetId(), entityNode.getGlobalAssetIdNode(), false);
                }
                submodelElementAasMap.put(entityNode.getGlobalAssetIdNode().getKeysNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_GLOBAL_ASSET_ID, entityRef));
            }
            // SpecificAssetIds
            IdentifierKeyValuePair specificAssetId = aasEntity.getSpecificAssetId();
            if (specificAssetId != null) {
                if (entityNode.getSpecificAssetIdNode() == null) {
                    addIdentifierKeyValuePair(entityNode, specificAssetId, AASEntityType.SPECIFIC_ASSET_ID);
                } else {
                    setIdentifierKeyValuePairData(entityNode.getSpecificAssetIdNode(), specificAssetId);
                }
            }
            // Statements
            addSubmodelElements(entityNode.getStatementNode(), aasEntity.getStatements(), submodel, entityRef);
            submodelElementOpcUAMap.put(entityRef, entityNode);
            if (ordered) {
                node.addReference(entityNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(entityNode);
            }
            referableMap.put(entityRef, new ObjectData(aasEntity, entityNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("addAasEntity Exception", ex);
        throw ex;
    }
}
Also used : AASEntityType(opc.i4aas.AASEntityType) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) 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) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 4 with AddressSpaceException

use of com.prosysopc.ua.client.AddressSpaceException in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addSubmodel.

/**
 * Adds a submodel to a given Node
 *
 * @param node The desired Node where the submodel should be added
 * @param submodel The desired AAS submodel
 */
private void addSubmodel(UaNode node, Submodel submodel) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    if (submodel == null) {
        throw new IllegalArgumentException("submodel is null");
    }
    try {
        String shortId = submodel.getIdShort();
        if (!shortId.isEmpty()) {
            String displayName = "Submodel:" + shortId;
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelType.getNamespaceUri(), shortId).toQualifiedName(getNamespaceTable());
            NodeId nid = createNodeId(node, browseName);
            if (findNode(nid) != null) {
                // The NodeId already exists
                nid = getDefaultNodeId();
            }
            LOG.trace("addSubmodel: create Submodel {}; NodeId: {}", submodel.getIdShort(), nid);
            AASSubmodelType smNode = createInstance(AASSubmodelType.class, nid, browseName, LocalizedText.english(displayName));
            // ModelingKind
            smNode.setModelingKind(ValueConverter.convertModelingKind(submodel.getKind()));
            addIdentifiable(smNode, submodel.getIdentification(), submodel.getAdministration(), submodel.getCategory());
            // DataSpecifications
            addEmbeddedDataSpecifications(smNode, submodel.getEmbeddedDataSpecifications());
            // Qualifiers
            List<Constraint> qualifiers = submodel.getQualifiers();
            if ((qualifiers != null) && (!qualifiers.isEmpty())) {
                if (smNode.getQualifierNode() == null) {
                    addQualifierNode(smNode);
                }
                addQualifiers(smNode.getQualifierNode(), qualifiers);
            }
            // SemanticId
            if (submodel.getSemanticId() != null) {
                addSemanticId(smNode, submodel.getSemanticId());
            }
            // Description
            addDescriptions(smNode, submodel.getDescriptions());
            Reference refSubmodel = AasUtils.toReference(submodel);
            // SubmodelElements
            addSubmodelElements(smNode, submodel.getSubmodelElements(), submodel, refSubmodel);
            if (VALUES_READ_ONLY) {
                smNode.getModelingKindNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
            submodelOpcUAMap.put(AasUtils.toReference(submodel), smNode);
            node.addComponent(smNode);
            referableMap.put(AasUtils.toReference(submodel), new ObjectData(submodel, smNode));
        } else {
            LOG.warn("addSubmodel: IdShort is empty!");
        }
    } catch (Exception ex) {
        LOG.error("addSubmodel Exception", ex);
        throw ex;
    }
}
Also used : AASSubmodelType(opc.i4aas.AASSubmodelType) Constraint(io.adminshell.aas.v3.model.Constraint) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) 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)

Example 5 with AddressSpaceException

use of com.prosysopc.ua.client.AddressSpaceException in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addAasSubmodelElementCollection.

/**
 * Adds a SubmodelElementCollection to the given node.
 *
 * @param node The desired UA node
 * @param aasColl The corresponding SubmodelElementCollection to add
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param parentRef The AAS reference to the parent object
 * @param ordered Specifies whether the entity should be added ordered
 *            (true) or unordered (false)
 * @throws StatusException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private void addAasSubmodelElementCollection(UaNode node, SubmodelElementCollection aasColl, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasColl != null)) {
            String name = aasColl.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASSubmodelElementCollectionType collNode;
            if (aasColl.getOrdered()) {
                collNode = createAasOrderedSubmodelElementCollection(name, nid);
            } else {
                collNode = createInstance(AASSubmodelElementCollectionType.class, nid, browseName, LocalizedText.english(name));
            }
            addSubmodelElementBaseData(collNode, aasColl);
            // AllowDuplicates
            if (collNode.getAllowDuplicatesNode() == null) {
                NodeId myPropertyId = new NodeId(getNamespaceIndex(), collNode.getNodeId().getValue().toString() + "." + AASSubmodelElementCollectionType.ALLOW_DUPLICATES);
                PlainProperty<Boolean> myProperty = new PlainProperty<>(this, myPropertyId, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), AASSubmodelElementCollectionType.ALLOW_DUPLICATES).toQualifiedName(getNamespaceTable()), LocalizedText.english(AASSubmodelElementCollectionType.ALLOW_DUPLICATES));
                myProperty.setDataTypeId(Identifiers.Boolean);
                myProperty.setDescription(new LocalizedText("", ""));
                if (VALUES_READ_ONLY) {
                    myProperty.setAccessLevel(AccessLevelType.CurrentRead);
                }
                collNode.addProperty(myProperty);
            }
            collNode.setAllowDuplicates(aasColl.getAllowDuplicates());
            Reference collRef = AasUtils.toReference(parentRef, aasColl);
            // SubmodelElements
            addSubmodelElements(collNode, aasColl.getValues(), submodel, collRef, aasColl.getOrdered());
            if (ordered) {
                node.addReference(collNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(collNode);
            }
            referableMap.put(collRef, new ObjectData(aasColl, collNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("createAasSubmodelElementCollection Exception", ex);
        throw ex;
    }
}
Also used : PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) AASSubmodelElementCollectionType(opc.i4aas.AASSubmodelElementCollectionType) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) 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)

Aggregations

ServiceException (com.prosysopc.ua.ServiceException)8 StatusException (com.prosysopc.ua.StatusException)8 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)8 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)8 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)8 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)7 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)4 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)4 LangString (io.adminshell.aas.v3.model.LangString)4 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)3 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)3 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 Constraint (io.adminshell.aas.v3.model.Constraint)3 Reference (io.adminshell.aas.v3.model.Reference)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 Asset (io.adminshell.aas.v3.model.Asset)2 Submodel (io.adminshell.aas.v3.model.Submodel)2 AASSubmodelType (opc.i4aas.AASSubmodelType)2 PlainProperty (com.prosysopc.ua.server.nodes.PlainProperty)1 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)1