Search in sources :

Example 71 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class PageWorkItem method loadWorkItemDtoIfNecessary.

private WorkItemDto loadWorkItemDtoIfNecessary() {
    if (workItemDtoModel.isLoaded()) {
        return workItemDtoModel.getObject();
    }
    Task task = createSimpleTask(OPERATION_LOAD_WORK_ITEM);
    OperationResult result = task.getResult();
    WorkItemDto workItemDto = null;
    try {
        final ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext()).item(F_EXTERNAL_ID).eq(taskId).build();
        final Collection<SelectorOptions<GetOperationOptions>> options = resolveItemsNamed(F_ASSIGNEE_REF, F_ORIGINAL_ASSIGNEE_REF);
        List<WorkItemType> workItems = getModelService().searchContainers(WorkItemType.class, query, options, task, result);
        if (workItems.size() > 1) {
            throw new SystemException("More than one work item with ID of " + taskId);
        } else if (workItems.size() == 0) {
            throw new SystemException("No work item with ID of " + taskId);
        }
        final WorkItemType workItem = workItems.get(0);
        //final String taskOid = workItem.getTaskRef() != null ? workItem.getTaskRef().getOid() : null;
        final String taskOid = WfContextUtil.getTask(workItem).getOid();
        TaskType taskType = null;
        List<TaskType> relatedTasks = new ArrayList<>();
        if (taskOid != null) {
            final Collection<SelectorOptions<GetOperationOptions>> getTaskOptions = resolveItemsNamed(new ItemPath(F_WORKFLOW_CONTEXT, F_REQUESTER_REF));
            getTaskOptions.addAll(retrieveItemsNamed(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM)));
            try {
                taskType = getModelService().getObject(TaskType.class, taskOid, getTaskOptions, task, result).asObjectable();
            } catch (AuthorizationException e) {
                LoggingUtils.logExceptionOnDebugLevel(LOGGER, "Access to the task {} was denied", e, taskOid);
            }
            if (taskType != null && taskType.getParent() != null) {
                final ObjectQuery relatedTasksQuery = QueryBuilder.queryFor(TaskType.class, getPrismContext()).item(F_PARENT).eq(taskType.getParent()).build();
                List<PrismObject<TaskType>> relatedTaskObjects = getModelService().searchObjects(TaskType.class, relatedTasksQuery, null, task, result);
                for (PrismObject<TaskType> relatedObject : relatedTaskObjects) {
                    relatedTasks.add(relatedObject.asObjectable());
                }
            }
        }
        workItemDto = new WorkItemDto(workItem, taskType, relatedTasks);
        workItemDto.prepareDeltaVisualization("pageWorkItem.delta", getPrismContext(), getModelInteractionService(), task, result);
        result.recordSuccessIfUnknown();
    } catch (CommonException | RuntimeException ex) {
        result.recordFatalError("Couldn't get work item.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get work item.", ex);
    }
    showResult(result, false);
    if (!result.isSuccess()) {
        throw getRestartResponseException(PageDashboard.class);
    }
    return workItemDto;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WorkItemDto(com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 72 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class ProcessInstanceDtoProvider method internalIterator.

@Override
public Iterator<? extends ProcessInstanceDto> internalIterator(long first, long count) {
    getAvailableData().clear();
    Task opTask = getTaskManager().createTaskInstance(OPERATION_LIST_ITEMS);
    OperationResult result = opTask.getResult();
    try {
        //            SortParam sortParam = getSort();
        //            OrderDirectionType order;
        //            if (sortParam.isAscending()) {
        //                order = OrderDirectionType.ASCENDING;
        //            } else {
        //                order = OrderDirectionType.DESCENDING;
        //            }
        ObjectQuery query = getObjectQuery();
        // we know the paging object is not null
        query.getPaging().setOffset(safeLongToInteger(first));
        query.getPaging().setMaxSize(safeLongToInteger(count));
        Collection<SelectorOptions<GetOperationOptions>> options = createCollection(createResolveNames());
        List<PrismObject<TaskType>> tasks = getModel().searchObjects(TaskType.class, query, options, opTask, result);
        for (PrismObject<TaskType> task : tasks) {
            try {
                getAvailableData().add(new ProcessInstanceDto(task.asObjectable()));
            } catch (Exception e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing workflow task {}", e, task);
                result.recordPartialError("Couldn't list process instance.", e);
            }
        }
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing wf-related tasks", ex);
        result.recordFatalError("Couldn't list wf-related tasks.", ex);
    }
    if (result.isUnknown()) {
        result.computeStatus();
    }
    if (!result.isSuccess()) {
        getPage().showResult(result);
    }
    return getAvailableData().iterator();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 73 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class RepositoryObjectDataProvider method loadDescription.

private ResourceDescription loadDescription(String oid, OperationResult result) {
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ResourceType.F_CONNECTOR, GetOperationOptions.createResolve());
    OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
    subResult.addParam("oid", oid);
    PrismObject<ResourceType> resource = null;
    String type = null;
    try {
        resource = getModel().getObject(ResourceType.class, oid, options, getPage().createSimpleTask(OPERATION_LOAD_RESOURCE), subResult);
        PrismReference ref = resource.findReference(ResourceType.F_CONNECTOR_REF);
        if (ref != null && ref.getValue() != null) {
            PrismReferenceValue refValue = ref.getValue();
            if (refValue.getObject() != null) {
                PrismObject connector = refValue.getObject();
                PrismProperty<String> pType = connector.findProperty(ConnectorType.F_CONNECTOR_TYPE);
                if (pType != null && pType.getRealValue() != null) {
                    type = pType.getRealValue(String.class);
                }
            }
        }
        subResult.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource for account", ex);
        subResult.recordFatalError("Couldn't load resource for account.");
    } finally {
        subResult.recomputeStatus();
    }
    return new ResourceDescription(oid, WebComponentUtil.getName(resource), type);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismReference(com.evolveum.midpoint.prism.PrismReference) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Example 74 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class RepositoryObjectDataProvider method internalIterator.

@Override
public Iterator<DebugObjectItem> internalIterator(long first, long count) {
    LOGGER.trace("begin::iterator() from {} count {}.", new Object[] { first, count });
    getAvailableData().clear();
    OperationResult result = new OperationResult(OPERATION_SEARCH_OBJECTS);
    try {
        ObjectPaging paging = createPaging(first, count);
        ObjectQuery query = getQuery();
        if (query == null) {
            query = new ObjectQuery();
        }
        query.setPaging(paging);
        //RAW and DEFAULT retrieve option selected
        Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<SelectorOptions<GetOperationOptions>>();
        GetOperationOptions opt = GetOperationOptions.createRaw();
        opt.setRetrieve(RetrieveOption.DEFAULT);
        options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, opt));
        List<PrismObject<? extends ObjectType>> list = getModel().searchObjects((Class) type, query, options, getPage().createSimpleTask(OPERATION_SEARCH_OBJECTS), result);
        for (PrismObject<? extends ObjectType> object : list) {
            getAvailableData().add(createItem(object, result));
        }
    } catch (Exception ex) {
        result.recordFatalError("Couldn't list objects.", ex);
    } finally {
        result.computeStatusIfUnknown();
    }
    getPage().showResult(result, false);
    LOGGER.trace("end::iterator()");
    return getAvailableData().iterator();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 75 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class AssignmentEditorPanel method getTargetObject.

private <O extends ObjectType> PrismObject<O> getTargetObject(AssignmentEditorDto dto) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismContainerValue<AssignmentType> assignment = dto.getOldValue();
    PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF);
    if (targetRef == null) {
        return null;
    }
    PrismReferenceValue refValue = targetRef.getValue();
    if (refValue != null && refValue.getObject() != null) {
        PrismObject object = refValue.getObject();
        return object;
    }
    String oid = targetRef.getOid();
    OperationResult result = new OperationResult(OPERATION_LOAD_OBJECT);
    PageBase page = getPageBase();
    ModelService model = page.getMidpointApplication().getModel();
    Task task = page.createSimpleTask(OPERATION_LOAD_OBJECT);
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
    Class<O> type = (Class<O>) ObjectType.class;
    if (refValue.getTargetType() != null) {
        type = getPageBase().getPrismContext().getSchemaRegistry().determineCompileTimeClass(refValue.getTargetType());
    }
    PrismObject<O> object = model.getObject(type, oid, options, task, result);
    refValue.setObject(object);
    return object;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ModelService(com.evolveum.midpoint.model.api.ModelService) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Aggregations

SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)127 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)106 Task (com.evolveum.midpoint.task.api.Task)82 Test (org.testng.annotations.Test)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)34 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)31 PrismObject (com.evolveum.midpoint.prism.PrismObject)28 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)28 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ArrayList (java.util.ArrayList)19 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 QName (javax.xml.namespace.QName)17 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)16 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)16 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)14 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)14 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12