Skip to content

Commit

Permalink
removing base64-encoded twice for jasper report template (MID-5075)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Jul 25, 2019
1 parent 5fcfc3c commit 993e97b
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 21 deletions.
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.gui.impl.model;

import com.evolveum.midpoint.util.exception.SystemException;

import org.apache.commons.codec.binary.Base64;
import org.apache.wicket.model.IModel;

import java.io.UnsupportedEncodingException;

/**
* @author skublik
*/
public class JasperTemplateModel implements IModel<String> {

private IModel<byte[]> model;

public JasperTemplateModel(IModel<byte[]> model) {
this.model = model;
}

@Override
public String getObject() {
if (model.getObject() == null) {
return null;
}
byte[] obj;
if (Base64.isBase64(model.getObject())) {
obj = Base64.decodeBase64(model.getObject());
} else {
obj = model.getObject();
}

try {
return new String(obj, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new SystemException(e);
}
}

@Override
public void setObject(String object) {
if (object == null) {
model.setObject(null);
}

try {
byte[] val = object.getBytes("utf-8");
model.setObject(val);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

@Override
public void detach() {
}
}
Expand Up @@ -134,7 +134,7 @@ public class PageCreatedReports extends PageAdminObjectList<ReportOutputType> {

public PageCreatedReports(PageParameters pageParameters) {
super(pageParameters);

initReportTypeMap();
}

Expand All @@ -155,10 +155,14 @@ private String getReportType(){
}
return "undefined";
}

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

private void customInitLayout() {

String reportName = reportTypeMal.get(getReportType());
List<String> values = new ArrayList<>(reportTypeMal.values());
Expand Down
Expand Up @@ -20,6 +20,7 @@

import com.evolveum.midpoint.prism.delta.DeltaFactory;
import com.evolveum.midpoint.web.page.admin.PageAdmin;

import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
Expand All @@ -33,6 +34,7 @@
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.model.JasperTemplateModel;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -49,7 +51,6 @@
import com.evolveum.midpoint.web.page.admin.reports.component.JasperReportConfigurationPanel;
import com.evolveum.midpoint.web.page.admin.reports.component.ReportConfigurationPanel;
import com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto;
import com.evolveum.midpoint.web.util.Base64Model;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportEngineSelectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;
Expand Down Expand Up @@ -158,7 +159,7 @@ public WebMarkupContainer getPanel(String panelId) {
@Override
public WebMarkupContainer getPanel(String panelId) {
IModel<String> title = PageReport.this.createStringResource("PageReport.jasperTemplateStyle");
IModel<String> data = new Base64Model(new PropertyModel(model, "templateStyle"));
IModel<String> data = new JasperTemplateModel(new PropertyModel(model, "templateStyle"));
return new AceEditorPanel(panelId, title, data);
}
});
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.apache.wicket.validation.ValidationError;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.impl.model.JasperTemplateModel;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.column.CheckBoxColumn;
Expand Down Expand Up @@ -64,7 +65,7 @@ protected void initLayout() {
initParametersTable();
initFiledsTable();

IModel<String> data = new Base64Model(new PropertyModel<>(getModel(), "jasperReportDto.jasperReportXml"));
IModel<String> data = new JasperTemplateModel(new PropertyModel<>(getModel(), "jasperReportDto.jasperReportXml"));
AceEditorPanel templateEditor = new AceEditorPanel(ID_TEMPLATE,
createStringResource("PageReport.jasperTemplate"), data, 300);
add(templateEditor);
Expand Down
Expand Up @@ -33,7 +33,7 @@ public class JasperReportDto implements Serializable{

public JasperReportDto(byte[] jasperReportxml, boolean onlyForPromptingParams) {
this.jasperReportXml = jasperReportxml;

String st = new String(jasperReportxml);
initFileds(onlyForPromptingParams);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ private void initFileds(boolean onlyForPromptingParams){
design.removeParameter(param.getName());
}

detail = new String(Base64.decodeBase64(jasperReportXml));
detail = new String(Base64.isBase64(jasperReportXml) ? Base64.decodeBase64(jasperReportXml) :jasperReportXml);


} catch (SchemaException e) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public byte[] getTemplate(){
oldDesign.setQuery(q);

String reportAsString = JRXmlWriter.writeReport(oldDesign, "UTF-8");
return Base64.encodeBase64(reportAsString.getBytes("UTF-8"));
return reportAsString.getBytes("UTF-8");

} catch (JRException | ClassNotFoundException | SchemaException | UnsupportedEncodingException ex) {
throw new IllegalStateException(ex.getMessage(), ex.getCause());
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -77,7 +77,13 @@ public class ReportTypeUtil {

public static JasperDesign loadJasperDesign(byte[] template) throws SchemaException{
try {
byte[] reportTemplate = Base64.decodeBase64(template);
byte[] reportTemplate;

if(Base64.isBase64(template)) {
reportTemplate = Base64.decodeBase64(template);
} else {
reportTemplate = template;
}

InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate);
JasperDesign jasperDesign = JRXmlLoader.load(inputStreamJRXML);
Expand Down

0 comments on commit 993e97b

Please sign in to comment.