Search in sources :

Example 21 with ObjectAlreadyExistsException

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

the class TaskManagerQuartzImpl method persist.

private void persist(Task task, OperationResult parentResult) {
    if (task.getPersistenceStatus() == TaskPersistenceStatus.PERSISTENT) {
        // Task already persistent. Nothing to do.
        return;
    }
    TaskQuartzImpl taskImpl = (TaskQuartzImpl) task;
    if (task.getName() == null) {
        PolyStringType polyStringName = new PolyStringType("Task " + task.getTaskIdentifier());
        taskImpl.setNameTransient(polyStringName);
    }
    if (taskImpl.getOid() != null) {
        // We don't support user-specified OIDs
        throw new IllegalArgumentException("Transient task must not have OID (task:" + task + ")");
    }
    // hack: set Category if it is not set yet
    if (taskImpl.getCategory() == null) {
        taskImpl.setCategoryTransient(taskImpl.getCategoryFromHandler());
    }
    // Make sure that the task has repository service instance, so it can fully work as "persistent"
    if (taskImpl.getRepositoryService() == null) {
        RepositoryService repoService = (RepositoryService) this.beanFactory.getBean("repositoryService");
        taskImpl.setRepositoryService(repoService);
    }
    try {
        addTaskToRepositoryAndQuartz(taskImpl, parentResult);
    } catch (ObjectAlreadyExistsException ex) {
        // This should not happen. If it does, it is a bug. It is OK to convert to a runtime exception
        throw new IllegalStateException("Got ObjectAlreadyExistsException while not expecting it (task:" + task + ")", ex);
    } catch (SchemaException ex) {
        // This should not happen. If it does, it is a bug. It is OK to convert to a runtime exception
        throw new IllegalStateException("Got SchemaException while not expecting it (task:" + task + ")", ex);
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 22 with ObjectAlreadyExistsException

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

the class TaskQuartzImpl method setOtherHandlersUriStackImmediate.

public void setOtherHandlersUriStackImmediate(UriStack value, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    try {
        processModificationNow(setOtherHandlersUriStackAndPrepareDelta(value), parentResult);
        checkHandlerUriConsistency();
    } catch (ObjectAlreadyExistsException ex) {
        throw new SystemException(ex);
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 23 with ObjectAlreadyExistsException

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

the class TestReport method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    super.initSystem(initTask, initResult);
    repoAddObjectFromFile(USER_JACK_FILE, true, initResult).asObjectable();
    repoAddObjectFromFile(ROLE_SUPERUSER_FILE, initResult);
    // System Configuration
    modelService.postInit(initResult);
    try {
        repoAddObjectFromFile(SYSTEM_CONFIGURATION_FILE, initResult);
    } catch (ObjectAlreadyExistsException e) {
        throw new ObjectAlreadyExistsException("System configuration already exists in repository;" + "looks like the previous test haven't cleaned it up", e);
    }
    // User administrator
    PrismObject<UserType> userAdministrator = repoAddObjectFromFile(USER_ADMINISTRATOR_FILE, initResult);
    importObjectFromFile(RESOURCE_DUMMY_FILE, initResult);
    login(userAdministrator);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
//		caseIgnoreMatchingRule = matchingRuleRegistry.getMatchingRule(StringIgnoreCaseMatchingRule.NAME, DOMUtil.XSD_STRING);
//		importSystemTasks(initResult);
}
Also used : ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 24 with ObjectAlreadyExistsException

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

the class AbstractUninitializedCertificationTest method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    logger.trace("initSystem");
    super.initSystem(initTask, initResult);
    modelService.postInit(initResult);
    // System Configuration
    try {
        repoAddObjectFromFile(getSystemConfigurationFile(), initResult);
    } catch (ObjectAlreadyExistsException e) {
        throw new ObjectAlreadyExistsException("System configuration already exists in repository;" + "looks like the previous test haven't cleaned it up", e);
    }
    // Administrator
    roleSuperuser = repoAddObjectFromFile(ROLE_SUPERUSER_FILE, RoleType.class, initResult).asObjectable();
    userAdministrator = repoAddObjectFromFile(getUserAdministratorFile(), UserType.class, initResult).asObjectable();
    login(userAdministrator.asPrismObject());
}
Also used : ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 25 with ObjectAlreadyExistsException

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

the class TriggerScanItemProcessor method removeTriggers.

private void removeTriggers(PrismObject<? extends ObjectType> object, Collection<TriggerType> triggers, Task task, PrismContainerDefinition<TriggerType> triggerContainerDef) {
    ContainerDelta<TriggerType> triggerDelta = triggerContainerDef.createEmptyDelta(F_TRIGGER);
    for (TriggerType trigger : triggers) {
        // noinspection unchecked
        triggerDelta.addValueToDelete(trigger.asPrismContainerValue().clone());
    }
    Collection<? extends ItemDelta<?, ?>> modifications = MiscSchemaUtil.createCollection(triggerDelta);
    // This is detached result. It will not take part of the task result. We do not really care.
    OperationResult result = new OperationResult(TriggerScanActivityHandler.class.getName() + ".removeTriggers");
    try {
        activityRun.getModelBeans().cacheRepositoryService.modifyObject(requireNonNull(object.getCompileTimeClass()), object.getOid(), modifications, result);
        result.computeStatus();
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
    } catch (ObjectNotFoundException e) {
        // Object is gone. Ergo there are no triggers left. Ergo the trigger was removed.
        // Ergo this is not really an error.
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
        LOGGER.trace("Unable to remove trigger from {}: {} (but this is probably OK)", object, e.getMessage(), e);
    } catch (SchemaException | ObjectAlreadyExistsException e) {
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
        LOGGER.error("Unable to remove trigger from {}: {}", object, e.getMessage(), e);
    } catch (Throwable t) {
        task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
        throw t;
    }
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)142 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)84 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)76 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)69 SystemException (com.evolveum.midpoint.util.exception.SystemException)50 PrismObject (com.evolveum.midpoint.prism.PrismObject)39 Test (org.testng.annotations.Test)36 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)31 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)29 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)28 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)27 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)24 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)24 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)22 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)22 QName (javax.xml.namespace.QName)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)17 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)17