Search in sources :

Example 26 with GetOperationOptions

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);
    }
}
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 27 with GetOperationOptions

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;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SimpleAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)

Example 28 with GetOperationOptions

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

Example 29 with GetOperationOptions

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 30 with GetOperationOptions

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

Aggregations

GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)52 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)38 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)31 Task (com.evolveum.midpoint.task.api.Task)22 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)19 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 Collection (java.util.Collection)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)11 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)11 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)10 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)10 QName (javax.xml.namespace.QName)10 Test (org.testng.annotations.Test)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 ArrayList (java.util.ArrayList)9 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7