Search in sources :

Example 41 with ResultHandler

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);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AssertJUnit(org.testng.AssertJUnit) OP_SEARCH_OBJECTS(com.evolveum.midpoint.repo.api.RepositoryService.OP_SEARCH_OBJECTS) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ArrayList(java.util.ArrayList) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 42 with ResultHandler

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);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AssertJUnit(org.testng.AssertJUnit) OP_SEARCH_OBJECTS(com.evolveum.midpoint.repo.api.RepositoryService.OP_SEARCH_OBJECTS) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ArrayList(java.util.ArrayList) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 43 with ResultHandler

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()));
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AssertJUnit(org.testng.AssertJUnit) OP_SEARCH_OBJECTS(com.evolveum.midpoint.repo.api.RepositoryService.OP_SEARCH_OBJECTS) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ArrayList(java.util.ArrayList) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 44 with ResultHandler

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);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AssertJUnit(org.testng.AssertJUnit) OP_SEARCH_OBJECTS(com.evolveum.midpoint.repo.api.RepositoryService.OP_SEARCH_OBJECTS) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ArrayList(java.util.ArrayList) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 45 with ResultHandler

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());
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

ResultHandler (com.evolveum.midpoint.schema.ResultHandler)54 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)53 PrismObject (com.evolveum.midpoint.prism.PrismObject)39 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)33 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)29 Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)24 SystemException (com.evolveum.midpoint.util.exception.SystemException)23 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)22 Task (com.evolveum.midpoint.task.api.Task)19 QName (javax.xml.namespace.QName)19 DirtiesContext (org.springframework.test.annotation.DirtiesContext)19 ContextConfiguration (org.springframework.test.context.ContextConfiguration)19 AssertJUnit (org.testng.AssertJUnit)17 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)16 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)16 List (java.util.List)16 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)15 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)14 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)13