Search in sources :

Example 61 with SelectorOptions

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));
    }
}
Also used : SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) java.util(java.util) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) Transformers(org.hibernate.transform.Transformers) Session(org.hibernate.Session) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Component(org.springframework.stereotype.Component) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Query(org.hibernate.Query) NotNull(org.jetbrains.annotations.NotNull) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Query(org.hibernate.Query) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 62 with SelectorOptions

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 63 with SelectorOptions

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 64 with SelectorOptions

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);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) FocusSubwrapperDto(com.evolveum.midpoint.web.page.admin.users.dto.FocusSubwrapperDto)

Example 65 with SelectorOptions

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();
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) RestartResponseException(org.apache.wicket.RestartResponseException)

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