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);
}
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;
}
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;
}
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);
}
Aggregations