Search in sources :

Example 1 with ExecuteScriptOutputType

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

the class ModelRestService method executeScript.

@POST
@Path("/rpc/executeScript")
//	@Produces({"text/html", "application/xml"})
@Consumes({ "application/xml" })
public Response executeScript(@Convertor(ExecuteScriptConvertor.class) ExecuteScriptType command, @QueryParam("asynchronous") Boolean asynchronous, @Context UriInfo uriInfo, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult result = task.getResult().createSubresult(OPERATION_EXECUTE_SCRIPT);
    Response response;
    try {
        if (Boolean.TRUE.equals(asynchronous)) {
            scriptingService.evaluateExpression(command, task, result);
            URI resourceUri = uriInfo.getAbsolutePathBuilder().path(task.getOid()).build(task.getOid());
            response = RestServiceUtil.createResponse(Response.Status.CREATED, resourceUri, result);
        } else {
            ScriptExecutionResult executionResult = scriptingService.evaluateExpression(command, task, result);
            ExecuteScriptResponseType responseData = new ExecuteScriptResponseType().result(result.createOperationResultType()).output(new ExecuteScriptOutputType().consoleOutput(executionResult.getConsoleOutput()).dataOutput(ModelWebService.prepareXmlData(executionResult.getDataOutput(), command.getOptions())));
            response = RestServiceUtil.createResponse(Response.Status.OK, responseData, result);
        }
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(result, ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute script.", ex);
    }
    result.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecuteScriptOutputType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptOutputType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) URI(java.net.URI) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 ExecuteScriptOutputType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptOutputType)1 URI (java.net.URI)1