Search in sources :

Example 31 with StatusException

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

the class AasServiceNodeManager method addAasReference.

/**
 * Adds an AAS Reference to the given node with the given namespace.
 *
 * @param node The node in which the object is created
 * @param ref The desired AAS reference object to add
 * @param name The desired name
 * @param namespaceUri The desired namespace URI tu use
 * @param readOnly True if the value should be read-only
 * @return The created node
 * @throws StatusException If the operation fails
 */
private UaNode addAasReference(UaNode node, Reference ref, String name, String namespaceUri, boolean readOnly) throws StatusException {
    UaNode retval = null;
    try {
        if (ref != null) {
            QualifiedName browseName = UaQualifiedName.from(namespaceUri, name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASReferenceType nodeRef = createInstance(AASReferenceType.class, nid, browseName, LocalizedText.english(name));
            LOG.debug("addAasReference: add Node {} to Node {}", nid, node.getNodeId());
            setAasReferenceData(ref, nodeRef, readOnly);
            node.addComponent(nodeRef);
            retval = nodeRef;
        }
    } catch (Exception ex) {
        LOG.error("addAasReference Exception", ex);
        throw ex;
    }
    return retval;
}
Also used : AASReferenceType(opc.i4aas.AASReferenceType) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaNode(com.prosysopc.ua.nodes.UaNode) NodeManagerUaNode(com.prosysopc.ua.server.NodeManagerUaNode) MethodManagerUaNode(com.prosysopc.ua.server.MethodManagerUaNode) 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 32 with StatusException

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

the class AasServiceNodeManager method setRangeValue.

/**
 * Sets the value for the given Range.
 *
 * @param range The desired Range.
 * @param value The new value
 * @throws StatusException If the operation fails
 */
private void setRangeValue(AASRangeType range, RangeValue<?> value) throws StatusException {
    if (range == null) {
        throw new IllegalArgumentException("range is null");
    } else if (value == null) {
        throw new IllegalArgumentException(VALUE_NULL);
    }
    try {
        // special treatment for some not directly supported types
        TypedValue<?> tvmin = value.getMin();
        Object objmin = tvmin.getValue();
        if ((tvmin instanceof DecimalValue) || (tvmin instanceof IntegerValue)) {
            objmin = Long.parseLong(objmin.toString());
        }
        TypedValue<?> tvmax = value.getMax();
        Object objmax = tvmax.getValue();
        if ((tvmax instanceof DecimalValue) || (tvmax instanceof IntegerValue)) {
            objmax = Long.parseLong(objmax.toString());
        }
        range.setMin(objmin);
        range.setMax(objmax);
    } catch (Exception ex) {
        LOG.error("setRangeValue 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 33 with StatusException

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

the class AasServiceNodeManager method addSubmodelElementBaseData.

/**
 * Adds base data to the given submodel element.
 *
 * @param node The desired submodel element UA node
 * @param element The corresponding AAS submodel element
 * @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 addSubmodelElementBaseData(AASSubmodelElementType node, SubmodelElement element) throws StatusException {
    try {
        if ((node != null) && (element != null)) {
            // Category
            String category = element.getCategory();
            if (category == null) {
                category = "";
            }
            node.setCategory(category);
            node.setModelingKind(ValueConverter.convertModelingKind(element.getKind()));
            // DataSpecifications
            addEmbeddedDataSpecifications(node, element.getEmbeddedDataSpecifications());
            // SemanticId
            if (element.getSemanticId() != null) {
                addSemanticId(node, element.getSemanticId());
            }
            // Qualifiers
            List<Constraint> qualifiers = element.getQualifiers();
            if ((qualifiers != null) && (!qualifiers.isEmpty())) {
                if (node.getQualifierNode() == null) {
                    addQualifierNode(node);
                }
                addQualifiers(node.getQualifierNode(), qualifiers);
            }
            // Description
            addDescriptions(node, element.getDescriptions());
            if (VALUES_READ_ONLY) {
                node.getCategoryNode().setAccessLevel(AccessLevelType.CurrentRead);
                node.getModelingKindNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
        }
    } catch (Exception ex) {
        LOG.error("addSubmodelElementBaseData Exception", ex);
        throw ex;
    }
}
Also used : Constraint(io.adminshell.aas.v3.model.Constraint) 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 34 with StatusException

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

the class AasServiceNodeManager method createAasNodes.

/**
 * Creates the AAS nodes in the address space.
 *
 * @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 createAasNodes() throws StatusException, ServiceResultException, ServiceException, AddressSpaceException {
    try {
        if (aasEnvironment != null) {
            // add AASEnvironmentType
            addAasEnvironmentNode();
            // ConceptDescriptions.
            addConceptDescriptions(aasEnvironment.getConceptDescriptions());
            // Assets
            List<Asset> assets = aasEnvironment.getAssets();
            if ((assets != null) && (!assets.isEmpty())) {
                for (Asset asset : assets) {
                    addAsset(aasEnvironmentNode, asset);
                }
            }
            // Submodels
            List<Submodel> submodels = aasEnvironment.getSubmodels();
            if ((submodels != null) && (!submodels.isEmpty())) {
                for (Submodel submodel : submodels) {
                    addSubmodel(aasEnvironmentNode, submodel);
                }
            }
            addAssetAdministrationShells();
        }
    } catch (Exception ex) {
        LOG.error("createAasNodes Exception", ex);
        throw ex;
    }
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) Asset(io.adminshell.aas.v3.model.Asset) 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 35 with StatusException

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

the class AasServiceNodeManager method addSubmodelReferences.

/**
 * Adds the given submodel references to the given node.
 *
 * @param node The desired UA node in which the objects should be created
 * @param submodelRefs The desired submodel references
 * @throws StatusException If the operation fails
 */
private void addSubmodelReferences(AASAssetAdministrationShellType node, List<Reference> submodelRefs) throws StatusException {
    if (node == null) {
        throw new IllegalArgumentException(NODE_NULL);
    } else if (submodelRefs == null) {
        throw new IllegalArgumentException("sumodelRefs = null");
    }
    try {
        String name = "Submodel";
        AASReferenceList referenceListNode = node.getSubmodelNode();
        LOG.info("addSubmodelReferences: add {} Submodels to Node: {}", submodelRefs.size(), node);
        boolean added = false;
        if (referenceListNode == null) {
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASReferenceList.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = createNodeId(node, browseName);
            referenceListNode = createInstance(AASReferenceList.class, nid, browseName, LocalizedText.english(name));
            LOG.info("addSubmodelReferences: add Node {} to Node {}", referenceListNode.getNodeId(), node.getNodeId());
            added = true;
        }
        int counter = 1;
        for (Reference ref : submodelRefs) {
            UaNode submodelNode = null;
            String submodelName = getSubmodelName(ref);
            if (submodelName.isEmpty()) {
                submodelName = name + counter++;
            }
            if (submodelOpcUAMap.containsKey(ref)) {
                submodelNode = submodelOpcUAMap.get(ref);
            }
            UaNode refNode = addAasReferenceAasNS(referenceListNode, ref, submodelName);
            if (refNode != null) {
                // add hasAddIn reference to the submodel
                if (submodelNode != null) {
                    refNode.addReference(submodelNode, Identifiers.HasAddIn, false);
                } else {
                    LOG.warn("addSubmodelReferences: Submodel {} not found in submodelRefMap", ref);
                }
            }
        }
        if (added) {
            node.addComponent(referenceListNode);
        }
    } catch (Exception ex) {
        LOG.error("addSubmodelReferences 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) AASReferenceList(opc.i4aas.AASReferenceList) 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) Constraint(io.adminshell.aas.v3.model.Constraint) 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