Search in sources :

Example 1 with AnnotatedRelationshipElement

use of io.adminshell.aas.v3.model.AnnotatedRelationshipElement in project FAAAST-Service by FraunhoferIOSB.

the class AnnotatedRelationshipElementValueMapper method setValue.

@Override
public AnnotatedRelationshipElement setValue(AnnotatedRelationshipElement submodelElement, AnnotatedRelationshipElementValue value) {
    if (submodelElement == null || value == null) {
        return null;
    }
    submodelElement.setFirst(new DefaultReference.Builder().keys(value.getFirst()).build());
    submodelElement.setSecond(new DefaultReference.Builder().keys(value.getSecond()).build());
    for (SubmodelElement element : submodelElement.getAnnotations()) {
        if (value.getAnnotations().containsKey(element.getIdShort())) {
            ElementValueMapper.setValue(element, value.getAnnotations().get(element.getIdShort()));
        }
    }
    return submodelElement;
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference)

Example 2 with AnnotatedRelationshipElement

use of io.adminshell.aas.v3.model.AnnotatedRelationshipElement in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addAasRelationshipElement.

/**
 * Adds an AAS Relationship Element to the given node.
 *
 * @param node The desired UA node
 * @param aasRelElem The corresponding AAS Relationship Element
 * @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 addAasRelationshipElement(UaNode node, RelationshipElement aasRelElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasRelElem != null)) {
            Reference relElemRef = AasUtils.toReference(parentRef, aasRelElem);
            String name = aasRelElem.getIdShort();
            AASRelationshipElementType relElemNode;
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRelationshipElementType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            if (aasRelElem instanceof AnnotatedRelationshipElement) {
                relElemNode = createAnnotatedRelationshipElement((AnnotatedRelationshipElement) aasRelElem, submodel, relElemRef, nid);
            } else {
                relElemNode = createInstance(AASRelationshipElementType.class, nid, browseName, LocalizedText.english(name));
            }
            if (relElemNode != null) {
                addSubmodelElementBaseData(relElemNode, aasRelElem);
                setAasReferenceData(aasRelElem.getFirst(), relElemNode.getFirstNode(), false);
                setAasReferenceData(aasRelElem.getSecond(), relElemNode.getSecondNode(), false);
                submodelElementAasMap.put(relElemNode.getFirstNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_FIRST, relElemRef));
                submodelElementAasMap.put(relElemNode.getSecondNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_SECOND, relElemRef));
                submodelElementOpcUAMap.put(relElemRef, relElemNode);
                if (ordered) {
                    node.addReference(relElemNode, Identifiers.HasOrderedComponent, false);
                } else {
                    node.addComponent(relElemNode);
                }
                referableMap.put(relElemRef, new ObjectData(aasRelElem, relElemNode, submodel));
            }
        }
    } catch (Throwable ex) {
        logger.error("addAasRelationshipElement 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) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) AASRelationshipElementType(opc.i4aas.AASRelationshipElementType) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 3 with AnnotatedRelationshipElement

use of io.adminshell.aas.v3.model.AnnotatedRelationshipElement 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 4 with AnnotatedRelationshipElement

use of io.adminshell.aas.v3.model.AnnotatedRelationshipElement 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 5 with AnnotatedRelationshipElement

use of io.adminshell.aas.v3.model.AnnotatedRelationshipElement in project FAAAST-Service by FraunhoferIOSB.

the class TypeExtractor method extractTypeInfo.

public static TypeInfo extractTypeInfo(Object obj) {
    if (obj == null) {
        return null;
    }
    Class<?> type = obj.getClass();
    if (SubmodelElement.class.isAssignableFrom(type)) {
        ElementValueTypeInfo.Builder builder = ElementValueTypeInfo.builder();
        SubmodelElement submodelElement = (SubmodelElement) obj;
        builder.type(ElementValueMapper.getValueClass((Class<? extends SubmodelElement>) submodelElement.getClass()));
        if (AnnotatedRelationshipElement.class.isAssignableFrom(type)) {
            AnnotatedRelationshipElement annotatedRelationshipElement = (AnnotatedRelationshipElement) obj;
            annotatedRelationshipElement.getAnnotations().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        } else if (SubmodelElementCollection.class.isAssignableFrom(type)) {
            SubmodelElementCollection submodelElementCollection = (SubmodelElementCollection) obj;
            submodelElementCollection.getValues().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        } else if (Entity.class.isAssignableFrom(type)) {
            Entity entity = (Entity) obj;
            entity.getStatements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        } else if (Property.class.isAssignableFrom(obj.getClass())) {
            Property property = (Property) obj;
            builder.datatype(Datatype.fromName(property.getValueType()));
        } else if (Range.class.isAssignableFrom(obj.getClass())) {
            Range range = (Range) obj;
            builder.datatype(Datatype.fromName(range.getValueType()));
        }
        return builder.build();
    }
    if (Submodel.class.isAssignableFrom(type)) {
        Submodel submodel = (Submodel) obj;
        ContainerTypeInfo.Builder<Object> builder = ContainerTypeInfo.<Object>builder();
        builder.type(Submodel.class);
        submodel.getSubmodelElements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        return builder.build();
    }
    if (Collection.class.isAssignableFrom(type)) {
        Collection collection = (Collection) obj;
        ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
        builder.type(Collection.class);
        builder.contentType(TypeToken.of(type).resolveType(COLLECTION_GENERIC_TOKEN).getRawType());
        Iterator iterator = collection.iterator();
        int i = 0;
        while (iterator.hasNext()) {
            builder.element(i, extractTypeInfo(iterator.next()));
            i++;
        }
        return builder.build();
    }
    if (Map.class.isAssignableFrom(type)) {
        Map map = (Map) obj;
        ContainerTypeInfo.Builder<String> builder = ContainerTypeInfo.<String>builder();
        builder.type(Map.class);
        builder.contentType(TypeToken.of(type).resolveType(MAP_GENERIC_TOKEN).getRawType());
        map.forEach((key, value) -> builder.element(key.toString(), extractTypeInfo(value)));
        return builder.build();
    }
    if (type.isArray()) {
        Object[] array = (Object[]) obj;
        ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
        builder.type(Array.class);
        builder.contentType(type.getComponentType());
        for (int i = 0; i < array.length; i++) {
            builder.element(i, extractTypeInfo(array[i]));
        }
        return builder.build();
    }
    return ContainerTypeInfo.<Object>builder().build();
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Array(java.lang.reflect.Array) Iterator(java.util.Iterator) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) Collection(java.util.Collection) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) TypeToken(com.google.common.reflect.TypeToken) Property(io.adminshell.aas.v3.model.Property) Type(java.lang.reflect.Type) Range(io.adminshell.aas.v3.model.Range) Map(java.util.Map) Entity(io.adminshell.aas.v3.model.Entity) Submodel(io.adminshell.aas.v3.model.Submodel) Submodel(io.adminshell.aas.v3.model.Submodel) Entity(io.adminshell.aas.v3.model.Entity) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) Range(io.adminshell.aas.v3.model.Range) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Iterator(java.util.Iterator) Collection(java.util.Collection) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Property(io.adminshell.aas.v3.model.Property) Map(java.util.Map)

Aggregations

AnnotatedRelationshipElement (io.adminshell.aas.v3.model.AnnotatedRelationshipElement)3 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 AASAnnotatedRelationshipElementType (opc.i4aas.AASAnnotatedRelationshipElementType)3 AASRelationshipElementType (opc.i4aas.AASRelationshipElementType)3 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)2 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)2 DataElement (io.adminshell.aas.v3.model.DataElement)2 LangString (io.adminshell.aas.v3.model.LangString)2 Reference (io.adminshell.aas.v3.model.Reference)2 SubmodelElementCollection (io.adminshell.aas.v3.model.SubmodelElementCollection)2 TypeToken (com.google.common.reflect.TypeToken)1 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)1 UaNode (com.prosysopc.ua.nodes.UaNode)1 MethodManagerUaNode (com.prosysopc.ua.server.MethodManagerUaNode)1 NodeManagerUaNode (com.prosysopc.ua.server.NodeManagerUaNode)1 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)1 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)1 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)1 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)1