Search in sources :

Example 11 with SearchResultList

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());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with SearchResultList

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 13 with SearchResultList

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);
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

Example 14 with SearchResultList

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());
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) java.util(java.util) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) TaskService(org.activiti.engine.TaskService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WorkflowManager(com.evolveum.midpoint.wf.api.WorkflowManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) PrismContext(com.evolveum.midpoint.prism.PrismContext) CommonProcessVariableNames(com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoryService(org.activiti.engine.HistoryService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) ActivitiEngine(com.evolveum.midpoint.wf.impl.activiti.ActivitiEngine) Component(org.springframework.stereotype.Component) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

SearchResultList (com.evolveum.midpoint.schema.SearchResultList)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 Task (com.evolveum.midpoint.task.api.Task)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 DebugUtil (com.evolveum.midpoint.util.DebugUtil)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 Trace (com.evolveum.midpoint.util.logging.Trace)2 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)2 ArrayList (java.util.ArrayList)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1