Search in sources :

Example 11 with NodeId

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

the class AasServiceNodeManager method doRemoveFromMaps.

/**
 * Removes the given SubmodelElement from the maps.
 *
 * @param element The desired SubmodelElement
 * @param reference The reference to the desired SubmodelElement
 * @param referable The corresponding referable
 */
private void doRemoveFromMaps(AASSubmodelElementType element, Reference reference, Referable referable) {
    try {
        logger.debug("doRemoveFromMaps: remove SubmodelElement " + AasUtils.asString(reference));
        if (submodelElementOpcUAMap.containsKey(reference)) {
            submodelElementOpcUAMap.remove(reference);
            logger.debug("doRemoveFromMaps: remove SubmodelElement from submodelElementOpcUAMap: " + AasUtils.asString(reference));
        }
        if (element instanceof AASPropertyType) {
            AASPropertyType prop = (AASPropertyType) element;
            if (submodelElementAasMap.containsKey(prop.getValueNode().getNodeId())) {
                submodelElementAasMap.remove(prop.getValueNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove Property NodeId " + prop.getValueNode().getNodeId());
            }
        } else if (element instanceof AASRangeType) {
            AASRangeType range = (AASRangeType) element;
            if (submodelElementAasMap.containsKey(range.getMinNode().getNodeId())) {
                submodelElementAasMap.remove(range.getMinNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove Range Min NodeId " + range.getMinNode().getNodeId());
            }
            if (submodelElementAasMap.containsKey(range.getMaxNode().getNodeId())) {
                submodelElementAasMap.remove(range.getMaxNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove Range Max NodeId " + range.getMaxNode().getNodeId());
            }
        } else if (element instanceof AASOperationType) {
            AASOperationType oper = (AASOperationType) element;
            if (submodelElementAasMap.containsKey(oper.getOperationNode().getNodeId())) {
                submodelElementAasMap.remove(oper.getOperationNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove Operation NodeId " + oper.getOperationNode().getNodeId());
            }
        } else if (element instanceof AASBlobType) {
            AASBlobType blob = (AASBlobType) element;
            if (submodelElementAasMap.containsKey(blob.getValueNode().getNodeId())) {
                submodelElementAasMap.remove(blob.getValueNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove Blob NodeId " + blob.getValueNode().getNodeId());
            }
        } else if (element instanceof AASMultiLanguagePropertyType) {
            AASMultiLanguagePropertyType mlp = (AASMultiLanguagePropertyType) element;
            if (submodelElementAasMap.containsKey(mlp.getValueNode().getNodeId())) {
                submodelElementAasMap.remove(mlp.getValueNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove AASMultiLanguageProperty NodeId " + mlp.getValueNode().getNodeId());
            }
        } else if (element instanceof AASReferenceElementType) {
            AASReferenceElementType refElem = (AASReferenceElementType) element;
            NodeId nid = refElem.getValueNode().getKeysNode().getNodeId();
            if (submodelElementAasMap.containsKey(nid)) {
                submodelElementAasMap.remove(nid);
                logger.debug("doRemoveFromMaps: remove AASReferenceElement NodeId " + nid);
            }
        } else if (element instanceof AASRelationshipElementType) {
            AASRelationshipElementType relElem = (AASRelationshipElementType) element;
            NodeId nid = relElem.getFirstNode().getKeysNode().getNodeId();
            if (submodelElementAasMap.containsKey(nid)) {
                submodelElementAasMap.remove(nid);
                logger.debug("doRemoveFromMaps: remove AASRelationshipElement First NodeId " + nid);
            }
            nid = relElem.getSecondNode().getKeysNode().getNodeId();
            if (submodelElementAasMap.containsKey(nid)) {
                submodelElementAasMap.remove(nid);
                logger.debug("doRemoveFromMaps: remove AASRelationshipElement Second NodeId " + nid);
            }
            if (relElem instanceof AASAnnotatedRelationshipElementType) {
                if (referable instanceof AnnotatedRelationshipElement) {
                    AnnotatedRelationshipElement annRelElem = (AnnotatedRelationshipElement) referable;
                    for (DataElement de : annRelElem.getAnnotations()) {
                        doRemoveFromMaps(reference, de);
                    }
                }
            }
        } else if (element instanceof AASEntityType) {
            AASEntityType ent = (AASEntityType) element;
            if ((ent.getGlobalAssetIdNode() != null) && (ent.getGlobalAssetIdNode().getKeysNode() != null)) {
                NodeId nid = ent.getGlobalAssetIdNode().getKeysNode().getNodeId();
                if (submodelElementAasMap.containsKey(nid)) {
                    submodelElementAasMap.remove(nid);
                    logger.debug("doRemoveFromMaps: remove Entity GlobalAssetId NodeId " + nid);
                }
            }
            if (submodelElementAasMap.containsKey(ent.getEntityTypeNode().getNodeId())) {
                submodelElementAasMap.remove(ent.getEntityTypeNode().getNodeId());
                logger.debug("doRemoveFromMaps: remove Entity EntityType NodeId " + ent.getEntityTypeNode().getNodeId());
            }
        } else if (referable instanceof SubmodelElementCollection) {
            SubmodelElementCollection sec = (SubmodelElementCollection) referable;
            for (SubmodelElement se : sec.getValues()) {
                doRemoveFromMaps(reference, se);
            }
        }
    // Capability and File are currently not relevant here
    } catch (Throwable ex) {
        logger.error("doRemoveFromMaps Exception", ex);
        throw ex;
    }
}
Also used : AASEntityType(opc.i4aas.AASEntityType) AASRangeType(opc.i4aas.AASRangeType) AASBlobType(opc.i4aas.AASBlobType) AASPropertyType(opc.i4aas.AASPropertyType) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) AASOperationType(opc.i4aas.AASOperationType) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) AASRelationshipElementType(opc.i4aas.AASRelationshipElementType) DataElement(io.adminshell.aas.v3.model.DataElement) AASMultiLanguagePropertyType(opc.i4aas.AASMultiLanguagePropertyType) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) AASAnnotatedRelationshipElementType(opc.i4aas.AASAnnotatedRelationshipElementType) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) AASReferenceElementType(opc.i4aas.AASReferenceElementType)

Example 12 with NodeId

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

the class AasServiceNodeManager method addAasEvent.

/**
 * Adds an AAS Event to the given node.
 *
 * @param node The desired UA node
 * @param aasEvent The AAS Event 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 addAasEvent(UaNode node, Event aasEvent, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasEvent != null)) {
            String name = aasEvent.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEventType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASEventType eventNode = createInstance(AASEventType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(eventNode, aasEvent);
            if (aasEvent instanceof BasicEvent) {
                setBasicEventData(eventNode, (BasicEvent) aasEvent);
            }
            Reference eventRef = AasUtils.toReference(parentRef, aasEvent);
            if (ordered) {
                node.addReference(eventNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(eventNode);
            }
            referableMap.put(eventRef, new ObjectData(aasEvent, eventNode, submodel));
        }
    } catch (Throwable ex) {
        logger.error("addAasEvent 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) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) BasicEvent(io.adminshell.aas.v3.model.BasicEvent) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) AASEventType(opc.i4aas.AASEventType)

Example 13 with NodeId

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

the class AasServiceNodeManager method addSubmodel.

/**
 * Adds a submodel to a given Node
 *
 * @param node The desired Node where the submodel should be added
 * @param submodel The desired AAS submodel
 */
private void addSubmodel(UaNode node, Submodel submodel) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    if (submodel == null) {
        throw new IllegalArgumentException("submodel is null");
    }
    try {
        String shortId = submodel.getIdShort();
        if (!shortId.isEmpty()) {
            String displayName = "Submodel:" + shortId;
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelType.getNamespaceUri(), shortId).toQualifiedName(getNamespaceTable());
            NodeId nid = createNodeId(node, browseName);
            if (findNode(nid) != null) {
                // The NodeId already exists
                nid = getDefaultNodeId();
            }
            logger.trace("addSubmodel: create Submodel " + submodel.getIdShort() + "; NodeId: " + nid.toString());
            AASSubmodelType smNode = createInstance(AASSubmodelType.class, nid, browseName, LocalizedText.english(displayName));
            // ModelingKind
            smNode.setModelingKind(ValueConverter.convertModelingKind(submodel.getKind()));
            addIdentifiable(smNode, submodel.getIdentification(), submodel.getAdministration(), submodel.getCategory());
            // DataSpecifications
            addEmbeddedDataSpecifications(smNode, submodel.getEmbeddedDataSpecifications());
            // Qualifiers
            List<Constraint> qualifiers = submodel.getQualifiers();
            if ((qualifiers != null) && (!qualifiers.isEmpty())) {
                if (smNode.getQualifierNode() == null) {
                    addQualifierNode(smNode);
                }
                addQualifiers(smNode.getQualifierNode(), qualifiers);
            }
            // SemanticId
            if (submodel.getSemanticId() != null) {
                addSemanticId(smNode, submodel.getSemanticId());
            }
            // Description
            addDescriptions(smNode, submodel.getDescriptions());
            Reference refSubmodel = AasUtils.toReference(submodel);
            // SubmodelElements
            addSubmodelElements(smNode, submodel.getSubmodelElements(), submodel, refSubmodel);
            if (VALUES_READ_ONLY) {
                smNode.getModelingKindNode().setAccessLevel(AccessLevelType.CurrentRead);
            }
            submodelOpcUAMap.put(AasUtils.toReference(submodel), smNode);
            node.addComponent(smNode);
            referableMap.put(AasUtils.toReference(submodel), new ObjectData(submodel, smNode));
        } else {
            logger.warn("addSubmodel: IdShort is empty!");
        }
    } catch (Throwable ex) {
        logger.error("addSubmodel Exception", ex);
        throw ex;
    }
}
Also used : AASSubmodelType(opc.i4aas.AASSubmodelType) Constraint(io.adminshell.aas.v3.model.Constraint) 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)

Example 14 with NodeId

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

the class AasServiceNodeManager method addAasMultiLanguageProperty.

/**
 * Adds an AAS Multi Language Property to the given node.
 *
 * @param node The desired UA node
 * @param aasMultiLang The AAS Multi Language Property 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 multi language property 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 addAasMultiLanguageProperty(UaNode node, MultiLanguageProperty aasMultiLang, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasMultiLang != null)) {
            String name = aasMultiLang.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASMultiLanguagePropertyType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASMultiLanguagePropertyType multiLangNode = createInstance(AASMultiLanguagePropertyType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(multiLangNode, aasMultiLang);
            List<LangString> values = aasMultiLang.getValues();
            if (values != null) {
                if (multiLangNode.getValueNode() == null) {
                    addMultiLanguageValueNode(multiLangNode, values.size());
                }
                multiLangNode.getValueNode().setValue(ValueConverter.getLocalizedTextFromLangStringSet(values));
            }
            if (aasMultiLang.getValueId() != null) {
                addAasReferenceAasNS(multiLangNode, aasMultiLang.getValueId(), AASMultiLanguagePropertyType.VALUE_ID);
            }
            Reference multiLangRef = AasUtils.toReference(parentRef, aasMultiLang);
            submodelElementAasMap.put(multiLangNode.getValueNode().getNodeId(), new SubmodelElementData(aasMultiLang, submodel, SubmodelElementData.Type.MULTI_LANGUAGE_VALUE, multiLangRef));
            submodelElementOpcUAMap.put(multiLangRef, multiLangNode);
            if (ordered) {
                node.addReference(multiLangNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(multiLangNode);
            }
            referableMap.put(multiLangRef, new ObjectData(aasMultiLang, multiLangNode, submodel));
        }
    } catch (Throwable ex) {
        logger.error("addAasMultiLanguageProperty Exception", ex);
        throw ex;
    }
}
Also used : AASMultiLanguagePropertyType(opc.i4aas.AASMultiLanguagePropertyType) LangString(io.adminshell.aas.v3.model.LangString) 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) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 15 with NodeId

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

the class AasServiceNodeManager method addAasEntity.

/**
 * Adds an AAS entity to the given node.
 *
 * @param node The desired UA node
 * @param aasEntity The AAS entity to add
 * @param submodel The corresponding Submodel
 * @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 addAasEntity(UaNode node, Entity aasEntity, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasEntity != null)) {
            String name = aasEntity.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEntityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASEntityType entityNode = createInstance(AASEntityType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(entityNode, aasEntity);
            Reference entityRef = AasUtils.toReference(parentRef, aasEntity);
            // EntityType
            entityNode.setEntityType(ValueConverter.getAasEntityType(aasEntity.getEntityType()));
            submodelElementAasMap.put(entityNode.getEntityTypeNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_TYPE, entityRef));
            // GlobalAssetId
            if (aasEntity.getGlobalAssetId() != null) {
                if (entityNode.getGlobalAssetIdNode() == null) {
                    addAasReferenceAasNS(entityNode, aasEntity.getGlobalAssetId(), AASEntityType.GLOBAL_ASSET_ID, false);
                } else {
                    setAasReferenceData(aasEntity.getGlobalAssetId(), entityNode.getGlobalAssetIdNode(), false);
                }
                submodelElementAasMap.put(entityNode.getGlobalAssetIdNode().getKeysNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_GLOBAL_ASSET_ID, entityRef));
            }
            // SpecificAssetIds
            IdentifierKeyValuePair specificAssetId = aasEntity.getSpecificAssetId();
            if (specificAssetId != null) {
                if (entityNode.getSpecificAssetIdNode() == null) {
                    addIdentifierKeyValuePair(entityNode, specificAssetId, AASEntityType.SPECIFIC_ASSET_ID);
                } else {
                    setIdentifierKeyValuePairData(entityNode.getSpecificAssetIdNode(), specificAssetId);
                }
            }
            // Statements
            addSubmodelElements(entityNode.getStatementNode(), aasEntity.getStatements(), submodel, entityRef);
            submodelElementOpcUAMap.put(entityRef, entityNode);
            if (ordered) {
                node.addReference(entityNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(entityNode);
            }
            referableMap.put(entityRef, new ObjectData(aasEntity, entityNode, submodel));
        }
    } catch (Throwable ex) {
        logger.error("addAasEntity Exception", ex);
        throw ex;
    }
}
Also used : AASEntityType(opc.i4aas.AASEntityType) IdentifierKeyValuePair(io.adminshell.aas.v3.model.IdentifierKeyValuePair) 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) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Aggregations

NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)79 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)59 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 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)16 ExpandedNodeId (com.prosysopc.ua.stack.builtintypes.ExpandedNodeId)15 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)12 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)10 PlainProperty (com.prosysopc.ua.server.nodes.PlainProperty)9 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)8