Search in sources :

Example 1 with AndFilter

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

the class ObjectSelectionPanel method createObjectQuery.

private ObjectQuery createObjectQuery() {
    ObjectSearchDto dto = searchModel.getObject();
    ObjectQuery query = null;
    if (StringUtils.isEmpty(dto.getText())) {
        if (context.getDataProviderQuery() != null) {
            return context.getDataProviderQuery();
        } else {
            return query;
        }
    }
    try {
        PageBase pageBase = WebComponentUtil.getPageBase(this);
        PrismContext prismContext = pageBase.getPrismContext();
        PolyStringNormalizer normalizer = prismContext.getDefaultPolyStringNormalizer();
        String normalized = normalizer.normalize(dto.getText());
        ObjectFilter filter = QueryBuilder.queryFor(objectType, prismContext).item(context.getSearchProperty()).contains(normalized).matchingNorm().buildFilter();
        if (context.getDataProviderQuery() != null) {
            AndFilter and = AndFilter.createAnd(context.getDataProviderQuery().getFilter(), filter);
            query = ObjectQuery.createObjectQuery(and);
        } else {
            query = ObjectQuery.createObjectQuery(filter);
        }
    } catch (Exception e) {
        error(getString("chooseTypeDialog.message.queryError") + " " + e.getMessage());
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create query filter.", e);
    }
    return query;
}
Also used : AndFilter(com.evolveum.midpoint.prism.query.AndFilter) ObjectSearchDto(com.evolveum.midpoint.web.page.admin.configuration.dto.ObjectSearchDto) PrismContext(com.evolveum.midpoint.prism.PrismContext) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PolyStringNormalizer(com.evolveum.midpoint.prism.polystring.PolyStringNormalizer)

Example 2 with AndFilter

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

the class NaryLogicalFilterProcessor method process.

@Override
public Predicate process(NaryLogicalFilter filter) throws RepositoryException {
    Predicate predicate = null;
    Operator operator = (filter instanceof AndFilter) ? Ops.AND : Ops.OR;
    for (ObjectFilter subfilter : filter.getConditions()) {
        Predicate right = context.process(subfilter);
        if (right != null) {
            predicate = predicate != null ? ExpressionUtils.predicate(operator, predicate, right) : right;
        }
    }
    return predicate;
}
Also used : Operator(com.querydsl.core.types.Operator) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) Predicate(com.querydsl.core.types.Predicate)

Example 3 with AndFilter

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

the class TestDummy method testSeachIterative.

private void testSeachIterative(final String TEST_NAME, ObjectFilter attrFilter, GetOperationOptions rootOptions, final boolean fullShadow, boolean useObjectClassFilter, final boolean useRepo, String... expectedAccountNames) throws Exception {
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    ObjectQuery query;
    if (useObjectClassFilter) {
        query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME), prismContext);
        if (attrFilter != null) {
            AndFilter filter = (AndFilter) query.getFilter();
            filter.getConditions().add(attrFilter);
        }
    } else {
        query = ObjectQueryUtil.createResourceQuery(RESOURCE_DUMMY_OID, prismContext);
        if (attrFilter != null) {
            query.setFilter(AndFilter.createAnd(query.getFilter(), attrFilter));
        }
    }
    display("Query", query);
    final XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) {
            foundObjects.add(shadow);
            XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
            assertTrue(shadow.canRepresent(ShadowType.class));
            if (!useRepo) {
                try {
                    checkAccountShadow(shadow, parentResult, fullShadow, startTs, endTs);
                } catch (SchemaException e) {
                    throw new SystemException(e.getMessage(), e);
                }
            }
            return true;
        }
    };
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(rootOptions);
    // WHEN
    if (useRepo) {
        repositoryService.searchObjectsIterative(ShadowType.class, query, handler, null, false, result);
    } else {
        provisioningService.searchObjectsIterative(ShadowType.class, query, options, handler, null, result);
    }
    // THEN
    result.computeStatus();
    display("searchObjectsIterative result", result);
    TestUtil.assertSuccess(result);
    display("found shadows", foundObjects);
    for (String expectedAccountId : expectedAccountNames) {
        boolean found = false;
        for (PrismObject<ShadowType> foundObject : foundObjects) {
            if (expectedAccountId.equals(foundObject.asObjectable().getName().getOrig())) {
                found = true;
                break;
            }
        }
        if (!found) {
            AssertJUnit.fail("Account " + expectedAccountId + " was expected to be found but it was not found (found " + foundObjects.size() + ", expected " + expectedAccountNames.length + ")");
        }
    }
    assertEquals("Wrong number of found objects (" + foundObjects + "): " + foundObjects, expectedAccountNames.length, foundObjects.size());
    if (!useRepo) {
        checkConsistency(foundObjects);
    }
    assertSteadyResource();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Example 4 with AndFilter

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

the class TestAdHocCertification method test010HireUserOutOfScope.

@Test
public void test010HireUserOutOfScope() throws Exception {
    // GIVEN
    Task task = getTestTask();
    task.setOwner(userAdministrator.asPrismObject());
    OperationResult result = task.getResult();
    // WHEN
    when();
    assignOrg(USER_INDIGO_OID, ORG_LABORATORY_OID, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    SearchResultList<PrismObject<AccessCertificationCampaignType>> campaigns = getAllCampaigns(result);
    assertEquals("Wrong # of campaigns", 1, campaigns.size());
    AccessCertificationObjectBasedScopeType scope = (AccessCertificationObjectBasedScopeType) campaigns.get(0).asObjectable().getScopeDefinition();
    Class<? extends ObjectType> objectClass = ObjectTypes.getObjectTypeClass(scope.getObjectType());
    ObjectFilter parsedFilter = prismContext.getQueryConverter().parseFilter(scope.getSearchFilter(), objectClass);
    assertTrue("Unexpected type of scope filter, expected AndFilter", parsedFilter instanceof AndFilter);
    for (ObjectFilter subFilter : ((AndFilter) parsedFilter).getConditions()) {
        assertTrue("Unexpected type of subfilter in scope filter, expected EqualFilter or InOidFilter", (subFilter instanceof EqualFilter || subFilter instanceof InOidFilter));
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) Test(org.testng.annotations.Test)

Example 5 with AndFilter

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

the class LogicalOperation method interpret.

@Override
public <T> Filter interpret(ObjectFilter objectFilter, ConnIdNameMapper icfNameMapper) throws SchemaException {
    if (objectFilter instanceof NotFilter) {
        NotFilter not = (NotFilter) objectFilter;
        if (not.getFilter() == null) {
            LOGGER.debug("Not filter does not contain any condition. Skipping processing not filter.");
            return null;
        }
        Filter f = getInterpreter().interpret(not.getFilter(), icfNameMapper);
        return FilterBuilder.not(f);
    } else {
        NaryLogicalFilter nAry = (NaryLogicalFilter) objectFilter;
        List<? extends ObjectFilter> conditions = nAry.getConditions();
        if (conditions == null || conditions.isEmpty()) {
            LOGGER.debug("No conditions specified for logical filter. Skipping processing logical filter.");
            return null;
        }
        if (conditions.size() < 2) {
            LOGGER.debug("Logical filter contains only one condition. Skipping processing logical filter and process simple operation of type {}.", conditions.get(0).getClass().getSimpleName());
            return getInterpreter().interpret(conditions.get(0), icfNameMapper);
        }
        List<Filter> filters = new ArrayList<>();
        for (ObjectFilter objFilter : nAry.getConditions()) {
            Filter f = getInterpreter().interpret(objFilter, icfNameMapper);
            filters.add(f);
        }
        Filter nAryFilter = null;
        if (filters.size() >= 2) {
            if (nAry instanceof AndFilter) {
                nAryFilter = interpretAnd(filters.get(0), filters.subList(1, filters.size()));
            } else if (nAry instanceof OrFilter) {
                nAryFilter = interpretOr(filters.get(0), filters.subList(1, filters.size()));
            }
        }
        return nAryFilter;
    }
}
Also used : NaryLogicalFilter(com.evolveum.midpoint.prism.query.NaryLogicalFilter) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) NaryLogicalFilter(com.evolveum.midpoint.prism.query.NaryLogicalFilter) Filter(org.identityconnectors.framework.common.objects.filter.Filter) AndFilter(com.evolveum.midpoint.prism.query.AndFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) NotFilter(com.evolveum.midpoint.prism.query.NotFilter) OrFilter(com.evolveum.midpoint.prism.query.OrFilter) NotFilter(com.evolveum.midpoint.prism.query.NotFilter) ArrayList(java.util.ArrayList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) OrFilter(com.evolveum.midpoint.prism.query.OrFilter)

Aggregations

AndFilter (com.evolveum.midpoint.prism.query.AndFilter)5 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ArrayList (java.util.ArrayList)2 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PolyStringNormalizer (com.evolveum.midpoint.prism.polystring.PolyStringNormalizer)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 InOidFilter (com.evolveum.midpoint.prism.query.InOidFilter)1 NaryLogicalFilter (com.evolveum.midpoint.prism.query.NaryLogicalFilter)1 NotFilter (com.evolveum.midpoint.prism.query.NotFilter)1 OrFilter (com.evolveum.midpoint.prism.query.OrFilter)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 Task (com.evolveum.midpoint.task.api.Task)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ObjectSearchDto (com.evolveum.midpoint.web.page.admin.configuration.dto.ObjectSearchDto)1