Search in sources :

Example 11 with ExpressionEvaluationException

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

the class ModelObjectResolver method getObject.

public <T extends ObjectType> T getObject(Class<T> clazz, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    T objectType = null;
    try {
        PrismObject<T> object = null;
        ObjectTypes.ObjectManager manager = ObjectTypes.getObjectManagerForClass(clazz);
        final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
        switch(manager) {
            case PROVISIONING:
                object = provisioning.getObject(clazz, oid, options, task, result);
                if (object == null) {
                    throw new SystemException("Got null result from provisioning.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using provisioning implementation " + provisioning.getClass().getName());
                }
                break;
            case TASK_MANAGER:
                object = taskManager.getObject(clazz, oid, options, result);
                if (object == null) {
                    throw new SystemException("Got null result from taskManager.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using task manager implementation " + taskManager.getClass().getName());
                }
                if (workflowManager != null && TaskType.class.isAssignableFrom(clazz) && !GetOperationOptions.isRaw(rootOptions) && !GetOperationOptions.isNoFetch(rootOptions)) {
                    workflowManager.augmentTaskObject(object, options, task, result);
                }
                break;
            default:
                object = cacheRepositoryService.getObject(clazz, oid, options, result);
                if (object == null) {
                    throw new SystemException("Got null result from repository.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using repository implementation " + cacheRepositoryService.getClass().getName());
                }
        }
        objectType = object.asObjectable();
        if (!clazz.isInstance(objectType)) {
            throw new ObjectNotFoundException("Bad object type returned for referenced oid '" + oid + "'. Expected '" + clazz + "', but was '" + (objectType == null ? "null" : objectType.getClass()) + "'.");
        }
        if (hookRegistry != null) {
            for (ReadHook hook : hookRegistry.getAllReadHooks()) {
                hook.invoke(object, options, task, result);
            }
        }
    } catch (SystemException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException ex) {
        result.recordFatalError(ex);
        throw ex;
    } catch (RuntimeException | Error ex) {
        LoggingUtils.logException(LOGGER, "Error resolving object with oid {}, expected type was {}.", ex, oid, clazz);
        throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
    } finally {
        result.computeStatus();
    }
    return objectType;
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ReadHook(com.evolveum.midpoint.model.api.hooks.ReadHook) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 12 with ExpressionEvaluationException

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

the class ModelCrudService method modifyObject.

/**
	 * <p>
	 * Modifies object using relative change description.
	 * </p>
	 * <p>
	 * Must fail if user with provided OID does not exists. Must fail if any of
	 * the described changes cannot be applied. Should be atomic.
	 * </p>
	 * <p>
	 * If two or more modify operations are executed in parallel, the operations
	 * should be merged. In case that the operations are in conflict (e.g. one
	 * operation adding a value and the other removing the same value), the
	 * result is not deterministic.
	 * </p>
	 * <p>
	 * The operation may fail if the modified object does not conform to the
	 * underlying schema of the storage system or the schema enforced by the
	 * implementation.
	 * </p>
	 * 
	 * @param parentResult
	 *            parent OperationResult (in/out)
	 * @throws ObjectNotFoundException
	 *             specified object does not exist
	 * @throws SchemaException
	 *             resulting object would violate the schema
	 * @throws ExpressionEvaluationException
	 * 				evaluation of expression associated with the object has failed
	 * @throws CommunicationException 
	 * @throws ObjectAlreadyExistsException
	 * 				If the account or another "secondary" object already exists and cannot be created
	 * @throws PolicyViolationException 
	 * 				Policy violation was detected during processing of the object
	 * @throws IllegalArgumentException
	 *             wrong OID format, described change is not applicable
	 * @throws SystemException
	 *             unknown error from underlying layers or other unexpected
	 *             state
	 */
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
    Validate.notNull(modifications, "Object modification must not be null.");
    Validate.notEmpty(oid, "Change oid must not be null or empty.");
    Validate.notNull(parentResult, "Result type must not be null.");
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Modifying object with oid {}", oid);
        LOGGER.trace(DebugUtil.debugDump(modifications));
    }
    if (modifications.isEmpty()) {
        LOGGER.warn("Calling modifyObject with empty modificaiton set");
        return;
    }
    ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
    // TODO: check definitions, but tolerate missing definitions in <attributes>
    OperationResult result = parentResult.createSubresult(MODIFY_OBJECT);
    result.addCollectionOfSerializablesAsParam("modifications", modifications);
    RepositoryCache.enter();
    try {
        ObjectDelta<T> objectDelta = (ObjectDelta<T>) ObjectDelta.createModifyDelta(oid, modifications, type, prismContext);
        Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
        modelService.executeChanges(deltas, options, task, result);
        result.computeStatus();
    } catch (ExpressionEvaluationException ex) {
        LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (ObjectNotFoundException ex) {
        LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
        result.recordFatalError(ex);
        throw ex;
    } catch (SchemaException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (ConfigurationException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (SecurityViolationException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } catch (RuntimeException ex) {
        ModelUtils.recordFatalError(result, ex);
        throw ex;
    } finally {
        RepositoryCache.exit();
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 13 with ExpressionEvaluationException

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

the class TestFilterExpression method test130EvaluateExpressionEmployeeTypeError.

@Test
public void test130EvaluateExpressionEmployeeTypeError() throws Exception {
    final String TEST_NAME = "testEvaluateExpressionEmployeeTypeError";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestFilterExpression.class.getName() + "." + TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    try {
        evaluateExpressionAssertFilter("expression-employeeType-error.xml", null, NoneFilter.class, task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (ExpressionEvaluationException e) {
        // this is expected
        assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("evaluated to no value"));
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 14 with ExpressionEvaluationException

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

the class PageTaskEdit method refreshTaskModels.

public void refreshTaskModels() {
    TaskDto oldTaskDto = taskDtoModel.getObject();
    if (oldTaskDto == null) {
        LOGGER.warn("Null or empty taskModel");
        return;
    }
    TaskManager taskManager = getTaskManager();
    OperationResult result = new OperationResult("refresh");
    Task operationTask = taskManager.createTaskInstance("refresh");
    try {
        LOGGER.debug("Refreshing task {}", oldTaskDto);
        TaskType taskType = loadTaskType(oldTaskDto.getOid(), operationTask, result);
        TaskDto newTaskDto = prepareTaskDto(taskType, operationTask, result);
        final ObjectWrapper<TaskType> newWrapper = loadObjectWrapper(taskType.asPrismObject(), operationTask, result);
        previousTaskDto = currentTaskDto;
        currentTaskDto = newTaskDto;
        taskDtoModel.setObject(newTaskDto);
        objectWrapperModel.setObject(newWrapper);
    } catch (ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't refresh task {}", e, oldTaskDto);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) TaskManager(com.evolveum.midpoint.task.api.TaskManager) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TaskDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskDto)

Example 15 with ExpressionEvaluationException

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

the class WebModelServiceUtils method countObjects.

public static <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query, PageBase page) {
    LOGGER.debug("Count object: type => {}, query => {}", type, query);
    Task task = page.createSimpleTask(OPERATION_COUNT_OBJECT);
    OperationResult parentResult = new OperationResult(OPERATION_COUNT_OBJECT);
    int count = 0;
    try {
        count = page.getModelService().countObjects(type, query, null, task, parentResult);
    } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | ConfigurationException | CommunicationException | ExpressionEvaluationException ex) {
        parentResult.recordFatalError("WebModelUtils.couldntCountObjects", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count objects", ex);
    }
    LOGGER.debug("Count objects with result {}", new Object[] { parentResult });
    return count;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)120 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)93 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)92 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)71 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)71 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)69 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)59 Task (com.evolveum.midpoint.task.api.Task)35 SystemException (com.evolveum.midpoint.util.exception.SystemException)32 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)28 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)26 QName (javax.xml.namespace.QName)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 ArrayList (java.util.ArrayList)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)13 Collection (java.util.Collection)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12