private ObjectQuery createQueryBySecondaryIdentifier(ShadowType shadow) throws SchemaException { // TODO TODO TODO set matching rule instead of null in equlas filter Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow); S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class); q = q.block(); if (secondaryIdentifiers.isEmpty()) { for (ResourceAttribute<?> primaryIdentifier: ShadowUtil.getPrimaryIdentifiers(shadow)) { q = q.itemAs(primaryIdentifier).or(); } } else { // secondary identifiers connected by 'or' clause for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) { q = q.itemAs(secondaryIdentifier).or(); } } q = q.none().endBlock().and(); // resource + object class q = q.item(ShadowType.F_RESOURCE_REF).ref(shadow.getResourceRef().getOid()).and(); return q.item(ShadowType.F_OBJECT_CLASS).eq(shadow.getObjectClass()).build(); }
@Test public void test350Substring() throws Exception { final String TEST_NAME = "test350Substring"; displayTestTitle(TEST_NAME); ObjectQuery q = getPrismContext().queryFor(UserType.class) .item(UserType.F_EMPLOYEE_TYPE).contains("A") .or().item(UserType.F_EMPLOYEE_TYPE).startsWith("B") .or().item(UserType.F_EMPLOYEE_TYPE).endsWith("C") .or().item(UserType.F_NAME).startsWithPoly("john", "john").matchingOrig() .build(); checkQueryRoundtripFile(UserType.class, q, TEST_NAME); }
@Test public void testMatchOrFilter() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_GIVEN_NAME).eq("Jack") .or().item(UserType.F_GIVEN_NAME).eq("Jackie") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); }
q = q.item(secondaryIdentifier.getPath(), secondaryIdentifier.getDefinition()) .eq(getNormalizedValue(secondaryIdentifier, ctx.getObjectClassDefinition())) .or();
.or().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .or().item(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .or().item(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .build();
.or().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .or().exists(F_ASSIGNMENT) .block() .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .or().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .endBlock() .build();
if (checkFocusValidity(partition)) { i = i.or().item(F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp) .or().item(F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp); .block() .item(AssignmentType.F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp) .or().item(AssignmentType.F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp) .endBlock(); i = i.or().item(F_ACTIVATION, F_VALID_FROM).gt(lastScanTimestamp) .and().item(F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp) .or().item(F_ACTIVATION, F_VALID_TO).gt(lastScanTimestamp) .and().item(F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp); .item(AssignmentType.F_ACTIVATION, F_VALID_FROM).gt(lastScanTimestamp) .and().item(AssignmentType.F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp) .or().item(AssignmentType.F_ACTIVATION, F_VALID_TO).gt(lastScanTimestamp) .and().item(AssignmentType.F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp) .endBlock();
@Test public void test0021QueryTwoOrganizationsStrictOr() throws Exception { Session session = open(); try { /* * UserType: Or (Equal (organization, 'asdf'), * Equal (organization, 'ghjk')) */ ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_ORGANIZATION).eqPoly("asdf", "asdf") .or().item(UserType.F_ORGANIZATION).eqPoly("ghjk", "ghjk") .build(); String expected = "select\n" + " u.oid, u.fullObject, u.stringsCount, u.longsCount, u.datesCount, u.referencesCount, u.polysCount, u.booleansCount\n" + "from\n" + " RUser u\n" + " left join u.organization o\n" + " left join u.organization o2\n" + "where\n" + " ( ( o.orig = :orig and o.norm = :norm ) or\n" + " ( o2.orig = :orig2 and o2.norm = :norm2 ) )"; // NOTE: this could be implemented more efficiently by using only one join... or the query itself can be formulated // via In filter (when available) or Exists filter (also, when available) String real = getInterpretedQuery2(session, UserType.class, query); assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test310AllComparisons() throws Exception { final String TEST_NAME = "test310AllComparisons"; displayTestTitle(TEST_NAME); ObjectQuery q = getPrismContext().queryFor(UserType.class) .item(UserType.F_COST_CENTER).gt("100000") .and().item(UserType.F_COST_CENTER).lt("999999") .or() .item(UserType.F_COST_CENTER).ge("X100") .and().item(UserType.F_COST_CENTER).le("X999") .build(); checkQueryRoundtripFile(UserType.class, q, TEST_NAME); }
private boolean checkAttributeUniqueness(PrismProperty identifier, RefinedObjectClassDefinition accountDefinition, ResourceType resourceType, String oid, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { List<PrismPropertyValue<?>> identifierValues = identifier.getValues(); if (identifierValues.isEmpty()) { throw new SchemaException("Empty identifier "+identifier+" while checking uniqueness of "+oid+" ("+resourceType+")"); } //TODO: set matching rule instead of null ObjectQuery query = prismContext.queryFor(ShadowType.class) .itemWithDef(identifier.getDefinition(), ShadowType.F_ATTRIBUTES, identifier.getDefinition().getName()) .eq(PrismValueCollectionsUtil.cloneCollection(identifierValues)) .and().item(ShadowType.F_OBJECT_CLASS).eq(accountDefinition.getObjectClassDefinition().getTypeName()) .and().item(ShadowType.F_RESOURCE_REF).ref(resourceType.getOid()) .and().block() .item(ShadowType.F_DEAD).eq(false) .or().item(ShadowType.F_DEAD).isNull() .endBlock() .build(); boolean unique = checkUniqueness(oid, identifier, query, task, result); return unique; }
.or().item(RoleType.F_INDUCEMENT, AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS).eq(ActivationStatusType.ENABLED) .build(); String real = getInterpretedQuery2(session, RoleType.class, query);
@Test public void test134SingleOrWithNot() throws Exception{ ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") .or().not().item(UserType.F_DESCRIPTION).eq("desc") .build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( OrFilterImpl.createOr( createEqual(UserType.F_LOCALITY, UserType.class, null, "Caribbean"), NotFilterImpl.createNot( createEqual(UserType.F_DESCRIPTION, UserType.class, null, "desc") ) ) ); compare(actual, expected); }
@Test public void test595Logicals2() throws Exception { final String TEST_NAME = "test595Logicals2"; displayTestTitle(TEST_NAME); ObjectQuery q = getPrismContext().queryFor(UserType.class) .item(UserType.F_DESCRIPTION).eq("A") .and().item(UserType.F_DESCRIPTION).eq("B") .or().item(UserType.F_DESCRIPTION).eq("C") .and().item(UserType.F_DESCRIPTION).eq("D") .and() .block() .item(UserType.F_DESCRIPTION).eq("E1") .and().item(UserType.F_DESCRIPTION).eq("E2") .or().item(UserType.F_DESCRIPTION).eq("E3") .endBlock() .build(); checkQueryRoundtripFile(UserType.class, q, TEST_NAME); }
protected <T> void testSeachIterativeAlternativeAttrFilter(final String TEST_NAME, QName attr1QName, T attr1Val, QName attr2QName, T attr2Val, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME); ResourceAttributeDefinition<T> attr1Def = objectClassDef.findAttributeDefinition(attr1QName); ResourceAttributeDefinition<T> attr2Def = objectClassDef.findAttributeDefinition(attr2QName); ObjectFilter filter = prismContext.queryFor(ShadowType.class) .itemWithDef(attr1Def, ShadowType.F_ATTRIBUTES, attr1Def.getName()).eq(attr1Val) .or().itemWithDef(attr2Def, ShadowType.F_ATTRIBUTES, attr2Def.getName()).eq(attr2Val) .buildFilter(); testSeachIterative(TEST_NAME, filter, rootOptions, fullShadow, false, true, expectedAccountNames); }
@Test public void testComplexMatch() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); // System.out.println("user given name" + user.asObjectable().getGivenName()); System.out.println("definition: " +user.findItem(UserType.F_FAMILY_NAME).getDefinition().debugDump()); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_FAMILY_NAME).eq("Sparrow") .and().item(UserType.F_FULL_NAME).contains("arr") .and() .block() .item(UserType.F_GIVEN_NAME).eq("Jack") .or().item(UserType.F_GIVEN_NAME).eq("Jackie") .endBlock() .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); }
.block() .item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).le(XmlTypeConverter.createXMLGregorianCalendar(startTimestamp)) .or().item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).isNull() .endBlock() .and().item(ShadowType.F_RESOURCE_REF).ref(ObjectTypeUtil.createObjectRef(resource, prismContext).asReferenceValue())
.block() .item(UserType.F_LOCALITY).eqPoly("Caribbean", "caribbean") .or().item(UserType.F_LOCALITY).eqPoly("Adriatic", "adriatic") .endBlock() .or().type(OrgType.class)
.item(AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM).gt(lastScanTimestamp) .and().item(AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .or() .item(AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).gt(lastScanTimestamp) .and().item(AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp)
ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") .or() .not().item(UserType.F_DESCRIPTION).eq("desc") .and().all()