Search in sources :

Example 71 with QualifiedName

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

the class AasServiceNodeManager method addQualifier.

/**
 * Creates and adds a Qualifier to the given Node.
 *
 * @param node The UA node in which the Qualifier should be created
 * @param qualifier The desired Qualifier
 * @param name The name of the qualifier
 */
private void addQualifier(UaNode node, Qualifier qualifier, String name) throws StatusException {
    if (node == null) {
        throw new IllegalArgumentException(NODE_NULL);
    } else if (qualifier == null) {
        throw new IllegalArgumentException("qualifier = null");
    }
    try {
        LOG.info("addQualifier {}; to Node: {}", name, node);
        QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASQualifierType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
        NodeId nid = createNodeId(node, browseName);
        AASQualifierType qualifierNode = createInstance(AASQualifierType.class, nid, browseName, LocalizedText.english(name));
        // Type
        qualifierNode.setType(qualifier.getType());
        // ValueType
        qualifierNode.setValueType(ValueConverter.stringToValueType(qualifier.getValueType()));
        // Value
        if (qualifier.getValue() != null) {
            if (qualifierNode.getValueNode() == null) {
                addQualifierValueNode(qualifierNode);
            }
            qualifierNode.setValue(qualifier.getValue());
        }
        // ValueId
        if (qualifier.getValueId() != null) {
            addAasReferenceAasNS(qualifierNode, qualifier.getValueId(), AASQualifierType.VALUE_ID);
        }
        if (VALUES_READ_ONLY) {
            if (qualifierNode.getValueNode() != null) {
                qualifierNode.getValueNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
            if (qualifierNode.getValueTypeNode() != null) {
                qualifierNode.getValueTypeNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
            if (qualifierNode.getTypeNode() != null) {
                qualifierNode.getTypeNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
        }
        node.addComponent(qualifierNode);
    } catch (Exception ex) {
        LOG.error("addQualifier Exception", ex);
        throw ex;
    }
}
Also used : AASQualifierType(opc.i4aas.AASQualifierType) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) 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 72 with QualifiedName

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

the class AasServiceNodeManager method addAssetAdministrationShell.

/**
 * Adds the given AssetAdministrationShell.
 *
 * @throws StatusException If the operation fails
 */
private void addAssetAdministrationShell(AssetAdministrationShell aas) throws StatusException {
    try {
        TypeDefinitionBasedNodeBuilderConfiguration.Builder conf = TypeDefinitionBasedNodeBuilderConfiguration.builder();
        Reference derivedFrom = aas.getDerivedFrom();
        if (derivedFrom != null) {
            UaBrowsePath bp = UaBrowsePath.from(opc.i4aas.ObjectTypeIds.AASAssetAdministrationShellType, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASAssetAdministrationShellType.getNamespaceUri(), AASAssetAdministrationShellType.DERIVED_FROM));
            conf.addOptional(bp);
        }
        this.setNodeBuilderConfiguration(conf.build());
        QualifiedName browseName = UaQualifiedName.from(NAMESPACE_URI, aas.getIdShort()).toQualifiedName(getNamespaceTable());
        String displayName = "AAS:" + aas.getIdShort();
        NodeId nid = new NodeId(getNamespaceIndex(), aas.getIdShort());
        if (findNode(nid) != null) {
            // The NodeId already exists
            nid = getDefaultNodeId();
        }
        AASAssetAdministrationShellType aasShell = createInstance(AASAssetAdministrationShellTypeNode.class, nid, browseName, LocalizedText.english(displayName));
        addIdentifiable(aasShell, aas.getIdentification(), aas.getAdministration(), aas.getCategory());
        // DataSpecifications
        addEmbeddedDataSpecifications(aasShell, aas.getEmbeddedDataSpecifications());
        // AssetInformation
        AssetInformation assetInformation = aas.getAssetInformation();
        if (assetInformation != null) {
            addAssetInformation(aasShell, assetInformation);
        }
        // submodel references
        List<Reference> submodelRefs = aas.getSubmodels();
        if ((submodelRefs != null) && (!submodelRefs.isEmpty())) {
            addSubmodelReferences(aasShell, submodelRefs);
        }
        // add AAS to Environment
        addNodeAndReference(aasEnvironmentNode, aasShell, Identifiers.Organizes);
        referableMap.put(AasUtils.toReference(aas), new ObjectData(aas, aasShell));
    } catch (Exception ex) {
        LOG.error("addAssetAdministrationShell Exception", ex);
        throw ex;
    }
}
Also used : AssetInformation(io.adminshell.aas.v3.model.AssetInformation) AASAssetAdministrationShellType(opc.i4aas.AASAssetAdministrationShellType) 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) TypeDefinitionBasedNodeBuilderConfiguration(com.prosysopc.ua.server.instantiation.TypeDefinitionBasedNodeBuilderConfiguration) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) UaBrowsePath(com.prosysopc.ua.UaBrowsePath) 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 73 with QualifiedName

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

the class AasServiceNodeManager method addAasReferenceElement.

/**
 * Adds an AAS reference element to the given node.
 *
 * @param node The desired UA node
 * @param aasRefElem The AAS reference element 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 reference element should be added
 *            ordered (true) or unordered (false)
 * @throws StatusException If the operation fails
 */
private void addAasReferenceElement(UaNode node, ReferenceElement aasRefElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
    try {
        if ((node != null) && (aasRefElem != null)) {
            String name = aasRefElem.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASReferenceElementType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASReferenceElementType refElemNode = createInstance(AASReferenceElementType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(refElemNode, aasRefElem);
            if (aasRefElem.getValue() != null) {
                setAasReferenceData(aasRefElem.getValue(), refElemNode.getValueNode(), false);
            }
            Reference refElemRef = AasUtils.toReference(parentRef, aasRefElem);
            submodelElementAasMap.put(refElemNode.getValueNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRefElem, submodel, SubmodelElementData.Type.REFERENCE_ELEMENT_VALUE, refElemRef));
            submodelElementOpcUAMap.put(refElemRef, refElemNode);
            if (ordered) {
                node.addReference(refElemNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(refElemNode);
            }
            referableMap.put(refElemRef, new ObjectData(aasRefElem, refElemNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("addAasReferenceElement 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) AASReferenceElementType(opc.i4aas.AASReferenceElementType) 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 74 with QualifiedName

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

the class AasServiceNodeManager method setPropertyValueAndType.

/**
 * Adds the OPC UA property itself to the given Property object and sets the value.
 *
 * @param aasProperty The AAS property
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param prop The UA Property object
 * @param propRef The AAS reference to the property
 */
@SuppressWarnings("java:S125")
private void setPropertyValueAndType(Property aasProperty, Submodel submodel, AASPropertyType prop, Reference propRef) {
    try {
        NodeId myPropertyId = new NodeId(getNamespaceIndex(), prop.getNodeId().getValue().toString() + "." + AASPropertyType.VALUE);
        QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASPropertyType.getNamespaceUri(), AASPropertyType.VALUE).toQualifiedName(getNamespaceTable());
        LocalizedText displayName = LocalizedText.english(AASPropertyType.VALUE);
        submodelElementAasMap.put(myPropertyId, new SubmodelElementData(aasProperty, submodel, SubmodelElementData.Type.PROPERTY_VALUE, propRef));
        LOG.debug("setPropertyValueAndType: NodeId {}; Property: {}", myPropertyId, aasProperty);
        if (submodel != null) {
            submodelElementOpcUAMap.put(propRef, prop);
        }
        AASValueTypeDataType valueDataType;
        PropertyValue typedValue = PropertyValue.of(aasProperty.getValueType(), aasProperty.getValue());
        if ((typedValue != null) && (typedValue.getValue() != null)) {
            valueDataType = ValueConverter.datatypeToValueType(typedValue.getValue().getDataType());
        } else {
            valueDataType = ValueConverter.stringToValueType(aasProperty.getValueType());
        }
        prop.setValueType(valueDataType);
        switch(valueDataType) {
            // 
            case Boolean:
                PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myBoolProperty.setDataTypeId(Identifiers.Boolean);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    myBoolProperty.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(myBoolProperty);
                break;
            // 
            case Int32:
                PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myIntProperty.setDataTypeId(Identifiers.Int32);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    myIntProperty.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(myIntProperty);
                break;
            // 
            case Int64:
                PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myLongProperty.setDataTypeId(Identifiers.Int64);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    Object obj = typedValue.getValue().getValue();
                    if (!(obj instanceof Long)) {
                        obj = Long.parseLong(obj.toString());
                    }
                    myLongProperty.setValue(obj);
                }
                prop.addProperty(myLongProperty);
                break;
            // 
            case Int16:
                PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myInt16Property.setDataTypeId(Identifiers.Int16);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    myInt16Property.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(myInt16Property);
                break;
            // 
            case SByte:
                PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                mySByteProperty.setDataTypeId(Identifiers.SByte);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    mySByteProperty.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(mySByteProperty);
                break;
            case Double:
                PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myDoubleProperty.setDataTypeId(Identifiers.Double);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    myDoubleProperty.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(myDoubleProperty);
                break;
            case Float:
                PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myFloatProperty.setDataTypeId(Identifiers.Float);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    myFloatProperty.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(myFloatProperty);
                break;
            // 
            case String:
                PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myStringProperty.setDataTypeId(Identifiers.String);
                if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
                    myStringProperty.setValue(typedValue.getValue().getValue());
                }
                prop.addProperty(myStringProperty);
                break;
            // 
            default:
                LOG.warn("setValueAndType: Property {}: Unknown type: {}; use string as default", prop.getBrowseName().getName(), aasProperty.getValueType());
                PlainProperty<String> myDefaultProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
                myDefaultProperty.setDataTypeId(Identifiers.String);
                myDefaultProperty.setValue(aasProperty.getValue());
                prop.addProperty(myDefaultProperty);
                break;
        }
        if ((prop.getValueNode() != null) && (prop.getValueNode().getDescription() == null)) {
            prop.getValueNode().setDescription(new LocalizedText("", ""));
        }
    } catch (Exception ex) {
        LOG.error("setPropertyValueAndType Exception", ex);
    }
}
Also used : ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) AASValueTypeDataType(opc.i4aas.AASValueTypeDataType) PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue) 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) UnsignedInteger(com.prosysopc.ua.stack.builtintypes.UnsignedInteger) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaObject(com.prosysopc.ua.nodes.UaObject) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Aggregations

QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)74 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)60 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)46 ArrayList (java.util.ArrayList)46 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)45 RelativePath (com.prosysopc.ua.stack.core.RelativePath)45 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)40 StatusException (com.prosysopc.ua.StatusException)29 ServiceException (com.prosysopc.ua.ServiceException)28 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)28 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)28 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)27 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)26 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)26 Test (org.junit.Test)26 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)24 Reference (io.adminshell.aas.v3.model.Reference)19