use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class PageAdminFocus method loadSubWrapperDto.
private <S extends ObjectType> FocusSubwrapperDto<S> loadSubWrapperDto(Class<S> type, String oid, boolean noFetch, Task task) {
if (oid == null) {
return null;
}
OperationResult subResult = task.getResult().createMinorSubresult(OPERATION_LOAD_SHADOW);
String resourceName = null;
try {
Collection<SelectorOptions<GetOperationOptions>> loadOptions = null;
if (ShadowType.class.equals(type)) {
GetOperationOptions resourceOption = GetOperationOptions.createResolve();
resourceOption.setReadOnly(true);
loadOptions = SelectorOptions.createCollection(ShadowType.F_RESOURCE, resourceOption);
}
if (noFetch) {
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(loadOptions);
if (rootOptions == null) {
loadOptions.add(new SelectorOptions<GetOperationOptions>(GetOperationOptions.createNoFetch()));
} else {
rootOptions.setNoFetch(true);
}
}
PrismObject<S> projection = WebModelServiceUtils.loadObject(type, oid, loadOptions, this, task, subResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Loaded projection {} ({}):\n{}", oid, loadOptions, projection == null ? null : projection.debugDump());
}
if (projection == null) {
// No access or error
return null;
}
S projectionType = projection.asObjectable();
OperationResultType fetchResult = projectionType.getFetchResult();
StringBuilder description = new StringBuilder();
if (ShadowType.class.equals(type)) {
ShadowType shadowType = (ShadowType) projectionType;
ResourceType resource = shadowType.getResource();
resourceName = WebComponentUtil.getName(resource);
if (shadowType.getIntent() != null) {
description.append(shadowType.getIntent()).append(", ");
}
} else if (OrgType.class.equals(type)) {
OrgType orgType = (OrgType) projectionType;
resourceName = orgType.getDisplayName() != null ? WebComponentUtil.getOrigStringFromPoly(orgType.getDisplayName()) : "";
}
description.append(WebComponentUtil.getOrigStringFromPoly(projectionType.getName()));
ObjectWrapper<S> wrapper = ObjectWrapperUtil.createObjectWrapper(resourceName, description.toString(), projection, ContainerStatus.MODIFYING, true, task, this);
wrapper.setLoadOptions(loadOptions);
wrapper.setFetchResult(OperationResult.createOperationResult(fetchResult));
wrapper.setSelectable(true);
wrapper.setMinimalized(true);
wrapper.initializeContainers(this);
subResult.computeStatus();
return new FocusSubwrapperDto<S>(wrapper, UserDtoStatus.MODIFY);
} catch (Exception ex) {
subResult.recordFatalError("Couldn't load account." + ex.getMessage(), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load account", ex);
subResult.computeStatus();
return new FocusSubwrapperDto<S>(false, resourceName, subResult);
}
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class PageSelfDashboard method loadAccounts.
private AccountCallableResult<List<SimpleAccountDto>> loadAccounts() throws Exception {
LOGGER.debug("Loading accounts.");
AccountCallableResult callableResult = new AccountCallableResult();
List<SimpleAccountDto> list = new ArrayList<SimpleAccountDto>();
callableResult.setValue(list);
PrismObject<UserType> user = principalModel.getObject();
if (user == null) {
return callableResult;
}
Task task = createSimpleTask(OPERATION_LOAD_ACCOUNTS);
OperationResult result = task.getResult();
callableResult.setResult(result);
GetOperationOptions getOpts = GetOperationOptions.createResolve();
getOpts.setNoFetch(Boolean.TRUE);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ShadowType.F_RESOURCE, getOpts);
SelectorOptions<GetOperationOptions> resolveNamesOptions = new SelectorOptions(GetOperationOptions.createResolveNames());
resolveNamesOptions.getOptions().setNoFetch(Boolean.TRUE);
options.add(resolveNamesOptions);
List<ObjectReferenceType> references = user.asObjectable().getLinkRef();
for (ObjectReferenceType reference : references) {
PrismObject<ShadowType> account = WebModelServiceUtils.loadObject(ShadowType.class, reference.getOid(), options, this, task, result);
if (account == null) {
continue;
}
ShadowType accountType = account.asObjectable();
OperationResultType fetchResult = accountType.getFetchResult();
if (fetchResult != null) {
callableResult.getFetchResults().add(OperationResult.createOperationResult(fetchResult));
}
ResourceType resource = accountType.getResource();
String resourceName = WebComponentUtil.getName(resource);
list.add(new SimpleAccountDto(WebComponentUtil.getOrigStringFromPoly(accountType.getName()), resourceName));
}
result.recordSuccessIfUnknown();
result.recomputeStatus();
LOGGER.debug("Finished accounts loading.");
return callableResult;
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class PageAccountActivation method loadUser.
private UserType loadUser(PageParameters params) {
String userOid = getOidFromParameter(params);
if (userOid == null) {
getSession().error(getString("PageAccountActivation.user.not found"));
throw new RestartResponseException(PageLogin.class);
}
Task task = createAnonymousTask(LOAD_USER);
OperationResult result = new OperationResult(LOAD_USER);
return runPrivileged(new Producer<UserType>() {
@Override
public UserType run() {
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(UserType.F_LINK_REF, GetOperationOptions.createResolve());
return WebModelServiceUtils.loadObject(UserType.class, userOid, options, PageAccountActivation.this, task, result).asObjectable();
}
});
}
use of com.evolveum.midpoint.schema.GetOperationOptions in project midpoint by Evolveum.
the class PageDebugDownloadBehaviour method dumpObjectsToStream.
private <T extends ObjectType> void dumpObjectsToStream(final Writer writer, OperationResult result) throws Exception {
final PageBase page = getPage();
ResultHandler handler = new ResultHandler() {
@Override
public boolean handle(PrismObject object, OperationResult parentResult) {
try {
String xml = page.getPrismContext().serializeObjectToString(object, PrismContext.LANG_XML);
writer.write('\t');
writer.write(xml);
writer.write('\n');
} catch (IOException ex) {
throw new SystemException(ex.getMessage(), ex);
} catch (SchemaException ex) {
throw new SystemException(ex.getMessage(), ex);
}
return true;
}
};
ModelService service = page.getModelService();
GetOperationOptions options = GetOperationOptions.createRaw();
options.setResolveNames(true);
service.searchObjectsIterative(type, query, handler, SelectorOptions.createCollection(options), page.createSimpleTask(OPERATION_SEARCH_OBJECT), result);
}
use of com.evolveum.midpoint.schema.GetOperationOptions 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();
}
Aggregations