Search in sources :

Example 11 with StatusException

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

Example 12 with StatusException

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

the class AasServiceNodeManager method setPropertyValue.

/**
 * Sets the value of a property.
 *
 * @param property The desired Property
 * @param value The new value.
 * @throws StatusException If the operation fails.
 */
@SuppressWarnings("java:S125")
private void setPropertyValue(AASPropertyType property, PropertyValue value) throws StatusException {
    if (property == null) {
        throw new IllegalArgumentException("property is null");
    } else if (value == null) {
        throw new IllegalArgumentException(VALUE_NULL);
    }
    LOG.debug("setPropertyValue: {} to {}", property.getBrowseName().getName(), value.getValue());
    try {
        // special treatment for some not directly supported types
        TypedValue<?> tv = value.getValue();
        Object obj = tv.getValue();
        if ((tv instanceof DecimalValue) || (tv instanceof IntegerValue)) {
            obj = Long.parseLong(obj.toString());
        }
        property.setValue(obj);
    // switch (property.getValueType()) {
    // case ByteString:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Boolean:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case DateTime:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Int32:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UInt32:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Int64:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UInt64:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Int16:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UInt16:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Byte:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case SByte:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Double:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Float:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case LocalizedText:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case String:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UtcTime:
    // // TO DO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // default:
    // logger.warn("setPropertyValue: Property " + property.getBrowseName().getName() + ": Unknown type: " + property.getValueType());
    // break;
    // }
    } catch (Exception ex) {
        LOG.error("setPropertyValue Exception", ex);
        throw ex;
    }
}
Also used : DecimalValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DecimalValue) IntegerValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.IntegerValue) UaObject(com.prosysopc.ua.nodes.UaObject) 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 13 with StatusException

use of com.prosysopc.ua.StatusException 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 14 with StatusException

use of com.prosysopc.ua.StatusException 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 15 with StatusException

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

Aggregations

StatusException (com.prosysopc.ua.StatusException)47 ServiceException (com.prosysopc.ua.ServiceException)43 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)43 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)43 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)42 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)41 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)27 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)26 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)25 Reference (io.adminshell.aas.v3.model.Reference)25 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)24 LangString (io.adminshell.aas.v3.model.LangString)24 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)23 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)18 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)9 ArrayList (java.util.ArrayList)9 Constraint (io.adminshell.aas.v3.model.Constraint)8 UaNode (com.prosysopc.ua.nodes.UaNode)7 MethodManagerUaNode (com.prosysopc.ua.server.MethodManagerUaNode)7 NodeManagerUaNode (com.prosysopc.ua.server.NodeManagerUaNode)7