Search in sources :

Example 91 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class MidpointUtil method recordEventInTask.

// additional delta is a bit hack ... TODO refactor (but without splitting the modify operation!)
public static void recordEventInTask(CaseEventType event, ObjectDeltaType additionalDelta, String taskOid, OperationResult result) {
    RepositoryService cacheRepositoryService = getCacheRepositoryService();
    PrismContext prismContext = getPrismContext();
    try {
        S_ItemEntry deltaBuilder = DeltaBuilder.deltaFor(TaskType.class, getPrismContext()).item(F_WORKFLOW_CONTEXT, F_EVENT).add(event);
        if (additionalDelta != null) {
            PrismObject<TaskType> task = cacheRepositoryService.getObject(TaskType.class, taskOid, null, result);
            WfPrimaryChangeProcessorStateType state = WfContextUtil.getPrimaryChangeProcessorState(task.asObjectable().getWorkflowContext());
            ObjectTreeDeltasType updatedDelta = ObjectTreeDeltas.mergeDeltas(state.getDeltasToProcess(), additionalDelta, prismContext);
            // assuming it already exists!
            ItemPath deltasToProcessPath = new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, WfPrimaryChangeProcessorStateType.F_DELTAS_TO_PROCESS);
            ItemDefinition<?> deltasToProcessDefinition = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(WfPrimaryChangeProcessorStateType.class).findItemDefinition(WfPrimaryChangeProcessorStateType.F_DELTAS_TO_PROCESS);
            deltaBuilder = deltaBuilder.item(deltasToProcessPath, deltasToProcessDefinition).replace(updatedDelta);
        }
        cacheRepositoryService.modifyObject(TaskType.class, taskOid, deltaBuilder.asItemDeltas(), result);
    } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) {
        throw new SystemException("Couldn't record decision to the task " + taskOid + ": " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SpringApplicationContextHolder.getCacheRepositoryService(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getCacheRepositoryService) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 92 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class ActivitiInterface method notifyMidpointAboutProcessEvent.

private void notifyMidpointAboutProcessEvent(ProcessEvent event) {
    OperationResult result = new OperationResult(DOT_CLASS + "notifyMidpointAboutProcessEvent");
    String taskOid = ActivitiUtil.getTaskOid(event.getVariables());
    Task task;
    try {
        task = taskManager.getTask(taskOid, result);
    } catch (ObjectNotFoundException | SchemaException | RuntimeException e) {
        throw new SystemException("Couldn't get task " + taskOid + " from repository: " + e.getMessage(), e);
    }
    if (task.getExecutionStatus() != TaskExecutionStatus.WAITING) {
        LOGGER.trace("Asynchronous message received in a state different from WAITING (actual state: {}), ignoring it. Task = {}", task.getExecutionStatus(), task);
        return;
    }
    try {
        wfTaskController.onProcessEvent(event, task, result);
    } catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | RuntimeException e) {
        throw new SystemException("Couldn't process a process-related event: " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 93 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class TestDummy method test600AddAccountAlreadyExist.

@Test
public void test600AddAccountAlreadyExist() throws Exception {
    final String TEST_NAME = "test600AddAccountAlreadyExist";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResourceCtl.addAccount(ACCOUNT_MURRAY_USERNAME, ACCOUNT_MURRAY_USERNAME);
    PrismObject<ShadowType> account = createShadowNameOnly(resource, ACCOUNT_MURRAY_USERNAME);
    account.checkConsistence();
    display("Adding shadow", account);
    // WHEN
    try {
        provisioningService.addObject(account, null, null, task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (ObjectAlreadyExistsException e) {
        // This is expected
        display("Expected exception", e);
    }
    // THEN
    result.computeStatus();
    display("add object result", result);
    TestUtil.assertFailure(result);
    // Even though the operation failed a shadow should be created for the conflicting object
    PrismObject<ShadowType> accountRepo = findAccountShadowByUsername(getMurrayRepoIcfName(), resource, result);
    assertNotNull("Shadow was not created in the repository", accountRepo);
    display("Repository shadow", accountRepo);
    checkRepoAccountShadow(accountRepo);
    assertEquals("Wrong ICF NAME in murray (repo) shadow", getMurrayRepoIcfName(), getIcfName(accountRepo));
    assertSteadyResource();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Test(org.testng.annotations.Test)

Aggregations

ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)93 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)57 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)50 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)45 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)35 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)33 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)32 SystemException (com.evolveum.midpoint.util.exception.SystemException)31 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)25 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)18 Task (com.evolveum.midpoint.task.api.Task)17 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)14 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)14 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)12 ArrayList (java.util.ArrayList)11 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)9