Search in sources :

Example 16 with Operation

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

the class AasServiceNodeManager method addAasCapability.

/**
 * Adds an AAS Capability to the given node.
 *
 * @param node The desired UA node
 * @param aasCapability The corresponding AAS Capability 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 capability should be added ordered
 *            (true) or unordered (false)
 * @throws StatusException If the operation fails
 */
private void addAasCapability(UaNode node, Capability aasCapability, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
    try {
        if ((node != null) && (aasCapability != null)) {
            String name = aasCapability.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASCapabilityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASCapabilityType capabilityNode = createInstance(AASCapabilityType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(capabilityNode, aasCapability);
            if (ordered) {
                node.addReference(capabilityNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(capabilityNode);
            }
            Reference capabilityRef = AasUtils.toReference(parentRef, aasCapability);
            referableMap.put(capabilityRef, new ObjectData(aasCapability, capabilityNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("addAasCapability 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) AASCapabilityType(opc.i4aas.AASCapabilityType) 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 17 with Operation

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

the class AasServiceNodeManager method setRelationshipValue.

/**
 * Sets the values for the given RelationshipElement.
 *
 * @param aasElement The desired RelationshipElement.
 * @param value The new value.
 * @throws StatusException If the operation fails
 */
private void setRelationshipValue(AASRelationshipElementType aasElement, RelationshipElementValue value) throws StatusException {
    if (aasElement == null) {
        throw new IllegalArgumentException("aasElement is null");
    } else if (value == null) {
        throw new IllegalArgumentException(VALUE_NULL);
    }
    try {
        Reference ref = new DefaultReference.Builder().keys(value.getFirst()).build();
        setAasReferenceData(ref, aasElement.getFirstNode(), false);
        ref = new DefaultReference.Builder().keys(value.getSecond()).build();
        setAasReferenceData(ref, aasElement.getSecondNode(), false);
        if ((aasElement instanceof AASAnnotatedRelationshipElementType) && (value instanceof AnnotatedRelationshipElementValue)) {
            AASAnnotatedRelationshipElementType annotatedElement = (AASAnnotatedRelationshipElementType) aasElement;
            AnnotatedRelationshipElementValue annotatedValue = (AnnotatedRelationshipElementValue) value;
            UaNode[] annotationNodes = annotatedElement.getAnnotationNode().getComponents();
            Map<String, DataElementValue> valueMap = annotatedValue.getAnnotations();
            if (annotationNodes.length != valueMap.size()) {
                LOG.warn("Size of Value ({}) doesn't match the number of AnnotationNodes ({})", valueMap.size(), annotationNodes.length);
                throw new IllegalArgumentException("Size of Value doesn't match the number of AnnotationNodes");
            }
            // The Key of the Map is the IDShort of the DataElement (in our case the BrowseName)
            for (UaNode annotationNode : annotationNodes) {
                if (valueMap.containsKey(annotationNode.getBrowseName().getName())) {
                    setDataElementValue(annotationNode, valueMap.get(annotationNode.getBrowseName().getName()));
                }
            }
        } else {
            LOG.info("setRelationshipValue: No AnnotatedRelationshipElement {}", aasElement.getBrowseName().getName());
        }
    } catch (Exception ex) {
        LOG.error("setAnnotatedRelationshipValue Exception", ex);
        throw ex;
    }
}
Also used : Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaNode(com.prosysopc.ua.nodes.UaNode) NodeManagerUaNode(com.prosysopc.ua.server.NodeManagerUaNode) MethodManagerUaNode(com.prosysopc.ua.server.MethodManagerUaNode) 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) AASAnnotatedRelationshipElementType(opc.i4aas.AASAnnotatedRelationshipElementType) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)

Example 18 with Operation

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

the class AasServiceNodeManager method setOperationArgument.

/**
 * Sets the arguments for the given Operation Variable.
 *
 * @param arg The UA argument
 * @param var The corresponding Operation Variable
 */
private void setOperationArgument(Argument arg, OperationVariable operVar) {
    try {
        if (operVar.getValue() instanceof Property) {
            Property prop = (Property) operVar.getValue();
            arg.setName(prop.getIdShort());
            arg.setValueRank(ValueRanks.Scalar);
            arg.setArrayDimensions(null);
            // Description
            addDescriptions(arg, prop.getDescriptions());
            NodeId type = ValueConverter.convertValueTypeStringToNodeId(prop.getValueType());
            if (type.isNullNodeId()) {
                LOG.warn("setOperationArgument: Property {}: Unknown type: {}", prop.getIdShort(), prop.getValueType());
                // Default type is String. That's what we receive from the AAS Service
                arg.setDataType(Identifiers.String);
            } else {
                arg.setDataType(type);
            }
        } else {
            LOG.warn("setOperationArgument: unknown Argument type");
        }
    } catch (Exception ex) {
        LOG.error("setOperationArgument Exception", ex);
        throw ex;
    }
}
Also used : NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) Property(io.adminshell.aas.v3.model.Property) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) 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 19 with Operation

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

the class AasServiceNodeManager method addEmbeddedDataSpecifications.

/**
 * Adds the references to the given Embedded Data Specifications.
 *
 * @param assetNode The desired node where the DataSpecifications should be added
 * @param list The list of the desired Data Specifications
 * @throws StatusException If the operation fails
 */
private void addEmbeddedDataSpecifications(AASAssetType assetNode, List<EmbeddedDataSpecification> list) throws StatusException {
    try {
        if ((list != null) && (!list.isEmpty())) {
            List<Reference> refList = new ArrayList<>();
            for (EmbeddedDataSpecification eds : list) {
                refList.add(eds.getDataSpecification());
            }
            AASReferenceList listNode = assetNode.getDataSpecificationNode();
            if (listNode == null) {
                addAasReferenceList(assetNode, refList, AASAssetType.DATA_SPECIFICATION);
            } else {
                addEmbeddedDataSpecificationsReferences(listNode, refList);
            }
        }
    } catch (Exception ex) {
        LOG.error(ADD_EMBED_DS_EXC, ex);
        throw ex;
    }
}
Also used : EmbeddedDataSpecification(io.adminshell.aas.v3.model.EmbeddedDataSpecification) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) ArrayList(java.util.ArrayList) AASReferenceList(opc.i4aas.AASReferenceList) 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 20 with Operation

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

the class AasServiceNodeManager method setReferenceElementValue.

/**
 * Sets the value for the given ReferenceElement.
 *
 * @param refElement The desired ReferenceElement.
 * @param value The new value.
 * @throws StatusException If the operation fails
 */
private void setReferenceElementValue(AASReferenceElementType refElement, ReferenceElementValue value) throws StatusException {
    if (refElement == null) {
        throw new IllegalArgumentException("refElement is null");
    } else if (value == null) {
        throw new IllegalArgumentException(VALUE_NULL);
    }
    try {
        DefaultReference ref = new DefaultReference.Builder().keys(value.getKeys()).build();
        setAasReferenceData(ref, refElement.getValueNode());
    } catch (Exception ex) {
        LOG.error("setReferenceElementValue Exception", ex);
        throw ex;
    }
}
Also used : DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) 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

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