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;
}
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();
}
}
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"));
}
}
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);
}
}
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;
}
Aggregations