Search in sources :

Example 46 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class ModelRestService method testResource.

@POST
@Path("/resources/{resourceOid}/test")
public //	@Produces({"text/html", "application/xml"})
Response testResource(@PathParam("resourceOid") String resourceOid, @Context MessageContext mc) {
    LOGGER.debug("model rest service for test resource operation start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_TEST_RESOURCE);
    Response response;
    OperationResult testResult = null;
    try {
        testResult = model.testResource(resourceOid, task);
        response = RestServiceUtil.createResponse(Response.Status.OK, testResult, parentResult);
    //			response = Response.ok(testResult).build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    if (testResult != null) {
        parentResult.getSubresults().add(testResult);
    }
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 47 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class ModelRestService method findShadowOwner.

@GET
@Path("/shadows/{oid}/owner")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public Response findShadowOwner(@PathParam("oid") String shadowOid, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_FIND_SHADOW_OWNER);
    Response response;
    try {
        PrismObject<UserType> user = model.findShadowOwner(shadowOid, task, parentResult);
        //			response = Response.ok().entity(user).build();
        response = RestServiceUtil.createResponse(Response.Status.NO_CONTENT, user, parentResult);
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 48 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class ModelRestService method addObject.

@POST
@Path("/{type}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response addObject(@PathParam("type") String type, PrismObject<T> object, @QueryParam("options") List<String> options, @Context UriInfo uriInfo, @Context MessageContext mc) {
    LOGGER.debug("model rest service for add operation start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_ADD_OBJECT);
    Class clazz = ObjectTypes.getClassFromRestType(type);
    if (!object.getCompileTimeClass().equals(clazz)) {
        finishRequest(task);
        parentResult.recordFatalError("Request to add object of type " + object.getCompileTimeClass().getSimpleName() + " to the collection of " + type);
        return RestServiceUtil.createErrorResponseBuilder(Status.BAD_REQUEST, parentResult).build();
    }
    ModelExecuteOptions modelExecuteOptions = ModelExecuteOptions.fromRestOptions(options);
    String oid;
    Response response;
    try {
        oid = model.addObject(object, modelExecuteOptions, task, parentResult);
        LOGGER.debug("returned oid :  {}", oid);
        ResponseBuilder builder;
        if (oid != null) {
            URI resourceURI = uriInfo.getAbsolutePathBuilder().path(oid).build(oid);
            response = // TODO not the other way around?
            clazz.isAssignableFrom(TaskType.class) ? RestServiceUtil.createResponse(Response.Status.ACCEPTED, resourceURI, parentResult) : RestServiceUtil.createResponse(Response.Status.CREATED, resourceURI, parentResult);
        //				builder = clazz.isAssignableFrom(TaskType.class) ?		// TODO not the other way around?
        //						Response.accepted().location(resourceURI) : Response.created(resourceURI);
        } else {
            // OID might be null e.g. if the object creation is a subject of workflow approval
            //				builder = Response.accepted();			// TODO is this ok ?
            response = RestServiceUtil.createResponse(Response.Status.ACCEPTED, parentResult);
        }
    // (not used currently)
    //validateIfRequested(object, options, builder, task, parentResult);
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 49 with Task

use of com.evolveum.midpoint.task.api.Task 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)

Example 50 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class ModelRestService method deleteObject.

@DELETE
@Path("/{type}/{id}")
public //	@Produces({"text/html", "application/xml"})
Response deleteObject(@PathParam("type") String type, @PathParam("id") String id, @QueryParam("options") List<String> options, @Context MessageContext mc) {
    LOGGER.debug("model rest service for delete operation start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_DELETE_OBJECT);
    Class clazz = ObjectTypes.getClassFromRestType(type);
    Response response;
    try {
        if (clazz.isAssignableFrom(TaskType.class)) {
            model.suspendAndDeleteTasks(MiscUtil.createCollection(id), WAIT_FOR_TASK_STOP, true, parentResult);
            parentResult.computeStatus();
            finishRequest(task);
            if (parentResult.isSuccess()) {
                return Response.noContent().build();
            }
            return Response.serverError().entity(parentResult.getMessage()).build();
        }
        ModelExecuteOptions modelExecuteOptions = ModelExecuteOptions.fromRestOptions(options);
        model.deleteObject(clazz, id, modelExecuteOptions, task, parentResult);
        //			response = Response.noContent().build();
        response = RestServiceUtil.createResponse(Response.Status.NO_CONTENT, parentResult);
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

Task (com.evolveum.midpoint.task.api.Task)4943 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4698 Test (org.testng.annotations.Test)3991 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)599 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)542 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)464 PrismObject (com.evolveum.midpoint.prism.PrismObject)327 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)323 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)290 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)282 ArrayList (java.util.ArrayList)249 QName (javax.xml.namespace.QName)208 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)199 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)193 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)175 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)159 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)140 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)123 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)108 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)108