private static ObjectFilter createResourceAndKindFilter(String resourceOid, ShadowKindType kind, PrismContext prismContext) throws SchemaException { Validate.notNull(resourceOid, "Resource where to search must not be null."); Validate.notNull(kind, "Kind to search must not be null."); Validate.notNull(prismContext, "Prism context must not be null."); return prismContext.queryFor(ShadowType.class) .item(ShadowType.F_RESOURCE_REF).ref(resourceOid) .and().item(ShadowType.F_KIND).eq(kind) .buildFilter(); }
<C extends Containerable, T> ObjectFilter createEqualFilter(ItemPath propertyPath, Class<C> type, T realValue) throws SchemaException { return prismContext.queryFor(type) .item(propertyPath).eq(realValue) .buildFilter(); }
public static ObjectFilter createObjectClassFilter(QName objectClass, PrismContext prismContext) { return prismContext.queryFor(ShadowType.class) .item(ShadowType.F_OBJECT_CLASS).eq(objectClass) .buildFilter(); }
<C extends Containerable, T> ObjectFilter createEqualFilter(QName propertyName, Class<C> type, T realValue) throws SchemaException { return prismContext.queryFor(type) .item(propertyName).eq(realValue) .buildFilter(); }
public static ObjectFilter createResourceAndKindIntentFilter(String resourceOid, ShadowKindType kind, String intent, PrismContext prismContext) throws SchemaException { Validate.notNull(resourceOid, "Resource where to search must not be null."); Validate.notNull(kind, "Kind to search must not be null."); Validate.notNull(prismContext, "Prism context must not be null."); return prismContext.queryFor(ShadowType.class) .item(ShadowType.F_RESOURCE_REF).ref(resourceOid) .and().item(ShadowType.F_KIND).eq(kind) .and().item(ShadowType.F_INTENT).eq(intent) .buildFilter(); }
private ObjectFilter createFilterFor(Class<? extends Containerable> type, ItemPath path, XMLGregorianCalendar lastScanTimestamp, XMLGregorianCalendar thisScanTimestamp) { if (lastScanTimestamp == null) { return prismContext.queryFor(type) .item(path).le(thisScanTimestamp) .buildFilter(); } else { return prismContext.queryFor(type) .item(path).gt(lastScanTimestamp) .and().item(path).le(thisScanTimestamp) .buildFilter(); } }
private <T> ObjectFilter createAttributeEqualFilter(ProvisioningContext ctx, ResourceAttribute<T> secondaryIdentifier) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException { return prismContext.queryFor(ShadowType.class) .item(secondaryIdentifier.getPath(), secondaryIdentifier.getDefinition()) .eq(getNormalizedValue(secondaryIdentifier, ctx.getObjectClassDefinition())) .buildFilter(); }
@Test public void testDontMatchEqualFilter() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_GIVEN_NAME).eq("Jackie") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); }
@Test // MID-4217 public void testMultiRootPositive() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION).eq("Assignment 2") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object, but it should", match); }
@Test // MID-4217 public void testMultiRootNegative() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION).eq("Assignment XXXXX") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); }
@Test public void testMatchEqualNonEmptyAgainstEmptyItem() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); // jack has no locality ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("some") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); }
@Test // MID-4120 public void testMatchSubstringAgainstEmptyItem() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); // jack has no locality ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).startsWith("C") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); }
@Test public void testPolystringMatchEqualFilter() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); PolyString name = new PolyString("jack", "jack"); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_NAME).eq(name) .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); }
@Test // MID-4173 public void testExistsNegative() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .item(AssignmentType.F_DESCRIPTION).eq("Assignment NONE") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); }
@Test // MID-4173 public void testExistsPositive() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .item(AssignmentType.F_DESCRIPTION).eq("Assignment 2") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object, but it should", match); }
@Test public void testMatchEqualMultivalue() throws Exception { PrismObject<UserType> user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); MutablePrismPropertyDefinition<?> def = getPrismContext().definitionFactory().createPropertyDefinition(new QName("indexedString"), DOMUtil.XSD_STRING); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(ItemPath.create(UserType.F_EXTENSION, "indexedString"), def).eq("alpha") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); }
@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); }
@Test public void testMatchAndFilter() 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").matchingCaseIgnore() .and().item(UserType.F_FULL_NAME).contains("arr") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); }
protected <T> void testSeachIterativeSingleAttrFilter(final String TEST_NAME, QName attrQName, T attrVal, 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> attrDef = objectClassDef.findAttributeDefinition(attrQName); ObjectFilter filter = prismContext.queryFor(ShadowType.class) .itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attrVal) .buildFilter(); testSeachIterative(TEST_NAME, filter, rootOptions, fullShadow, true, false, expectedAccountNames); }
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); }