use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testReferenceElementSetValueMapping.
@Test
public void testReferenceElementSetValueMapping() {
SubmodelElement actual = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().build()).build();
ReferenceElementValue value = ReferenceElementValue.builder().key(KeyType.IRI, KeyElements.SUBMODEL, "http://example.org/submodel/1").key(KeyType.ID_SHORT, KeyElements.PROPERTY, "property1").build();
SubmodelElement expected = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().keys(value.getKeys()).build()).build();
ElementValueMapper.setValue(actual, value);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ReferenceElementValueDeserializer method deserializeValue.
@Override
public ReferenceElementValue deserializeValue(JsonNode node, DeserializationContext context) throws IOException, JacksonException {
if (node == null || !node.isArray()) {
return null;
}
ReferenceElementValue.Builder builder = ReferenceElementValue.builder();
if (!node.elements().hasNext()) {
return builder.build();
}
Iterable<JsonNode> iterable = () -> node.elements();
for (JsonNode element : StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList())) {
if (element.isObject()) {
if (!element.has(JsonFieldNames.REFERENCE_ELEMENT_VALUE_ID_TYPE)) {
throw new RuntimeException(String.format("missing property '%s'", JsonFieldNames.REFERENCE_ELEMENT_VALUE_ID_TYPE));
}
if (!element.has(JsonFieldNames.REFERENCE_ELEMENT_VALUE_TYPE)) {
throw new RuntimeException(String.format("missing property '%s'", JsonFieldNames.REFERENCE_ELEMENT_VALUE_TYPE));
}
if (!element.has(JsonFieldNames.REFERENCE_ELEMENT_VALUE_VALUE)) {
throw new RuntimeException(String.format("missing property '%s'", JsonFieldNames.REFERENCE_ELEMENT_VALUE_VALUE));
}
builder.key(context.readTreeAsValue(element.get(JsonFieldNames.REFERENCE_ELEMENT_VALUE_ID_TYPE), KeyType.class), context.readTreeAsValue(element.get(JsonFieldNames.REFERENCE_ELEMENT_VALUE_TYPE), KeyElements.class), element.get(JsonFieldNames.REFERENCE_ELEMENT_VALUE_VALUE).textValue());
} else if (element.isTextual()) {
builder.key(KeyType.IRI, KeyElements.GLOBAL_REFERENCE, element.textValue());
} else {
context.reportBadDefinition(ReferenceElementValue.class, "unknown format of reference element");
}
}
return builder.build();
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ReferenceElementValueMapper method toValue.
@Override
public ReferenceElementValue toValue(ReferenceElement submodelElement) {
if (submodelElement == null) {
return null;
}
ReferenceElementValue referenceElementValue = new ReferenceElementValue();
referenceElementValue.setKeys(submodelElement.getValue() == null ? null : submodelElement.getValue().getKeys());
return referenceElementValue;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testReferenceElementToValueMapping.
@Test
public void testReferenceElementToValueMapping() {
ReferenceElementValue expected = ReferenceElementValue.builder().key(KeyType.IRI, KeyElements.SUBMODEL, "http://example.org/submodel/1").key(KeyType.ID_SHORT, KeyElements.PROPERTY, "property1").build();
SubmodelElement input = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().keys(expected.getKeys()).build()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
Aggregations