use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class NameResolutionHelper method resolveNamesIfRequested.
public void resolveNamesIfRequested(Session session, List<? extends PrismContainerValue> containerValues, Collection<SelectorOptions<GetOperationOptions>> options) {
List<ItemPath> pathsToResolve = getPathsToResolve(options);
if (pathsToResolve.isEmpty()) {
return;
}
final Set<String> oidsToResolve = new HashSet<>();
Visitor oidExtractor = visitable -> {
if (visitable instanceof PrismReferenceValue) {
PrismReferenceValue value = (PrismReferenceValue) visitable;
if (!ItemPath.containsSubpathOrEquivalent(pathsToResolve, value.getPath())) {
return;
}
if (value.getTargetName() != null) {
return;
}
if (value.getObject() != null) {
value.setTargetName(value.getObject().getName());
return;
}
if (value.getOid() == null) {
return;
}
oidsToResolve.add(value.getOid());
}
};
Set<PrismContainerValue> roots = containerValues.stream().map(pcv -> pcv.getRootValue()).collect(Collectors.toSet());
roots.forEach(root -> root.accept(oidExtractor));
Map<String, PolyString> oidNameMap = new HashMap<>();
List<String> batch = new ArrayList<>();
for (Iterator<String> iterator = oidsToResolve.iterator(); iterator.hasNext(); ) {
batch.add(iterator.next());
if (batch.size() >= MAX_OIDS_TO_RESOLVE_AT_ONCE || !iterator.hasNext()) {
Query query = session.getNamedQuery("resolveReferences");
query.setParameterList("oid", batch);
query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
@SuppressWarnings({ "unchecked", "raw" }) List<Map<String, Object>> // returns oid + name
results = query.list();
for (Map<String, Object> result : results) {
String oid = (String) result.get("0");
RPolyString name = (RPolyString) result.get("1");
oidNameMap.put(oid, new PolyString(name.getOrig(), name.getNorm()));
}
batch.clear();
}
}
if (!oidNameMap.isEmpty()) {
Visitor nameSetter = visitable -> {
if (visitable instanceof PrismReferenceValue) {
PrismReferenceValue value = (PrismReferenceValue) visitable;
if (value.getTargetName() == null && value.getOid() != null) {
value.setTargetName(oidNameMap.get(value.getOid()));
}
}
};
roots.forEach(root -> root.accept(nameSetter));
}
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class DeleteAllPanel method createDeleteOrgUnitsMessage.
private String createDeleteOrgUnitsMessage() {
if (!model.getObject().getDeleteOrgs()) {
return createStringResource("deleteAllDialog.label.orgUnitsDelete", 0).getString();
}
DeleteAllDto dto = model.getObject();
Task task = getPagebase().createSimpleTask(OPERATION_COUNT_TASK);
OperationResult result = new OperationResult(OPERATION_COUNT_TASK);
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
GetOperationOptions opt = GetOperationOptions.createRaw();
options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, opt));
try {
dto.setOrgUnitCount(getPagebase().getModelService().countObjects(OrgType.class, null, options, task, result));
dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getOrgUnitCount());
} catch (Exception ex) {
result.computeStatus(getString("deleteAllDialog.message.countSearchProblem"));
LoggingUtils.logUnexpectedException(LOGGER, getString("deleteAllDialog.message.countSearchProblem"), ex);
}
return createStringResource("deleteAllDialog.label.orgUnitsDelete", dto.getOrgUnitCount()).getString();
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class DeleteAllPanel method createDeleteUsersMessage.
private String createDeleteUsersMessage() {
if (!model.getObject().getDeleteUsers()) {
return createStringResource("deleteAllDialog.label.usersDelete", 0).getString();
}
DeleteAllDto dto = model.getObject();
Task task = getPagebase().createSimpleTask(OPERATION_COUNT_TASK);
OperationResult result = new OperationResult(OPERATION_COUNT_TASK);
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
GetOperationOptions opt = GetOperationOptions.createRaw();
options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, opt));
try {
dto.setUserCount(getPagebase().getModelService().countObjects(UserType.class, null, options, task, result));
//We need to substract 1, because we are not deleting user 'Administrator'
dto.setUserCount(dto.getUserCount() - 1);
dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getUserCount());
} catch (Exception ex) {
result.computeStatus(getString("deleteAllDialog.message.countSearchProblem"));
LoggingUtils.logUnexpectedException(LOGGER, getString("deleteAllDialog.message.countSearchProblem"), ex);
}
return createStringResource("deleteAllDialog.label.usersDelete", dto.getUserCount()).getString();
}
use of com.evolveum.midpoint.schema.SelectorOptions 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.SelectorOptions in project midpoint by Evolveum.
the class CertCaseDtoProvider method internalIterator.
@Override
public Iterator<CertCaseOrWorkItemDto> internalIterator(long first, long count) {
LOGGER.trace("begin::iterator() from {} count {}.", first, count);
getAvailableData().clear();
Task task = getPage().createSimpleTask(OPERATION_SEARCH_OBJECTS);
OperationResult result = task.getResult();
try {
ObjectPaging paging = createPaging(first, count);
Collection<SelectorOptions<GetOperationOptions>> resolveNames = createCollection(createResolveNames());
List<AccessCertificationCaseType> caseList = searchCases(campaignOid, paging, resolveNames, task, result);
for (AccessCertificationCaseType _case : caseList) {
getAvailableData().add(new CertCaseDto(_case, getPage(), task, result));
}
} catch (Exception ex) {
result.recordFatalError("Couldn't list decisions.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list decisions", ex);
} finally {
result.computeStatusIfUnknown();
}
if (!WebComponentUtil.isSuccessOrHandledError(result)) {
handleNotSuccessOrHandledErrorInIterator(result);
}
LOGGER.trace("end::iterator()");
return getAvailableData().iterator();
}
Aggregations