Search in sources :

Example 1 with AnnotatedRelationshipElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testAnnotatedRelationshipElementToValueMapping.

@Test
public void testAnnotatedRelationshipElementToValueMapping() throws ValueFormatException {
    AnnotatedRelationshipElementValue expected = createAnnotatedRelationshipElementValue();
    SubmodelElement input = new DefaultAnnotatedRelationshipElement.Builder().first(new DefaultReference.Builder().keys(expected.getFirst()).build()).second(new DefaultReference.Builder().keys(expected.getSecond()).build()).annotation(new DefaultProperty.Builder().idShort(expected.getAnnotations().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).build();
    ElementValue actual = ElementValueMapper.toValue(input);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) Test(org.junit.Test)

Example 2 with AnnotatedRelationshipElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue in project FAAAST-Service by FraunhoferIOSB.

the class AnnotatedRelationshipElementValueMapper method toValue.

@Override
public AnnotatedRelationshipElementValue toValue(AnnotatedRelationshipElement submodelElement) {
    if (submodelElement == null) {
        return null;
    }
    AnnotatedRelationshipElementValue value = new AnnotatedRelationshipElementValue();
    value.setAnnotations(submodelElement.getAnnotations().stream().collect(Collectors.toMap(x -> x.getIdShort(), x -> ElementValueMapper.toValue(x))));
    value.setFirst(submodelElement.getFirst().getKeys());
    value.setSecond(submodelElement.getSecond().getKeys());
    return value;
}
Also used : AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)

Example 3 with AnnotatedRelationshipElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue 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 AnnotatedRelationshipElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testAnnotatedRelationshipElementSetValueMapping.

@Test
public void testAnnotatedRelationshipElementSetValueMapping() throws ValueFormatException {
    SubmodelElement actual = new DefaultAnnotatedRelationshipElement.Builder().annotation(new DefaultProperty.Builder().idShort("property").build()).build();
    AnnotatedRelationshipElementValue value = createAnnotatedRelationshipElementValue();
    SubmodelElement expected = new DefaultAnnotatedRelationshipElement.Builder().first(new DefaultReference.Builder().keys(value.getFirst()).build()).second(new DefaultReference.Builder().keys(value.getSecond()).build()).annotation(new DefaultProperty.Builder().idShort(value.getAnnotations().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).build();
    ElementValueMapper.setValue(actual, value);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) Test(org.junit.Test)

Aggregations

AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)4 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)2 Test (org.junit.Test)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 DataElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)1 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)1 ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)1 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)1 LangString (io.adminshell.aas.v3.model.LangString)1 Reference (io.adminshell.aas.v3.model.Reference)1 AASAnnotatedRelationshipElementType (opc.i4aas.AASAnnotatedRelationshipElementType)1