Search in sources :

Example 21 with ElementValue

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;
}
Also used : ContainerTypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.ContainerTypeInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo) ContainerTypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.ContainerTypeInfo)

Example 22 with ElementValue

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);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) DefaultBlob(io.adminshell.aas.v3.model.impl.DefaultBlob) 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) BlobValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.BlobValue) Test(org.junit.Test)

Example 23 with ElementValue

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);
}
Also used : ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) 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) Test(org.junit.Test)

Example 24 with ElementValue

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);
}
Also used : FileValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.FileValue) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) DefaultFile(io.adminshell.aas.v3.model.impl.DefaultFile) 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) Test(org.junit.Test)

Example 25 with ElementValue

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);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) 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) Test(org.junit.Test)

Aggregations

ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)25 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)20 Test (org.junit.Test)15 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)11 ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)11 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)11 PropertyValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue)7 TypeInfo (de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo)6 ElementValueMapper (de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper)5 Reference (io.adminshell.aas.v3.model.Reference)5 DefaultProperty (io.adminshell.aas.v3.model.impl.DefaultProperty)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 DeserializationException (de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException)4 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)4 DataElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)4 RangeValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue)4 Datatype (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype)4 TypeExtractor (de.fraunhofer.iosb.ilt.faaast.service.typing.TypeExtractor)4