Search in sources :

Example 51 with Task

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

the class ModelRestService method compare.

@POST
@Path("/rpc/compare")
//	@Produces({"text/html", "application/xml"})
@Consumes({ "application/xml" })
public <T extends ObjectType> Response compare(PrismObject<T> clientObject, @QueryParam("readOptions") List<String> restReadOptions, @QueryParam("compareOptions") List<String> restCompareOptions, @QueryParam("ignoreItems") List<String> restIgnoreItems, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult result = task.getResult().createSubresult(OPERATION_COMPARE);
    Response response;
    try {
        ResponseBuilder builder;
        List<ItemPath> ignoreItemPaths = ItemPath.fromStringList(restIgnoreItems);
        final GetOperationOptions getOpOptions = GetOperationOptions.fromRestOptions(restReadOptions);
        Collection<SelectorOptions<GetOperationOptions>> readOptions = getOpOptions != null ? SelectorOptions.createCollection(getOpOptions) : null;
        ModelCompareOptions compareOptions = ModelCompareOptions.fromRestOptions(restCompareOptions);
        CompareResultType compareResult = modelService.compareObject(clientObject, readOptions, compareOptions, ignoreItemPaths, task, result);
        response = RestServiceUtil.createResponse(Response.Status.OK, compareResult, result);
    //			builder = Response.ok();
    //			builder.entity(compareResult);
    //
    //			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) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 52 with Task

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

the class ModelRestService method scheduleTasksNow.

@POST
@Path("tasks/{oid}/run")
public Response scheduleTasksNow(@PathParam("oid") String taskOid, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_SCHEDULE_TASKS_NOW);
    Collection<String> taskOids = MiscUtil.createCollection(taskOid);
    Response response;
    try {
        model.scheduleTasksNow(taskOids, parentResult);
        parentResult.computeStatus();
        response = RestServiceUtil.createResponse(Response.Status.NO_CONTENT, 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 53 with Task

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

the class ModelWebService method executeChanges.

@Override
public ObjectDeltaOperationListType executeChanges(ObjectDeltaListType deltaList, ModelExecuteOptionsType optionsType) throws FaultMessage {
    notNullArgument(deltaList, "Object delta list must not be null.");
    Task task = createTaskInstance(EXECUTE_CHANGES);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        Collection<ObjectDelta> deltas = DeltaConvertor.createObjectDeltas(deltaList, prismContext);
        for (ObjectDelta delta : deltas) {
            prismContext.adopt(delta);
        }
        ModelExecuteOptions options = ModelExecuteOptions.fromModelExecutionOptionsType(optionsType);
        // brutally eliminating type-safety compiler barking
        Collection<ObjectDeltaOperation<? extends ObjectType>> objectDeltaOperations = modelService.executeChanges((Collection) deltas, options, task, operationResult);
        ObjectDeltaOperationListType retval = new ObjectDeltaOperationListType();
        for (ObjectDeltaOperation objectDeltaOperation : objectDeltaOperations) {
            ObjectDeltaOperationType objectDeltaOperationType = DeltaConvertor.toObjectDeltaOperationType(objectDeltaOperation, null);
            retval.getDeltaOperation().add(objectDeltaOperationType);
        }
        return retval;
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL executeChanges() failed", ex);
        throwFault(ex, operationResult);
        // notreached
        return null;
    } finally {
        auditLogout(task);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException)

Example 54 with Task

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

the class ModelWebService method findShadowOwner.

@Override
public void findShadowOwner(String accountOid, Holder<UserType> userHolder, Holder<OperationResultType> result) throws FaultMessage {
    notEmptyArgument(accountOid, "Account oid must not be null or empty.");
    Task task = createTaskInstance(LIST_ACCOUNT_SHADOW_OWNER);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        PrismObject<UserType> user = model.findShadowOwner(accountOid, task, operationResult);
        handleOperationResult(operationResult, result);
        if (user != null) {
            userHolder.value = user.asObjectable();
        }
        return;
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL findShadowOwner() failed", ex);
        throwFault(ex, operationResult);
    } finally {
        auditLogout(task);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException)

Example 55 with Task

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

the class ModelWebService method importFromResource.

@Override
public TaskType importFromResource(String resourceOid, QName objectClass) throws FaultMessage {
    notEmptyArgument(resourceOid, "Resource oid must not be null or empty.");
    notNullArgument(objectClass, "Object class must not be null.");
    Task task = createTaskInstance(IMPORT_FROM_RESOURCE);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        model.importFromResource(resourceOid, objectClass, task, operationResult);
        operationResult.computeStatus();
        return handleTaskResult(task);
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL importFromResource() failed", ex);
        auditLogout(task);
        throwFault(ex, operationResult);
        // notreached
        return null;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException)

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