Search in sources :

Example 1 with AASAnnotatedRelationshipElementType

use of opc.i4aas.AASAnnotatedRelationshipElementType in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method setRelationshipValue.

/**
 * Sets the values for the given RelationshipElement.
 *
 * @param aasElement The desired RelationshipElement.
 * @param value The new value.
 * @throws StatusException If the operation fails
 */
private void setRelationshipValue(AASRelationshipElementType aasElement, RelationshipElementValue value) throws StatusException {
    if (aasElement == null) {
        throw new IllegalArgumentException("aasElement is null");
    } else if (value == null) {
        throw new IllegalArgumentException("value is null");
    }
    try {
        Reference ref = new DefaultReference.Builder().keys(value.getFirst()).build();
        setAasReferenceData(ref, aasElement.getFirstNode(), false);
        ref = new DefaultReference.Builder().keys(value.getSecond()).build();
        setAasReferenceData(ref, aasElement.getSecondNode(), false);
        if ((aasElement instanceof AASAnnotatedRelationshipElementType) && (value instanceof AnnotatedRelationshipElementValue)) {
            AASAnnotatedRelationshipElementType annotatedElement = (AASAnnotatedRelationshipElementType) aasElement;
            AnnotatedRelationshipElementValue annotatedValue = (AnnotatedRelationshipElementValue) value;
            UaNode[] annotationNodes = annotatedElement.getAnnotationNode().getComponents();
            Map<String, DataElementValue> valueMap = annotatedValue.getAnnotations();
            if (annotationNodes.length != valueMap.size()) {
                logger.warn("Size of Value (" + valueMap.size() + ") doesn't match the number of AnnotationNodes (" + annotationNodes.length + ")");
                throw new IllegalArgumentException("Size of Value doesn't match the number of AnnotationNodes");
            }
            // The Key of the Map is the IDShort of the DataElement (in our case the BrowseName)
            for (UaNode annotationNode : annotationNodes) {
                if (valueMap.containsKey(annotationNode.getBrowseName().getName())) {
                    setDataElementValue(annotationNode, valueMap.get(annotationNode.getBrowseName().getName()));
                }
            }
        } else {
            logger.info("setRelationshipValue: No AnnotatedRelationshipElement " + aasElement.getBrowseName().getName());
        }
    } catch (Throwable ex) {
        logger.error("setAnnotatedRelationshipValue Exception", ex);
        throw ex;
    }
}
Also used : Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) 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) AASAnnotatedRelationshipElementType(opc.i4aas.AASAnnotatedRelationshipElementType) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)

Example 2 with AASAnnotatedRelationshipElementType

use of opc.i4aas.AASAnnotatedRelationshipElementType 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 3 with AASAnnotatedRelationshipElementType

use of opc.i4aas.AASAnnotatedRelationshipElementType in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method createAnnotatedRelationshipElement.

/**
 * Creates an Annotated Relationship Element.
 *
 * @param aasRelElem The AAS Annotated Relationship Element
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param relElemRef The AAS reference to the AnnotatedRelationshipElement
 * @param nodeId The desired NodeId for the node to be created
 * @return The create UA Annotated Relationship 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 AASRelationshipElementType createAnnotatedRelationshipElement(AnnotatedRelationshipElement aasRelElem, Submodel submodel, Reference relElemRef, NodeId nodeId) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    AASRelationshipElementType retval = null;
    try {
        AASAnnotatedRelationshipElementType relElemNode = createInstance(AASAnnotatedRelationshipElementType.class, nodeId, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASAnnotatedRelationshipElementType.getNamespaceUri(), aasRelElem.getIdShort()).toQualifiedName(getNamespaceTable()), LocalizedText.english(aasRelElem.getIdShort()));
        // Annotations
        for (DataElement de : aasRelElem.getAnnotations()) {
            addAasDataElement(relElemNode.getAnnotationNode(), de, submodel, relElemRef, false);
        }
        retval = relElemNode;
    } catch (Throwable ex) {
        logger.error("createAnnotatedRelationshipElement Exception", ex);
        throw ex;
    }
    return retval;
}
Also used : DataElement(io.adminshell.aas.v3.model.DataElement) AASAnnotatedRelationshipElementType(opc.i4aas.AASAnnotatedRelationshipElementType) AASRelationshipElementType(opc.i4aas.AASRelationshipElementType)

Aggregations

AASAnnotatedRelationshipElementType (opc.i4aas.AASAnnotatedRelationshipElementType)3 DataElement (io.adminshell.aas.v3.model.DataElement)2 AASRelationshipElementType (opc.i4aas.AASRelationshipElementType)2 UaNode (com.prosysopc.ua.nodes.UaNode)1 MethodManagerUaNode (com.prosysopc.ua.server.MethodManagerUaNode)1 NodeManagerUaNode (com.prosysopc.ua.server.NodeManagerUaNode)1 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)1 DataElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)1 AnnotatedRelationshipElement (io.adminshell.aas.v3.model.AnnotatedRelationshipElement)1 LangString (io.adminshell.aas.v3.model.LangString)1 Reference (io.adminshell.aas.v3.model.Reference)1 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)1 SubmodelElementCollection (io.adminshell.aas.v3.model.SubmodelElementCollection)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1 AASBlobType (opc.i4aas.AASBlobType)1 AASEntityType (opc.i4aas.AASEntityType)1 AASMultiLanguagePropertyType (opc.i4aas.AASMultiLanguagePropertyType)1 AASOperationType (opc.i4aas.AASOperationType)1