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);
}
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;
}
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;
}
}
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);
}
Aggregations