use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test102SimpleSequentialIterationWithMaxSize.
@Test
public void test102SimpleSequentialIterationWithMaxSize() throws Exception {
OperationResult result = new OperationResult("test102SimpleSequentialIterationWithMaxSize");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
return true;
};
SearchOpAsserter asserter = new SearchOpAsserter();
ObjectQuery query = prismContext.queryFactory().createQuery(prismContext.queryFactory().createPaging(null, 70));
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
result.recomputeStatus();
// assuming 50 + 20
asserter.assertIncrement(2);
assertTrue(result.isSuccess());
assertObjects(objects, 70);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test130AddOneForOne.
@Test
public void test130AddOneForOne() throws Exception {
OperationResult result = new OperationResult("test130AddOneForOne");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
System.out.print("Got object " + object.getOid());
logger.info("Got object {} ({})", object.getOid(), object.asObjectable().getName().getOrig());
try {
int number = Integer.parseInt(object.asObjectable().getCostCenter());
if (number >= 0) {
UserType user = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).instantiate().asObjectable();
user.setOid("user-" + (2 * BASE + COUNT - number) + "-FF");
user.setName(new PolyStringType(new PolyString("user-new-" + number)));
user.setCostCenter(String.valueOf(-number));
repositoryService.addObject(user.asPrismObject(), null, parentResult);
System.out.print(" ... creating object " + user.getOid());
}
} catch (ObjectAlreadyExistsException | SchemaException e) {
throw new SystemException(e);
}
System.out.println();
return true;
};
repositoryService.searchObjectsIterative(UserType.class, null, handler, null, true, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
boolean[] map = assertObjects(objects, null);
for (int i = 0; i < COUNT; i++) {
if (i % 2 == 0) {
assertFalse("Object " + (BASE + i) + " does exist but it should not", map[i]);
} else {
assertTrue("Object " + (BASE + i) + " does not exist but it should", map[i]);
}
}
System.out.println("Object processed: " + objects.size());
int count = repositoryService.countObjects(UserType.class, null, null, result);
assertEquals("Wrong # of objects after operation", COUNT, count);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test120DeleteHalf.
@Test
public void test120DeleteHalf() throws Exception {
OperationResult result = new OperationResult("test120DeleteHalf");
createObjects();
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
try {
int number = Integer.parseInt(object.asObjectable().getCostCenter());
if (number % 2 == 0) {
repositoryService.deleteObject(UserType.class, object.getOid(), parentResult);
}
} catch (ObjectNotFoundException e) {
throw new SystemException(e);
}
return true;
};
repositoryService.searchObjectsIterative(UserType.class, null, handler, null, true, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertObjects(objects, COUNT);
int count = repositoryService.countObjects(UserType.class, null, null, result);
assertEquals("Wrong # of objects after operation", COUNT / 2, count);
ObjectQuery query = prismContext.queryFor(UserType.class).asc(UserType.F_NAME).build();
List<PrismObject<UserType>> objectsAfter = repositoryService.searchObjects(UserType.class, query, null, result);
objectsAfter.forEach(o -> System.out.println("Exists: " + o.asObjectable().getName()));
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test103SimpleSequentialIterationWithCustomPagingLarge.
@Test
public void test103SimpleSequentialIterationWithCustomPagingLarge() throws Exception {
OperationResult result = new OperationResult("test103SimpleSequentialIterationWithCustomPagingLarge");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
return true;
};
SearchOpAsserter searchOpAsserter = new SearchOpAsserter();
OpAsserter countOpAsserter = new OpAsserter(RepositoryService.OP_COUNT_OBJECTS);
ObjectQuery query = prismContext.queryFactory().createQuery(prismContext.queryFactory().createPaging(1, null));
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
result.recomputeStatus();
// repo had to switch to simple paging
countOpAsserter.assertIncrement(1);
searchOpAsserter.assertIncrement(COUNT / BATCH);
assertTrue(result.isSuccess());
assertObjects(objects, COUNT - 1);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchTest method iterateGeneral.
private void iterateGeneral(int offset, int size, int batch, final String... names) throws Exception {
OperationResult result = new OperationResult("search general");
final List<PrismObject<?>> objects = new ArrayList<>();
ResultHandler<UserType> handler = new ResultHandler<>() {
private int index = 0;
@Override
public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
objects.add(object);
assertEquals("Incorrect object name was read", names[index++], object.asObjectable().getName().getOrig());
return true;
}
};
SqlRepositoryConfiguration config = ((SqlRepositoryServiceImpl) repositoryService).sqlConfiguration();
int oldBatchSize = config.getIterativeSearchByPagingBatchSize();
config.setIterativeSearchByPagingBatchSize(batch);
logger.trace(">>>>>> iterateGeneral: offset = " + offset + ", size = " + size + ", batch = " + batch + " <<<<<<");
ObjectQuery query = prismContext.queryFactory().createQuery();
query.setPaging(prismContext.queryFactory().createPaging(offset, size, ObjectType.F_NAME, OrderDirection.ASCENDING));
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, false, result);
result.recomputeStatus();
config.setIterativeSearchByPagingBatchSize(oldBatchSize);
assertTrue(result.isSuccess());
assertEquals(size, objects.size());
}
Aggregations