use of io.adminshell.aas.v3.model.MultiLanguageProperty 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 io.adminshell.aas.v3.model.MultiLanguageProperty in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasMultiLanguageProperty.
/**
* Adds an AAS Multi Language Property to the given node.
*
* @param node The desired UA node
* @param aasMultiLang The AAS Multi Language Property to add
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The AAS reference to the parent object
* @param ordered Specifies whether the multi language property should be
* added ordered (true) or unordered (false)
* @throws StatusException If the operation fails
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private void addAasMultiLanguageProperty(UaNode node, MultiLanguageProperty aasMultiLang, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasMultiLang != null)) {
String name = aasMultiLang.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASMultiLanguagePropertyType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASMultiLanguagePropertyType multiLangNode = createInstance(AASMultiLanguagePropertyType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(multiLangNode, aasMultiLang);
List<LangString> values = aasMultiLang.getValues();
if (values != null) {
if (multiLangNode.getValueNode() == null) {
addMultiLanguageValueNode(multiLangNode, values.size());
}
multiLangNode.getValueNode().setValue(ValueConverter.getLocalizedTextFromLangStringSet(values));
}
if (aasMultiLang.getValueId() != null) {
addAasReferenceAasNS(multiLangNode, aasMultiLang.getValueId(), AASMultiLanguagePropertyType.VALUE_ID);
}
Reference multiLangRef = AasUtils.toReference(parentRef, aasMultiLang);
submodelElementAasMap.put(multiLangNode.getValueNode().getNodeId(), new SubmodelElementData(aasMultiLang, submodel, SubmodelElementData.Type.MULTI_LANGUAGE_VALUE, multiLangRef));
submodelElementOpcUAMap.put(multiLangRef, multiLangNode);
if (ordered) {
node.addReference(multiLangNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(multiLangNode);
}
referableMap.put(multiLangRef, new ObjectData(aasMultiLang, multiLangNode, submodel));
}
} catch (Throwable ex) {
logger.error("addAasMultiLanguageProperty Exception", ex);
throw ex;
}
}
Aggregations