use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class LookupTableHelper method findLookupTableGetOption.
public GetOperationOptions findLookupTableGetOption(Collection<SelectorOptions<GetOperationOptions>> options) {
final ItemPath tablePath = new ItemPath(LookupTableType.F_ROW);
Collection<SelectorOptions<GetOperationOptions>> filtered = SelectorOptions.filterRetrieveOptions(options);
for (SelectorOptions<GetOperationOptions> option : filtered) {
ObjectSelector selector = option.getSelector();
if (selector == null) {
// apply to lookup table
continue;
}
ItemPath selected = selector.getPath();
if (tablePath.equivalent(selected)) {
return option.getOptions();
}
}
return null;
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class LookupTableHelper method updateLoadedLookupTable.
public <T extends ObjectType> void updateLoadedLookupTable(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
if (!SelectorOptions.hasToLoadPath(LookupTableType.F_ROW, options)) {
return;
}
LOGGER.debug("Loading lookup table data.");
GetOperationOptions getOption = findLookupTableGetOption(options);
RelationalValueSearchQuery queryDef = getOption == null ? null : getOption.getRelationalValueSearchQuery();
Criteria criteria = setupLookupTableRowsQuery(session, queryDef, object.getOid());
if (queryDef != null && queryDef.getPaging() != null) {
ObjectPaging paging = queryDef.getPaging();
if (paging.getOffset() != null) {
criteria.setFirstResult(paging.getOffset());
}
if (paging.getMaxSize() != null) {
criteria.setMaxResults(paging.getMaxSize());
}
ItemPath orderByPath = paging.getOrderBy();
if (paging.getDirection() != null && orderByPath != null && !orderByPath.isEmpty()) {
if (orderByPath.size() > 1 || !(orderByPath.first() instanceof NameItemPathSegment) && !(orderByPath.first() instanceof IdentifierPathSegment)) {
throw new SchemaException("OrderBy has to consist of just one naming or identifier segment");
}
ItemPathSegment first = orderByPath.first();
String orderBy = first instanceof NameItemPathSegment ? ((NameItemPathSegment) first).getName().getLocalPart() : RLookupTableRow.ID_COLUMN_NAME;
switch(paging.getDirection()) {
case ASCENDING:
criteria.addOrder(Order.asc(orderBy));
break;
case DESCENDING:
criteria.addOrder(Order.desc(orderBy));
break;
}
}
}
List<RLookupTableRow> rows = criteria.list();
if (rows == null || rows.isEmpty()) {
return;
}
LookupTableType lookup = (LookupTableType) object.asObjectable();
List<LookupTableRowType> jaxbRows = lookup.getRow();
for (RLookupTableRow row : rows) {
LookupTableRowType jaxbRow = row.toJAXB();
jaxbRows.add(jaxbRow);
}
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class ProvisioningServiceImpl method countObjects.
public <T extends ObjectType> Integer countObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".countObjects");
result.addParam("objectType", type);
result.addParam("query", query);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
ObjectFilter filter = null;
if (query != null) {
filter = ObjectQueryUtil.simplify(query.getFilter());
query = query.cloneEmpty();
query.setFilter(filter);
}
if (filter != null && filter instanceof NoneFilter) {
result.recordSuccessIfUnknown();
result.cleanupResult();
LOGGER.trace("Finished counting. Nothing to do. Filter is NONE");
return 0;
}
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (!ShadowType.class.isAssignableFrom(type) || GetOperationOptions.isNoFetch(rootOptions) || GetOperationOptions.isRaw(rootOptions)) {
int count = getCacheRepositoryService().countObjects(type, query, parentResult);
result.computeStatus();
result.recordSuccessIfUnknown();
result.cleanupResult();
return count;
}
Integer count;
try {
count = getShadowCache(Mode.STANDARD).countObjects(query, task, result);
result.computeStatus();
} catch (ConfigurationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
result.cleanupResult();
}
return count;
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class ProvisioningServiceImpl method getObject.
@SuppressWarnings("unchecked")
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(oid, "Oid of object to get must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
// Result type for this operation
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getObject");
result.addParam(OperationResult.PARAM_OID, oid);
result.addParam(OperationResult.PARAM_TYPE, type);
result.addCollectionOfSerializablesAsParam("options", options);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
PrismObject<T> resultingObject = null;
if (ResourceType.class.isAssignableFrom(type)) {
if (GetOperationOptions.isRaw(rootOptions)) {
try {
resultingObject = (PrismObject<T>) cacheRepositoryService.getObject(ResourceType.class, oid, null, result);
} catch (ObjectNotFoundException | SchemaException ex) {
// catching an exception is important because otherwise the result is UNKNOWN
result.recordFatalError(ex);
throw ex;
}
try {
applyDefinition(resultingObject, task, result);
} catch (ObjectNotFoundException ex) {
// this is almost OK, we use raw for debug pages, so we want
// to return resource and it can be fixed
result.muteLastSubresultError();
ProvisioningUtil.logWarning(LOGGER, result, "Bad connector reference defined for resource: " + ex.getMessage(), ex);
} catch (SchemaException ex) {
result.muteLastSubresultError();
ProvisioningUtil.logWarning(LOGGER, result, "Schema violation: " + ex.getMessage(), ex);
} catch (ConfigurationException ex) {
result.muteLastSubresultError();
ProvisioningUtil.logWarning(LOGGER, result, "Configuration problem: " + ex.getMessage(), ex);
}
} else {
// schema
try {
resultingObject = (PrismObject<T>) resourceManager.getResource(oid, SelectorOptions.findRootOptions(options), task, result);
} catch (ObjectNotFoundException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Resource object not found", ex);
throw ex;
} catch (SchemaException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Schema violation", ex);
throw ex;
} catch (CommunicationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error communicating with resource", ex);
throw ex;
} catch (ConfigurationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Bad resource configuration", ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Expression error", ex);
throw ex;
}
}
} else {
// Not resource
PrismObject<T> repositoryObject = getRepoObject(type, oid, rootOptions, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Retrieved repository object:\n{}", repositoryObject.debugDump());
}
if (repositoryObject.canRepresent(ShadowType.class)) {
try {
resultingObject = (PrismObject<T>) getShadowCache(Mode.STANDARD).getShadow(oid, (PrismObject<ShadowType>) (repositoryObject), options, task, result);
} catch (ObjectNotFoundException e) {
if (!GetOperationOptions.isAllowNotFound(rootOptions)) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
} else {
result.muteLastSubresultError();
result.computeStatus();
}
throw e;
} catch (CommunicationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (SchemaException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (ConfigurationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (SecurityViolationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (SystemException e) {
// Do NOT wrap this into SystemException again
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (RuntimeException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw new SystemException(e);
}
} else {
resultingObject = repositoryObject;
}
}
result.computeStatus();
if (!GetOperationOptions.isRaw(rootOptions)) {
resultingObject = resultingObject.cloneIfImmutable();
resultingObject.asObjectable().setFetchResult(result.createOperationResultType());
}
result.cleanupResult();
validateObject(resultingObject);
return resultingObject;
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class TaskManagerQuartzImpl method getObject.
//endregion
//region Getting and searching for tasks and nodes
/*
* ********************* GETTING AND SEARCHING FOR TASKS AND NODES *********************
*/
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
OperationResult result = parentResult.createSubresult(DOT_INTERFACE + ".getObject");
result.addParam("objectType", type);
result.addParam("oid", oid);
result.addCollectionOfSerializablesAsParam("options", options);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, TaskManagerQuartzImpl.class);
try {
if (TaskType.class.isAssignableFrom(type)) {
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (GetOperationOptions.isRaw(rootOptions)) {
return (PrismObject<T>) repositoryService.getObject(TaskType.class, oid, options, result);
} else {
return (PrismObject<T>) getTaskAsObject(oid, options, result);
}
} else if (NodeType.class.isAssignableFrom(type)) {
// TODO add transient attributes just like in searchObject
return (PrismObject<T>) repositoryService.getObject(NodeType.class, oid, options, result);
} else {
throw new IllegalArgumentException("Unsupported object type: " + type);
}
} finally {
result.computeStatusIfUnknown();
}
}
Aggregations