Search in sources :

Example 1 with GetOperationOptionsBuilder

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

the class SelectableBeanContainerDataProvider method internalIterator.

@Override
public Iterator<SelectableBean<C>> internalIterator(long offset, long pageSize) {
    LOGGER.trace("begin::iterator() offset {} pageSize {}.", offset, pageSize);
    preprocessSelectedData();
    OperationResult result = new OperationResult(OPERATION_SEARCH_OBJECTS);
    try {
        ObjectPaging paging = createPaging(offset, pageSize);
        Task task = getPageBase().createSimpleTask(OPERATION_SEARCH_OBJECTS);
        ObjectQuery query = getQuery();
        if (query == null) {
            if (emptyListOnNullQuery) {
                return Collections.emptyIterator();
            }
            query = getPrismContext().queryFactory().createQuery();
        }
        query.setPaging(paging);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query {} with {}", getType().getSimpleName(), query.debugDump());
        }
        Collection<SelectorOptions<GetOperationOptions>> options = getOptions();
        if (ResourceType.class.equals(getType()) && (options == null || options.isEmpty())) {
            options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
        }
        GetOperationOptionsBuilder optionsBuilder = getOperationOptionsBuilder(options);
        if (export) {
            // TODO also for other classes
            if (ShadowType.class.equals(getType())) {
                optionsBuilder = optionsBuilder.definitionProcessing(ONLY_IF_EXISTS).item(ShadowType.F_FETCH_RESULT).definitionProcessing(FULL).item(ShadowType.F_AUXILIARY_OBJECT_CLASS).definitionProcessing(FULL);
            }
        }
        optionsBuilder.mergeFrom(getDistinctRelatedOptions());
        getAvailableData().addAll(createDataObjectWrappers(getType(), query, optionsBuilder.build(), task, result));
    } catch (Exception ex) {
        result.recordFatalError(getPageBase().createStringResource("ObjectDataProvider.message.listObjects.fatalError").getString(), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list objects", ex);
        return handleNotSuccessOrHandledErrorInIterator(result);
    } finally {
        result.computeStatusIfUnknown();
    }
    LOGGER.trace("end::iterator() {}", result);
    return getAvailableData().iterator();
}
Also used : ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 2 with GetOperationOptionsBuilder

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

the class SearchProducerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    try {
        GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
        if (options.isRaw()) {
            optionsBuilder = optionsBuilder.raw();
        }
        optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, type.getClassDefinition());
        ResultHandler<?> handler = (object, parentResult) -> {
            try {
                queue.put(object.asObjectable());
            } catch (InterruptedException ex) {
                log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
            }
            return true;
        };
        RepositoryService repository = context.getRepository();
        repository.searchObjectsIterative(type.getClassDefinition(), query, handler, optionsBuilder.build(), true, operation.getResult());
    } catch (SchemaException ex) {
        log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            if (!operation.isFinished()) {
                operation.producerFinish();
            }
        }
    }
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ExportOptions(com.evolveum.midpoint.ninja.opts.ExportOptions) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) BlockingQueue(java.util.concurrent.BlockingQueue) NinjaContext(com.evolveum.midpoint.ninja.impl.NinjaContext) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) List(java.util.List) Log(com.evolveum.midpoint.ninja.util.Log) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Log(com.evolveum.midpoint.ninja.util.Log) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 3 with GetOperationOptionsBuilder

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

the class ExportAuditProducerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    try {
        GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
        optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, AuditEventRecordType.class);
        AuditResultHandler handler = (object, parentResult) -> {
            try {
                queue.put(object);
            } catch (InterruptedException ex) {
                log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
            }
            return true;
        };
        AuditService auditService = context.getAuditService();
        auditService.searchObjectsIterative(query, handler, optionsBuilder.build(), operation.getResult());
    } catch (SchemaException ex) {
        log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            if (!operation.isFinished()) {
                operation.producerFinish();
            }
        }
    }
}
Also used : AuditService(com.evolveum.midpoint.audit.api.AuditService) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) BlockingQueue(java.util.concurrent.BlockingQueue) NinjaContext(com.evolveum.midpoint.ninja.impl.NinjaContext) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) List(java.util.List) Log(com.evolveum.midpoint.ninja.util.Log) BaseWorker(com.evolveum.midpoint.ninja.action.worker.BaseWorker) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Log(com.evolveum.midpoint.ninja.util.Log) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) AuditService(com.evolveum.midpoint.audit.api.AuditService)

Example 4 with GetOperationOptionsBuilder

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

the class SqaleRepoLookupTableTest method test125LookupLanguagesGetByKeyContainingReturningNothing.

@Test
public void test125LookupLanguagesGetByKeyContainingReturningNothing() throws Exception {
    given();
    OperationResult result = createOperationResult();
    when();
    GetOperationOptionsBuilder optionsBuilder = SchemaService.get().getOperationOptionsBuilder().item(LookupTableType.F_ROW).retrieveQuery().item(LookupTableRowType.F_KEY).contains("xyz").end();
    PrismObject<LookupTableType> lookup = repositoryService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, optionsBuilder.build(), result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());
    PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
    assertTrue("Unexpected content in tableContainer", tableContainer == null || tableContainer.size() == 0);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 5 with GetOperationOptionsBuilder

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

the class SqaleRepoLookupTableTest method test133LookupLanguagesGetByValueContainingWithPaging.

@Test
public void test133LookupLanguagesGetByValueContainingWithPaging() throws Exception {
    given();
    OperationResult result = createOperationResult();
    when();
    GetOperationOptionsBuilder optionsBuilder = SchemaService.get().getOperationOptionsBuilder().item(LookupTableType.F_ROW).retrieveQuery().item(LookupTableRowType.F_VALUE).contains("n").offset(0).maxSize(1).desc(// using sorting key other than the one used in search
    LookupTableRowType.F_LABEL).end();
    PrismObject<LookupTableType> lookup = repositoryService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, optionsBuilder.build(), result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    checkLookupResult(lookup, new String[] { "en_US", "en", "English (US)" });
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) LookupTableType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Aggregations

GetOperationOptionsBuilder (com.evolveum.midpoint.schema.GetOperationOptionsBuilder)20 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)9 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)9 Test (org.testng.annotations.Test)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 QName (javax.xml.namespace.QName)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ArrayList (java.util.ArrayList)3 NinjaContext (com.evolveum.midpoint.ninja.impl.NinjaContext)2 NinjaException (com.evolveum.midpoint.ninja.impl.NinjaException)2 Log (com.evolveum.midpoint.ninja.util.Log)2 NinjaUtils (com.evolveum.midpoint.ninja.util.NinjaUtils)2 OperationStatus (com.evolveum.midpoint.ninja.util.OperationStatus)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)2 Task (com.evolveum.midpoint.task.api.Task)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 List (java.util.List)2