Search in sources :

Example 26 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class UserProfileServiceImpl method findByUsername.

private PrismObject<UserType> findByUsername(String username, OperationResult result) throws SchemaException, ObjectNotFoundException {
    PolyString usernamePoly = new PolyString(username);
    ObjectQuery query = ObjectQueryUtil.createNormNameQuery(usernamePoly, prismContext);
    LOGGER.trace("Looking for user, query:\n" + query.debugDump());
    List<PrismObject<UserType>> list = repositoryService.searchObjects(UserType.class, query, null, result);
    LOGGER.trace("Users found: {}.", list.size());
    if (list.size() != 1) {
        return null;
    }
    return list.get(0);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 27 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class SelectableBeanObjectDataProvider method internalIterator.

@Override
public Iterator<SelectableBean<O>> internalIterator(long offset, long pageSize) {
    LOGGER.trace("begin::iterator() offset {} pageSize {}.", new Object[] { offset, pageSize });
    //        if (pageSize > 1000000) {
    //        	// Failsafe. Do not even try this. This can have huge impact on the resource. (MID-3336)
    //        	throw new IllegalArgumentException("Requested huge page size: "+pageSize);
    //        }
    preprocessSelectedData();
    OperationResult result = new OperationResult(OPERATION_SEARCH_OBJECTS);
    try {
        ObjectPaging paging = createPaging(offset, pageSize);
        Task task = getPage().createSimpleTask(OPERATION_SEARCH_OBJECTS);
        ObjectQuery query = getQuery();
        if (query == null) {
            if (emptyListOnNullQuery) {
                return new ArrayList<SelectableBean<O>>().iterator();
            }
            query = new ObjectQuery();
        }
        query.setPaging(paging);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} with {}", type.getSimpleName(), query.debugDump());
        }
        if (ResourceType.class.equals(type) && (options == null || options.isEmpty())) {
            options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
        }
        List<PrismObject<? extends O>> list = (List) getModel().searchObjects(type, query, options, task, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} resulted in {} objects", type.getSimpleName(), list.size());
        }
        for (PrismObject<? extends O> object : list) {
            getAvailableData().add(createDataObjectWrapper(object.asObjectable()));
        }
    //            result.recordSuccess();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't list objects.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list objects", ex);
        return handleNotSuccessOrHandledErrorInIterator(result);
    } finally {
        result.computeStatusIfUnknown();
    }
    LOGGER.trace("end::iterator() {}", result);
    return getAvailableData().iterator();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RestartResponseException(org.apache.wicket.RestartResponseException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 28 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class DeleteAllPanel method countShadows.

private void countShadows(boolean isAccountShadow) {
    DeleteAllDto dto = model.getObject();
    Task task = getPagebase().createSimpleTask(OPERATION_SEARCH_ITERATIVE_TASK);
    OperationResult result = new OperationResult(OPERATION_SEARCH_ITERATIVE_TASK);
    Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
    GetOperationOptions opt = GetOperationOptions.createRaw();
    options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, opt));
    try {
        ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, getPagebase().getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).buildFilter();
        if (isAccountShadow) {
            ObjectQuery query = ObjectQuery.createObjectQuery(filter);
            dto.setAccountShadowCount(getPagebase().getModelService().countObjects(ShadowType.class, query, options, task, result));
            dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getAccountShadowCount());
        } else {
            ObjectQuery query = ObjectQuery.createObjectQuery(NotFilter.createNot(filter));
            dto.setNonAccountShadowCount(getPagebase().getModelService().countObjects(ShadowType.class, query, options, task, result));
            dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getNonAccountShadowCount());
        }
    } catch (Exception ex) {
        result.computeStatus(getString("deleteAllDialog.message.countSearchProblem"));
        LoggingUtils.logUnexpectedException(LOGGER, getString("deleteAllDialog.message.countSearchProblem"), ex);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 29 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class AbstractOrgTabPanel method loadOrgRoots.

private List<PrismObject<OrgType>> loadOrgRoots() {
    Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ORG_UNIT);
    OperationResult result = new OperationResult(OPERATION_LOAD_ORG_UNIT);
    List<PrismObject<OrgType>> list = new ArrayList<>();
    try {
        ObjectQuery query = ObjectQueryUtil.createRootOrgQuery(getPageBase().getPrismContext());
        list = getPageBase().getModelService().searchObjects(OrgType.class, query, null, task, result);
        if (list.isEmpty()) {
            warn(getString("PageOrgTree.message.noOrgStructDefined"));
        }
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Unable to load org. unit", ex);
        result.recordFatalError("Unable to load org unit", ex);
    } finally {
        result.computeStatus();
    }
    if (WebComponentUtil.showResultInPage(result)) {
        getPageBase().showResult(result);
    }
    return list;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 30 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class ControllerSearchObjectsTest method nullResult.

@Test(expectedExceptions = IllegalArgumentException.class)
public void nullResult() throws Exception {
    ObjectPaging paging = ObjectPaging.createPaging(0, Integer.MAX_VALUE, ObjectType.F_NAME, OrderDirection.ASCENDING);
    ObjectQuery query = ObjectQuery.createObjectQuery(paging);
    controller.searchObjects(null, query, null, null, null);
}
Also used : ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)355 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)241 PrismObject (com.evolveum.midpoint.prism.PrismObject)217 Test (org.testng.annotations.Test)159 Task (com.evolveum.midpoint.task.api.Task)150 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)67 QName (javax.xml.namespace.QName)58 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)50 ArrayList (java.util.ArrayList)50 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)38 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)35 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)33 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)30 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)21 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)17 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)16