public static S_AtomicFilterExit createResourceAndObjectClassFilterPrefix(String resourceOid, QName objectClass, PrismContext prismContext) throws SchemaException { Validate.notNull(resourceOid, "Resource where to search must not be null."); Validate.notNull(objectClass, "Object class 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_OBJECT_CLASS).eq(objectClass); }
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()); }
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; }
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(); } }
public static ObjectQuery createOrigNameQuery(PolyString name, PrismContext prismContext) throws SchemaException { return prismContext.queryFor(ObjectType.class) .item(ObjectType.F_NAME).eq(name).matchingOrig() .build(); }
public static ObjectQuery createAllShadowsQuery(ResourceType resourceType, PrismContext prismContext) throws SchemaException { return prismContext.queryFor(ShadowType.class) .item(ShadowType.F_RESOURCE_REF).ref(resourceType.getOid()) .build(); }
.item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).le(XmlTypeConverter.createXMLGregorianCalendar(startTimestamp)) .or().item(ShadowType.F_FULL_SYNCHRONIZATION_TIMESTAMP).isNull() .endBlock() .and().item(ShadowType.F_RESOURCE_REF).ref(ObjectTypeUtil.createObjectRef(resource, prismContext).asReferenceValue()) .and().item(ShadowType.F_OBJECT_CLASS).eq(objectclassDef.getTypeName()) .build();
try { ObjectQuery query = prismContext.queryFor(GenericObjectType.class) .item(F_NAME).eqPoly("generic object", "generic object").matchingNorm() .and().item(F_EXTENSION, new QName("intType")).ge(100) .and().item(F_EXTENSION, new QName("intType")).lt(200) .and().item(F_EXTENSION, new QName("longType")).eq(335) .build();
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); }
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(); } }
.item(WorkItemType.F_CREATE_TIMESTAMP).lt(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis())) .and().item(WorkItemType.F_CREATE_TIMESTAMP).gt(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis()-300000)) .build(); SearchResultList<WorkItemType> items2 = modelService.searchContainers(WorkItemType.class, query2, null, task, result); .item(WorkItemType.F_CREATE_TIMESTAMP).gt(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis())) .build(); SearchResultList<WorkItemType> items3 = modelService.searchContainers(WorkItemType.class, query3, null, task, result); .item(WorkItemType.F_CREATE_TIMESTAMP).eq(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis())) .build(); SearchResultList<WorkItemType> items4 = modelService.searchContainers(WorkItemType.class, query4, null, task, result); .item(WorkItemType.F_CREATE_TIMESTAMP).eq(created) .build(); SearchResultList<WorkItemType> items5 = modelService.searchContainers(WorkItemType.class, query5, null, task, result);
@NotNull @Override public List<ObjectFilter> createSpecificFilters(@NotNull WorkBucketType bucket, AbstractWorkSegmentationType configuration, Class<? extends ObjectType> type, Function<ItemPath, ItemDefinition<?>> itemDefinitionProvider) { AbstractWorkBucketContentType content = bucket.getContent(); if (hasNoBoundaries(content)) { return new ArrayList<>(); } if (configuration == null) { throw new IllegalStateException("No buckets configuration but having defined bucket content: " + content); } ItemPath discriminator = getDiscriminator(configuration, content); ItemDefinition<?> discriminatorDefinition = itemDefinitionProvider != null ? itemDefinitionProvider.apply(discriminator) : null; QName matchingRuleName = configuration.getMatchingRule() != null ? QNameUtil.uriToQName(configuration.getMatchingRule(), PrismConstants.NS_MATCHING_RULE) : null; List<ObjectFilter> filters = new ArrayList<>(); if (getFrom(content) != null) { filters.add(prismContext.queryFor(type) .item(discriminator, discriminatorDefinition).ge(getFrom(content)).matching(matchingRuleName) .buildFilter()); } if (getTo(content) != null) { filters.add(prismContext.queryFor(type) .item(discriminator, discriminatorDefinition).lt(getTo(content)).matching(matchingRuleName) .buildFilter()); } return filters; }
public static <T extends ObjectType> ObjectQuery createNameQuery(Class<T> clazz, PrismContext prismContext, String name) throws SchemaException { return prismContext.queryFor(clazz) .item(ObjectType.F_NAME).eqPoly(name) .build(); }
@Test public void test310AllComparisons() throws Exception { final String TEST_NAME = "test310AllComparisons"; displayTestTitle(TEST_NAME); ObjectQuery q = getPrismContext().queryFor(UserType.class) .item(UserType.F_COST_CENTER).gt("100000") .and().item(UserType.F_COST_CENTER).lt("999999") .or() .item(UserType.F_COST_CENTER).ge("X100") .and().item(UserType.F_COST_CENTER).le("X999") .build(); checkQueryRoundtripFile(UserType.class, q, TEST_NAME); }
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()); }
@Override protected ObjectQuery createQuery(AbstractScannerResultHandler<ObjectType> handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException { initProcessedTriggers(task); return prismContext.queryFor(ObjectType.class) .item(F_TRIGGER, F_TIMESTAMP).le(handler.getThisScanTimestamp()) .build(); }
@Test public void test350Substring() throws Exception { final String TEST_NAME = "test350Substring"; displayTestTitle(TEST_NAME); ObjectQuery q = getPrismContext().queryFor(UserType.class) .item(UserType.F_EMPLOYEE_TYPE).contains("A") .or().item(UserType.F_EMPLOYEE_TYPE).startsWith("B") .or().item(UserType.F_EMPLOYEE_TYPE).endsWith("C") .or().item(UserType.F_NAME).startsWithPoly("john", "john").matchingOrig() .build(); checkQueryRoundtripFile(UserType.class, q, TEST_NAME); }