Search in sources :

Example 6 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId 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 7 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addAasProperty.

/**
 * Adds an AAS property the given node.
 *
 * @param node The desired node
 * @param aasProperty The corresponding AAS property to add
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param parentRef The AAS reference to the parent node
 * @param ordered Specifies whether the property should be added ordered
 *            (true) or unordered (false)
 */
private void addAasProperty(UaNode node, Property aasProperty, Submodel submodel, Reference parentRef, boolean ordered) {
    try {
        String name = aasProperty.getIdShort();
        QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASPropertyType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
        NodeId nid = getDefaultNodeId();
        AASPropertyType prop = createInstance(AASPropertyType.class, nid, browseName, LocalizedText.english(name));
        addSubmodelElementBaseData(prop, aasProperty);
        Reference propRef = AasUtils.toReference(parentRef, aasProperty);
        // ValueId
        Reference ref = aasProperty.getValueId();
        if (ref != null) {
            addAasReferenceAasNS(prop, ref, AASPropertyType.VALUE_ID);
        }
        // here Value and ValueType are set
        setPropertyValueAndType(aasProperty, submodel, prop, propRef);
        if (VALUES_READ_ONLY) {
            // ValueType read-only
            prop.getValueTypeNode().setAccessLevel(AccessLevelType.CurrentRead);
            // if the Submodel is null, we also make the value read-only
            if ((submodel == null) && (prop.getValueNode() != null)) {
                prop.getValueNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
        }
        LOG.info("addAasProperty: add Property {}", nid);
        if (ordered) {
            node.addReference(prop, Identifiers.HasOrderedComponent, false);
        } else {
            node.addComponent(prop);
        }
        referableMap.put(propRef, new ObjectData(aasProperty, prop, submodel));
    } catch (Exception ex) {
        LOG.error("addAasProperty Exception", 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) AASPropertyType(opc.i4aas.AASPropertyType) 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 8 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId 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 9 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId 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 10 with NodeId

use of com.prosysopc.ua.stack.builtintypes.NodeId 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)

Aggregations

NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)79 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)59 StatusException (com.prosysopc.ua.StatusException)37 ServiceException (com.prosysopc.ua.ServiceException)35 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)35 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)35 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)35 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)35 ArrayList (java.util.ArrayList)33 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)32 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)32 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)31 RelativePath (com.prosysopc.ua.stack.core.RelativePath)31 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)29 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)19 Test (org.junit.Test)19 Reference (io.adminshell.aas.v3.model.Reference)17 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)17