private Set<String> getProcessInstancesToKeep(OperationResult result) throws SchemaException { ObjectQuery query = prismContext.queryFor(TaskType.class) .not().item(TaskType.F_WORKFLOW_CONTEXT, WfContextType.F_PROCESS_INSTANCE_ID).isNull() .build(); SearchResultList<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, query, null, result); return tasks.stream() .map(t -> t.asObjectable().getWorkflowContext().getProcessInstanceId()) .collect(Collectors.toSet()); }
private ObjectFilter getReviewerAndEnabledFilterForWI(MidPointPrincipal principal) throws SchemaException { if (principal != null) { return QueryUtils.filterForAssignees( prismContext.queryFor(AccessCertificationWorkItemType.class), principal, OtherPrivilegesLimitationType.F_CERTIFICATION_WORK_ITEMS, relationRegistry) .and().item(F_CLOSE_TIMESTAMP).isNull() .buildFilter(); } else { return prismContext.queryFor(AccessCertificationWorkItemType.class) .item(F_CLOSE_TIMESTAMP).isNull() .buildFilter(); } }
private ObjectQuery createQueryForOpenWorkItems(ObjectQuery baseWorkItemsQuery, MidPointPrincipal principal, boolean notDecidedOnly) throws SchemaException { ObjectFilter reviewerAndEnabledFilter = getReviewerAndEnabledFilterForWI(principal); ObjectFilter filter; if (notDecidedOnly) { ObjectFilter noResponseFilter = prismContext.queryFor(AccessCertificationWorkItemType.class) .item(F_OUTPUT, F_OUTCOME).isNull() .buildFilter(); filter = prismContext.queryFactory().createAnd(reviewerAndEnabledFilter, noResponseFilter); } else { filter = reviewerAndEnabledFilter; } return addFilter(baseWorkItemsQuery, filter); }
private ObjectFilter getReviewerAndEnabledFilter(String reviewerOid) { return prismContext.queryFor(AccessCertificationCaseType.class) .exists(F_WORK_ITEM) .block() .item(F_ASSIGNEE_REF).ref(reviewerOid, UserType.COMPLEX_TYPE) .and().item(F_CLOSE_TIMESTAMP).isNull() .endBlock() .buildFilter(); }
@Test public void testExtensionReferenceNull() throws SchemaException { ObjectQuery query = prismContext.queryFor(GenericObjectType.class) .item(ObjectType.F_EXTENSION, new QName("referenceType")) .isNull() .build(); OperationResult result = new OperationResult("search"); List<PrismObject<GenericObjectType>> cases = repositoryService.searchObjects(GenericObjectType.class, query, null, result); result.recomputeStatus(); assertTrue(result.isSuccess()); assertEquals("Should find no object", 0, cases.size()); }
@Test(expectedExceptions = QueryException.class) public void test0610QueryGenericClob() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(GenericObjectType.class) .item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "locations")).isNull() .build(); getInterpretedQuery2(session, GenericObjectType.class, query); } catch (QueryException ex) { LOGGER.info("Exception", ex); throw ex; } finally { close(session); } }
@Test public void testExtensionReferenceNonNull() throws SchemaException { ObjectQuery query = prismContext.queryFor(GenericObjectType.class) .not().item(ObjectType.F_EXTENSION, new QName("referenceType")) .isNull() .build(); OperationResult result = new OperationResult("search"); List<PrismObject<GenericObjectType>> cases = repositoryService.searchObjects(GenericObjectType.class, query, null, result); result.recomputeStatus(); assertTrue(result.isSuccess()); assertEquals("Should find 1 object", 1, cases.size()); }
@Test public void testMatchEqualEmptyAgainstNonEmptyItem() 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_NAME).isNull() .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); }
@Test public void testMatchEqualEmptyAgainstEmptyItem() 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).isNull() .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); }
@Test public void emptyRoleTypeSearchTest() throws Exception { ObjectQuery query = prismContext.queryFor(RoleType.class) .item(RoleType.F_ROLE_TYPE).isNull() .build(); OperationResult result = new OperationResult("search"); List<PrismObject<RoleType>> roles = repositoryService.searchObjects(RoleType.class, query, null, result); result.recomputeStatus(); assertTrue(result.isSuccess()); assertEquals("Should find two roles", 2, roles.size()); int judge = roles.get(0).getName().getOrig().startsWith("J") ? 0 : 1; assertEquals("Wrong role1 name", "Judge", roles.get(judge).getName().getOrig()); assertEquals("Wrong role2 name", "Admin-owned role", roles.get(1-judge).getName().getOrig()); }
@Test public void nonEmptyRoleTypeSearchTest() throws Exception { ObjectQuery query = prismContext.queryFor(RoleType.class) .not().item(RoleType.F_ROLE_TYPE).isNull() .build(); OperationResult result = new OperationResult("search"); List<PrismObject<RoleType>> roles = repositoryService.searchObjects(RoleType.class, query, null, result); result.recomputeStatus(); assertTrue(result.isSuccess()); assertEquals("Should find one role", 1, roles.size()); assertEquals("Wrong role name", "Pirate", roles.get(0).getName().getOrig()); }
private int getCount(String campaignOid, Integer stage, AccessCertificationResponseType response, boolean onlyRemedied, Task task, OperationResult result) throws SchemaException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException { QName outcomeItem; String responseUri = OutcomeUtils.toUri(response); S_FilterEntry entry; if (stage != null) { outcomeItem = AccessCertificationCaseType.F_CURRENT_STAGE_OUTCOME; entry = prismContext.queryFor(AccessCertificationCaseType.class) .item(AccessCertificationCaseType.F_STAGE_NUMBER).eq(stage) .and(); } else { outcomeItem = AccessCertificationCaseType.F_OUTCOME; entry = prismContext.queryFor(AccessCertificationCaseType.class); } S_AtomicFilterExit exit; if (response == AccessCertificationResponseType.NO_RESPONSE) { exit = entry.item(outcomeItem).isNull().or().item(outcomeItem).eq(responseUri); } else { exit = entry.item(outcomeItem).eq(responseUri); } if (onlyRemedied) { exit = exit.and().not().item(AccessCertificationCaseType.F_REMEDIED_TIMESTAMP).isNull(); } exit = exit.and().ownerId(campaignOid); ObjectQuery query = exit.build(); return modelService.countContainers(AccessCertificationCaseType.class, query, null, task, result); }
@Test public void test0142QueryUserAccountRefNull() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_LINK_REF).isNull() .build(); String real = getInterpretedQuery2(session, UserType.class, query); String expected = "select\n" + " u.oid, u.fullObject,\n" + " u.stringsCount,\n" + " u.longsCount,\n" + " u.datesCount,\n" + " u.referencesCount,\n" + " u.polysCount,\n" + " u.booleansCount\n" + "from\n" + " RUser u\n" + " left join u.linkRef l\n" + "where\n" + " l is null"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test1120NullRefSingle() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(ResourceType.class) .item(ResourceType.F_CONNECTOR_REF).isNull() .build(); String real = getInterpretedQuery2(session, ResourceType.class, query); String expected = "select\n" + " r.oid, r.fullObject,\n" + " r.stringsCount,\n" + " r.longsCount,\n" + " r.datesCount,\n" + " r.referencesCount,\n" + " r.polysCount,\n" + " r.booleansCount\n" + "from\n" + " RResource r\n" + "where\n" + " r.connectorRef is null"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test1150NullEqMulti() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_EMPLOYEE_TYPE).isNull() .build(); String real = getInterpretedQuery2(session, UserType.class, query); String expected = "select\n" + " u.oid,\n" + " u.fullObject,\n" + " u.stringsCount,\n" + " u.longsCount,\n" + " u.datesCount,\n" + " u.referencesCount,\n" + " u.polysCount,\n" + " u.booleansCount\n" + "from\n" + " RUser u\n" + " left join u.employeeType e\n" + "where\n" + " e is null"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test1140NullEqSingle() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_EMPLOYEE_NUMBER).isNull() .build(); String real = getInterpretedQuery2(session, UserType.class, query); String expected = "select\n" + " u.oid, u.fullObject,\n" + " u.stringsCount,\n" + " u.longsCount,\n" + " u.datesCount,\n" + " u.referencesCount,\n" + " u.polysCount,\n" + " u.booleansCount\n" + "from\n" + " RUser u\n" + "where\n" + " u.employeeNumber is null"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test0144QueryUserAccountRefNotNull() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(UserType.class) .not().item(UserType.F_LINK_REF).isNull() .build(); String real = getInterpretedQuery2(session, UserType.class, query); String expected = "select\n" + " u.oid, u.fullObject,\n" + " u.stringsCount,\n" + " u.longsCount,\n" + " u.datesCount,\n" + " u.referencesCount,\n" + " u.polysCount,\n" + " u.booleansCount\n" + "from\n" + " RUser u\n" + " left join u.linkRef l\n" + "where\n" + " not l is null"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
/** * Q{AND: (EQUALS: parent, PPV(null)),PAGING: O: 0,M: 5,BY: name, D:ASCENDING, */ @Test public void test0320CountTaskOrderByName() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(TaskType.class) .item(TaskType.F_PARENT).isNull() .asc(F_NAME) .build(); String real = getInterpretedQuery2(session, TaskType.class, query, true); String expected = "select\n" + " count(t.oid)\n" + "from\n" + " RTask t\n" + "where\n" + " t.parent is null"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
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; }
@Test public void test730CurrentUnansweredCases() throws Exception { OperationResult result = new OperationResult("test730CurrentUnansweredCases"); ObjectQuery query = prismContext.queryFor(AccessCertificationCaseType.class) .item(AccessCertificationCaseType.F_STAGE_NUMBER).eq().item(T_PARENT, AccessCertificationCampaignType.F_STAGE_NUMBER) .and().item(T_PARENT, F_STATE).eq(IN_REVIEW_STAGE) .and().exists(F_WORK_ITEM).block() .item(F_CLOSE_TIMESTAMP).isNull() .and().block() .item(F_OUTPUT, F_OUTCOME).isNull() .endBlock() .endBlock() .build(); List<AccessCertificationCaseType> cases = repositoryService.searchContainers(AccessCertificationCaseType.class, query, createCollection(createDistinct()), result); AccessCertificationCampaignType campaign1 = getFullCampaign(campaign1Oid, result).asObjectable(); AccessCertificationCampaignType campaign2 = getFullCampaign(campaign2Oid, result).asObjectable(); List<AccessCertificationCaseType> expectedCases = new ArrayList<>(); addUnansweredActiveCases(expectedCases, campaign1.getCase(), campaign1); addUnansweredActiveCases(expectedCases, campaign2.getCase(), campaign2); PrismAsserts.assertEqualsCollectionUnordered("list of cases is different", cases, expectedCases.toArray(new AccessCertificationCaseType[0])); }