Search in sources :

Example 1 with UaNode

use of com.prosysopc.ua.nodes.UaNode 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 is 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()) {
                logger.warn("Size of Value (" + valueMap.size() + ") doesn't match the number of AnnotationNodes (" + 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 {
            logger.info("setRelationshipValue: No AnnotatedRelationshipElement " + aasElement.getBrowseName().getName());
        }
    } catch (Throwable ex) {
        logger.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) 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 2 with UaNode

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

the class TestUtils method checkQualifierNode.

/**
 * Searches for the Qualifier Node in the given Node.
 *
 * @param client The OPC UA client
 * @param node The desired node
 * @param aasns The namespace index of the AAS namespace
 * @param qualifierList The list of qualifiers
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws StatusException If the operation fails
 */
public static void checkQualifierNode(UaClient client, NodeId node, int aasns, List<Qualifier> qualifierList) throws ServiceException, ServiceResultException, AddressSpaceException, StatusException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.QUALIFIER_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkQualifierNode Browse Result Null", bpres);
    Assert.assertTrue("checkQualifierNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkQualifierNode Node Targets Null", targets);
    Assert.assertTrue("checkQualifierNode Node targets empty", targets.length > 0);
    // Currently we only check that the NodeId is not null and we have the correct type
    NodeId qualNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertFalse("checkQualifierNode Node not found", NodeId.isNull(qualNode));
    checkType(client, qualNode, new NodeId(aasns, TestDefines.AAS_QUALIFIER_LIST_ID));
    List<AASQualifierType> nodeList = new ArrayList<>();
    List<ReferenceDescription> refs = client.getAddressSpace().browse(qualNode);
    for (ReferenceDescription ref : refs) {
        NodeId nid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
        checkType(client, nid, new NodeId(aasns, TestDefines.AAS_QUALIFIER_TYPE_ID));
        UaNode qnode = client.getAddressSpace().getNode(nid);
        if (qnode instanceof AASQualifierType) {
            nodeList.add((AASQualifierType) qnode);
        }
    }
    checkQualifierList(qualifierList, nodeList);
// Assert.assertArrayEquals(qualifierList.toArray(), nodeList.toArray());
}
Also used : AASQualifierType(opc.i4aas.AASQualifierType) RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaNode(com.prosysopc.ua.nodes.UaNode) ReferenceDescription(com.prosysopc.ua.stack.core.ReferenceDescription) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 3 with UaNode

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

the class TestUtils method checkType.

/**
 * Checks if the given Node is of the desired type.
 *
 * @param client The OPC UA Client
 * @param node The desired Node
 * @param typeNode The expected type.
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
public static void checkType(UaClient client, NodeId node, NodeId typeNode) throws ServiceException, AddressSpaceException, ServiceResultException {
    UaNode uanode = client.getAddressSpace().getNode(node);
    Assert.assertNotNull("checkType UaNode Null", uanode);
    UaReference ref = uanode.getReference(Identifiers.HasTypeDefinition, false);
    Assert.assertNotNull("checkType Reference Null", ref);
    NodeId refId = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getTargetId());
    Assert.assertEquals("type not equal", typeNode, refId);
}
Also used : NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) UaNode(com.prosysopc.ua.nodes.UaNode) UaReference(com.prosysopc.ua.nodes.UaReference)

Example 4 with UaNode

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

the class TestUtils method checkBrowseName.

/**
 * Checks the Browse Name of the given Node.
 *
 * @param client The OPC UA Client
 * @param nodeId The NodeId of the desired Node.
 * @param desiredName The desired Browse Name.
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
public static void checkBrowseName(UaClient client, NodeId nodeId, String desiredName) throws ServiceException, AddressSpaceException {
    UaNode node = client.getAddressSpace().getNode(nodeId);
    Assert.assertNotNull("Node is null: " + desiredName, node);
    checkBrowseName(node, desiredName);
}
Also used : UaNode(com.prosysopc.ua.nodes.UaNode)

Example 5 with UaNode

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

the class AasServiceNodeManager method setEntityValue.

/**
 * Sets the values for the given Entity.
 *
 * @param entity The desired Entity.
 * @param value The new value.
 * @throws StatusException If the operation fails
 */
private void setEntityValue(AASEntityType entity, EntityValue value) throws StatusException {
    if (entity == null) {
        throw new IllegalArgumentException("entity is null");
    } else if (value == null) {
        throw new IllegalArgumentException("value is null");
    }
    try {
        // EntityType
        entity.setEntityType(ValueConverter.getAasEntityType(value.getEntityType()));
        // GlobalAssetId
        if ((value.getGlobalAssetId() != null) && (value.getGlobalAssetId().size() > 0)) {
            DefaultReference ref = new DefaultReference.Builder().keys(value.getGlobalAssetId()).build();
            setAasReferenceData(ref, entity.getGlobalAssetIdNode());
        }
        // Statements
        Map<String, ElementValue> valueMap = value.getStatements();
        AASSubmodelElementList statementNode = entity.getStatementNode();
        if (statementNode != null) {
            UaNode[] statementNodes = statementNode.getComponents();
            if (statementNodes.length != valueMap.size()) {
                logger.warn("Size of Value (" + valueMap.size() + ") doesn't match the number of StatementNodes (" + statementNodes.length + ")");
                throw new IllegalArgumentException("Size of Value doesn't match the number of StatementNodes");
            }
            for (UaNode statementNode1 : statementNodes) {
                if (statementNode1 instanceof AASSubmodelElementType) {
                    if (value.getStatements().containsKey(statementNode1.getBrowseName().getName())) {
                        setSubmodelElementValue((AASSubmodelElementType) statementNode1, value.getStatements().get(statementNode1.getBrowseName().getName()));
                    }
                }
            }
        }
    } catch (Throwable ex) {
        logger.error("setEntityValue Exception", ex);
        throw ex;
    }
}
Also used : AASSubmodelElementList(opc.i4aas.AASSubmodelElementList) AASSubmodelElementType(opc.i4aas.AASSubmodelElementType) 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) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference)

Aggregations

UaNode (com.prosysopc.ua.nodes.UaNode)9 MethodManagerUaNode (com.prosysopc.ua.server.MethodManagerUaNode)5 NodeManagerUaNode (com.prosysopc.ua.server.NodeManagerUaNode)5 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)5 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)4 LangString (io.adminshell.aas.v3.model.LangString)4 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)2 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)2 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)2 DataElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)2 Reference (io.adminshell.aas.v3.model.Reference)2 UaReference (com.prosysopc.ua.nodes.UaReference)1 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)1 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)1 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)1 ReferenceDescription (com.prosysopc.ua.stack.core.ReferenceDescription)1 RelativePath (com.prosysopc.ua.stack.core.RelativePath)1 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)1