use of com.evolveum.midpoint.model.api.hooks.ReadHook 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.model.api.hooks.ReadHook in project midpoint by Evolveum.
the class ModelController method searchObjects.
@Override
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(type, "Object type must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
if (query != null) {
ModelUtils.validatePaging(query.getPaging());
}
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
ObjectTypes.ObjectManager searchProvider = ObjectTypes.getObjectManagerForClass(type);
if (searchProvider == null || searchProvider == ObjectTypes.ObjectManager.MODEL || GetOperationOptions.isRaw(rootOptions)) {
searchProvider = ObjectTypes.ObjectManager.REPOSITORY;
}
OperationResult result = parentResult.createSubresult(SEARCH_OBJECTS);
result.addParams(new String[] { "query", "paging", "searchProvider" }, query, (query != null ? query.getPaging() : "undefined"), searchProvider);
query = preProcessQuerySecurity(type, query);
if (isFilterNone(query, result)) {
return new SearchResultList(new ArrayList<>());
}
SearchResultList<PrismObject<T>> list;
try {
RepositoryCache.enter();
logQuery(query);
try {
if (GetOperationOptions.isRaw(rootOptions)) {
// MID-2218
QNameUtil.setTemporarilyTolerateUndeclaredPrefixes(true);
}
switch(searchProvider) {
case REPOSITORY:
list = cacheRepositoryService.searchObjects(type, query, options, result);
break;
case PROVISIONING:
list = provisioning.searchObjects(type, query, options, task, result);
break;
case TASK_MANAGER:
list = taskManager.searchObjects(type, query, options, result);
if (workflowManager != null && TaskType.class.isAssignableFrom(type) && !GetOperationOptions.isRaw(rootOptions) && !GetOperationOptions.isNoFetch(rootOptions)) {
workflowManager.augmentTaskObjectList(list, options, task, result);
}
break;
default:
throw new AssertionError("Unexpected search provider: " + searchProvider);
}
result.computeStatus();
result.cleanupResult();
} catch (CommunicationException | ConfigurationException | SchemaException | SecurityViolationException | RuntimeException | ObjectNotFoundException e) {
processSearchException(e, rootOptions, searchProvider, result);
throw e;
} finally {
QNameUtil.setTemporarilyTolerateUndeclaredPrefixes(false);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(result.dump(false));
}
}
if (list == null) {
list = new SearchResultList(new ArrayList<PrismObject<T>>());
}
for (PrismObject<T> object : list) {
if (hookRegistry != null) {
for (ReadHook hook : hookRegistry.getAllReadHooks()) {
hook.invoke(object, options, task, result);
}
}
resolve(object, options, task, result);
}
} finally {
RepositoryCache.exit();
}
// TODO generalize this approach somehow (something like "postprocess" in task/provisioning interface)
if (searchProvider == ObjectTypes.ObjectManager.REPOSITORY && !GetOperationOptions.isRaw(rootOptions)) {
for (PrismObject<T> object : list) {
if (object.asObjectable() instanceof ResourceType || object.asObjectable() instanceof ShadowType) {
provisioning.applyDefinition(object, task, result);
}
}
}
schemaTransformer.applySchemasAndSecurityToObjects(list, rootOptions, null, task, result);
return list;
}
use of com.evolveum.midpoint.model.api.hooks.ReadHook in project midpoint by Evolveum.
the class ModelController method searchObjectsIterative.
@Override
public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<T> type, ObjectQuery query, final ResultHandler<T> handler, final Collection<SelectorOptions<GetOperationOptions>> options, final Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(type, "Object type must not be null.");
Validate.notNull(parentResult, "Result type must not be null.");
if (query != null) {
ModelUtils.validatePaging(query.getPaging());
}
final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
ObjectTypes.ObjectManager searchProvider = ObjectTypes.getObjectManagerForClass(type);
if (searchProvider == null || searchProvider == ObjectTypes.ObjectManager.MODEL || GetOperationOptions.isRaw(rootOptions)) {
searchProvider = ObjectTypes.ObjectManager.REPOSITORY;
}
final OperationResult result = parentResult.createSubresult(SEARCH_OBJECTS);
result.addParams(new String[] { "query", "paging", "searchProvider" }, query, (query != null ? query.getPaging() : "undefined"), searchProvider);
query = preProcessQuerySecurity(type, query);
if (isFilterNone(query, result)) {
return null;
}
ResultHandler<T> internalHandler = (object, parentResult1) -> {
try {
object = object.cloneIfImmutable();
if (hookRegistry != null) {
for (ReadHook hook : hookRegistry.getAllReadHooks()) {
// TODO result or parentResult??? [med]
hook.invoke(object, options, task, result);
}
}
resolve(object, options, task, result);
schemaTransformer.applySchemasAndSecurity(object, rootOptions, null, task, parentResult1);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException ex) {
parentResult1.recordFatalError(ex);
throw new SystemException(ex.getMessage(), ex);
}
return handler.handle(object, parentResult1);
};
SearchResultMetadata metadata;
try {
RepositoryCache.enter();
logQuery(query);
try {
switch(searchProvider) {
// TODO move strictSequential flag to model API in some form
case REPOSITORY:
metadata = cacheRepositoryService.searchObjectsIterative(type, query, internalHandler, options, false, result);
break;
case PROVISIONING:
metadata = provisioning.searchObjectsIterative(type, query, options, internalHandler, task, result);
break;
case TASK_MANAGER:
metadata = taskManager.searchObjectsIterative(type, query, options, internalHandler, result);
break;
default:
throw new AssertionError("Unexpected search provider: " + searchProvider);
}
result.computeStatusIfUnknown();
result.cleanupResult();
} catch (CommunicationException | ConfigurationException | ObjectNotFoundException | SchemaException | SecurityViolationException | ExpressionEvaluationException | RuntimeException | Error e) {
processSearchException(e, rootOptions, searchProvider, result);
throw e;
} finally {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(result.dump(false));
}
}
} finally {
RepositoryCache.exit();
}
return metadata;
}
Aggregations