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 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(); } }
/** * Returns numbers of assignees with the given relation name. */ private int getNumberOfAssigneesExceptMyself(AbstractRoleType target, String selfOid, QName relation, OperationResult result) throws SchemaException { if (target.getOid() == null) { return 0; } S_AtomicFilterExit q = prismContext.queryFor(FocusType.class) .item(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref( prismContext.itemFactory().createReferenceValue(target.getOid()).relation(relation)); if (selfOid != null) { q = q.and().not().id(selfOid); } ObjectQuery query = q.build(); return repositoryService.countObjects(FocusType.class, query, null, result); }
ObjectQuery query = prismContext.queryFor(AccessCertificationCampaignType.class) .item(AccessCertificationCampaignType.F_STATE).eq(AccessCertificationCampaignStateType.CLOSED) .and().not().id("10-10-10-10-10") // hoping there are not many of these .desc(AccessCertificationCampaignType.F_END_TIMESTAMP) .offset(100)
.item(AccessCertificationCampaignType.F_STATE).eq(AccessCertificationCampaignStateType.CLOSED) .and().item(AccessCertificationCampaignType.F_END_TIMESTAMP).lt(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis())) .and().not().id(new String[0]) .maxSize(10) .build();