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