Search in sources :

Example 11 with Operation

use of io.adminshell.aas.v3.model.Operation 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 12 with Operation

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

the class AasServiceNodeManager method addAasBlob.

/**
 * Adds an AAS Blob to the given UA node.
 *
 * @param node The desired UA node
 * @param aasBlob The AAS blob to add
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param parentRef Tne reference to the parent object
 * @param ordered Specifies whether the blob should be added ordered (true)
 *            or unordered (false)
 * @throws StatusException If the operation fails
 */
private void addAasBlob(UaNode node, Blob aasBlob, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
    try {
        if ((node != null) && (aasBlob != null)) {
            String name = aasBlob.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASBlobType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASBlobType blobNode = createInstance(AASBlobType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(blobNode, aasBlob);
            // MimeType
            blobNode.setMimeType(aasBlob.getMimeType());
            Reference blobRef = AasUtils.toReference(parentRef, aasBlob);
            // Value
            if (aasBlob.getValue() != null) {
                if (blobNode.getValueNode() == null) {
                    addBlobValueNode(blobNode);
                }
                submodelElementAasMap.put(blobNode.getValueNode().getNodeId(), new SubmodelElementData(aasBlob, submodel, SubmodelElementData.Type.BLOB_VALUE, blobRef));
                LOG.debug("addAasBlob: NodeId {}; Blob: {}", blobNode.getValueNode().getNodeId(), aasBlob);
                submodelElementOpcUAMap.put(blobRef, blobNode);
                blobNode.setValue(ByteString.valueOf(aasBlob.getValue()));
            }
            if (ordered) {
                node.addReference(blobNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(blobNode);
            }
            referableMap.put(blobRef, new ObjectData(aasBlob, blobNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("addAasBlob Exception", ex);
        throw ex;
    }
}
Also used : AASBlobType(opc.i4aas.AASBlobType) 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 13 with Operation

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

the class AasServiceNodeManager method addAasOperation.

/**
 * Adds an AAS Operation to the given node.
 *
 * @param node The desired UA node
 * @param aasOperation The corresponding AAS operation to add
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param parentRef The reference to the parent object
 * @param ordered Specifies whether the operation should be added ordered
 *            (true) or unordered (false)
 */
private void addAasOperation(UaNode node, Operation aasOperation, Submodel submodel, Reference parentRef, boolean ordered) {
    try {
        String name = aasOperation.getIdShort();
        QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASOperationType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
        NodeId nid = getDefaultNodeId();
        AASOperationType oper = createInstance(AASOperationType.class, nid, browseName, LocalizedText.english(name));
        addSubmodelElementBaseData(oper, aasOperation);
        Reference operRef = AasUtils.toReference(parentRef, aasOperation);
        // for operations we put the corresponding operation object into the map
        submodelElementAasMap.put(nid, new SubmodelElementData(aasOperation, submodel, SubmodelElementData.Type.OPERATION, operRef));
        LOG.debug("addAasOperation: NodeId {}; Property: {}", nid, aasOperation);
        // add method
        NodeId myMethodId = new NodeId(getNamespaceIndex(), nid.getValue().toString() + "." + name);
        PlainMethod method = new PlainMethod(this, myMethodId, name, Locale.ENGLISH);
        Argument[] inputs = new Argument[aasOperation.getInputVariables().size()];
        for (int i = 0; i < aasOperation.getInputVariables().size(); i++) {
            OperationVariable v = aasOperation.getInputVariables().get(i);
            inputs[i] = new Argument();
            setOperationArgument(inputs[i], v);
        }
        method.setInputArguments(inputs);
        Argument[] outputs = new Argument[1];
        for (int i = 0; i < aasOperation.getOutputVariables().size(); i++) {
            OperationVariable v = aasOperation.getOutputVariables().get(i);
            outputs[i] = new Argument();
            setOperationArgument(outputs[i], v);
        }
        method.setOutputArguments(outputs);
        MethodManagerUaNode m = (MethodManagerUaNode) this.getMethodManager();
        m.addCallListener(aasMethodManagerListener);
        method.setDescription(new LocalizedText("", ""));
        oper.addComponent(method);
        if (ordered) {
            node.addReference(oper, Identifiers.HasOrderedComponent, false);
        } else {
            node.addComponent(oper);
        }
        referableMap.put(operRef, new ObjectData(aasOperation, oper, submodel));
    } catch (Exception ex) {
        LOG.error("addAasOperation Exception", ex);
    }
}
Also used : OperationVariable(io.adminshell.aas.v3.model.OperationVariable) Argument(com.prosysopc.ua.stack.core.Argument) 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) 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) AASOperationType(opc.i4aas.AASOperationType) Constraint(io.adminshell.aas.v3.model.Constraint) 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) MethodManagerUaNode(com.prosysopc.ua.server.MethodManagerUaNode) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) PlainMethod(com.prosysopc.ua.server.nodes.PlainMethod) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 14 with Operation

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

the class AasServiceNodeManager method addAasEvent.

/**
 * Adds an AAS Event to the given node.
 *
 * @param node The desired UA node
 * @param aasEvent The AAS Event 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
 */
private void addAasEvent(UaNode node, Event aasEvent, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
    try {
        if ((node != null) && (aasEvent != null)) {
            String name = aasEvent.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEventType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASEventType eventNode = createInstance(AASEventType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(eventNode, aasEvent);
            if (aasEvent instanceof BasicEvent) {
                setBasicEventData(eventNode, (BasicEvent) aasEvent);
            }
            Reference eventRef = AasUtils.toReference(parentRef, aasEvent);
            if (ordered) {
                node.addReference(eventNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(eventNode);
            }
            referableMap.put(eventRef, new ObjectData(aasEvent, eventNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("addAasEvent Exception", ex);
        throw ex;
    }
}
Also used : 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) BasicEvent(io.adminshell.aas.v3.model.BasicEvent) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) AASEventType(opc.i4aas.AASEventType) 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 15 with Operation

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

the class AasServiceNodeManager method addAasRelationshipElement.

/**
 * Adds an AAS Relationship Element to the given node.
 *
 * @param node The desired UA node
 * @param aasRelElem The corresponding AAS Relationship Element
 * @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
 */
private void addAasRelationshipElement(UaNode node, RelationshipElement aasRelElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
    try {
        if ((node != null) && (aasRelElem != null)) {
            Reference relElemRef = AasUtils.toReference(parentRef, aasRelElem);
            String name = aasRelElem.getIdShort();
            AASRelationshipElementType relElemNode;
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRelationshipElementType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            if (aasRelElem instanceof AnnotatedRelationshipElement) {
                relElemNode = createAnnotatedRelationshipElement((AnnotatedRelationshipElement) aasRelElem, submodel, relElemRef, nid);
            } else {
                relElemNode = createInstance(AASRelationshipElementType.class, nid, browseName, LocalizedText.english(name));
            }
            if (relElemNode != null) {
                addSubmodelElementBaseData(relElemNode, aasRelElem);
                setAasReferenceData(aasRelElem.getFirst(), relElemNode.getFirstNode(), false);
                setAasReferenceData(aasRelElem.getSecond(), relElemNode.getSecondNode(), false);
                submodelElementAasMap.put(relElemNode.getFirstNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_FIRST, relElemRef));
                submodelElementAasMap.put(relElemNode.getSecondNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_SECOND, relElemRef));
                submodelElementOpcUAMap.put(relElemRef, relElemNode);
                if (ordered) {
                    node.addReference(relElemNode, Identifiers.HasOrderedComponent, false);
                } else {
                    node.addComponent(relElemNode);
                }
                referableMap.put(relElemRef, new ObjectData(aasRelElem, relElemNode, submodel));
            }
        }
    } catch (Exception ex) {
        LOG.error("addAasRelationshipElement Exception", ex);
        throw ex;
    }
}
Also used : 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) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) AASRelationshipElementType(opc.i4aas.AASRelationshipElementType) 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)

Aggregations

StatusException (com.prosysopc.ua.StatusException)39 ServiceException (com.prosysopc.ua.ServiceException)36 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)36 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)36 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)36 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)35 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)34 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)29 Reference (io.adminshell.aas.v3.model.Reference)29 LangString (io.adminshell.aas.v3.model.LangString)28 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)26 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)26 ArrayList (java.util.ArrayList)22 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)19 Test (org.junit.Test)19 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)16 IOException (java.io.IOException)15 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)12 UaClient (com.prosysopc.ua.client.UaClient)10 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)10