Skip to content

Commit

Permalink
adding support for import report
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Aug 4, 2021
1 parent a4324de commit a5fd91f
Show file tree
Hide file tree
Showing 15 changed files with 1,060 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.report.impl.activity;

import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.repo.common.activity.Activity;
import com.evolveum.midpoint.repo.common.activity.ActivityExecutionException;
import com.evolveum.midpoint.repo.common.activity.execution.ExecutionInstantiationContext;
import com.evolveum.midpoint.repo.common.activity.state.ActivityState;
import com.evolveum.midpoint.repo.common.task.CommonTaskBeans;
import com.evolveum.midpoint.report.impl.ReportServiceImpl;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.RunningTask;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportExportWorkStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;

import org.jetbrains.annotations.NotNull;

import static com.evolveum.midpoint.schema.result.OperationResultStatus.FATAL_ERROR;
import static com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.ReportExportWorkStateType.F_REPORT_DATA_REF;

import static java.util.Objects.requireNonNull;

/**
* Contains common functionality for all activity executions (export and import).
* This is an experiment - using object composition instead of inheritance.
*
* TODO better name
*/
abstract class AbstractReportActivitySupport {

@NotNull protected final RunningTask runningTask;
@NotNull protected final CommonTaskBeans beans;

/**
* Resolved report object.
*/
private ReportType report;

/**
* Compiled final collection from more collections and archetypes related to object type.
*/
private CompiledObjectCollectionView compiledView;

AbstractReportActivitySupport(
ExecutionInstantiationContext context) {
runningTask = context.getTaskExecution().getRunningTask();
beans = context.getTaskExecution().getBeans();
}

void initializeExecution(OperationResult result) throws CommonException, ActivityExecutionException {
setupReportObject(result);
}

private void setupReportObject(OperationResult result) throws CommonException {
AbstractReportWorkDefinition workDefinition = getWorkDefinition();
report = getObjectResolver().resolve(workDefinition.getReportRef(), ReportType.class,
null, "resolving report", runningTask, result);
}

protected abstract ObjectResolver getObjectResolver();

protected abstract AbstractReportWorkDefinition getWorkDefinition();

private void setupCompiledView(OperationResult result) throws CommonException {
compiledView = getReportService().createCompiledView(report.getObjectCollection(), true, runningTask, result);
}

protected abstract ReportServiceImpl getReportService();

/**
* Should be called only after initialization.
*/
public @NotNull ReportType getReport() {
return requireNonNull(report);
}

/**
* Should be called only after initialization.
*/
@NotNull CompiledObjectCollectionView getCompiledCollectionView(OperationResult result) throws CommonException {
if (compiledView == null) {
setupCompiledView(result);
}
return compiledView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.evolveum.midpoint.report.impl.activity;

import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.repo.common.activity.Activity;
import com.evolveum.midpoint.repo.common.activity.ActivityExecutionException;
import com.evolveum.midpoint.repo.common.activity.execution.ExecutionInstantiationContext;
Expand Down Expand Up @@ -37,42 +38,23 @@
*
* TODO better name
*/
class ActivityExecutionSupport {
class ActivityExecutionSupport extends AbstractReportActivitySupport {

@NotNull private final RunningTask runningTask;
@NotNull private final Activity<DistributedReportExportWorkDefinition, DistributedReportExportActivityHandler> activity;
@NotNull private final CommonTaskBeans beans;

/**
* Resolved report object.
*/
private ReportType report;

/**
* Global report data - point of aggregation.
*/
private ObjectReferenceType globalReportDataRef;

/**
* Compiled final collection from more collections and archetypes related to object type.
*/
private CompiledObjectCollectionView compiledView;

/**
* Service for reports.
*/
private ReportServiceImpl reportService;

ActivityExecutionSupport(
ExecutionInstantiationContext<DistributedReportExportWorkDefinition, DistributedReportExportActivityHandler> context, ReportServiceImpl reportService) {
runningTask = context.getTaskExecution().getRunningTask();
ExecutionInstantiationContext<DistributedReportExportWorkDefinition, DistributedReportExportActivityHandler> context) {
super(context);
activity = context.getActivity();
beans = context.getTaskExecution().getBeans();
this.reportService = reportService;
}

void initializeExecution(OperationResult result) throws CommonException, ActivityExecutionException {
setupReportObject(result);
super.initializeExecution(result);
globalReportDataRef = fetchGlobalReportDataRef(result);
}

Expand All @@ -93,32 +75,25 @@ void initializeExecution(OperationResult result) throws CommonException, Activit
return globalReportDataRef;
}

private void setupReportObject(OperationResult result) throws CommonException {
DistributedReportExportWorkDefinition workDefinition = activity.getWorkDefinition();
report = activity.getHandler().objectResolver.resolve(workDefinition.getReportRef(), ReportType.class,
null, "resolving report", runningTask, result);
@Override
protected ObjectResolver getObjectResolver() {
return activity.getHandler().objectResolver;
}

/**
* Should be called only after initialization.
*/
@NotNull ObjectReferenceType getGlobalReportDataRef() {
return requireNonNull(globalReportDataRef);
@Override
protected AbstractReportWorkDefinition getWorkDefinition() {
return activity.getWorkDefinition();
}

@Override
protected ReportServiceImpl getReportService() {
return activity.getHandler().reportService;
}

/**
* Should be called only after initialization.
*/
public @NotNull ReportType getReport() {
return requireNonNull(report);
}

@NotNull CompiledObjectCollectionView getCompiledCollectionView(OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
if (compiledView == null) {
compiledView = reportService.createCompiledView(report.getObjectCollection(), true, runningTask, result);
}
return compiledView;
@NotNull ObjectReferenceType getGlobalReportDataRef() {
return requireNonNull(globalReportDataRef);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.report.impl.activity;

import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.repo.common.ObjectResolver;
import com.evolveum.midpoint.repo.common.activity.Activity;
import com.evolveum.midpoint.repo.common.activity.ActivityExecutionException;
import com.evolveum.midpoint.repo.common.activity.execution.ExecutionInstantiationContext;
import com.evolveum.midpoint.repo.common.activity.state.ActivityState;
import com.evolveum.midpoint.report.impl.ReportServiceImpl;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportDataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportExportWorkStateType;

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

import org.jetbrains.annotations.NotNull;

import static com.evolveum.midpoint.schema.result.OperationResultStatus.FATAL_ERROR;
import static com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.ReportExportWorkStateType.F_REPORT_DATA_REF;

import static java.util.Objects.requireNonNull;

/**
* Contains common functionality for both activity executions (data creation + data aggregation).
* This is an experiment - using object composition instead of inheritance.
*
* TODO better name
*/
class ActivityImportSupport extends AbstractReportActivitySupport {

@NotNull private final Activity<ClassicReportImportWorkDefinition, ClassicReportImportActivityHandler> activity;

/**
* Resolved report data object.
*/
private ReportDataType reportData;

ActivityImportSupport(
ExecutionInstantiationContext<ClassicReportImportWorkDefinition, ClassicReportImportActivityHandler> context) {
super(context);
activity = context.getActivity();
}

@Override
void initializeExecution(OperationResult result) throws CommonException, ActivityExecutionException {
super.initializeExecution(result);
setupReportDataObject(result);
}

private void setupReportDataObject(OperationResult result) throws CommonException {
@NotNull ClassicReportImportWorkDefinition workDefinition = activity.getWorkDefinition();
reportData = getObjectResolver().resolve(workDefinition.getReportDataRef(), ReportDataType.class,
null, "resolving report data", runningTask, result);
}

@Override
protected ObjectResolver getObjectResolver() {
return activity.getHandler().objectResolver;
}

@Override
protected AbstractReportWorkDefinition getWorkDefinition() {
return activity.getWorkDefinition();
}

@Override
protected ReportServiceImpl getReportService() {
return activity.getHandler().reportService;
}

public ReportDataType getReportData() {
return reportData;
}

boolean existImportScript() {
return getReport().getBehavior() != null && getReport().getBehavior().getImportScript() != null;
}

boolean existCollectionConfiguration() {
return getReport().getObjectCollection() != null;
}
}
Loading

0 comments on commit a5fd91f

Please sign in to comment.