Search in sources :

Example 1 with AsyncProvisioningRequest

use of com.evolveum.midpoint.provisioning.ucf.api.async.AsyncProvisioningRequest in project midpoint by Evolveum.

the class OperationRequestTransformer method transformOperationRequested.

@NotNull
public AsyncProvisioningRequest transformOperationRequested(@NotNull OperationRequested operationRequested, Task task, OperationResult result) {
    try {
        PredefinedOperationRequestTransformationType predefinedTransformation = connectorInstance.getPredefinedTransformation();
        if (predefinedTransformation != null) {
            return transformerHelper.applyPredefinedTransformation(operationRequested, predefinedTransformation);
        }
        ExpressionType transformExpression = connectorInstance.getTransformExpression();
        if (transformExpression != null) {
            VariablesMap variables = new VariablesMap();
            variables.put(VAR_OPERATION_REQUESTED, operationRequested, operationRequested.getClass());
            variables.put(VAR_TRANSFORMER_HELPER, transformerHelper, TransformerHelper.class);
            variables.put(VAR_REQUEST_FORMATTER, transformerHelper.jsonRequestFormatter(operationRequested), JsonRequestFormatter.class);
            List<?> list = connectorInstance.getUcfExpressionEvaluator().evaluate(transformExpression, variables, SchemaConstantsGenerated.C_ASYNC_PROVISIONING_REQUEST, "creating asynchronous provisioning request", task, result);
            if (list.isEmpty()) {
                throw new IllegalStateException("Transformational script returned no value");
            }
            if (list.size() > 1) {
                throw new IllegalStateException("Transformational script returned more than single value: " + list);
            }
            Object o = list.get(0);
            if (o == null) {
                // In the future we can call e.g. default request creator here
                throw new IllegalStateException("Transformational script returned no value");
            } else if (o instanceof AsyncProvisioningRequest) {
                return (AsyncProvisioningRequest) o;
            } else if (o instanceof String) {
                return StringAsyncProvisioningRequest.of((String) o);
            } else {
                throw new IllegalStateException("Transformational script should provide an AsyncProvisioningRequest but created " + MiscUtil.getClass(o) + " instead");
            }
        } else {
            return transformerHelper.applyPredefinedTransformation(operationRequested, SIMPLIFIED_JSON);
        }
    } catch (RuntimeException | SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException | IOException e) {
        throw new SystemException("Couldn't evaluate message transformation expression: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) PredefinedOperationRequestTransformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.PredefinedOperationRequestTransformationType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) StringAsyncProvisioningRequest(com.evolveum.midpoint.provisioning.ucf.api.async.StringAsyncProvisioningRequest) AsyncProvisioningRequest(com.evolveum.midpoint.provisioning.ucf.api.async.AsyncProvisioningRequest) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AsyncProvisioningRequest

use of com.evolveum.midpoint.provisioning.ucf.api.async.AsyncProvisioningRequest in project midpoint by Evolveum.

the class AsyncProvisioningConnectorInstance method createAndSendRequest.

private <X> AsynchronousOperationReturnValue<X> createAndSendRequest(OperationRequested operation, Task task, OperationResult result) {
    AsyncProvisioningRequest request = transformer.transformOperationRequested(operation, task, result);
    String asyncOperationReference = sendRequest(request, result);
    AsynchronousOperationReturnValue<X> ret = new AsynchronousOperationReturnValue<>();
    if (configuration.isOperationExecutionConfirmation()) {
        ret.setOperationType(PendingOperationTypeType.ASYNCHRONOUS);
        result.setInProgress();
        result.setAsynchronousOperationReference(asyncOperationReference);
    } else {
        result.setStatus(OperationResultStatus.SUCCESS);
    }
    ret.setOperationResult(result);
    return ret;
}
Also used : AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) AsyncProvisioningRequest(com.evolveum.midpoint.provisioning.ucf.api.async.AsyncProvisioningRequest)

Aggregations

AsyncProvisioningRequest (com.evolveum.midpoint.provisioning.ucf.api.async.AsyncProvisioningRequest)2 StringAsyncProvisioningRequest (com.evolveum.midpoint.provisioning.ucf.api.async.StringAsyncProvisioningRequest)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1 AsynchronousOperationReturnValue (com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue)1 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)1 PredefinedOperationRequestTransformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.PredefinedOperationRequestTransformationType)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1