@Test public void test0162QueryTriggerBeforeAfter() throws Exception { final Date NOW = new Date(); Session session = open(); try { XMLGregorianCalendar lastScanTimestamp = XmlTypeConverter.createXMLGregorianCalendar(NOW.getTime()); XMLGregorianCalendar thisScanTimestamp = XmlTypeConverter.createXMLGregorianCalendar(NOW.getTime()); ObjectQuery query = prismContext.queryFor(ObjectType.class) .exists(ObjectType.F_TRIGGER) .block() .item(F_TIMESTAMP).gt(lastScanTimestamp) .and().item(F_TIMESTAMP).le(thisScanTimestamp) .endBlock() .build(); String real = getInterpretedQuery2(session, ObjectType.class, query); String expected = "select\n" + " o.oid, o.fullObject, o.stringsCount, o.longsCount, o.datesCount, o.referencesCount, o.polysCount, o.booleansCount\n" + "from\n" + " RObject o\n" + " left join o.trigger t\n" + "where\n" + " ( t.timestamp > :timestamp and t.timestamp <= :timestamp2 )\n"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void testOperationExecutionWithTask2() throws SchemaException { ObjectQuery query = prismContext.queryFor(CaseType.class) .exists(ObjectType.F_OPERATION_EXECUTION) .block() .item(OperationExecutionType.F_TASK_REF).ref("task-oid-2") .and().item(OperationExecutionType.F_STATUS).eq(OperationResultStatusType.FATAL_ERROR) .endBlock() .build(); OperationResult result = new OperationResult("search"); List<PrismObject<CaseType>> cases = repositoryService.searchObjects(CaseType.class, query, null, result); result.recomputeStatus(); assertTrue(result.isSuccess()); assertEquals("Should find no object", 0, cases.size()); }
@Test public void test142TypeWithEqualsInBlock() throws Exception{ ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .block() .item(UserType.F_LOCALITY).eq("Caribbean") .endBlock() .build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( TypeFilterImpl.createType( USER_TYPE_QNAME, createEqual(UserType.F_LOCALITY, UserType.class, null, "Caribbean") ) ); compare(actual, expected); }
@Test public void testOperationExecutionWithTask() throws SchemaException { ObjectQuery query = prismContext.queryFor(CaseType.class) .exists(ObjectType.F_OPERATION_EXECUTION) .block() .item(OperationExecutionType.F_TASK_REF).ref("task-oid-2") .and().item(OperationExecutionType.F_STATUS).eq(OperationResultStatusType.SUCCESS) .endBlock() .build(); OperationResult result = new OperationResult("search"); List<PrismObject<CaseType>> cases = repositoryService.searchObjects(CaseType.class, query, null, result); result.recomputeStatus(); assertTrue(result.isSuccess()); assertEquals("Should find one object", 1, cases.size()); }
.block() .item(ShadowType.F_NAME).eqPoly("aaa") .endBlock() .build();
.item(OperationExecutionType.F_STATUS).eq(OperationResultStatusType.FATAL_ERROR) .and().item(OperationExecutionType.F_TIMESTAMP).le(XmlTypeConverter.createXMLGregorianCalendar(new Date())) .endBlock() .build(); String real = getInterpretedQuery2(session, ShadowType.class, query);
.item(AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS) .eq(ActivationStatusType.ENABLED) .endBlock() .asc(F_NAME) .build();
.block() .item(ShadowType.F_NAME).eqPoly("aaa") .endBlock() .endBlock() .build();
.item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).gt(lastScanTimestamp) .and().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .endBlock() .or().block() .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).gt(lastScanTimestamp) .and().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .endBlock() .or().block() .item(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM).gt(lastScanTimestamp) .and().item(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .endBlock() .or().block() .item(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).gt(lastScanTimestamp) .and().item(F_ASSIGNMENT, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .endBlock() .build();
.item(AssignmentType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS) .eq(ActivationStatusType.ENABLED) .endBlock() .endBlock() .asc(F_NAME)
@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); }
.item(OperationExecutionType.F_TASK_REF).ref("oid1") .and().item(OperationExecutionType.F_STATUS).eq(OperationResultStatusType.SUCCESS) .endBlock() .build(); String real = getInterpretedQuery2(session, ShadowType.class, query);
.item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).gt(lastScanTimestamp) .and().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .endBlock() .or().block() .item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).gt(lastScanTimestamp) .and().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .endBlock() .or() .exists(F_ASSIGNMENT) .item(AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).gt(lastScanTimestamp) .and().item(AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .endBlock() .build();
.item(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM).le(thisScanTimestamp) .or().item(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO).le(thisScanTimestamp) .endBlock() .build();
@Test public void test152ExistsWithEqualsInBlock() throws Exception{ ObjectQuery actual = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .block() .item(AssignmentType.F_NOTE).endsWith("DONE.") .endBlock() .build(); ComplexTypeDefinition assCtd = getPrismContext().getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(AssignmentType.class); PrismContainerDefinition userPcd = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(UserType.class); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( ExistsFilterImpl.createExists( UserType.F_ASSIGNMENT, userPcd, SubstringFilterImpl.createSubstring( AssignmentType.F_NOTE, assCtd.findPropertyDefinition(AssignmentType.F_NOTE), getPrismContext(), null, "DONE.", false, true) ) ); compare(actual, expected); }
.item(AssignmentType.F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp) .or().item(AssignmentType.F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp) .endBlock(); .or().item(AssignmentType.F_ACTIVATION, F_VALID_TO).gt(lastScanTimestamp) .and().item(AssignmentType.F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp) .endBlock();
@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); }