Skip to content

Commit

Permalink
Enhance display text for multi selections (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky authored Nov 18, 2024
1 parent b95fb42 commit 9cdd419
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (c) 2004 Actuate Corporation and others.
* Copyright (c) 2004, 2024 Actuate Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -8,7 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Actuate Corporation - Initial implementation.
* Actuate Corporation - Initial implementation
* Thomas Gutmann - Enhanced exchange of display text for multi selections
************************************************************************************/

package org.eclipse.birt.report.service;
Expand Down Expand Up @@ -783,9 +784,13 @@ public void runAndRenderReport(IReportRunnable runnable, OutputStream outputStre
}
}

/**
* @throws ReportServiceException
*/
private IRunAndRenderTask createRunAndRenderTask(IReportRunnable runnable, OutputStream outputStream,
InputOptions inputOptions, Map parameters, Boolean embeddable, List activeIds, RenderOption aRenderOption,
Map displayTexts, String reportTitle, Integer maxRows) throws ReportServiceException {
InputOptions inputOptions, Map<?, ?> parameters, Boolean embeddable, List<?> activeIds,
RenderOption aRenderOption,
Map<?, ?> displayTexts, String reportTitle, Integer maxRows) throws ReportServiceException {
RenderOption renderOption = aRenderOption;

HttpServletRequest request = (HttpServletRequest) inputOptions.getOption(InputOptions.OPT_REQUEST);
Expand Down Expand Up @@ -819,13 +824,19 @@ private IRunAndRenderTask createRunAndRenderTask(IReportRunnable runnable, Outpu
runAndRenderTask.setParameterValues(parameters);
}

// Set display Text for select parameters
// Set display text for selected parameters
if (displayTexts != null) {
Iterator keys = displayTexts.keySet().iterator();
Iterator<?> keys = displayTexts.keySet().iterator();
while (keys.hasNext()) {
String paramName = DataUtil.getString(keys.next());
String displayText = DataUtil.getString(displayTexts.get(paramName));
runAndRenderTask.setParameterDisplayText(paramName, displayText);
if (displayTexts.get(paramName) instanceof ArrayList) {
ArrayList<String> displayTextList = (ArrayList<String>) displayTexts.get(paramName);
String[] displayText = displayTextList.toArray(new String[displayTextList.size()]);
runAndRenderTask.setParameterDisplayText(paramName, displayText);
} else {
String displayText = DataUtil.getString(displayTexts.get(paramName));
runAndRenderTask.setParameterDisplayText(paramName, displayText);
}
}
}

Expand Down Expand Up @@ -1033,21 +1044,21 @@ private void runReport(HttpServletRequest request, IReportRunnable runnable, Str
* @param request
*
* @param runnable
* @param archive
* @param documentName
* @param locale
* @param timeZone
* @param parameters
* @param displayTexts
* @param maxRows
* @return list of exceptions which occured during the run or null
* @return list of exceptions which occurred during the run or null
* @throws RemoteException
*/
public List<Exception> runReport(HttpServletRequest request, IReportRunnable runnable, String documentName,
Locale locale, TimeZone timeZone, Map parameters, Map displayTexts, Integer maxRows)
Locale locale, TimeZone timeZone, Map<?, ?> parameters, Map<?, ?> displayTexts, Integer maxRows)
throws RemoteException {
assert runnable != null;

// Preapre the run report task.
// Prepare the run report task.
IRunTask runTask;
runTask = engine.createRunTask(runnable);
runTask.setLocale(locale);
Expand All @@ -1067,13 +1078,19 @@ public List<Exception> runReport(HttpServletRequest request, IReportRunnable run
// add task into session
BirtUtility.addTask(request, runTask);

// Set display Text for select parameters
// Set display text for selected parameters
if (displayTexts != null) {
Iterator keys = displayTexts.keySet().iterator();
Iterator<?> keys = displayTexts.keySet().iterator();
while (keys.hasNext()) {
String paramName = DataUtil.getString(keys.next());
String displayText = DataUtil.getString(displayTexts.get(paramName));
runTask.setParameterDisplayText(paramName, displayText);
if (displayTexts.get(paramName) instanceof ArrayList) {
ArrayList<String> displayTextList = (ArrayList<String>) displayTexts.get(paramName);
String[] displayText = displayTextList.toArray(new String[displayTextList.size()]);
runTask.setParameterDisplayText(paramName, displayText);
} else {
String displayText = DataUtil.getString(displayTexts.get(paramName));
runTask.setParameterDisplayText(paramName, displayText);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (c) 2004 Actuate Corporation and others.
* Copyright (c) 2004, 2024 Actuate Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -8,7 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Actuate Corporation - Initial implementation.
* Actuate Corporation - Initial implementation.
* Thomas Gutmann - Implementation of display text for multi selections
************************************************************************************/

package org.eclipse.birt.report.utility;
Expand All @@ -19,6 +20,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.net.URL;
Expand All @@ -31,6 +33,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;

import javax.servlet.ServletException;
Expand Down Expand Up @@ -77,13 +80,13 @@
*/
public class BirtUtility {

/*
/**
* none value
*/
public final static String NONE = "none"; //$NON-NLS-1$

/*
* Request attribute name that indicates the viewer markder has been cleared
/**
* Request attribute name that indicates the viewer marker has been cleared
*/
public final static String VIEWER_MARKER_CLEARED = "ViewerMarkerCleared"; //$NON-NLS-1$

Expand Down Expand Up @@ -302,23 +305,28 @@ public static Map getModuleOptions(HttpServletRequest request) {
* @param request
* @return Map
*/
public static Map getDisplayTexts(Collection parameters, Map displayTexts, HttpServletRequest request) {
public static Map<String, Serializable> getDisplayTexts(Collection<?> parameters,
Map<String, Serializable> displayTexts,
HttpServletRequest request) {
if (displayTexts == null) {
displayTexts = new HashMap();
displayTexts = new HashMap<String, Serializable>();
}

Enumeration params = request.getParameterNames();
Enumeration<String> params = request.getParameterNames();
while (params != null && params.hasMoreElements()) {
String param = DataUtil.getString(params.nextElement());
String paramName = ParameterAccessor.isDisplayText(param);
if (paramName != null) {
ParameterDefinition parameter = findParameterDefinition(parameters, paramName);

// TODO: Currently, Multi-value parameter doesn't support
// displayText.( set to NULL value )
if (parameter != null) {
if (parameter.isMultiValue()) {
displayTexts.put(paramName, null);
ArrayList<String> tmpDisplayTexts = new ArrayList<String>();
Set<String> setDisplayText = ParameterAccessor.getParameterValues(request, param);
Iterator<?> displayTextIter = setDisplayText.iterator();
while (displayTextIter.hasNext()) {
tmpDisplayTexts.add((String) displayTextIter.next());
}
displayTexts.put(paramName, tmpDisplayTexts);
} else {
displayTexts.put(paramName, ParameterAccessor.getParameter(request, param));
}
Expand Down Expand Up @@ -413,15 +421,15 @@ public static boolean validateParameters(Collection parameterList, Map parameter
* @param displayTexts
* @throws Exception
*/
public static void handleOperation(Operation operation, ViewerAttributeBean bean, Map parameterMap,
Map displayTexts) throws Exception {
public static void handleOperation(Operation operation, ViewerAttributeBean bean, Map<String, Object> parameterMap,
Map<String, Object> displayTexts) throws Exception {
if (operation == null || bean == null || parameterMap == null || displayTexts == null) {
return;
}

// convert parameter from SOAP operation
List locs = new ArrayList();
Map params = new HashMap();
List<Object> locs = new ArrayList();
Map<String, List> params = new HashMap<String, List>();
String displayTextParam = null;
Oprand[] oprands = operation.getOprand();
for (int i = 0; i < oprands.length; i++) {
Expand All @@ -439,12 +447,15 @@ public static void handleOperation(Operation operation, ViewerAttributeBean bean
// display text of parameter
else if ((displayTextParam = ParameterAccessor.isDisplayText(paramName)) != null) {
ParameterDefinition parameter = bean.findParameterDefinition(displayTextParam);

// TODO: Currently, Multi-value parameter doesn't support
// displayText.( set to NULL value )
if (parameter != null) {
if (parameter.isMultiValue()) {
displayTexts.put(displayTextParam, null);
ArrayList<String> tmpDisplayTexts = new ArrayList<String>();
if (displayTexts.containsKey(displayTextParam)) {
tmpDisplayTexts = (ArrayList<String>) displayTexts.get(displayTextParam);
displayTexts.remove(displayTextParam);
}
tmpDisplayTexts.add((String) paramValue);
displayTexts.put(displayTextParam, tmpDisplayTexts);
} else {
displayTexts.put(displayTextParam, paramValue);
}
Expand Down

0 comments on commit 9cdd419

Please sign in to comment.