Search in sources :

Example 1 with ReferenceElementValue

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

Example 2 with ReferenceElementValue

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();
}
Also used : ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) KeyType(io.adminshell.aas.v3.model.KeyType) JsonNode(com.fasterxml.jackson.databind.JsonNode) KeyElements(io.adminshell.aas.v3.model.KeyElements)

Example 3 with ReferenceElementValue

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

Example 4 with 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);
}
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)

Aggregations

ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)4 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)1 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)1 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)1 KeyElements (io.adminshell.aas.v3.model.KeyElements)1 KeyType (io.adminshell.aas.v3.model.KeyType)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1