Search in sources :

Example 1 with TypedValue

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

the class OpcUaAssetConnection method registerOperationProvider.

/**
 * {@inheritdoc}
 *
 * @throws AssetConnectionException if nodeId could not be parsed
 * @throws AssetConnectionException if nodeId does not refer to a method
 *             node
 * @throws AssetConnectionException if parent node of nodeId could not be
 *             resolved
 * @throws AssetConnectionException if output variables are null or do
 *             contain any other type than
 *             {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue}
 */
@Override
public void registerOperationProvider(Reference reference, OpcUaOperationProviderConfig operationProvider) throws AssetConnectionException {
    String baseErrorMessage = "error registering operation provider";
    final NodeId nodeId = parseNodeId(operationProvider.getNodeId());
    final UaNode node;
    try {
        node = client.getAddressSpace().getNode(nodeId);
    } catch (UaException ex) {
        throw new AssetConnectionException(String.format("%s - could not resolve nodeId (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    if (!UaMethodNode.class.isAssignableFrom(node.getClass())) {
        throw new AssetConnectionException(String.format("%s - provided node must be a method (nodeId: %s", baseErrorMessage, operationProvider.getNodeId()));
    }
    final UaMethodNode methodNode = (UaMethodNode) node;
    final NodeId parentNodeId;
    try {
        parentNodeId = client.getAddressSpace().getNode(nodeId).browseNodes(AddressSpace.BrowseOptions.builder().setBrowseDirection(BrowseDirection.Inverse).build()).get(0).getNodeId();
    } catch (UaException ex) {
        throw new AssetConnectionException(String.format("%s - could not resolve parent node (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    final Argument[] methodArguments;
    try {
        methodArguments = methodNode.readInputArgumentsAsync().get() != null ? methodNode.readInputArgumentsAsync().get() : new Argument[0];
    } catch (InterruptedException | ExecutionException ex) {
        throw new AssetConnectionException(String.format("%s - could not read input arguments (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    final Argument[] methodOutputArguments;
    try {
        methodOutputArguments = methodNode.readOutputArgumentsAsync().get() != null ? methodNode.readOutputArgumentsAsync().get() : new Argument[0];
    } catch (InterruptedException | ExecutionException ex) {
        throw new AssetConnectionException(String.format("%s - could not read ouput arguments (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()), ex);
    }
    final OperationVariable[] outputVariables = serviceContext.getOperationOutputVariables(reference) != null ? serviceContext.getOperationOutputVariables(reference) : new OperationVariable[0];
    for (var outputVariable : outputVariables) {
        if (outputVariable == null) {
            throw new AssetConnectionException(String.format("%s - output variable must be non-null (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()));
        }
        SubmodelElement submodelElement = outputVariable.getValue();
        if (submodelElement == null) {
            throw new AssetConnectionException(String.format("%s - output variable must contain non-null submodel element (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()));
        }
        if (!Property.class.isAssignableFrom(submodelElement.getClass())) {
            throw new AssetConnectionException(String.format("%s - unsupported element type (nodeId: %s, element type: %s)", baseErrorMessage, submodelElement.getClass(), operationProvider.getNodeId()));
        }
    }
    this.operationProviders.put(reference, new AssetOperationProvider() {

        @Override
        public OperationVariable[] invoke(OperationVariable[] input, OperationVariable[] inoutput) throws AssetConnectionException {
            String baseErrorMessage = "error invoking operation on asset connection";
            Map<String, ElementValue> inputParameter = input == null ? new HashMap<>() : Stream.of(input).collect(Collectors.toMap(x -> x.getValue().getIdShort(), x -> ElementValueMapper.toValue(x.getValue())));
            Map<String, ElementValue> inoutputParameter = inoutput == null ? new HashMap<>() : Stream.of(inoutput).collect(Collectors.toMap(x -> x.getValue().getIdShort(), x -> ElementValueMapper.toValue(x.getValue())));
            if (methodArguments.length != (inputParameter.size() + inoutputParameter.size())) {
                throw new AssetConnectionException(String.format("%s - argument count mismatch (expected: %d, provided input arguments: %d, provided inoutput arguments: %d)", baseErrorMessage, methodArguments.length, inputParameter.size(), inoutputParameter.size()));
            }
            Variant[] actualParameters = new Variant[methodArguments.length];
            for (int i = 0; i < methodArguments.length; i++) {
                String argumentName = methodArguments[i].getName();
                ElementValue parameterValue;
                if (inputParameter.containsKey(argumentName)) {
                    parameterValue = inputParameter.get(argumentName);
                } else if (inoutputParameter.containsKey(argumentName)) {
                    parameterValue = inoutputParameter.get(argumentName);
                } else {
                    throw new AssetConnectionException(String.format("%s - missing argument (argument name: %s)", baseErrorMessage, argumentName));
                }
                if (parameterValue == null) {
                    throw new AssetConnectionException(String.format("%s - parameter value must be non-null (argument name: %s)", baseErrorMessage, argumentName));
                }
                if (!PropertyValue.class.isAssignableFrom(parameterValue.getClass())) {
                    throw new AssetConnectionException(String.format("%s - currently only parameters of the Property are supported (argument name: %s, provided type: %s)", baseErrorMessage, argumentName, parameterValue.getClass()));
                }
                actualParameters[i] = valueConverter.convert(((PropertyValue) parameterValue).getValue(), methodArguments[i].getDataType());
            }
            CallMethodResult methodResult;
            try {
                methodResult = client.call(new CallMethodRequest(parentNodeId, nodeId, actualParameters)).get();
            } catch (InterruptedException | ExecutionException ex) {
                throw new AssetConnectionException(String.format("%s - executing OPC UA method failed (nodeId: %s)", baseErrorMessage, operationProvider.getNodeId()));
            }
            OperationVariable[] result = new OperationVariable[outputVariables.length];
            for (int i = 0; i < methodOutputArguments.length; i++) {
                String argumentName = methodArguments[i].getName();
                for (int j = 0; j < outputVariables.length; j++) {
                    if (Objects.equals(argumentName, outputVariables[j].getValue().getIdShort())) {
                        SubmodelElement element = outputVariables[j].getValue();
                        Datatype targetType = ((PropertyValue) ElementValueMapper.toValue(element)).getValue().getDataType();
                        TypedValue<?> newValue = valueConverter.convert(methodResult.getOutputArguments()[i], targetType);
                        // TODO better use deep copy?
                        DefaultProperty newProperty = new DefaultProperty.Builder().idShort(element.getIdShort()).build();
                        ElementValueMapper.setValue(newProperty, PropertyValue.builder().value(newValue).build());
                        result[j] = new DefaultOperationVariable.Builder().value(newProperty).build();
                    }
                }
                // update inoutput variable values
                if (inoutputParameter.containsKey(argumentName)) {
                    // find in original array and set there
                    for (int j = 0; j < inoutput.length; j++) {
                        if (Objects.equals(argumentName, inoutput[j].getValue().getIdShort())) {
                            ElementValueMapper.setValue(inoutput[j].getValue(), new PropertyValue(valueConverter.convert(methodResult.getOutputArguments()[i], ((PropertyValue) inoutputParameter.get(argumentName)).getValue().getDataType())));
                        }
                    }
                }
            }
            return result;
        }
    });
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ValueConversionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConversionException) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) LoggerFactory(org.slf4j.LoggerFactory) CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) NewDataListener(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.NewDataListener) Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) ManagedDataItem(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Property(io.adminshell.aas.v3.model.Property) Map(java.util.Map) AssetConnection(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection) UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) ManagedSubscription(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription) AnonymousProvider(org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) Reference(io.adminshell.aas.v3.model.Reference) Collectors(java.util.stream.Collectors) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) AasUtils(io.adminshell.aas.v3.dataformat.core.util.AasUtils) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo) Optional(java.util.Optional) ElementValueTypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) ServiceContext(de.fraunhofer.iosb.ilt.faaast.service.ServiceContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) SecurityPolicy(org.eclipse.milo.opcua.stack.core.security.SecurityPolicy) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) ValueConverter(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConverter) AssetSubscriptionProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetSubscriptionProvider) ExecutionException(java.util.concurrent.ExecutionException) UaException(org.eclipse.milo.opcua.stack.core.UaException) LambdaExceptionHelper(de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper) AssetValueProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) HashMap(java.util.HashMap) UaException(org.eclipse.milo.opcua.stack.core.UaException) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) ExecutionException(java.util.concurrent.ExecutionException) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Property(io.adminshell.aas.v3.model.Property) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with TypedValue

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

the class AasServiceNodeManager method setPropertyValue.

/**
 * Sets the value of a property.
 *
 * @param property The desired Property
 * @param value The new value.
 * @throws StatusException If the operation fails.
 */
private void setPropertyValue(AASPropertyType property, PropertyValue value) throws StatusException {
    if (property == null) {
        throw new IllegalArgumentException("property is null");
    } else if (value == null) {
        throw new IllegalArgumentException("value is null");
    }
    logger.debug("setPropertyValue: " + property.getBrowseName().getName() + " to " + value.getValue());
    try {
        // special treatment for some not directly supported types
        TypedValue tv = value.getValue();
        Object obj = tv.getValue();
        if ((tv instanceof DecimalValue) || (tv instanceof IntegerValue)) {
            obj = Long.parseLong(obj.toString());
        }
        property.setValue(obj);
    // switch (property.getValueType()) {
    // case ByteString:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Boolean:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case DateTime:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Int32:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UInt32:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Int64:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UInt64:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Int16:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UInt16:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Byte:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case SByte:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Double:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case Float:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case LocalizedText:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case String:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // case UtcTime:
    // // TODO integrate Property value
    // property.setValue(value.getValue());
    // break;
    // 
    // default:
    // logger.warn("setPropertyValue: Property " + property.getBrowseName().getName() + ": Unknown type: " + property.getValueType());
    // break;
    // }
    } catch (Throwable ex) {
        logger.error("setPropertyValue Exception", ex);
        throw ex;
    }
}
Also used : DecimalValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DecimalValue) IntegerValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.IntegerValue) UaObject(com.prosysopc.ua.nodes.UaObject) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue)

Example 3 with TypedValue

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

the class AasServiceNodeManager method setRangeValueAndType.

/**
 * Adds the min and max properties to the UA range object and sets the values
 *
 * @param aasRange The AAS range object
 * @param range The corresponding UA range object
 * @param submodel The corresponding submodel
 * @param rangeRef The AAS reference to the Range
 */
private void setRangeValueAndType(Range aasRange, AASRangeType range, Submodel submodel, Reference rangeRef) {
    try {
        String minValue = aasRange.getMin();
        String maxValue = aasRange.getMax();
        NodeId myPropertyIdMin = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MIN);
        NodeId myPropertyIdMax = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MAX);
        String valueType = aasRange.getValueType();
        QualifiedName browseNameMin = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MIN).toQualifiedName(getNamespaceTable());
        LocalizedText displayNameMin = LocalizedText.english(AASRangeType.MIN);
        QualifiedName browseNameMax = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MAX).toQualifiedName(getNamespaceTable());
        LocalizedText displayNameMax = LocalizedText.english(AASRangeType.MAX);
        submodelElementAasMap.put(myPropertyIdMin, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MIN, rangeRef));
        submodelElementAasMap.put(myPropertyIdMax, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MAX, rangeRef));
        submodelElementOpcUAMap.put(rangeRef, range);
        TypedValue minTypedValue = TypedValueFactory.create(valueType, minValue);
        TypedValue maxTypedValue = TypedValueFactory.create(valueType, maxValue);
        AASValueTypeDataType valueDataType;
        if (minTypedValue != null) {
            valueDataType = ValueConverter.datatypeToValueType(minTypedValue.getDataType());
        } else {
            valueDataType = ValueConverter.stringToValueType(valueType);
        }
        range.setValueType(valueDataType);
        switch(valueDataType) {
            // 
            case Boolean:
                if (minValue != null) {
                    PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myBoolProperty.setDataTypeId(Identifiers.Boolean);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myBoolProperty.setValue(minTypedValue.getValue());
                    }
                    myBoolProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myBoolProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myBoolProperty.setDataTypeId(Identifiers.Boolean);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myBoolProperty.setValue(maxTypedValue.getValue());
                    }
                    myBoolProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myBoolProperty);
                }
                break;
            // break;
            case Int32:
                if (minValue != null) {
                    PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myIntProperty.setDataTypeId(Identifiers.Int32);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myIntProperty.setValue(minTypedValue.getValue());
                    }
                    myIntProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myIntProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myIntProperty.setDataTypeId(Identifiers.Int32);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myIntProperty.setValue(maxTypedValue.getValue());
                    }
                    myIntProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myIntProperty);
                }
                break;
            case Int64:
                if (minValue != null) {
                    PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myLongProperty.setDataTypeId(Identifiers.Int64);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        Object obj = minTypedValue.getValue();
                        if (!(obj instanceof Long)) {
                            obj = Long.parseLong(obj.toString());
                        }
                        myLongProperty.setValue(obj);
                    }
                    myLongProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myLongProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myLongProperty.setDataTypeId(Identifiers.Int64);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        Object obj = maxTypedValue.getValue();
                        if (!(obj instanceof Long)) {
                            obj = Long.parseLong(obj.toString());
                        }
                        myLongProperty.setValue(obj);
                    }
                    myLongProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myLongProperty);
                }
                break;
            case Int16:
                if (minValue != null) {
                    PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myInt16Property.setDataTypeId(Identifiers.Int16);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myInt16Property.setValue(minTypedValue.getValue());
                    }
                    myInt16Property.setDescription(new LocalizedText("", ""));
                    range.addProperty(myInt16Property);
                }
                if (maxValue != null) {
                    PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myInt16Property.setDataTypeId(Identifiers.Int16);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myInt16Property.setValue(maxTypedValue.getValue());
                    }
                    myInt16Property.setDescription(new LocalizedText("", ""));
                    range.addProperty(myInt16Property);
                }
                break;
            case SByte:
                if (minValue != null) {
                    PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    mySByteProperty.setDataTypeId(Identifiers.SByte);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        mySByteProperty.setValue(minTypedValue.getValue());
                    }
                    mySByteProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(mySByteProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    mySByteProperty.setDataTypeId(Identifiers.SByte);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        mySByteProperty.setValue(maxTypedValue.getValue());
                    }
                    mySByteProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(mySByteProperty);
                }
                break;
            // 
            case Double:
                if (minValue != null) {
                    PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myDoubleProperty.setDataTypeId(Identifiers.Double);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myDoubleProperty.setValue(minTypedValue.getValue());
                    }
                    myDoubleProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myDoubleProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myDoubleProperty.setDataTypeId(Identifiers.Double);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myDoubleProperty.setValue(maxTypedValue.getValue());
                    }
                    myDoubleProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myDoubleProperty);
                }
                break;
            case Float:
                if (minValue != null) {
                    PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myFloatProperty.setDataTypeId(Identifiers.Float);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myFloatProperty.setValue(minTypedValue.getValue());
                    }
                    myFloatProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myFloatProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myFloatProperty.setDataTypeId(Identifiers.Float);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myFloatProperty.setValue(maxTypedValue.getValue());
                    }
                    myFloatProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myFloatProperty);
                }
                break;
            // 
            case String:
                if (minValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myStringProperty.setValue(minTypedValue.getValue());
                    }
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                if (maxValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myStringProperty.setValue(maxTypedValue.getValue());
                    }
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                break;
            // break;
            default:
                logger.warn("setRangeValueAndType: Range " + range.getBrowseName().getName() + ": Unknown type: " + valueType + "; use string as default");
                if (minValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    myStringProperty.setValue(minValue);
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                if (maxValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    myStringProperty.setValue(maxValue);
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                break;
        }
    } catch (Throwable ex) {
        logger.error("setRangeValueAndType Exception", ex);
    }
}
Also used : ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue) AASValueTypeDataType(opc.i4aas.AASValueTypeDataType) PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) UnsignedInteger(com.prosysopc.ua.stack.builtintypes.UnsignedInteger) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaObject(com.prosysopc.ua.nodes.UaObject) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 4 with TypedValue

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

the class AasServiceNodeManager method setRangeValue.

/**
 * Sets the value for the given Range.
 *
 * @param range The desired Range.
 * @param value The new value
 * @throws StatusException If the operation fails
 */
private void setRangeValue(AASRangeType range, RangeValue value) throws StatusException {
    if (range == null) {
        throw new IllegalArgumentException("range is null");
    } else if (value == null) {
        throw new IllegalArgumentException("value is null");
    }
    try {
        // special treatment for some not directly supported types
        TypedValue tvmin = value.getMin();
        Object objmin = tvmin.getValue();
        if ((tvmin instanceof DecimalValue) || (tvmin instanceof IntegerValue)) {
            objmin = Long.parseLong(objmin.toString());
        }
        TypedValue tvmax = value.getMax();
        Object objmax = tvmax.getValue();
        if ((tvmax instanceof DecimalValue) || (tvmax instanceof IntegerValue)) {
            objmax = Long.parseLong(objmax.toString());
        }
        range.setMin(objmin);
        range.setMax(objmax);
    } catch (Throwable ex) {
        logger.error("setRangeValue Exception", ex);
        throw ex;
    }
}
Also used : DecimalValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DecimalValue) IntegerValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.IntegerValue) UaObject(com.prosysopc.ua.nodes.UaObject) TypedValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue)

Aggregations

TypedValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.TypedValue)4 UaObject (com.prosysopc.ua.nodes.UaObject)3 DecimalValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DecimalValue)2 IntegerValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.IntegerValue)2 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)1 PlainProperty (com.prosysopc.ua.server.nodes.PlainProperty)1 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)1 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)1 UnsignedInteger (com.prosysopc.ua.stack.builtintypes.UnsignedInteger)1 ServiceContext (de.fraunhofer.iosb.ilt.faaast.service.ServiceContext)1 AssetConnection (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)1 AssetConnectionException (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException)1 AssetOperationProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider)1 AssetSubscriptionProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetSubscriptionProvider)1 AssetValueProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider)1 NewDataListener (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.NewDataListener)1 ValueConversionException (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConversionException)1 ValueConverter (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConverter)1