Skip to content

Commit

Permalink
reporting: low-level support for non-containerable nearly done
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jan 26, 2023
1 parent 2473301 commit d81862e
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -21,7 +21,7 @@

import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;
Expand Down Expand Up @@ -241,15 +241,13 @@ private static <C extends Containerable> void createColumns(GuiObjectListViewTyp
}

public static String processSpecialColumn(
ItemPath itemPath, PrismContainer<? extends Containerable> object, LocalizationService localization) {
return processSpecialColumn(itemPath, object.getRealValue(), localization);
}

public static String processSpecialColumn(
ItemPath itemPath, Containerable object, LocalizationService localization) {
ItemPath itemPath, Object object, LocalizationService localization) {
if (itemPath == null) {
return null;
}
if (object instanceof PrismValue) {
object = ((PrismValue) object).getRealValue();
}
if (object instanceof TaskType) {
TaskType task = (TaskType) object;
if (itemPath.equivalent(TaskType.F_COMPLETION_TIMESTAMP)) {
Expand Down Expand Up @@ -297,7 +295,7 @@ public static String processSpecialColumn(
return null;
}

public static boolean isSpecialColumn(ItemPath itemPath, Containerable value) {
public static boolean isSpecialColumn(ItemPath itemPath, Object value) {
if (value == null || itemPath == null) {
return false;
}
Expand Down Expand Up @@ -343,7 +341,7 @@ public static Collection<SelectorOptions<GetOperationOptions>> createOption(

private static class ColumnWrapper {

private ItemPath path;
private final ItemPath path;
private String label = null;
private boolean isSortable = false;
private DisplayValueType displayValue = DisplayValueType.STRING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,26 @@

import java.util.concurrent.atomic.AtomicInteger;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.repo.common.activity.run.*;
import com.evolveum.midpoint.repo.common.activity.run.processing.ContainerableProcessingRequest;
import com.evolveum.midpoint.repo.common.activity.run.processing.GenericProcessingRequest;
import com.evolveum.midpoint.repo.common.activity.run.processing.ItemProcessingRequest;
import com.evolveum.midpoint.report.impl.ReportServiceImpl;

import com.evolveum.midpoint.report.impl.ReportUtils;
import com.evolveum.midpoint.report.impl.controller.*;
import com.evolveum.midpoint.schema.ObjectHandler;
import com.evolveum.midpoint.task.api.RunningTask;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.repo.common.activity.run.ActivityRunException;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.RunningTask;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* Activity execution specifics for classical (i.e. not distributed) collection report export.
*/
public final class ClassicCollectionReportExportActivityRun
public final class ClassicCollectionReportExportActivityRun<T>
extends PlainIterativeActivityRun
<Containerable,
<T,
ClassicReportExportWorkDefinition,
ClassicReportExportActivityHandler,
ReportExportWorkStateType> {
Expand All @@ -52,12 +47,12 @@ public final class ClassicCollectionReportExportActivityRun
* Execution object (~ controller) that is used to transfer objects found into report data.
* Initialized on the activity execution start.
*/
private CollectionExportController<Containerable> controller;
private CollectionExportController<T> controller;

/**
* This is "master" search specification, derived from the report.
*/
private ContainerableReportDataSource searchSpecificationHolder;
private PrismableReportDataSource<T> searchSpecificationHolder;

ClassicCollectionReportExportActivityRun(
ActivityRunInstantiationContext<ClassicReportExportWorkDefinition, ClassicReportExportActivityHandler> context) {
Expand All @@ -83,7 +78,7 @@ public void beforeRun(OperationResult result) throws ActivityRunException, Commo

support.stateCheck(result);

searchSpecificationHolder = new ContainerableReportDataSource(support);
searchSpecificationHolder = new PrismableReportDataSource<>(support);
dataWriter = ReportUtils.createDataWriter(
report, FileFormatTypeType.CSV, getActivityHandler().reportService, support.getCompiledCollectionView(result));
controller = new CollectionExportController<>(
Expand Down Expand Up @@ -119,19 +114,19 @@ public void iterateOverItemsInBucket(OperationResult gResult) throws CommonExcep

AtomicInteger sequence = new AtomicInteger(0);

ObjectHandler<Containerable> handler = (record, lResult) -> {
ItemProcessingRequest<Containerable> request =
ContainerableProcessingRequest.create(sequence.getAndIncrement(), record, this);
ObjectHandler<T> handler = (record, lResult) -> {
ItemProcessingRequest<T> request =
new GenericProcessingRequest<>(sequence.getAndIncrement(), record, this);
return coordinator.submit(request, lResult);
};
searchSpecificationHolder.run(handler, gResult);
}

@Override
public boolean processItem(@NotNull ItemProcessingRequest<Containerable> request, @NotNull RunningTask workerTask,
public boolean processItem(@NotNull ItemProcessingRequest<T> request, @NotNull RunningTask workerTask,
OperationResult result)
throws CommonException, ActivityRunException {
Containerable record = request.getItem();
T record = request.getItem();
controller.handleDataRecord(request.getSequentialNumber(), record, workerTask, result);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -50,7 +50,7 @@ public final class ClassicDashboardReportExportActivityRun
/**
* Map of controllers for objects searched based on widgets.
*/
private Map<String, DashboardWidgetHolder> mapOfWidgetsController;
private Map<String, DashboardWidgetHolder<Containerable>> mapOfWidgetsController;

/**
* Controller for widgets.
Expand Down Expand Up @@ -94,8 +94,8 @@ public void beforeRun(OperationResult result) throws ActivityRunException, Commo
for (DashboardWidgetType widget : widgets) {
if (support.isWidgetTableVisible()) {
String widgetIdentifier = widget.getIdentifier();
ContainerableReportDataSource searchSpecificationHolder = new ContainerableReportDataSource(support);
DashboardExportController<Containerable> controller = new DashboardExportController(
PrismableReportDataSource<Containerable> searchSpecificationHolder = new PrismableReportDataSource<>(support);
DashboardExportController<Containerable> controller = new DashboardExportController<>(
searchSpecificationHolder,
dataWriter,
report,
Expand All @@ -106,7 +106,7 @@ public void beforeRun(OperationResult result) throws ActivityRunException, Commo
controller.initialize(task, result);
controller.beforeBucketExecution(1, result);

mapOfWidgetsController.put(widgetIdentifier, new DashboardWidgetHolder(searchSpecificationHolder, controller));
mapOfWidgetsController.put(widgetIdentifier, new DashboardWidgetHolder<>(searchSpecificationHolder, controller));
}
}
}
Expand All @@ -119,7 +119,7 @@ public void beforeRun(OperationResult result) throws ActivityRunException, Commo
@Override
public Integer determineOverallSize(OperationResult result) throws CommonException {
int expectedTotal = support.getDashboard().getWidget().size();
for (DashboardWidgetHolder holder : mapOfWidgetsController.values()) {
for (DashboardWidgetHolder<?> holder : mapOfWidgetsController.values()) {
expectedTotal += support.countRecords(
holder.getSearchSpecificationHolder().getType(),
holder.getSearchSpecificationHolder().getQuery(),
Expand Down Expand Up @@ -166,8 +166,8 @@ public void iterateOverItemsInBucket(OperationResult gResult) throws CommonExcep
}
};

DashboardWidgetHolder holder = mapOfWidgetsController.get(widget.getIdentifier());
ContainerableReportDataSource searchSpecificationHolder = holder.getSearchSpecificationHolder();
DashboardWidgetHolder<Containerable> holder = mapOfWidgetsController.get(widget.getIdentifier());
PrismableReportDataSource<Containerable> searchSpecificationHolder = holder.getSearchSpecificationHolder();
searchSpecificationHolder.run(handler, gResult);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -28,6 +28,7 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
Expand Down Expand Up @@ -69,41 +70,53 @@ void saveReportFile(ReportDataWriter<? extends ExportedReportDataRow, ? extends
/**
* Search container objects for iterative task.
*/
public void searchRecordsIteratively(
Class<? extends Containerable> type,
public <T> void searchRecordsIteratively(
Class<T> type,
ObjectQuery query,
ObjectHandler<Containerable> handler,
ObjectHandler<T> handler,
Collection<SelectorOptions<GetOperationOptions>> options,
OperationResult result) throws CommonException {
if (AuditEventRecordType.class.equals(type)) {
//noinspection unchecked
modelAuditService.searchObjectsIterative(
query,
options,
handler::handle,
((ObjectHandler<Containerable>) handler)::handle,
runningTask,
result);
} else if (ObjectType.class.isAssignableFrom(type)) {
Class<? extends ObjectType> objectType = type.asSubclass(ObjectType.class);
//noinspection unchecked
modelService.searchObjectsIterative(
objectType,
query,
(object, lResult) -> handler.handle(object.asObjectable(), lResult),
(object, lResult) -> ((ObjectHandler<Containerable>) handler).handle(object.asObjectable(), lResult),
options,
runningTask,
result);
} else {
} else if (Containerable.class.isAssignableFrom(type)) {
// Temporary - until iterative search is available
Class<? extends Containerable> containerableType = type.asSubclass(Containerable.class);
SearchResultList<? extends Containerable> values =
modelService.searchContainers(type, query, options, runningTask, result);
values.forEach(value -> handler.handle(value, result));
modelService.searchContainers(containerableType, query, options, runningTask, result);
//noinspection unchecked
values.forEach(value -> ((ObjectHandler<Containerable>) handler).handle(value, result));
} else if (Referencable.class.isAssignableFrom(type)) {
// Temporary - until iterative search is available
SearchResultList<ObjectReferenceType> values =
modelService.searchReferences(query, options, runningTask, result);
//noinspection unchecked
values.forEach(value -> ((ObjectHandler<ObjectReferenceType>) handler).handle(value, result));
} else {
throw new UnsupportedOperationException("Unsupported object type for report: " + type);
}
}

/**
* Count container objects for iterative task.
* Temporary until will be implemented iterative search for audit records and containerable objects.
*/
public int countRecords(Class<? extends Containerable> type,
public int countRecords(Class<?> type,
ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options,
OperationResult result) throws CommonException {
Expand All @@ -113,7 +126,8 @@ public int countRecords(Class<? extends Containerable> type,
Class<? extends ObjectType> objectType = type.asSubclass(ObjectType.class);
return or0(modelService.countObjects(objectType, query, options, runningTask, result));
} else if (Containerable.class.isAssignableFrom(type)) {
return or0(modelService.countContainers(type, query, options, runningTask, result));
//noinspection unchecked
return or0(modelService.countContainers(((Class<? extends Containerable>) type), query, options, runningTask, result));
} else if (Referencable.class.isAssignableFrom(type)) {
return or0(modelService.countReferences(query, options, runningTask, result));
} else {
Expand Down

0 comments on commit d81862e

Please sign in to comment.