Search in sources :

Example 51 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 52 with ResultHandler

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

the class SearchTest method test110IterateSet.

@Test
public void test110IterateSet() throws Exception {
    OperationResult result = new OperationResult("search set");
    final List<PrismObject<?>> objects = new ArrayList<>();
    ResultHandler<UserType> handler = (object, parentResult) -> {
        objects.add(object);
        return true;
    };
    repositoryService.searchObjectsIterative(UserType.class, null, handler, null, false, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertEquals(4, objects.size());
}
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) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 53 with ResultHandler

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

the class DeleteRepositoryAction method deleteByFilter.

private void deleteByFilter(ObjectTypes type, ObjectQuery query, OperationStatus operation, OperationResult result) throws SchemaException {
    ResultHandler<?> handler = (prismObject, operationResult) -> {
        try {
            State state = options.isAsk() ? askForState(prismObject) : State.DELETE;
            switch(state) {
                case SKIP:
                    operation.incrementSkipped();
                    return true;
                case STOP:
                    return false;
                case DELETE:
                default:
            }
            RepositoryService repository = context.getRepository();
            repository.deleteObject(prismObject.getCompileTimeClass(), prismObject.getOid(), operationResult);
            operation.incrementTotal();
        } catch (ObjectNotFoundException ex) {
        // object was already gone
        } catch (IOException ex) {
            context.getLog().error("Couldn't delete object {}, reason: {}", ex, prismObject, ex.getMessage());
            operation.incrementError();
        }
        return true;
    };
    Collection<SelectorOptions<GetOperationOptions>> opts = new ArrayList<>();
    if (options.isRaw()) {
        opts.add(new SelectorOptions<>(GetOperationOptions.createRaw()));
    }
    RepositoryService repository = context.getRepository();
    repository.searchObjectsIterative(type.getClassDefinition(), query, handler, opts, true, result);
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DeleteOptions(com.evolveum.midpoint.ninja.opts.DeleteOptions) InputStreamReader(java.io.InputStreamReader) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) Modifier(java.lang.reflect.Modifier) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) BufferedReader(java.io.BufferedReader) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 54 with ResultHandler

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

the class AbstractLdapHierarchyTest method reconcileAllOrgs.

protected void reconcileAllOrgs() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final Task task = getTestTask();
    OperationResult result = task.getResult();
    ResultHandler<OrgType> handler = (object, parentResult) -> {
        try {
            display("reconciling " + object);
            reconcileOrg(object.getOid(), task, parentResult);
        } catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
            throw new SystemException(e.getMessage(), e);
        }
        return true;
    };
    display("Reconciling all orgs");
    modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) Entry(org.opends.server.types.Entry) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) TestUtil(com.evolveum.midpoint.test.util.TestUtil) DirectoryException(org.opends.server.types.DirectoryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AfterClass(org.testng.annotations.AfterClass) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) File(java.io.File) OpenDJController(com.evolveum.midpoint.test.ldap.OpenDJController) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) AbstractLdapTest(com.evolveum.midpoint.testing.story.ldap.AbstractLdapTest) QName(javax.xml.namespace.QName) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

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