use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ValueArrayDeserializer method deserialize.
@Override
public ElementValue[] deserialize(JsonParser parser, DeserializationContext context, Object[] temp) throws IOException {
TypeInfo typeInfo = ContextAwareElementValueDeserializer.getTypeInfo(context);
if (typeInfo == null) {
return context.reportBadDefinition(Collection.class, "missing type information");
}
if (!ContainerTypeInfo.class.isAssignableFrom(typeInfo.getClass())) {
return context.reportBadDefinition(Collection.class, "type information mismatch - must be of type ContainerTypeInfo");
}
ContainerTypeInfo containerTypeInfo = (ContainerTypeInfo) typeInfo;
JsonNode node = context.readTree(parser);
if (!node.isArray()) {
return context.reportBadDefinition(Collection.class, "expected array");
}
if (node.size() != typeInfo.getElements().size()) {
return context.reportBadDefinition(Collection.class, String.format("number of elements mismatch (expected: %d, actual: %d)", typeInfo.getElements().size(), node.size()));
}
ElementValue[] result = new ElementValue[node.size()];
for (int i = 0; i < node.size(); i++) {
context.setAttribute(ContextAwareElementValueDeserializer.VALUE_TYPE_CONTEXT, typeInfo.getElements().get(i));
Class type = ((TypeInfo) typeInfo.getElements().get(i)).getType();
Object element = context.readTreeAsValue(node.get(i), type);
result[i] = (ElementValue) element;
}
return result;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testBlobToValueMapping.
@Test
public void testBlobToValueMapping() {
BlobValue expected = BlobValue.builder().mimeType("application/json").value("foo").build();
SubmodelElement input = new DefaultBlob.Builder().mimeType(expected.getMimeType()).value(expected.getValue()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue 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);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testFileToValueMapping.
@Test
public void testFileToValueMapping() {
FileValue expected = FileValue.builder().mimeType("application/json").value("{}").build();
SubmodelElement input = new DefaultFile.Builder().mimeType(expected.getMimeType()).value(expected.getValue()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testRelationshipElementToValueMapping.
@Test
public void testRelationshipElementToValueMapping() {
RelationshipElementValue expected = RelationshipElementValue.builder().first(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/1").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property1").build())).second(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/2").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property2").build())).build();
SubmodelElement input = new DefaultRelationshipElement.Builder().first(new DefaultReference.Builder().keys(expected.getFirst()).build()).second(new DefaultReference.Builder().keys(expected.getSecond()).build()).build();
ElementValue actual = ElementValueMapper.toValue(input);
Assert.assertEquals(expected, actual);
}
Aggregations