Search in sources :

Example 6 with UaNode

use of com.prosysopc.ua.nodes.UaNode 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 7 with UaNode

use of com.prosysopc.ua.nodes.UaNode 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)

Example 8 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_NULL);
    }
    try {
        // EntityType
        entity.setEntityType(ValueConverter.getAasEntityType(value.getEntityType()));
        // GlobalAssetId
        if ((value.getGlobalAssetId() != null) && (!value.getGlobalAssetId().isEmpty())) {
            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()) {
                LOG.warn("Size of Value ({}) doesn't match the number of StatementNodes ({})", valueMap.size(), statementNodes.length);
                throw new IllegalArgumentException("Size of Value doesn't match the number of StatementNodes");
            }
            for (UaNode statementNode1 : statementNodes) {
                if ((statementNode1 instanceof AASSubmodelElementType) && value.getStatements().containsKey(statementNode1.getBrowseName().getName())) {
                    setSubmodelElementValue((AASSubmodelElementType) statementNode1, value.getStatements().get(statementNode1.getBrowseName().getName()));
                }
            }
        }
    } catch (Exception ex) {
        LOG.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) 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 9 with UaNode

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

the class AasServiceNodeManager method addConceptDescriptions.

/**
 * Adds the given list of AAS Concept Descriptions.
 *
 * @param descriptions The desired list of AAS Concept Descriptions
 * @throws StatusException If the operation fails
 */
private void addConceptDescriptions(List<ConceptDescription> descriptions) throws StatusException {
    try {
        // create folder DictionaryEntries
        final UaNode dictionariesFolder = getServer().getNodeManagerRoot().getNodeOrExternal(Identifiers.Dictionaries);
        // Folder for my objects
        final NodeId dictionarieEntriesFolderId = new NodeId(getNamespaceIndex(), "Dictionaries.DictionaryEntries");
        FolderTypeNode dictEntriesFolder = createInstance(FolderTypeNode.class, "DictionaryEntries", dictionarieEntriesFolderId);
        this.addNodeAndReference(dictionariesFolder, dictEntriesFolder, Identifiers.Organizes);
        for (ConceptDescription c : descriptions) {
            String name = c.getIdShort();
            NodeId nid = createNodeId(dictionariesFolder, name);
            DictionaryEntryType dictNode;
            switch(c.getIdentification().getIdType()) {
                case IRDI:
                    AASIrdiConceptDescriptionType irdiNode = createInstance(AASIrdiConceptDescriptionType.class, name, nid);
                    addIdentifiable(irdiNode, c.getIdentification(), c.getAdministration(), name);
                    addConceptDescriptionReference(irdiNode, getReference(c));
                    dictEntriesFolder.addComponent(irdiNode);
                    dictionaryMap.put(getReference(c), irdiNode);
                    dictNode = irdiNode;
                    break;
                case IRI:
                    AASIriConceptDescriptionType iriNode = createInstance(AASIriConceptDescriptionType.class, name, nid);
                    addIdentifiable(iriNode, c.getIdentification(), c.getAdministration(), name);
                    addConceptDescriptionReference(iriNode, getReference(c));
                    dictEntriesFolder.addComponent(iriNode);
                    dictionaryMap.put(getReference(c), iriNode);
                    dictNode = iriNode;
                    break;
                default:
                    AASCustomConceptDescriptionType customNode = createInstance(AASCustomConceptDescriptionType.class, name, nid);
                    addIdentifiable(customNode, c.getIdentification(), c.getAdministration(), name);
                    addConceptDescriptionReference(customNode, getReference(c));
                    dictEntriesFolder.addComponent(customNode);
                    dictionaryMap.put(getReference(c), customNode);
                    dictNode = customNode;
                    break;
            }
            referableMap.put(AasUtils.toReference(c), new ObjectData(c, dictNode));
        }
    } catch (Exception ex) {
        LOG.error("addConceptDescriptions Exception", ex);
        throw ex;
    }
}
Also used : AASIriConceptDescriptionType(opc.i4aas.AASIriConceptDescriptionType) DictionaryEntryType(com.prosysopc.ua.types.opcua.DictionaryEntryType) AASCustomConceptDescriptionType(opc.i4aas.AASCustomConceptDescriptionType) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) UaNode(com.prosysopc.ua.nodes.UaNode) NodeManagerUaNode(com.prosysopc.ua.server.NodeManagerUaNode) MethodManagerUaNode(com.prosysopc.ua.server.MethodManagerUaNode) ConceptDescription(io.adminshell.aas.v3.model.ConceptDescription) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) FolderTypeNode(com.prosysopc.ua.types.opcua.server.FolderTypeNode) 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) AASIrdiConceptDescriptionType(opc.i4aas.AASIrdiConceptDescriptionType)

Aggregations

UaNode (com.prosysopc.ua.nodes.UaNode)9 ServiceException (com.prosysopc.ua.ServiceException)5 StatusException (com.prosysopc.ua.StatusException)5 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)5 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)5 MethodManagerUaNode (com.prosysopc.ua.server.MethodManagerUaNode)5 NodeManagerUaNode (com.prosysopc.ua.server.NodeManagerUaNode)5 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)5 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)5 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)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