Search in sources :

Example 41 with Task

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

the class ModelRestService method resumeTasks.

//	@DELETE
//	@Path("tasks/{oid}/suspend")
//    public Response suspendAndDeleteTasks(@PathParam("oid") String taskOid, @Context MessageContext mc) {
//
//    	Task task = RestServiceUtil.initRequest(mc);
//		OperationResult parentResult = task.getResult().createSubresult(OPERATION_SUSPEND_AND_DELETE_TASKS);
//
//		Response response;
//		Collection<String> taskOids = MiscUtil.createCollection(taskOid);
//		try {
//			model.suspendAndDeleteTasks(taskOids, WAIT_FOR_TASK_STOP, true, parentResult);
//
//			parentResult.computeStatus();
//			if (parentResult.isSuccess()) {
//				response = Response.accepted().build();
//			} else {
//				response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(parentResult.getMessage()).build();
//			}
//		} catch (Exception ex) {
//			response = RestServiceUtil.handleException(parentResult, ex);
//		}
//
//		finishRequest(task);
//		return response;
//    }
@POST
@Path("/tasks/{oid}/resume")
public Response resumeTasks(@PathParam("oid") String taskOid, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_RESUME_TASKS);
    Response response;
    Collection<String> taskOids = MiscUtil.createCollection(taskOid);
    try {
        model.resumeTasks(taskOids, parentResult);
        parentResult.computeStatus();
        response = RestServiceUtil.createResponse(Response.Status.ACCEPTED, parentResult);
    //			if (parentResult.isSuccess()) {
    //				response = Response.accepted().build();
    //			} else {
    //				response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(parentResult.getMessage()).build();
    //			}
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    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 42 with Task

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

the class ModelRestService method getLogFileSize.

@GET
@Path("/log/size")
@Produces({ "text/plain" })
public Response getLogFileSize(@Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult result = task.getResult().createSubresult(OPERATION_GET_LOG_FILE_SIZE);
    Response response;
    try {
        long size = modelDiagnosticService.getLogFileSize(task, result);
        response = RestServiceUtil.createResponse(Response.Status.OK, String.valueOf(size), result);
    //			ResponseBuilder builder = Response.ok();
    //			builder.entity(String.valueOf(size));
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(result, ex);
    }
    result.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 43 with Task

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

the class ModelRestService method getLog.

@GET
@Path("/log")
@Produces({ "text/plain" })
public Response getLog(@QueryParam("fromPosition") Long fromPosition, @QueryParam("maxSize") Long maxSize, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult result = task.getResult().createSubresult(OPERATION_GET_LOG_FILE_CONTENT);
    Response response;
    try {
        LogFileContentType content = modelDiagnosticService.getLogFileContent(fromPosition, maxSize, task, result);
        ResponseBuilder builder = Response.ok();
        builder.entity(content.getContent());
        builder.header("ReturnedDataPosition", content.getAt());
        builder.header("ReturnedDataComplete", content.isComplete());
        builder.header("CurrentLogFileSize", content.getLogFileSize());
        response = builder.build();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Cannot get log file content: fromPosition={}, maxSize={}", ex, fromPosition, maxSize);
        response = RestServiceUtil.handleException(result, ex);
    }
    result.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) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 44 with Task

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

the class ModelRestService method notifyChange.

@POST
@Path("/notifyChange")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public Response notifyChange(ResourceObjectShadowChangeDescriptionType changeDescription, @Context UriInfo uriInfo, @Context MessageContext mc) {
    LOGGER.debug("model rest service for notify change operation start");
    Validate.notNull(changeDescription, "Chnage description must not be null");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_NOTIFY_CHANGE);
    Response response;
    try {
        model.notifyChange(changeDescription, parentResult, task);
        response = RestServiceUtil.createResponse(Response.Status.OK, parentResult);
    //			return Response.ok().build();
    //			String oldShadowOid = changeDescription.getOldShadowOid();
    //			if (oldShadowOid != null){
    //				URI resourceURI = uriInfo.getAbsolutePathBuilder().path(oldShadowOid).build(oldShadowOid);
    //				return Response.accepted().location(resourceURI).build();
    //			} else {
    //				changeDescription.get
    //			}
    //			response = Response.seeOther((uriInfo.getBaseUriBuilder().path(this.getClass(), "getObject").build(ObjectTypes.TASK.getRestType(), task.getOid()))).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) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 45 with Task

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

the class ModelRestService method getValuePolicyForUser.

@GET
@Path("/users/{id}/policy")
public Response getValuePolicyForUser(@PathParam("id") String oid, @Context MessageContext mc) {
    LOGGER.debug("getValuePolicyForUser start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_GET);
    Response response;
    try {
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
        PrismObject<UserType> user = model.getObject(UserType.class, oid, options, task, parentResult);
        CredentialsPolicyType policy = modelInteraction.getCredentialsPolicy(user, task, parentResult);
        response = RestServiceUtil.createResponse(Response.Status.OK, policy, parentResult);
    //			ResponseBuilder builder = Response.ok();
    //			builder.entity(policy);
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    LOGGER.debug("getValuePolicyForUser finish");
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) 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