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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations