Search in sources :

Example 1 with MultiLanguagePropertyValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testMultiLanguagePropertyToValueMapping.

@Test
public void testMultiLanguagePropertyToValueMapping() {
    MultiLanguagePropertyValue expected = MultiLanguagePropertyValue.builder().value("deutsch", "de").value("english", "en").build();
    SubmodelElement input = new DefaultMultiLanguageProperty.Builder().values(List.copyOf(expected.getLangStringSet())).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) 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) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue) Test(org.junit.Test)

Example 2 with MultiLanguagePropertyValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpoint method writeValue.

/**
 * Writes the Value of the given SubmodelElement into the service.
 *
 * @param element The desired SubmodelElement including the new value
 * @param submodel The corresponding submodel
 * @param refElement The reference to the SubmodelElement
 * @return True if the write succeeded, false otherwise
 */
public boolean writeValue(SubmodelElement element, Submodel submodel, Reference refElement) {
    boolean retval = false;
    if (element == null) {
        throw new IllegalArgumentException("element == null");
    } else if (submodel == null) {
        throw new IllegalArgumentException("submodel == null");
    }
    try {
        SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest();
        List<Key> path = new ArrayList<>();
        path.addAll(refElement.getKeys());
        request.setId(submodel.getIdentification());
        request.setPath(path);
        request.setValueParser(new OpcUaElementValueParser());
        if (element instanceof MultiLanguageProperty) {
            MultiLanguageProperty mlp = (MultiLanguageProperty) element;
            if ((mlp.getValues() != null) && (mlp.getValues().size() > 1)) {
                for (int i = 0; i < mlp.getValues().size(); i++) {
                    logger.info("writeValue: MLP " + i + ": " + mlp.getValues().get(i).getValue());
                }
            }
        }
        request.setRawValue(ElementValueMapper.toValue(element));
        if (request.getRawValue() instanceof MultiLanguagePropertyValue) {
            MultiLanguagePropertyValue mlpv = (MultiLanguagePropertyValue) request.getRawValue();
            if ((mlpv.getLangStringSet() != null) && (mlpv.getLangStringSet().size() > 1)) {
                for (int i = 0; i < mlpv.getLangStringSet().size(); i++) {
                    logger.info("writeValue: MLPV " + i + ": " + mlpv.getLangStringSet().toArray()[i]);
                }
            }
        }
        Response response = service.execute(request);
        logger.info("writeValue: Submodel " + submodel.getIdentification().getIdentifier() + "; Element " + element.getIdShort() + "; Status: " + response.getStatusCode());
        if (isSuccess(response.getStatusCode())) {
            retval = true;
        }
    } catch (Exception ex) {
        logger.error("writeValue error", ex);
    }
    return retval;
}
Also used : SetSubmodelElementValueByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Response(de.fraunhofer.iosb.ilt.faaast.service.model.api.Response) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) ArrayList(java.util.ArrayList) Key(io.adminshell.aas.v3.model.Key) Endpoint(de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint) StatusException(com.prosysopc.ua.StatusException) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue)

Example 3 with MultiLanguagePropertyValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue in project FAAAST-Service by FraunhoferIOSB.

the class MultiLanguagePropertyValueMapper method toValue.

@Override
public MultiLanguagePropertyValue toValue(MultiLanguageProperty submodelElement) {
    if (submodelElement == null) {
        return null;
    }
    MultiLanguagePropertyValue multiLanguagePropertyValue = new MultiLanguagePropertyValue();
    // TODO: Check Why is in AAS Model value a List and in MultilanguagePropertyValue a Set?
    multiLanguagePropertyValue.setLangStringSet(new HashSet<>(submodelElement.getValues()));
    return multiLanguagePropertyValue;
}
Also used : MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue)

Example 4 with MultiLanguagePropertyValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testMultilanguagePropertySetValueMapping.

@Test
public void testMultilanguagePropertySetValueMapping() {
    SubmodelElement actual = new DefaultMultiLanguageProperty.Builder().build();
    MultiLanguagePropertyValue value = MultiLanguagePropertyValue.builder().value("deutsch", "de").value("english", "en").build();
    SubmodelElement expected = new DefaultMultiLanguageProperty.Builder().values(List.copyOf(value.getLangStringSet())).build();
    ElementValueMapper.setValue(actual, value);
    Assert.assertEquals(expected, actual);
}
Also used : DefaultMultiLanguageProperty(io.adminshell.aas.v3.model.impl.DefaultMultiLanguageProperty) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue) Test(org.junit.Test)

Aggregations

MultiLanguagePropertyValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue)4 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)2 Test (org.junit.Test)2 StatusException (com.prosysopc.ua.StatusException)1 Endpoint (de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint)1 Response (de.fraunhofer.iosb.ilt.faaast.service.model.api.Response)1 InvokeOperationSyncResponse (de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse)1 SetSubmodelElementValueByPathRequest (de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest)1 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)1 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)1 ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)1 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)1 Key (io.adminshell.aas.v3.model.Key)1 MultiLanguageProperty (io.adminshell.aas.v3.model.MultiLanguageProperty)1 DefaultMultiLanguageProperty (io.adminshell.aas.v3.model.impl.DefaultMultiLanguageProperty)1 ArrayList (java.util.ArrayList)1