public static void displayQuery(ObjectQuery query) { LOGGER.trace("object query:\n{}\n", query); System.out.println("object query:\n" + query + "\n"); if (query != null) { LOGGER.trace("object query debug dump:\n{}\n", query.debugDump()); System.out.println("object query debug dump:\n" + query.debugDump() + "\n"); } }
@Override protected ObjectQuery createQuery(ObjectIntegrityCheckResultHandler handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException { ObjectQuery query = createQueryFromTask(handler, runResult, task, opResult); LOGGER.info("Using query:\n{}", query.debugDump()); return query; }
private PrismObject<UserType> findByUsername(String username, OperationResult result) throws SchemaException, ObjectNotFoundException { PolyString usernamePoly = new PolyString(username); ObjectQuery query = ObjectQueryUtil.createNormNameQuery(usernamePoly, prismContext); LOGGER.trace("Looking for user, query:\n" + query.debugDump()); List<PrismObject<UserType>> list = repositoryService.searchObjects(UserType.class, query, null, result); LOGGER.trace("Users found: {}.", list.size()); if (list.size() != 1) { return null; } return list.get(0); }
/** * Checks i there is only a single shadow in repo for this account. */ private static void checkShadowUniqueness(ShadowType resourceShadow, ObjectClassComplexTypeDefinition objectClassDef, RepositoryService repositoryService, MatchingRule<String> uidMatchingRule, PrismContext prismContext, OperationResult parentResult) { try { ObjectQuery query = createShadowQuery(resourceShadow, objectClassDef, uidMatchingRule, prismContext); List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult); LOGGER.trace("Shadow check with filter\n{}\n found {} objects", query.debugDump(), results.size()); if (results.size() == 0) { AssertJUnit.fail("No shadow found with query:\n"+query.debugDump()); } if (results.size() == 1) { return; } if (results.size() > 1) { for (PrismObject<ShadowType> result: results) { LOGGER.trace("Search result:\n{}", result.debugDump()); } LOGGER.error("More than one shadows found for " + resourceShadow); // TODO: Better error handling later throw new IllegalStateException("More than one shadows found for " + resourceShadow); } } catch (SchemaException e) { throw new SystemException(e); } }
public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) { Validate.notNull(type, "Object type must not be null."); Validate.notNull(result, "Operation result must not be null."); LOGGER.debug("Counting objects of type '{}', query (on trace level).", type.getSimpleName()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Full query\n{}", query == null ? "undefined" : query.debugDump()); } OperationResult subResult = result.createMinorSubresult(COUNT_OBJECTS); subResult.addParam("type", type.getName()); subResult.addParam("query", query); return executeQueryAttemptsNoSchemaException(query, "countObjects", "counting", subResult, () -> 0, (q) -> objectRetriever.countObjectsAttempt(type, q, options, subResult)); }
@Override public <T extends Containerable> int countContainers(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) { Validate.notNull(type, "Object type must not be null."); Validate.notNull(parentResult, "Operation result must not be null."); LOGGER.debug("Counting containers of type '{}', query (on trace level).", type.getSimpleName()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Full query\n{}", query == null ? "undefined" : query.debugDump()); } OperationResult result = parentResult.createSubresult(COUNT_CONTAINERS); result.addParam("type", type.getName()); result.addParam("query", query); return executeQueryAttemptsNoSchemaException(query, "countContainers", "counting", result, () -> 0, (q) -> objectRetriever.countContainersAttempt(type, q, options, result)); }
public static void checkAllShadows(ResourceType resourceType, RepositoryService repositoryService, ObjectChecker<ShadowType> checker, PrismContext prismContext) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException { OperationResult result = new OperationResult(IntegrationTestTools.class.getName() + ".checkAllShadows"); ObjectQuery query = createAllShadowsQuery(resourceType, prismContext); List<PrismObject<ShadowType>> allShadows = repositoryService.searchObjects(ShadowType.class, query, GetOperationOptions.createRawCollection(), result); LOGGER.trace("Checking {} shadows, query:\n{}", allShadows.size(), query.debugDump()); for (PrismObject<ShadowType> shadow: allShadows) { checkShadow(shadow.asObjectable(), resourceType, repositoryService, checker, prismContext, result); } }
public Collection<PrismObject<ShadowType>> lookForPreviousDeadShadows(ProvisioningContext ctx, PrismObject<ShadowType> inputShadow, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { List<PrismObject<ShadowType>> deadShadows = new ArrayList<>(); ObjectQuery query = createSearchShadowQueryByPrimaryIdentifier(ctx, inputShadow, prismContext, parentResult); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Searching for dead shadows using filter:\n{}", query==null?null:query.debugDump(1)); } if (query == null) { // No primary identifier. So there are obviously no relevant previous dead shadows. return deadShadows; } List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult); MiscSchemaUtil.reduceSearchResult(results); LOGGER.trace("looking for previous dead shadows, found {} objects", results.size()); for (PrismObject<ShadowType> foundShadow : results) { if (Boolean.TRUE.equals(foundShadow.asObjectable().isDead())) { deadShadows.add(foundShadow); } } return deadShadows; }
private PrismObject<UserType> findByUsername(String username, OperationResult result) throws SchemaException, ObjectNotFoundException { PolyString usernamePoly = new PolyString(username); ObjectQuery query = ObjectQueryUtil.createNormNameQuery(usernamePoly, prismContext); LOGGER.trace("Looking for user, query:\n" + query.debugDump()); List<PrismObject<UserType>> list = repositoryService.searchObjects(UserType.class, query, null, result); LOGGER.trace("Users found: {}.", (list != null ? list.size() : 0)); if (list == null || list.size() != 1) { return null; } return list.get(0); }
if (LOGGER.isTraceEnabled()) { LOGGER.trace("Searching for shadow using filter (repo):\n{}", query.debugDump());
protected ObjectQuery createQueryFromTaskIfExists(H handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException { Class<? extends ObjectType> objectType = getType(task); LOGGER.trace("Object type = {}", objectType); QueryType queryFromTask = getObjectQueryTypeFromTask(task); if (queryFromTask != null) { ObjectQuery query = prismContext.getQueryConverter().createObjectQuery(objectType, queryFromTask); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Using object query from the task:\n{}", query.debugDump(1)); } return query; } else { return null; } }
protected void logQuery(ObjectQuery query) { if (!LOGGER.isTraceEnabled()) { return; } if (query != null) { if (query.getPaging() == null) { LOGGER.trace("Searching objects with null paging. Processed query:\n{}", query.debugDump(1)); } else { LOGGER.trace("Searching objects from {} to {} ordered {} by {}. Processed query:\n{}", query.getPaging().getOffset(), query.getPaging().getMaxSize(), query.getPaging().getDirection(), query.getPaging().getOrderBy(), query.debugDump(1)); } } else { LOGGER.trace("Searching objects with null paging and null (processed) query."); } }
private <T> void logSearchInputParameters(Class<T> type, ObjectQuery query, boolean iterative, Boolean strictlySequential) { ObjectPaging paging = query != null ? query.getPaging() : null; LOGGER.debug("Searching objects of type '{}', query (on trace level), offset {}, count {}, iterative {}, strictlySequential {}.", type.getSimpleName(), (paging != null ? paging.getOffset() : "undefined"), (paging != null ? paging.getMaxSize() : "undefined"), iterative, strictlySequential); if (!LOGGER.isTraceEnabled()) { return; } LOGGER.trace("Full query\n{}", query == null ? "undefined" : query.debugDump()); if (iterative) { LOGGER.trace("Iterative search by paging defined by the configuration: {}, batch size {}", getConfiguration().isIterativeSearchByPaging(), getConfiguration().getIterativeSearchByPagingBatchSize()); } }
@Test public void testUserQuery() throws Exception { displayTestTitle("testUserQuery"); File[] userQueriesToTest = new File[] { new File(TEST_DIR, "filter-user-by-fullName.xml"), new File(TEST_DIR, "filter-user-by-name.xml"), new File(TEST_DIR, "filter-user-substring-fullName.xml"), new File(TEST_DIR, "filter-user-substring-employeeType.xml"), new File(TEST_DIR, "filter-user-substring-expression.xml"), new File(TEST_DIR, "filter-user-substring-anchor-start-end-expression.xml") }; // prismContext.silentMarshalObject(queryTypeNew, LOGGER); for (File file : userQueriesToTest) { SearchFilterType filterType = PrismTestUtil.parseAtomicValue(file, SearchFilterType.COMPLEX_TYPE); LOGGER.info("===[ query type parsed ]==="); ObjectQuery query; try { query = getQueryConverter().createObjectQuery(UserType.class, filterType); LOGGER.info("query converted: "); LOGGER.info("QUERY DUMP: {}", query.debugDump()); LOGGER.info("QUERY Pretty print: {}", query.toString()); System.out.println("QUERY Pretty print: " + query.toString()); QueryType convertedQueryType = getQueryConverter().createQueryType(query); LOGGER.info(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext()))); } catch (Exception ex) { LOGGER.error("Error while converting query: {}", ex.getMessage(), ex); throw ex; } } }
if (LOGGER.isTraceEnabled()) { LOGGER.trace("Searching for shadow using filter on secondary identifier:\n{}", query.debugDump());
protected void checkUniqueness(PrismObject<? extends ShadowType> object) throws SchemaException { OperationResult result = new OperationResult(TestDummyNegative.class.getName() + ".checkConsistency"); PrismPropertyDefinition itemDef = ShadowUtil.getAttributesContainer(object).getDefinition().findAttributeDefinition(SchemaConstants.ICFS_NAME); LOGGER.info("item definition: {}", itemDef.debugDump()); //TODO: matching rule ObjectQuery query = prismContext.queryFor(ShadowType.class) .itemWithDef(itemDef, ShadowType.F_ATTRIBUTES, itemDef.getName()).eq(getWillRepoIcfName()) .build(); System.out.println("Looking for shadows of \"" + getWillRepoIcfName() + "\" with filter " + query.debugDump()); display("Looking for shadows of \"" + getWillRepoIcfName() + "\" with filter " + query.debugDump()); List<PrismObject<ShadowType>> objects = repositoryService.searchObjects(ShadowType.class, query, null, result); assertEquals("Wrong number of repo shadows for ICF NAME \"" + getWillRepoIcfName() + "\"", 1, objects.size()); }
@Test public void testSearchConnectorAnd() throws SchemaException{ TestUtil.displayTestTitle("testSearchConnectorAnd"); OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName() + ".testSearchConnector"); ObjectQuery query = prismContext.queryFor(ConnectorType.class) .item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(SchemaConstants.ICF_FRAMEWORK_URI) .and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(IntegrationTestTools.LDAP_CONNECTOR_TYPE) .build(); System.out.println("Query:\n"+query.debugDump()); List<PrismObject<ConnectorType>> connectors = repositoryService.searchObjects(ConnectorType.class, query, null, result); assertEquals("Unexpected number of results", 1, connectors.size()); PrismObject<ConnectorType> ldapConnector = connectors.get(0); assertEquals("Type does not match", IntegrationTestTools.LDAP_CONNECTOR_TYPE, ldapConnector.asObjectable().getConnectorType()); assertEquals("Framework does not match", SchemaConstants.ICF_FRAMEWORK_URI, ldapConnector.asObjectable().getFramework()); } }
@Test public void test360Ref() throws Exception { final String TEST_NAME = "test360Ref"; displayTestTitle(TEST_NAME); // we test only parsing here, as there are more serialized forms used here ObjectQuery q1object = getPrismContext().queryFor(ShadowType.class) .item(ShadowType.F_RESOURCE_REF).ref("oid1") .or().item(ShadowType.F_RESOURCE_REF).ref("oid2", ResourceType.COMPLEX_TYPE) .or().item(ShadowType.F_RESOURCE_REF).ref("oid3") .or().item(ShadowType.F_RESOURCE_REF).ref("oid4", ResourceType.COMPLEX_TYPE) .build(); q1object.getFilter().checkConsistence(true); String q2xml = FileUtils.readFileToString(new File(TEST_DIR + "/" + TEST_NAME + ".xml")); displayQueryXml(q2xml); QueryType q2jaxb = toQueryType(q2xml); displayQueryType(q2jaxb); ObjectQuery q2object = toObjectQuery(ShadowType.class, q2jaxb); System.out.println("q1object:\n"+q1object.debugDump(1)); System.out.println("q2object:\n"+q2object.debugDump(1)); assertEquals("Reparsed query is not as original one (via toString)", q1object.toString(), q2object.toString()); // primitive way of comparing parsed queries if (!q1object.equivalent(q2object)) { AssertJUnit.fail("Reparsed query is not as original one (via equivalent):\nq1="+q1object+"\nq2="+q2object); } }