Skip to content

Commit

Permalink
rewriting old dashboard tests to new multi thread task, fix bugs from…
Browse files Browse the repository at this point in the history
… testing
  • Loading branch information
skublik committed Aug 13, 2021
1 parent 46707e5 commit 5551597
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 116 deletions.
Expand Up @@ -478,6 +478,13 @@ private void compileObjectType(CompiledObjectCollectionView existingView, GuiObj
if (existingView.getContainerType() == null) {
existingView.setContainerType(objectListViewType.getType());
}
if (objectListViewType.getType() != null) {
Class<Object> existingType = prismContext.getSchemaRegistry().determineCompileTimeClass(existingView.getContainerType());
Class<Object> newType = prismContext.getSchemaRegistry().determineCompileTimeClass(objectListViewType.getType());
if (existingType != null && newType != null && existingType.isAssignableFrom(newType)) {
existingView.setContainerType(objectListViewType.getType());
}
}
}

private void compileActions(CompiledObjectCollectionView existingView, GuiObjectListViewType objectListViewType) {
Expand Down
Expand Up @@ -236,34 +236,33 @@ public CompiledObjectCollectionView createCompiledView(DashboardReportEngineConf
DashboardWidgetSourceTypeType sourceType = DashboardUtils.getSourceType(widget);
MiscUtil.stateCheck(sourceType != null, "No source type specified in " + widget);

CollectionRefSpecificationType collectionRefSpecification =
getDashboardService().getCollectionRefSpecificationType(widget, task, result);

CompiledObjectCollectionView compiledCollection = getModelInteractionService().compileObjectCollectionView(
collectionRefSpecification, null, task, result);

CompiledObjectCollectionView compiledCollection = new CompiledObjectCollectionView();
if (widget.getPresentation() != null && widget.getPresentation().getView() != null) {
getModelInteractionService().applyView(compiledCollection, widget.getPresentation().getView());
}
CollectionRefSpecificationType collectionRefSpecification =
getDashboardService().getCollectionRefSpecificationType(widget, task, result);
if (collectionRefSpecification != null) {
@NotNull CompiledObjectCollectionView compiledCollectionRefSpec = getModelInteractionService().compileObjectCollectionView(
collectionRefSpecification, compiledCollection.getTargetClass(prismContext), task, result);
getModelInteractionService().applyView(compiledCollectionRefSpec, compiledCollection.toGuiObjectListViewType());
compiledCollection = compiledCollectionRefSpec;
}

GuiObjectListViewType reportView = getReportViewByType(dashboardConfig, compiledCollection.getContainerType());
GuiObjectListViewType reportView = getReportViewByType(
dashboardConfig, ObjectUtils.defaultIfNull(compiledCollection.getContainerType(), ObjectType.COMPLEX_TYPE));
if (reportView != null) {
getModelInteractionService().applyView(compiledCollection, reportView);
}

if (compiledCollection.getColumns().isEmpty()) {
Class<Containerable> type = resolveTypeForReport(compiledCollection);
getModelInteractionService().applyView(compiledCollection, DefaultColumnUtils.getDefaultView(type));
getModelInteractionService().applyView(
compiledCollection, DefaultColumnUtils.getDefaultView(ObjectUtils.defaultIfNull(type, ObjectType.class)));
}
return compiledCollection;
}

private void applyView(CompiledObjectCollectionView compiledCollection, ObjectCollectionType collection) {
getModelInteractionService().applyView(compiledCollection, collection.getDefaultView());
if (compiledCollection.getContainerType() == null) {
compiledCollection.setContainerType(collection.getType());
}
}

private GuiObjectListViewType getReportViewByType(DashboardReportEngineConfigurationType dashboardConfig, QName type) {
for (GuiObjectListViewType view : dashboardConfig.getView()) {
if (QNameUtil.match(view.getType(), type)) {
Expand All @@ -276,38 +275,30 @@ private GuiObjectListViewType getReportViewByType(DashboardReportEngineConfigura
public CompiledObjectCollectionView createCompiledView(ObjectCollectionReportEngineConfigurationType collectionConfig, boolean useDefaultView, Task task, OperationResult result)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Validate.notNull(collectionConfig, "Collection engine in report couldn't be null.");
CollectionRefSpecificationType collectionRefSpecification = collectionConfig.getCollection();
ObjectReferenceType ref = null;
if (collectionRefSpecification != null) {
ref = collectionRefSpecification.getCollectionRef();
}
ObjectCollectionType collection = null;
if (ref != null && ref.getOid() != null) {
Class<ObjectType> type = getPrismContext().getSchemaRegistry().determineClassForType(ref.getType());
collection = (ObjectCollectionType) getModelService()
.getObject(type, ref.getOid(), null, task, result)
.asObjectable();
}
CompiledObjectCollectionView compiledCollection = new CompiledObjectCollectionView();
if (!Boolean.TRUE.equals(collectionConfig.isUseOnlyReportView())) {
if (collection != null) {
applyView(compiledCollection, collection);
} else if (collectionRefSpecification != null && collectionRefSpecification.getBaseCollectionRef() != null
&& collectionRefSpecification.getBaseCollectionRef().getCollectionRef() != null
&& collectionRefSpecification.getBaseCollectionRef().getCollectionRef().getOid() != null) {
ObjectCollectionType baseCollection = (ObjectCollectionType) getObjectFromReference(collectionRefSpecification.getBaseCollectionRef().getCollectionRef()).asObjectable();
applyView(compiledCollection, baseCollection);
}
}

CompiledObjectCollectionView compiledCollection = new CompiledObjectCollectionView();
GuiObjectListViewType reportView = collectionConfig.getView();
if (reportView != null) {
getModelInteractionService().applyView(compiledCollection, reportView);
}

CollectionRefSpecificationType collectionRefSpecification = collectionConfig.getCollection();
if (collectionRefSpecification != null) {
@NotNull CompiledObjectCollectionView compiledCollectionRefSpec = getModelInteractionService().compileObjectCollectionView(
collectionRefSpecification, compiledCollection.getTargetClass(prismContext), task, result);

if (Boolean.TRUE.equals(collectionConfig.isUseOnlyReportView())) {
compiledCollectionRefSpec.getColumns().clear();
}
getModelInteractionService().applyView(compiledCollectionRefSpec, compiledCollection.toGuiObjectListViewType());
compiledCollection = compiledCollectionRefSpec;
}

if (compiledCollection.getColumns().isEmpty()) {
if (useDefaultView) {
Class<Containerable> type = resolveTypeForReport(compiledCollection);
getModelInteractionService().applyView(compiledCollection, DefaultColumnUtils.getDefaultView(type));
getModelInteractionService().applyView(
compiledCollection, DefaultColumnUtils.getDefaultView(ObjectUtils.defaultIfNull(type, ObjectType.class)));
} else {
return null;
}
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.task.api.RunningTask;

import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.Producer;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
Expand All @@ -29,10 +30,14 @@

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.datatype.XMLGregorianCalendar;
import java.util.*;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static com.evolveum.midpoint.report.impl.controller.fileformat.CommonHtmlSupport.*;
Expand Down Expand Up @@ -80,7 +85,7 @@ class ColumnDataConverter<C extends Containerable> {
this(record, report, new VariablesMap(), reportService, task, result);
}

List<String> convertWidgetColumn(@NotNull String header) throws CommonException {
List<String> convertWidgetColumn(@NotNull String header, @Nullable Function<String, String> processValueForStatus) throws CommonException {
DashboardWidget data = reportService.getDashboardService().createWidgetData((DashboardWidgetType) record, task, result);
if (header.equals(LABEL_COLUMN)) {
return Collections.singletonList(data.getLabel(reportService.getLocalizationService()));
Expand All @@ -91,7 +96,11 @@ List<String> convertWidgetColumn(@NotNull String header) throws CommonException
if (header.equals(STATUS_COLUMN)) {
List<String> values = new ArrayList<>();
if (data.getDisplay() != null && StringUtils.isNoneBlank(data.getDisplay().getColor())) {
values.add(VALUE_CSS_STYLE_TAG + "{background-color: " + data.getDisplay().getColor() + " !important;}");
if (processValueForStatus == null) {
values.add(data.getDisplay().getColor());
} else {
values.add(processValueForStatus.apply(data.getDisplay().getColor()));
}
}
return values;
}
Expand Down
Expand Up @@ -139,8 +139,6 @@ public void handleDataRecord(int sequentialNumber, C record, RunningTask workerT
// }
// }

variables.putAll(this.reportService.evaluateSubreportParameters(report.asPrismObject(), variables, workerTask, result));

ColumnDataConverter<C> columnDataConverter =
new ColumnDataConverter<>(record, report, variables, reportService, workerTask, result);

Expand Down
Expand Up @@ -124,7 +124,7 @@ public void handleDataRecord(int sequentialNumber, C record, RunningTask workerT

for (String label : getHeadsOfWidget()) {
dataRow.addColumn(
columnDataConverter.convertWidgetColumn(label));
columnDataConverter.convertWidgetColumn(label, dataWriter.getFunctionForWidgetStatus()));
}

dataWriter.appendDataRow(dataRow);
Expand Down
Expand Up @@ -10,18 +10,19 @@
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.report.impl.ReportServiceImpl;

import j2html.TagCreator;
import j2html.tags.ContainerTag;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Creates and manipulates exported reports in HTML format for dashboard reports.
*/
public class HtmlDashboardReportDataWriter extends HtmlReportDataWriter<ExportedDashboardReportDataRow, ExportedDashboardReportHeaderRow> {
public class HtmlDashboardReportDataWriter
extends HtmlReportDataWriter<ExportedDashboardReportDataRow, ExportedDashboardReportHeaderRow> {

private static final String BASIC_WIDGET_ROW_KEY = "BaseWidgetID";

Expand Down Expand Up @@ -122,6 +123,9 @@ public String completizeReport(String aggregatedData) {
String tableData = Arrays.stream(
StringUtils.substringsBetween(aggregatedData, "<" +entry.getKey() + ">", "</" +entry.getKey() + ">"))
.collect(Collectors.joining());
if (!BASIC_WIDGET_ROW_KEY.equals(entry.getKey()) && !tableData.contains("<tbody>")) {
return;
}
String tableBox = createTableBox(tableData, entry.getValue().support, true);
body.append(tableBox).append("<br>");
});
Expand All @@ -140,6 +144,9 @@ public String completizeReport() {
body.append("<div> <style> ").append(cssStyle).append(" </style>");

data.entrySet().forEach(entry -> {
if (!BASIC_WIDGET_ROW_KEY.equals(entry.getKey()) && entry.getValue().dataRows.isEmpty()) {
return;
}
String tableData = getStringDataInternal(entry.getValue().headerRow, entry.getValue().dataRows);
String tableBox = createTableBox(tableData, entry.getValue().support, false);
body.append(tableBox).append("<br>");
Expand All @@ -154,6 +161,11 @@ private CommonHtmlSupport getDefaultSupport() {
return data.get(BASIC_WIDGET_ROW_KEY).support;
}

@Override
public @Nullable Function<String, String> getFunctionForWidgetStatus() {
return (value) -> CommonHtmlSupport.VALUE_CSS_STYLE_TAG + "{background-color: " + value + " !important;}";
}

class ExportedWidgetData {

List<ExportedDashboardReportDataRow> dataRows = new ArrayList<>();
Expand Down
Expand Up @@ -54,7 +54,9 @@ protected String getStringDataInternal(ExportedReportHeaderRow headerRow, List<E
});
tBody.with(tr);
});
sb.append(tBody.render());
if (tBody.getNumChildren() != 0) {
sb.append(tBody.render());
}
return sb.toString();
}

Expand Down
Expand Up @@ -7,6 +7,10 @@

package com.evolveum.midpoint.report.impl.controller.fileformat;

import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

/**
* Responsible for creating and manipulating text representation of an exported report.
*
Expand Down Expand Up @@ -64,4 +68,9 @@ public interface ReportDataWriter<ED extends ExportedReportDataRow, EH extends E
* Use data in data writer.
*/
String completizeReport();

@Nullable
default Function<String, String> getFunctionForWidgetStatus(){
return null;
};
}
Expand Up @@ -89,6 +89,12 @@ public abstract class EmptyReportIntegrationTest extends AbstractModelIntegratio
"report-user-list-script.xml", "222bf2b8-c89b-11e7-bf36-ebd4e4d45a80");
static final TestResource<ReportType> REPORT_DASHBOARD_WITH_DEFAULT_COLUMN = new TestResource<>(TEST_DIR_REPORTS,
"report-dashboard-with-default-column.xml", "2b44aa2e-dd86-4842-bcf5-762c8a9a8582");
static final TestResource<ReportType> REPORT_DASHBOARD_WITH_VIEW = new TestResource<>(TEST_DIR_REPORTS,
"report-dashboard-with-view.xml", "2b44aa2e-dd86-4842-bcf5-762c8a9a8533");
static final TestResource<ReportType> REPORT_DASHBOARD_WITH_TRIPLE_VIEW = new TestResource<>(TEST_DIR_REPORTS,
"report-dashboard-with-triple-view.xml", "2b87aa2e-dd86-4842-bcf5-76200a9a8533");
static final TestResource<ReportType> REPORT_DASHBOARD_EMPTY = new TestResource<>(TEST_DIR_REPORTS,
"report-dashboard-empty.xml", "2b44aa2e-dd86-4842-bcf5-762c8a9a8eq2");

static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_AUDIT_RECORDS = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-audit-records.xml", "00000000-0000-0000-0001-000000001234");
Expand All @@ -98,25 +104,41 @@ public abstract class EmptyReportIntegrationTest extends AbstractModelIntegratio
"object-collection-audit-empty.xml", "11000000-0000-0000-0001-000000gh1234");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_USERS = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-user.xml", "72b1f98e-f587-4b9f-b92b-72e251dbb266");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_ROLES = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-role.xml", "72b1f98e-f587-4b9f-b92b-72e251dbb255");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_USERS_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-user-with-view.xml", "11b1f98e-f587-4b9f-b92b-72e251dbb266");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_ROLES = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-role.xml", "72b1f98e-f587-4b9f-b92b-72e251dbb255");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_ROLES_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-role-with-view.xml", "11b1f98e-f587-4b9f-b92b-72e251dbb255");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_BASIC_FILTER = new TestResource<>(TEST_DIR_COMMON,
"object-collection-basic-filter.xml", "11b1f98e-f587-4b9f-b92b-72e251dbb299");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_EMPTY = new TestResource<>(TEST_DIR_COMMON,
"object-collection-empty.xml", "72b1f98e-f587-4b9f-b92b-72e251dbb201");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_RESOURCE = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-resource.xml", "00000000-0000-0000-0001-000000000006");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_ASSIGNMENT = new TestResource<>(TEST_DIR_COMMON,
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_RESOURCE_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-resource-with-view.xml", "11000000-0000-0000-0001-000000000006");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_ASSIGNMENT_HOLDER = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-assignment-holder.xml", "72b1f98e-f587-4b9f-b92b-72e251dbb775");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_ASSIGNMENT_HOLDER_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-assignment-holder-with-view.xml", "11b1f98e-f587-4b9f-b92b-72e251dbb775");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_TASK = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-task.xml", "00000000-0000-0000-0001-000000000007");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_ALL_TASK_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"object-collection-all-task-with-view.xml", "11000000-0000-0000-0001-000000000007");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_SHADOW_OF_RESOURCE = new TestResource<>(TEST_DIR_COMMON,
"object-collection-shadow-of-resource.xml", "72b1f98e-f587-4b9f-b92b-72e251dbb244");
static final TestResource<ObjectCollectionType> OBJECT_COLLECTION_SHADOW_OF_RESOURCE_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"object-collection-shadow-of-resource-with-view.xml", "11b1f98e-f587-4b9f-b92b-72e251dbb244");

static final TestResource<ObjectCollectionType> DASHBOARD_DEFAULT_COLUMNS = new TestResource<>(TEST_DIR_COMMON,
"dashboard-default-columns.xml", "00000000-0000-0000-0001-000000001231");
static final TestResource<ObjectCollectionType> DASHBOARD_WITH_VIEW = new TestResource<>(TEST_DIR_COMMON,
"dashboard-with-view.xml", "00000000-0000-0000-0001-000000661231");
static final TestResource<ObjectCollectionType> DASHBOARD_WITH_TRIPLE_VIEW = new TestResource<>(TEST_DIR_COMMON,
"dashboard-with-triple-view.xml", "00000000-0000-0000-0001-000022661231");
static final TestResource<ObjectCollectionType> DASHBOARD_EMPTY = new TestResource<>(TEST_DIR_COMMON,
"dashboard-empty.xml", "00000000-0000-0000-0001-000000kj1231");

static final TestResource<ObjectCollectionType> USER_WILL = new TestResource<>(TEST_DIR_COMMON,
"user-will.xml", "c0c010c0-d34d-b33f-f00d-111111111122");
Expand Down

0 comments on commit 5551597

Please sign in to comment.