Search in sources :

Example 46 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 47 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)

Example 48 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class SearchTest method test930IterateAndModify.

/**
 * See MID-5474 (just a quick attempt to replicate)
 */
@Test
public void test930IterateAndModify() throws Exception {
    OperationResult result = new OperationResult("iterateAndModify");
    AtomicInteger count = new AtomicInteger(0);
    ResultHandler<UserType> handler = (object, parentResult) -> {
        try {
            System.out.println("Modifying " + object);
            List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("desc1").asItemDeltas();
            repositoryService.modifyObject(UserType.class, object.getOid(), itemDeltas, parentResult);
            System.out.println("OK");
            count.incrementAndGet();
            return true;
        } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) {
            throw new SystemException(e.getMessage(), e);
        }
    };
    ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_NAME).eqPoly("atestuserX00002").matchingOrig().build();
    repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertEquals(1, count.get());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AssertJUnit(org.testng.AssertJUnit) java.util(java.util) RepoModifyOptions.createForceReindex(com.evolveum.midpoint.repo.api.RepoModifyOptions.createForceReindex) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) F_NAME(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME) Test(org.testng.annotations.Test) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Collections.emptySet(java.util.Collections.emptySet) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SystemException(com.evolveum.midpoint.util.exception.SystemException) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) SystemException(com.evolveum.midpoint.util.exception.SystemException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 49 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class SearchIterativeTest method test101SequentialIterationWithSmallResult.

// MID-5339
@Test
public void test101SequentialIterationWithSmallResult() throws Exception {
    OperationResult result = new OperationResult("test101SequentialIterationWithSmallResult");
    final List<PrismObject<UserType>> objects = new ArrayList<>();
    ResultHandler<UserType> handler = (object, parentResult) -> {
        objects.add(object);
        return true;
    };
    SearchOpAsserter asserter = new SearchOpAsserter();
    ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_COST_CENTER).eq(String.valueOf(BASE)).build();
    repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
    result.recomputeStatus();
    asserter.assertIncrement(1);
    assertTrue(result.isSuccess());
    assertObjects(objects, 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 50 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class SearchIterativeTest method test105SimpleNonSequentialIteration.

@Test
public void test105SimpleNonSequentialIteration() throws Exception {
    OperationResult result = new OperationResult("test105SimpleNonSequentialIteration");
    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);
    repositoryService.searchObjectsIterative(UserType.class, null, handler, null, false, result);
    result.recomputeStatus();
    countOpAsserter.assertIncrement(1);
    searchOpAsserter.assertIncrement(COUNT / BATCH);
    assertTrue(result.isSuccess());
    assertObjects(objects, 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) 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) Test(org.testng.annotations.Test)

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