Search in sources :

Example 1 with ObjectData

use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData 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
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private void addAasBlob(UaNode node, Blob aasBlob, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    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));
                logger.debug("addAasBlob: NodeId " + blobNode.getValueNode().getNodeId() + "; Blob: " + 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 (Throwable ex) {
        logger.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) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 2 with ObjectData

use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData 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);
            }
        }
        logger.info("addAasProperty: add Property " + nid.toString());
        if (ordered) {
            node.addReference(prop, Identifiers.HasOrderedComponent, false);
        } else {
            node.addComponent(prop);
        }
        referableMap.put(propRef, new ObjectData(aasProperty, prop, submodel));
    } catch (Throwable ex) {
        logger.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)

Example 3 with ObjectData

use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData 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));
        logger.debug("addAasOperation: NodeId " + nid + "; Property: " + 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 (Throwable ex) {
        logger.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) 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 4 with ObjectData

use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData 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
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private void addAasRelationshipElement(UaNode node, RelationshipElement aasRelElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    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 (Throwable ex) {
        logger.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) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 5 with ObjectData

use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData 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
 */
private void elementCreated(Reference element, Referable value) throws StatusException, ServiceResultException, ServiceException, AddressSpaceException {
    if (element == null) {
        throw new IllegalArgumentException("element is null");
    } else if (value == null) {
        throw new IllegalArgumentException("value is null");
    }
    try {
        logger.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 {
            logger.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 {
                    logger.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 {
                    logger.warn("elementCreated: Constraint parent class not found");
                }
            } else if (value instanceof SubmodelElement) {
                if (parent.getNode() instanceof AASSubmodelType) {
                    logger.info("elementCreated: call addSubmodelElements");
                    addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), (Submodel) parent.getReferable(), element);
                } else if (parent.getNode() instanceof AASSubmodelElementType) {
                    logger.info("elementCreated: call addSubmodelElements");
                    addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), parent.getSubmodel(), element);
                } else {
                    logger.warn("elementCreated: SubmodelElement parent class not found: " + parent.getNode().getNodeId().toString() + "; " + parent.getNode());
                }
            }
        } else {
            logger.warn("elementCreated: element not found: " + AasUtils.asString(element));
        }
    } catch (Throwable ex) {
        logger.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) 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

ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)19 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)16 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)16 LangString (io.adminshell.aas.v3.model.LangString)16 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)15 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)15 Reference (io.adminshell.aas.v3.model.Reference)15 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)15 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)6 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)3 Constraint (io.adminshell.aas.v3.model.Constraint)3 MethodManagerUaNode (com.prosysopc.ua.server.MethodManagerUaNode)2 ConceptDescription (io.adminshell.aas.v3.model.ConceptDescription)2 AASAssetAdministrationShellType (opc.i4aas.AASAssetAdministrationShellType)2 AASAssetType (opc.i4aas.AASAssetType)2 AASSubmodelElementType (opc.i4aas.AASSubmodelElementType)2 AASSubmodelType (opc.i4aas.AASSubmodelType)2 UaBrowsePath (com.prosysopc.ua.UaBrowsePath)1 UaNode (com.prosysopc.ua.nodes.UaNode)1 NodeManagerUaNode (com.prosysopc.ua.server.NodeManagerUaNode)1