Skip to content

Commit

Permalink
adding tab for csv export configuration on exporting popup and adding…
Browse files Browse the repository at this point in the history
… support for condition in object collection
  • Loading branch information
skublik committed Jun 4, 2020
1 parent 50b5721 commit 7c4b1bf
Show file tree
Hide file tree
Showing 21 changed files with 521 additions and 125 deletions.
Expand Up @@ -9,6 +9,8 @@
import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.button.CsvDownloadButtonPanel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder;
Expand All @@ -17,11 +19,10 @@
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.model.common.util.DefaultColumnUtils;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.DeltaFactory;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.SelectorOptions;
Expand Down Expand Up @@ -203,7 +204,7 @@ protected DisplayType getMainButtonDisplayType(){

@Override
protected Map<IconCssStyle, IconType> getMainButtonLayerIcons(){
if (!isCollectionViewPanel()){
if (!isCollectionViewPanelForCompiledView()){
return null;
}
Map<IconCssStyle, IconType> layerIconMap = new HashMap<>();
Expand Down Expand Up @@ -271,7 +272,8 @@ protected String getFilename() {
}

@Override
protected void createReportPerformed(String name, SearchFilterType filter, List<Integer> indexOfColumns, AjaxRequestTarget target) {
protected void createReportPerformed(String name, SearchFilterType filter, IModel<PrismObjectWrapper<ReportType>> reportWrapper,
List<Integer> indexOfColumns, AjaxRequestTarget target) {
PrismContext prismContext = getPageBase().getPrismContext();
PrismObjectDefinition<ReportType> def = prismContext.getSchemaRegistry().findObjectDefinitionByType(ReportType.COMPLEX_TYPE);
PrismObject<ReportType> obj = null;
Expand All @@ -290,6 +292,27 @@ protected void createReportPerformed(String name, SearchFilterType filter, List<
name = getPageBase().createStringResource("ObjectTypeGuiDescriptor.report").getString() + "-" + oid;
}
report.setName(WebComponentUtil.createPolyFromOrigString(name));
try {
PrismContainerWrapper<CsvExportType> csvConfig = reportWrapper.getObject().findContainer(ItemPath.create(ReportType.F_EXPORT, ExportConfigurationType.F_CSV));
if (csvConfig != null && csvConfig.getValue() != null) {
ExportConfigurationType export = new ExportConfigurationType();
export.setType(ExportType.CSV);
CsvExportType csv = csvConfig.getValue().getRealValue().clone();
List<Item> removedItem = new ArrayList();
for(Item item : (Collection<Item>) csv.asPrismContainerValue().getItems()) {
if (item.getRealValue() == null) {
removedItem.add(item);
}
}
for (Item item : removedItem) {
csv.asPrismContainerValue().getItems().remove(item);
}
export.setCsv(csv);
report.setExport(export);
}
} catch (SchemaException e) {
LOGGER.error("Couldn't find csv export container", e);
}
report.setReportEngine(ReportEngineSelectionType.COLLECTION);
ObjectCollectionReportEngineConfigurationType objectCollection = new ObjectCollectionReportEngineConfigurationType();
objectCollection.setUseOnlyReportView(true);
Expand Down Expand Up @@ -464,14 +487,14 @@ protected boolean isCreateNewObjectEnabled(){
}

protected List<CompiledObjectCollectionView> getNewObjectInfluencesList(){
if (isCollectionViewPanel()){
if (isCollectionViewPanelForCompiledView()){
return new ArrayList<>();
}
return getAllApplicableArchetypeViews();
}

protected DisplayType getNewObjectButtonStandardDisplayType(){
if (isCollectionViewPanel()) {
if (isCollectionViewPanelForCompiledView()) {

CompiledObjectCollectionView view = getObjectCollectionView();
if (isArchetypedCollectionView(view)) {
Expand Down
Expand Up @@ -27,7 +27,6 @@
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.SerializableSupplier;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.page.admin.home.PageDashboardConfigurable;
import com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusPresentationProperties;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -230,7 +229,7 @@ protected String getSearchByNameParameterValue() {
// }

protected Search createSearch() {
return SearchFactory.createSearch(type.getClassDefinition(), isCollectionViewPanel() ? getCollectionNameParameterValue().toString() : null,
return SearchFactory.createSearch(type.getClassDefinition(), isCollectionViewPanelForCompiledView() ? getCollectionNameParameterValue().toString() : null,
null, getPageBase(), true);
}

Expand Down Expand Up @@ -568,7 +567,7 @@ protected String getTableIdKeyValue(){
if (tableId == null) {
return null;
}
if (!isCollectionViewPanel()) {
if (!isCollectionViewPanelForCompiledView()) {
return tableId.name();
}
return tableId.name() + "." + getCollectionNameParameterValue().toString();
Expand Down Expand Up @@ -660,7 +659,7 @@ protected WebMarkupContainer createTableButtonToolbar(String id) {

protected String getStorageKey(){

if (isCollectionViewPanel()) {
if (isCollectionViewPanelForCompiledView()) {
StringValue collectionName = getCollectionNameParameterValue();
String collectionNameValue = collectionName != null ? collectionName.toString() : "";
return WebComponentUtil.getObjectListPageStorageKey(collectionNameValue);
Expand Down Expand Up @@ -753,6 +752,7 @@ protected CompiledObjectCollectionView getObjectCollectionView() {
}
compiledView.setCollection(widget.getData().getCollection());
dashboardWidgetView = compiledView;
return dashboardWidgetView;
} catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException
| ObjectNotFoundException e) {
LOGGER.error("Couldn't compile collection " + collection.getName(), e);
Expand All @@ -771,10 +771,24 @@ private StringValue getCollectionNameParameterValue(){
return parameters == null ? null : parameters.get(PageBase.PARAMETER_OBJECT_COLLECTION_NAME);
}

protected boolean isCollectionViewPanel() {
protected boolean isCollectionViewPanelForWidget() {
PageParameters parameters = getPageBase().getPageParameters();
if (parameters != null) {
StringValue widget = parameters.get(PageBase.PARAMETER_DASHBOARD_WIDGET_NAME);
StringValue dashboardOid = parameters.get(PageBase.PARAMETER_DASHBOARD_TYPE_OID);
return widget != null && widget.toString() != null && dashboardOid != null && dashboardOid.toString() != null;
}
return false;
}

protected boolean isCollectionViewPanelForCompiledView() {
return getCollectionNameParameterValue() != null && getCollectionNameParameterValue().toString() != null;
}

protected boolean isCollectionViewPanel() {
return isCollectionViewPanelForCompiledView() || isCollectionViewPanelForWidget();
}


@SuppressWarnings("unchecked")
protected BaseSortableDataProvider<SelectableBean<O>> getDataProvider() {
Expand Down
Expand Up @@ -12,13 +12,15 @@
import java.util.List;

import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.data.BaseSortableDataProvider;
import com.evolveum.midpoint.web.component.data.SelectableBeanObjectDataProvider;
import com.evolveum.midpoint.web.component.dialog.ExportingPanel;

import com.evolveum.midpoint.web.component.search.Search;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -160,8 +162,9 @@ public void exportPerformed(AjaxRequestTarget target) {
}

@Override
protected void createReportPerformed(String name, SearchFilterType filter, AjaxRequestTarget target) {
CsvDownloadButtonPanel.this.createReportPerformed(name, filter, exportableColumnsIndex, target);
protected void createReportPerformed(String name, SearchFilterType filter,
IModel<PrismObjectWrapper<ReportType>> report, AjaxRequestTarget target) {
CsvDownloadButtonPanel.this.createReportPerformed(name, filter, report, exportableColumnsIndex, target);
}

@Override
Expand All @@ -188,7 +191,7 @@ public boolean isVisibleCreateReportOption() {

protected abstract String getFilename();

protected abstract void createReportPerformed(String name, SearchFilterType filter, List<Integer> indexOfColumns, AjaxRequestTarget target);
protected abstract void createReportPerformed(String name, SearchFilterType filter, IModel<PrismObjectWrapper<ReportType>> report, List<Integer> indexOfColumns, AjaxRequestTarget target);

public boolean isVisibleCreateReportOption() {
return true;
Expand Down
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<!--
~ Copyright (c) 2010-2020 Evolveum
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<wicket:panel xmlns:wicket="http://wicket.apache.org">
<p align="center">
<div wicket:id="warningMessage"/>
<div wicket:id="csv"/>
</p>
</wicket:panel>
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2010-2019 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.web.component.dialog;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.form.CheckBoxPanel;
import com.evolveum.midpoint.gui.api.component.result.MessagePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AceEditor;
import com.evolveum.midpoint.web.component.message.FeedbackAlerts;
import com.evolveum.midpoint.web.component.search.Search;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.model.PrismContainerWrapperModel;
import com.evolveum.midpoint.web.model.PrismPropertyWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;

/**
* @author skublik
*/

public class CsvExportConfigurtionTabPanel extends BasePanel {

private static final Trace LOGGER = TraceManager.getTrace(ExportingFilterTabPanel.class);

private static final String ID_WARNING_MESSAGE = "warningMessage";
private static final String ID_CSV_FIELD = "csv";

private LoadableModel<Search> search;
private FeedbackAlerts feedbackList;
private IModel<PrismObjectWrapper<ReportType>> report;

public CsvExportConfigurtionTabPanel(String id, IModel<PrismObjectWrapper<ReportType>> report) {
super(id);
this.report = report;
}

@Override
protected void onInitialize() {
super.onInitialize();
initLayer();
}

private void initLayer() {

StringResourceModel messageModel = getPageBase().createStringResource("ExportingFilterTabPanel.message.useFilter");
MessagePanel warningMessage = new MessagePanel(ID_WARNING_MESSAGE, MessagePanel.MessagePanelType.WARN, messageModel);
warningMessage.setOutputMarkupId(true);
add(warningMessage);

Panel csv = null;
try {
csv = getPageBase().initItemPanel(ID_CSV_FIELD, CsvExportType.COMPLEX_TYPE, PrismContainerWrapperModel.fromContainerWrapper(report,
ItemPath.create(ReportType.F_EXPORT, ExportConfigurationType.F_CSV)), new ItemPanelSettingsBuilder().build());
} catch (SchemaException e) {
LOGGER.error("Could not create panel for filter. Reason: {}", e.getMessage(), e);
}
add(csv);
}

public CsvExportType getFilter() throws Exception {
PrismContainerWrapper<CsvExportType> csv = report.getObject().findContainer(ItemPath.create(ReportType.F_EXPORT, ExportConfigurationType.F_CSV));
return csv.getValue().getRealValue();
}
}
Expand Up @@ -42,7 +42,6 @@ public class ExportingFilterTabPanel extends BasePanel {
private static final String ID_FILTER_FIELD = "filter";

private LoadableModel<Search> search;
private FeedbackAlerts feedbackList;

private IModel<Boolean> check = new IModel<Boolean>() {
private boolean check = false;
Expand Down Expand Up @@ -78,10 +77,9 @@ public void setObject(String object) {
}
};

public ExportingFilterTabPanel(String id, LoadableModel<Search> search, FeedbackAlerts feedbackList) {
public ExportingFilterTabPanel(String id, LoadableModel<Search> search) {
super(id);
this.search = search;
this.feedbackList = feedbackList;
}

@Override
Expand Down
Expand Up @@ -7,7 +7,7 @@
-->

<wicket:panel xmlns:wicket="http://wicket.apache.org">
<div wicket:id="panel">
<form wicket:id="mainForm">

<p align="center">
<div wicket:id="warningMessage"/>
Expand All @@ -23,5 +23,5 @@
<a class="btn btn-primary btn-sm" wicket:id="export"/>
<a class="btn btn-default btn-sm" wicket:id="cancelButton"/>
</p>
</div>
</form>
</wicket:panel>

0 comments on commit 7c4b1bf

Please sign in to comment.