Search in sources :

Example 16 with Property

use of com.adobe.target.delivery.v1.model.Property 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 providerConfig) throws AssetConnectionException {
    String baseErrorMessage = "error registering operation provider";
    final NodeId nodeId = parseNodeId(providerConfig.getNodeId());
    final UaNode node;
    try {
        node = client.getAddressSpace().getNode(nodeId);
    } catch (UaException e) {
        throw new AssetConnectionException(String.format("%s - could not resolve nodeId (nodeId: %s)", baseErrorMessage, providerConfig.getNodeId()), e);
    }
    if (!UaMethodNode.class.isAssignableFrom(node.getClass())) {
        throw new AssetConnectionException(String.format("%s - provided node must be a method (nodeId: %s", baseErrorMessage, providerConfig.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 e) {
        throw new AssetConnectionException(String.format("%s - could not resolve parent node (nodeId: %s)", baseErrorMessage, providerConfig.getNodeId()), e);
    }
    final Argument[] methodArguments;
    try {
        methodArguments = methodNode.readInputArgumentsAsync().get() != null ? methodNode.readInputArgumentsAsync().get() : new Argument[0];
    } catch (InterruptedException | ExecutionException e) {
        Thread.currentThread().interrupt();
        throw new AssetConnectionException(String.format("%s - could not read input arguments (nodeId: %s)", baseErrorMessage, providerConfig.getNodeId()), e);
    }
    final Argument[] methodOutputArguments;
    try {
        methodOutputArguments = methodNode.readOutputArgumentsAsync().get() != null ? methodNode.readOutputArgumentsAsync().get() : new Argument[0];
    } catch (InterruptedException | ExecutionException e) {
        Thread.currentThread().interrupt();
        throw new AssetConnectionException(String.format("%s - could not read ouput arguments (nodeId: %s)", baseErrorMessage, providerConfig.getNodeId()), e);
    }
    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, providerConfig.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, providerConfig.getNodeId()));
        }
        if (!Property.class.isAssignableFrom(submodelElement.getClass())) {
            throw new AssetConnectionException(String.format("%s - unsupported element type (nodeId: %s, element type: %s)", baseErrorMessage, submodelElement.getClass(), providerConfig.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 = new HashMap<>();
            if (input != null) {
                try {
                    inputParameter = Stream.of(input).collect(Collectors.toMap(x -> x.getValue().getIdShort(), LambdaExceptionHelper.rethrowFunction(x -> ElementValueMapper.toValue(x.getValue()))));
                } catch (ValueMappingException e) {
                    throw new AssetConnectionException(String.format("%s - could not exract value of input parameters", baseErrorMessage), e);
                }
            }
            Map<String, ElementValue> inoutputParameter = new HashMap<>();
            if (inoutput != null) {
                try {
                    inoutputParameter = Stream.of(inoutput).collect(Collectors.toMap(x -> x.getValue().getIdShort(), LambdaExceptionHelper.rethrowFunction(x -> ElementValueMapper.toValue(x.getValue()))));
                } catch (ValueMappingException e) {
                    throw new AssetConnectionException(String.format("%s - could not exract value of inoutput parameters", baseErrorMessage), e);
                }
            }
            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 e) {
                Thread.currentThread().interrupt();
                throw new AssetConnectionException(String.format("%s - executing OPC UA method failed (nodeId: %s)", baseErrorMessage, providerConfig.getNodeId()), e);
            }
            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;
                        try {
                            targetType = ((PropertyValue) ElementValueMapper.toValue(element)).getValue().getDataType();
                        } catch (ValueMappingException e) {
                            throw new AssetConnectionException(String.format("%s - could not exract value of results variable with idShort '%s'", baseErrorMessage, element.getIdShort()), e);
                        }
                        TypedValue<?> newValue = valueConverter.convert(methodResult.getOutputArguments()[i], targetType);
                        Property newProperty = DeepCopyHelper.deepCopy(element, Property.class);
                        ElementValueMapper.setValue(newProperty, PropertyValue.builder().value(newValue).build());
                        result[j] = new DefaultOperationVariable.Builder().value(newProperty).build();
                    }
                }
                // update inoutput variable values
                if (inoutputParameter.containsKey(argumentName) && inoutput != null) {
                    // 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) ValueMappingException(de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException) 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) ConfigurationInitializationException(de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException) 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) DeepCopyHelper(de.fraunhofer.iosb.ilt.faaast.service.util.DeepCopyHelper) 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) UaException(org.eclipse.milo.opcua.stack.core.UaException) ValueMappingException(de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException) 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) 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) 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 17 with Property

use of com.adobe.target.delivery.v1.model.Property in project uPMT by coco35700.

the class TypeClassRepresentationController method loadProperties.

public void loadProperties() {
    // for each Property, add a representation
    if (!classe.getTypes().isEmpty()) {
        for (Type p : classe.getTypes()) {
            Property prop = (Property) p;
            TypePropertyRepresentation controller = new TypePropertyRepresentation(prop, moment, treeClassTreeItem, main);
            this.properties.getChildren().add(controller);
        }
    }
}
Also used : Type(model.Type) Property(model.Property)

Example 18 with Property

use of com.adobe.target.delivery.v1.model.Property in project synthea by synthetichealth.

the class FhirR4 method newEntry.

/**
 * Helper function to create an Entry for the given Resource within the given Bundle. Sets the
 * resourceID to a random UUID, sets the entry's fullURL to that resourceID, and adds the entry to
 * the bundle.
 *
 * @param bundle   The Bundle to add the Entry to
 * @param resource Resource the new Entry should contain
 * @param resourceID The Resource ID to assign
 * @return the created Entry
 */
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) {
    BundleEntryComponent entry = bundle.addEntry();
    resource.setId(resourceID);
    entry.setFullUrl(getUrlPrefix(resource.fhirType()) + resourceID);
    entry.setResource(resource);
    if (TRANSACTION_BUNDLE) {
        BundleEntryRequestComponent request = entry.getRequest();
        request.setMethod(HTTPVerb.POST);
        String resourceType = resource.getResourceType().name();
        request.setUrl(resourceType);
        if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
            Property prop = entry.getResource().getNamedProperty("identifier");
            if (prop != null && prop.getValues().size() > 0) {
                Identifier identifier = (Identifier) prop.getValues().get(0);
                request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
            }
        }
        entry.setRequest(request);
    }
    return entry;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) Property(org.hl7.fhir.r4.model.Property)

Example 19 with Property

use of com.adobe.target.delivery.v1.model.Property in project synthea by synthetichealth.

the class FhirStu3 method newEntry.

/**
 * Helper function to create an Entry for the given Resource within the given Bundle.
 * Sets the entry's fullURL to resourceID, and adds the entry to the bundle.
 *
 * @param bundle The Bundle to add the Entry to
 * @param resource Resource the new Entry should contain
 * @param resourceID The Resource ID to assign
 * @return the created Entry
 */
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) {
    BundleEntryComponent entry = bundle.addEntry();
    resource.setId(resourceID);
    if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
        entry.setFullUrl(resource.fhirType() + "/" + resourceID);
    } else {
        entry.setFullUrl("urn:uuid:" + resourceID);
    }
    entry.setResource(resource);
    if (TRANSACTION_BUNDLE) {
        BundleEntryRequestComponent request = entry.getRequest();
        request.setMethod(HTTPVerb.POST);
        String resourceType = resource.getResourceType().name();
        request.setUrl(resourceType);
        if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
            Property prop = entry.getResource().getNamedProperty("identifier");
            if (prop != null && prop.getValues().size() > 0) {
                Identifier identifier = (Identifier) prop.getValues().get(0);
                request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
            }
        }
        entry.setRequest(request);
    }
    return entry;
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.dstu3.model.Identifier) BundleEntryRequestComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent) Property(org.hl7.fhir.dstu3.model.Property)

Example 20 with Property

use of com.adobe.target.delivery.v1.model.Property in project FAAAST-Service by FraunhoferIOSB.

the class ValueConverter method setOutputArguments.

/**
 * Sets the output arguments for an operation from the given output variables.
 *
 * @param outputVariables The desired output variables
 * @param outputArguments The desired output arguments
 * @throws StatusException If the operation fails
 */
public static void setOutputArguments(List<OperationVariable> outputVariables, Variant[] outputArguments) throws StatusException {
    if (outputArguments.length != outputVariables.size()) {
        throw new StatusException(StatusCodes.Bad_InvalidArgument);
    } else {
        for (int i = 0; i < outputVariables.size(); i++) {
            SubmodelElement smelem = outputVariables.get(i).getValue();
            SubmodelElementData.Type type;
            if (smelem instanceof Property) {
                type = SubmodelElementData.Type.PROPERTY_VALUE;
            } else {
                throw new StatusException(StatusCodes.Bad_InvalidArgument);
            }
            outputArguments[i] = getSubmodelElementValue(smelem, type);
        }
    }
}
Also used : StatusException(com.prosysopc.ua.StatusException) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Property(io.adminshell.aas.v3.model.Property) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Aggregations

TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)10 Property (com.adobe.target.delivery.v1.model.Property)9 Test (org.junit.jupiter.api.Test)9 Context (com.adobe.target.delivery.v1.model.Context)8 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)8 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)8 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)8 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)8 TimingTool (com.adobe.target.edge.client.utils.TimingTool)8 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)7 Property (io.adminshell.aas.v3.model.Property)7 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)5 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)5 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)5 ArrayList (java.util.ArrayList)5 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)4 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)4 HashMap (java.util.HashMap)4 Property (model.Property)4 Type (model.Type)3