@Test public void test200OrderByName() throws Exception{ ObjectQuery actual = getPrismContext().queryFor(UserType.class) .asc(UserType.F_NAME) .build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( ObjectPagingImpl.createPaging(UserType.F_NAME, OrderDirection.ASCENDING) ); compare(actual, expected); }
private void cleanupCampaignsByNumber(int maxRecords, Task task, OperationResult parentResult) { OperationResult result = parentResult.createSubresult(OPERATION_CLEANUP_CAMPAIGNS_BY_NUMBER); LOGGER.info("Starting cleanup for closed certification campaigns, keeping {} ones.", maxRecords); int deleted = 0; Set<String> poisonedCampaigns = new HashSet<>(); try { for (;;) { ObjectQuery query = prismContext.queryFor(AccessCertificationCampaignType.class) .item(AccessCertificationCampaignType.F_STATE).eq(AccessCertificationCampaignStateType.CLOSED) .and().not().id(poisonedCampaigns.toArray(new String[0])) // hoping there are not many of these .desc(AccessCertificationCampaignType.F_END_TIMESTAMP) .offset(maxRecords) .maxSize(DELETE_BLOCK_SIZE) .build(); int delta = searchAndDeleteCampaigns(query, poisonedCampaigns, result, task); if (delta == 0) { LOGGER.info("Deleted {} campaigns.", deleted); return; } } } finally { result.computeStatusIfUnknown(); } }
private List<AccessCertificationCaseType> getCertificationCampaignCasesAsBeans(String campaignName) throws SchemaException, SecurityViolationException, ConfigurationException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException { Task task = taskManager.createTaskInstance(); ObjectQuery query; if (StringUtils.isEmpty(campaignName)) { //query = null; return new ArrayList<>(); } else { query = prismContext.queryFor(AccessCertificationCaseType.class) .item(PrismConstants.T_PARENT, F_NAME).eqPoly(campaignName, "").matchingOrig() // TODO first by object/target type then by name (not supported by the repository as of now) .asc(AccessCertificationCaseType.F_OBJECT_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME) .asc(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME) .build(); } Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames()); return model.searchContainers(AccessCertificationCaseType.class, query, options, task, task.getResult()); }
@Test public void test1410QueryOrderByNameOrigLimit20() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(RoleType.class).asc(RoleType.F_NAME).maxSize(20).build(); String expected = "select\n" + " r.oid, r.fullObject, r.stringsCount, r.longsCount, r.datesCount, r.referencesCount, r.polysCount, r.booleansCount\n" + "from\n" + " RRole r\n" + "order by\n" + "r.nameCopy.orig asc"; String real = getInterpretedQuery2(session, RoleType.class, query); assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test210OrderByNameAndId() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") .asc(UserType.F_NAME) .desc(PrismConstants.T_ID) .build(); ObjectPaging paging = ObjectPagingImpl.createEmptyPaging(); paging.addOrderingInstruction(UserType.F_NAME, OrderDirection.ASCENDING); paging.addOrderingInstruction(ItemPath.create(PrismConstants.T_ID), OrderDirection.DESCENDING); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( createEqual(UserType.F_LOCALITY, UserType.class, null, "Caribbean"), paging); compare(actual, expected); }
public List<PrismContainerValue<WorkItemType>> searchApprovalWorkItems(int days, QName sortColumn) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException, DatatypeConfigurationException { Task task = taskManager.createTaskInstance(); OperationResult result = task.getResult(); ObjectQuery query = prismContext.queryFor(AbstractWorkItemType.class).build(); if (days > 0) { XMLGregorianCalendar since = (new Clock()).currentTimeXMLGregorianCalendar(); DatatypeFactory df = DatatypeFactory.newInstance(); since.add (df.newDuration(false, 0, 0, days, 0, 0, 0)); query.addFilter(prismContext.queryFor(AbstractWorkItemType.class) .item(AbstractWorkItemType.F_CREATE_TIMESTAMP).lt(since).buildFilter()); } if (sortColumn != null) { query.addFilter(prismContext.queryFor(AbstractWorkItemType.class) .asc(sortColumn) .buildFilter()); } Object[] itemsToResolve = { WorkItemType.F_ASSIGNEE_REF, ItemPath.create(PrismConstants.T_PARENT, WfContextType.F_OBJECT_REF), ItemPath.create(PrismConstants.T_PARENT, WfContextType.F_TARGET_REF), ItemPath.create(PrismConstants.T_PARENT, WfContextType.F_REQUESTER_REF) }; SearchResultList<WorkItemType> workItems = model.searchContainers(WorkItemType.class, query, schemaHelper.getOperationOptionsBuilder().items(itemsToResolve).resolve().build(), task, result); return PrismContainerValue.toPcvList(workItems); }
@Test public void test1400QueryOrderByNameOrigLimit20() throws Exception { Session session = open(); try { ObjectQuery query = prismContext.queryFor(UserType.class).asc(UserType.F_NAME).maxSize(20).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" + "order by\n" + "u.nameCopy.orig asc"; String real = getInterpretedQuery2(session, UserType.class, query); assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
@Test public void test011OrgFilter() throws Exception { final String TEST_NAME = "test011OrgFilter"; TestUtil.displayTestTitle(TEST_NAME); OperationResult opResult = new OperationResult(TEST_NAME); ObjectQuery query = prismContext.queryFor(ObjectType.class) .isDirectChildOf(ORG_F001_OID) .asc(ObjectType.F_NAME) .build(); // WHEN List<PrismObject<ObjectType>> orgClosure = repositoryService.searchObjects(ObjectType.class, query, null, opResult); // THEN AssertJUnit.assertEquals(4, orgClosure.size()); }
private List<AccessCertificationCaseType> getCertificationCampaignNotRespondedCasesAsBeans(String campaignName) throws SchemaException, SecurityViolationException, ConfigurationException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException { Task task = taskManager.createTaskInstance(); ObjectQuery query; if (StringUtils.isEmpty(campaignName)) { //query = null; return new ArrayList<>(); } else { query = prismContext.queryFor(AccessCertificationCaseType.class) .item(PrismConstants.T_PARENT, F_NAME).eqPoly(campaignName, "").matchingOrig() .and().item(AccessCertificationCaseType.F_CURRENT_STAGE_OUTCOME).eq(SchemaConstants.MODEL_CERTIFICATION_OUTCOME_NO_RESPONSE) // TODO first by object/target type then by name (not supported by the repository as of now) .asc(AccessCertificationCaseType.F_OBJECT_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME) .asc(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME) .build(); } Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames()); return model.searchContainers(AccessCertificationCaseType.class, query, options, task, task.getResult()); }
@Test public void test006searchOrgStructUserUnbounded() throws Exception { OperationResult parentResult = new OperationResult("test006searchOrgStructUserUnbounded"); ObjectQuery objectQuery = prismContext.queryFor(ObjectType.class) .isChildOf(SEARCH_ORG_OID_UNBOUNDED_DEPTH) .asc(ObjectType.F_NAME) .build(); List<PrismObject<ObjectType>> orgClosure = repositoryService.searchObjects(ObjectType.class, objectQuery, null, parentResult); for (PrismObject<ObjectType> u : orgClosure) { LOGGER.info("USER000 ======> {}", ObjectTypeUtil.toShortString(u.asObjectable())); } AssertJUnit.assertEquals(7, orgClosure.size()); }
.item(AccessCertificationCaseType.F_OBJECT_REF).ref(userAdministrator.getOid()) .desc(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME) .offset(2).maxSize(2) .build(); List<AccessCertificationCaseType> caseList = modelService.searchContainers( AccessCertificationCaseType.class, query, resolveNames, task, result);
@Test public void test008searchRootOrg() throws Exception { OperationResult parentResult = new OperationResult("test008searchRootOrg"); ObjectQuery qSearch = prismContext.queryFor(ObjectType.class) .isRoot() .asc(ObjectType.F_NAME) .build(); List<PrismObject<OrgType>> rootOrgs = repositoryService.searchObjects(OrgType.class, qSearch, null, parentResult); for (PrismObject<OrgType> ro : rootOrgs) { LOGGER.info("ROOT ========= {}", ObjectTypeUtil.toShortString(ro.asObjectable())); } AssertJUnit.assertEquals(5, rootOrgs.size()); }
private void cleanupCampaignsByDate(Duration maxAge, Task task, OperationResult parentResult) { if (maxAge.getSign() > 0) { maxAge = maxAge.negate(); } Date deleteCampaignsFinishedUpTo = new Date(); maxAge.addTo(deleteCampaignsFinishedUpTo); LOGGER.info("Starting cleanup for closed certification campaigns deleting up to {} (max age '{}').", deleteCampaignsFinishedUpTo, maxAge); OperationResult result = parentResult.createSubresult(OPERATION_CLEANUP_CAMPAIGNS_BY_AGE); XMLGregorianCalendar timeXml = createXMLGregorianCalendar(deleteCampaignsFinishedUpTo); int deleted = 0; Set<String> poisonedCampaigns = new HashSet<>(); try { for (;;) { ObjectQuery query = prismContext.queryFor(AccessCertificationCampaignType.class) .item(AccessCertificationCampaignType.F_STATE).eq(AccessCertificationCampaignStateType.CLOSED) .and().item(AccessCertificationCampaignType.F_END_TIMESTAMP).lt(timeXml) .and().not().id(poisonedCampaigns.toArray(new String[0])) // hoping there are not many of these .maxSize(DELETE_BLOCK_SIZE) .build(); int delta = searchAndDeleteCampaigns(query, poisonedCampaigns, result, task); if (delta == 0) { LOGGER.info("Deleted {} campaigns.", deleted); return; } } } finally { result.computeStatusIfUnknown(); } }
@Test public void test0707QueryCertWorkItemAllOrderByCampaignName() throws Exception { Session session = open(); try { ObjectQuery q = prismContext.queryFor(AccessCertificationWorkItemType.class) .asc(PrismConstants.T_PARENT, PrismConstants.T_PARENT, F_NAME) .build(); String real = getInterpretedQuery2(session, AccessCertificationWorkItemType.class, q, false); String expected = "select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" + "from\n" + " RAccessCertificationWorkItem a\n" + " left join a.owner o\n" + " left join o.owner o2\n" + "order by o2.nameCopy.orig asc\n"; assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } }
public List<PrismObject<AccessCertificationCampaignType>> getCertificationCampaigns(Boolean alsoClosedCampaigns) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException { Task task = taskManager.createTaskInstance(); ObjectQuery query = prismContext.queryFor(AccessCertificationCampaignType.class) .asc(F_NAME) .build(); if (!Boolean.TRUE.equals(alsoClosedCampaigns)) { query.addFilter( prismContext.queryFor(AccessCertificationCampaignType.class) .not().item(F_STATE).eq(CLOSED) .buildFilter() ); } Collection<SelectorOptions<GetOperationOptions>> options = schemaHelper.getOperationOptionsBuilder() .root().resolveNames() .item(AccessCertificationCampaignType.F_CASE).retrieve() .build(); return model.searchObjects(AccessCertificationCampaignType.class, query, options, task, task.getResult()); }