Search in sources :

Example 21 with StatusException

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

the class OpcUaEndpointFullTest method testCallOperationArgsMissing.

/**
 * Test method for calling an operation with not enough arguments.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws MethodCallStatusException If the operation fails
 */
@Test
public void testCallOperationArgsMissing() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, MethodCallStatusException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    int serverns = client.getAddressSpace().getNamespaceTable().getIndex(AasServiceNodeManager.NAMESPACE_URI);
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_3_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_3_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(serverns, TestDefines.FULL_OPERATION_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testCallOperationArgsMissing Browse Result Null", bpres);
    Assert.assertEquals("testCallOperationArgsMissing Browse Result: size doesn't match", 2, bpres.length);
    Assert.assertTrue("testCallOperationArgsMissing Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testCallOperationArgsMissing Object Targets Null", targets);
    Assert.assertTrue("testCallOperationArgsMissing Object Targets empty", targets.length > 0);
    NodeId objectNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testCallOperationArgsMissing objectNode Null", objectNode);
    targets = bpres[1].getTargets();
    Assert.assertNotNull("testCallOperationArgsMissing Method Targets Null", targets);
    Assert.assertTrue("testCallOperationArgsMissing Method Targets empty", targets.length > 0);
    NodeId methodNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testCallOperationArgsMissing methodNode Null", methodNode);
    Variant[] inputArguments = new Variant[0];
    StatusException exception = Assert.assertThrows(StatusException.class, () -> {
        client.call(objectNode, methodNode, inputArguments);
    });
    Assert.assertEquals(StatusCodes.Bad_ArgumentsMissing, exception.getStatusCode().getValue());
    System.out.println("disconnect client");
    client.disconnect();
}
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) UaClient(com.prosysopc.ua.client.UaClient) Variant(com.prosysopc.ua.stack.builtintypes.Variant) MethodCallStatusException(com.prosysopc.ua.MethodCallStatusException) StatusException(com.prosysopc.ua.StatusException) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 22 with StatusException

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

the class ValueConverter method setOutputArguments.

/**
 * Sets the output arguments for an operation from the given output variables.
 *
 * @param outputVariables The desired output variables
 * @param outputArguments The desired output arguments
 * @throws StatusException If the operation fails
 */
public static void setOutputArguments(List<OperationVariable> outputVariables, Variant[] outputArguments) throws StatusException {
    if (outputArguments.length != outputVariables.size()) {
        throw new StatusException(StatusCodes.Bad_InvalidArgument);
    } else {
        for (int i = 0; i < outputVariables.size(); i++) {
            SubmodelElement smelem = outputVariables.get(i).getValue();
            SubmodelElementData.Type type;
            if (smelem instanceof Property) {
                type = SubmodelElementData.Type.PROPERTY_VALUE;
            } else {
                throw new StatusException(StatusCodes.Bad_InvalidArgument);
            }
            outputArguments[i] = getSubmodelElementValue(smelem, type);
        }
    }
}
Also used : StatusException(com.prosysopc.ua.StatusException) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Property(io.adminshell.aas.v3.model.Property) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 23 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 submodelElementNode The desired object where the
 *            DataSpecifications should be added
 * @param list The list of the desired Data Specifications
 * @throws StatusException If the operation fails
 */
private void addEmbeddedDataSpecifications(AASSubmodelElementType submodelElementNode, 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 = submodelElementNode.getDataSpecificationNode();
            if (listNode == null) {
                addAasReferenceList(submodelElementNode, refList, AASSubmodelElementType.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 24 with StatusException

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

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

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