Search in sources :

Example 1 with MultiLanguageProperty

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;
}
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 2 with MultiLanguageProperty

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;
    }
}
Also used : AASMultiLanguagePropertyType(opc.i4aas.AASMultiLanguagePropertyType) LangString(io.adminshell.aas.v3.model.LangString) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Aggregations

StatusException (com.prosysopc.ua.StatusException)1 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)1 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)1 Endpoint (de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint)1 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)1 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)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 MultiLanguagePropertyValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue)1 Key (io.adminshell.aas.v3.model.Key)1 LangString (io.adminshell.aas.v3.model.LangString)1 MultiLanguageProperty (io.adminshell.aas.v3.model.MultiLanguageProperty)1 Reference (io.adminshell.aas.v3.model.Reference)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1 ArrayList (java.util.ArrayList)1 AASMultiLanguagePropertyType (opc.i4aas.AASMultiLanguagePropertyType)1