Search in sources :

Example 1 with PipelineDataType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType in project midpoint by Evolveum.

the class ModelWebService method doExecuteScripts.

private ExecuteScriptsResponseType doExecuteScripts(List<JAXBElement<?>> scriptsToExecute, ExecuteScriptsOptionsType options, Task task, OperationResult result) {
    ExecuteScriptsResponseType response = new ExecuteScriptsResponseType();
    ScriptOutputsType outputs = new ScriptOutputsType();
    response.setOutputs(outputs);
    try {
        for (JAXBElement<?> script : scriptsToExecute) {
            Object scriptValue = script.getValue();
            if (!(scriptValue instanceof ScriptingExpressionType)) {
                throw new SchemaException("Expected that scripts will be of type ScriptingExpressionType, but it was " + scriptValue.getClass().getName());
            }
            ScriptExecutionResult executionResult = scriptingService.evaluateExpression((ScriptingExpressionType) script.getValue(), task, result);
            SingleScriptOutputType output = new SingleScriptOutputType();
            outputs.getOutput().add(output);
            output.setTextOutput(executionResult.getConsoleOutput());
            if (options == null || options.getOutputFormat() == null || options.getOutputFormat() == OutputFormatType.XML) {
                output.setDataOutput(prepareXmlData(executionResult.getDataOutput(), null));
            } else {
                // temporarily we send serialized XML in the case of MSL output
                PipelineDataType jaxbOutput = prepareXmlData(executionResult.getDataOutput(), null);
                output.setMslData(prismContext.xmlSerializer().serializeAnyData(jaxbOutput, SchemaConstants.C_VALUE));
            }
        }
        result.computeStatusIfUnknown();
    } catch (ScriptExecutionException | JAXBException | SchemaException | RuntimeException | SecurityViolationException e) {
        result.recordFatalError(e.getMessage(), e);
        LoggingUtils.logException(LOGGER, "Exception while executing script", e);
    }
    result.summarize();
    response.setResult(result.createOperationResultType());
    return response;
}
Also used : JAXBException(javax.xml.bind.JAXBException) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) ExecuteScriptsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)

Example 2 with PipelineDataType

use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType in project midpoint by Evolveum.

the class ModelWebService method prepareXmlData.

public static PipelineDataType prepareXmlData(List<PipelineItem> output, ScriptingExpressionEvaluationOptionsType options) throws JAXBException, SchemaException {
    boolean hideResults = options != null && Boolean.TRUE.equals(options.isHideOperationResults());
    PipelineDataType rv = new PipelineDataType();
    if (output != null) {
        for (PipelineItem item : output) {
            PipelineItemType itemType = new PipelineItemType();
            PrismValue value = item.getValue();
            if (value instanceof PrismReferenceValue) {
                // This is a bit of hack: value.getRealValue() would return unserializable object (PRV$1 - does not have type QName)
                ObjectReferenceType ort = new ObjectReferenceType();
                ort.setupReferenceValue((PrismReferenceValue) value);
                itemType.setValue(ort);
            } else {
                // TODO - ok?
                itemType.setValue(value.getRealValue());
            }
            if (!hideResults) {
                itemType.setResult(item.getResult().createOperationResultType());
            }
            rv.getItem().add(itemType);
        }
    }
    return rv;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

PipelineDataType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 ExecuteScriptsResponseType (com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType)1 PipelineItemType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType)1 ScriptingExpressionType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType)1 JAXBException (javax.xml.bind.JAXBException)1