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;
}
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();
}
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);
}
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();
}
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;
}
Aggregations