Search in sources :

Example 56 with NodeId

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

the class TestUtils method checkBillOfMaterialNode.

/**
 * Searches for the BillOfMaterial 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
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
public static void checkBillOfMaterialNode(UaClient client, NodeId node, int aasns) throws ServiceException, AddressSpaceException, ServiceResultException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.BILL_OF_MATERIAL_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkBillOfMaterialNode Browse Result Null", bpres);
    Assert.assertTrue("checkBillOfMaterialNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkBillOfMaterialNode Node Targets Null", targets);
    Assert.assertTrue("checkBillOfMaterialNode Node targets empty", targets.length > 0);
    // Currently we only check that the NodeId is not null and we have the correct type
    NodeId billNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertFalse("checkBillOfMaterialNode Node not found", NodeId.isNull(billNode));
    checkType(client, billNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_LIST_ID));
}
Also used : 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) 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 57 with NodeId

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

the class TestUtils method checkIdentification.

/**
 * Checks the Identification values in the given node.
 *
 * @param client The OPC UA Client.
 * @param identificationNode the desired Identification Node.
 * @param aasns The namespace index of the AAS namespace.
 * @param idType The expected IdType
 * @param id The expected ID
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private static void checkIdentification(UaClient client, NodeId identificationNode, int aasns, AASIdentifierTypeDataType idType, String id) throws ServiceException, StatusException, AddressSpaceException, ServiceResultException {
    checkType(client, identificationNode, new NodeId(aasns, TestDefines.AAS_IDENTIFIER_TYPE_ID));
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "IdType")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "Id")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(identificationNode, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkIdentification Browse Result Null", bpres);
    Assert.assertTrue("checkIdentification Browse Result: size doesn't match", bpres.length == 2);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkIdentification IdType Null", targets);
    Assert.assertTrue("checkIdentification IdType empty", targets.length > 0);
    DataValue value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(idType.ordinal(), value.getValue().intValue());
    targets = bpres[1].getTargets();
    Assert.assertNotNull("checkIdentification Id Null", targets);
    Assert.assertTrue("checkIdentification Id empty", targets.length > 0);
    value = client.readValue(targets[0].getTargetId());
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertEquals(id, value.getValue().toString());
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ExpandedNodeId(com.prosysopc.ua.stack.builtintypes.ExpandedNodeId) ArrayList(java.util.ArrayList) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget)

Example 58 with NodeId

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

the class TestUtils method checkDataSpecificationNode.

/**
 * Searches for the DataSpecification 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
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
public static void checkDataSpecificationNode(UaClient client, NodeId node, int aasns) throws ServiceException, ServiceResultException, AddressSpaceException {
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.DATA_SPECIFICATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("checkDataSpecificationNode Browse Result Null", bpres);
    Assert.assertTrue("checkDataSpecificationNode Browse Result: size doesn't match", bpres.length == 1);
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("checkDataSpecificationNode Node Targets Null", targets);
    Assert.assertTrue("checkDataSpecificationNode Node targets empty", targets.length > 0);
    // Currently we only check that the NodeId is not null and we have the correct type
    NodeId dataSpecNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertFalse("checkDataSpecificationNode Node not found", NodeId.isNull(dataSpecNode));
    checkType(client, dataSpecNode, new NodeId(aasns, TestDefines.AAS_REFERENCE_LIST_ID));
}
Also used : 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) 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 59 with NodeId

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

the class AasServiceNodeManager method addAsset.

/**
 * Adds an Asset to the given Node.
 *
 * @param node The UA node in which the Asset should be created
 * @param asset The desired Asset
 * @throws StatusException If the operation fails
 */
private void addAsset(UaNode node, Asset asset) throws StatusException {
    if (node == null) {
        throw new IllegalArgumentException(NODE_NULL);
    } else if (asset == null) {
        throw new IllegalArgumentException("asset = null");
    }
    try {
        String name = asset.getIdShort();
        String displayName = "Asset:" + name;
        LOG.info("addAsset {}; to Node: {}", name, node);
        QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASAssetType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
        NodeId nid = createNodeId(node, browseName);
        AASAssetType assetNode = createInstance(AASAssetType.class, nid, browseName, LocalizedText.english(displayName));
        addIdentifiable(assetNode, asset.getIdentification(), asset.getAdministration(), asset.getCategory());
        // DataSpecifications
        addEmbeddedDataSpecifications(assetNode, asset.getEmbeddedDataSpecifications());
        node.addComponent(assetNode);
        referableMap.put(AasUtils.toReference(asset), new ObjectData(asset, assetNode));
    } catch (Exception ex) {
        LOG.error("addAsset Exception", ex);
        throw ex;
    }
}
Also used : AASAssetType(opc.i4aas.AASAssetType) 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) 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 60 with NodeId

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

the class AasServiceNodeManager method addAasSubmodelElementCollection.

/**
 * Adds a SubmodelElementCollection to the given node.
 *
 * @param node The desired UA node
 * @param aasColl The corresponding SubmodelElementCollection 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 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 addAasSubmodelElementCollection(UaNode node, SubmodelElementCollection aasColl, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasColl != null)) {
            String name = aasColl.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASSubmodelElementCollectionType collNode;
            if (aasColl.getOrdered()) {
                collNode = createAasOrderedSubmodelElementCollection(name, nid);
            } else {
                collNode = createInstance(AASSubmodelElementCollectionType.class, nid, browseName, LocalizedText.english(name));
            }
            addSubmodelElementBaseData(collNode, aasColl);
            // AllowDuplicates
            if (collNode.getAllowDuplicatesNode() == null) {
                NodeId myPropertyId = new NodeId(getNamespaceIndex(), collNode.getNodeId().getValue().toString() + "." + AASSubmodelElementCollectionType.ALLOW_DUPLICATES);
                PlainProperty<Boolean> myProperty = new PlainProperty<>(this, myPropertyId, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), AASSubmodelElementCollectionType.ALLOW_DUPLICATES).toQualifiedName(getNamespaceTable()), LocalizedText.english(AASSubmodelElementCollectionType.ALLOW_DUPLICATES));
                myProperty.setDataTypeId(Identifiers.Boolean);
                myProperty.setDescription(new LocalizedText("", ""));
                if (VALUES_READ_ONLY) {
                    myProperty.setAccessLevel(AccessLevelType.CurrentRead);
                }
                collNode.addProperty(myProperty);
            }
            collNode.setAllowDuplicates(aasColl.getAllowDuplicates());
            Reference collRef = AasUtils.toReference(parentRef, aasColl);
            // SubmodelElements
            addSubmodelElements(collNode, aasColl.getValues(), submodel, collRef, aasColl.getOrdered());
            if (ordered) {
                node.addReference(collNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(collNode);
            }
            referableMap.put(collRef, new ObjectData(aasColl, collNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("createAasSubmodelElementCollection Exception", ex);
        throw ex;
    }
}
Also used : PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) 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) AASSubmodelElementCollectionType(opc.i4aas.AASSubmodelElementCollectionType) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) 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

NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)79 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)59 StatusException (com.prosysopc.ua.StatusException)37 ServiceException (com.prosysopc.ua.ServiceException)35 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)35 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)35 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)35 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)35 ArrayList (java.util.ArrayList)33 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)32 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)32 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)31 RelativePath (com.prosysopc.ua.stack.core.RelativePath)31 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)29 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)19 Test (org.junit.Test)19 Reference (io.adminshell.aas.v3.model.Reference)17 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)17