use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.
the class SchemaTransformer method applySchemasAndSecurityToContainers.
// Expecting that C is a direct child of T.
// Expecting that container values point to their respective parents (in order to evaluate the security!)
public <C extends Containerable, T extends ObjectType> SearchResultList<C> applySchemasAndSecurityToContainers(SearchResultList<C> originalResultList, Class<T> parentObjectType, QName childItemName, GetOperationOptions options, AuthorizationPhaseType phase, Task task, OperationResult result) throws SecurityViolationException, SchemaException, ObjectNotFoundException, ConfigurationException {
List<C> newValues = new ArrayList<>();
Map<PrismObject<T>, Object> processedParents = new IdentityHashMap<>();
final ItemPath childItemPath = new ItemPath(childItemName);
for (C value : originalResultList) {
Long originalId = value.asPrismContainerValue().getId();
if (originalId == null) {
throw new SchemaException("No ID in container value " + value);
}
PrismObject<T> parent = ObjectTypeUtil.getParentObject(value);
boolean wasProcessed;
if (parent != null) {
wasProcessed = processedParents.containsKey(parent);
} else {
// temporary solution TODO reconsider
parent = prismContext.createObject(parentObjectType);
PrismContainer<C> childContainer = parent.findOrCreateItem(childItemPath, PrismContainer.class);
childContainer.add(value.asPrismContainerValue());
wasProcessed = false;
}
if (!wasProcessed) {
// TODO what if parent is immutable?
applySchemasAndSecurity(parent, options, phase, task, result);
processedParents.put(parent, null);
}
PrismContainer<C> updatedChildContainer = parent.findContainer(childItemPath);
if (updatedChildContainer != null) {
PrismContainerValue<C> updatedChildValue = updatedChildContainer.getValue(originalId);
if (updatedChildValue != null) {
newValues.add(updatedChildValue.asContainerable());
}
}
}
return new SearchResultList<>(newValues, originalResultList.getMetadata());
}
use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.
the class UserProfileServiceImpl method resolveOwner.
@Override
public <F extends FocusType, O extends ObjectType> PrismObject<F> resolveOwner(PrismObject<O> object) {
if (object == null || object.getOid() == null) {
return null;
}
PrismObject<F> owner = null;
OperationResult result = new OperationResult(UserProfileServiceImpl.class + ".resolveOwner");
if (object.canRepresent(ShadowType.class)) {
owner = repositoryService.searchShadowOwner(object.getOid(), null, result);
} else if (object.canRepresent(UserType.class)) {
ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(FocusType.F_PERSONA_REF).ref(object.getOid()).build();
SearchResultList<PrismObject<UserType>> owners = null;
try {
owners = repositoryService.searchObjects(UserType.class, query, null, result);
if (owners.isEmpty()) {
return null;
}
if (owners.size() > 1) {
LOGGER.warn("More than one owner of {}: {}", object, owners);
}
owner = (PrismObject<F>) owners.get(0);
} catch (SchemaException e) {
LOGGER.warn("Cannot resolve owner of {}: {}", object, e.getMessage(), e);
}
} else if (object.canRepresent(AbstractRoleType.class)) {
ObjectReferenceType ownerRef = ((AbstractRoleType) (object.asObjectable())).getOwnerRef();
if (ownerRef != null && ownerRef.getOid() != null && ownerRef.getType() != null) {
try {
owner = (PrismObject<F>) repositoryService.getObject(ObjectTypes.getObjectTypeFromTypeQName(ownerRef.getType()).getClassDefinition(), ownerRef.getOid(), null, result);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.warn("Cannot resolve owner of {}: {}", object, e.getMessage(), e);
}
}
} else if (object.canRepresent(TaskType.class)) {
ObjectReferenceType ownerRef = ((TaskType) (object.asObjectable())).getOwnerRef();
if (ownerRef != null && ownerRef.getOid() != null && ownerRef.getType() != null) {
try {
owner = (PrismObject<F>) repositoryService.getObject(ObjectTypes.getObjectTypeFromTypeQName(ownerRef.getType()).getClassDefinition(), ownerRef.getOid(), null, result);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.warn("Cannot resolve owner of {}: {}", object, e.getMessage(), e);
}
}
}
if (owner == null) {
return null;
}
if (owner.canRepresent(UserType.class)) {
userComputer.recompute((PrismObject<UserType>) owner);
}
return owner;
}
use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.
the class WorkItemProvider method searchWorkItems.
public SearchResultList<WorkItemType> searchWorkItems(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
TaskQuery taskQuery = createTaskQuery(query, true, options, result);
if (taskQuery == null) {
return new SearchResultList<>(Collections.emptyList());
}
Integer offset = query != null ? query.getOffset() : null;
Integer maxSize = query != null ? query.getMaxSize() : null;
List<Task> tasks;
if (offset == null && maxSize == null) {
tasks = taskQuery.list();
} else {
tasks = taskQuery.listPage(defaultIfNull(offset, 0), defaultIfNull(maxSize, Integer.MAX_VALUE));
}
// TODO implement based on options
boolean getAllVariables = true;
// there's no need to fill-in assignee details ; but candidates are necessary to fill-in; TODO implement based on options (resolve)
return tasksToWorkItems(tasks, null, false, false, true, getAllVariables, result);
}
use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.
the class ProcessInstanceManager method getProcessInstancesToKeep.
private Set<String> getProcessInstancesToKeep(OperationResult result) throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext).not().item(TaskType.F_WORKFLOW_CONTEXT, WfContextType.F_PROCESS_INSTANCE_ID).isNull().build();
SearchResultList<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, query, null, result);
return tasks.stream().map(t -> t.asObjectable().getWorkflowContext().getProcessInstanceId()).collect(Collectors.toSet());
}
Aggregations