#1 2014-12-11 04:31:32

marcosfilho
Member
Registered: 2014-08-04

Internationalized reports?

Hi guys,

We need to get out reports internationalized. At the moment we have mostly Dynamic List, Script Report and Jasper Reports.

As per the jasper documentation, internationalization is supported by java.util.ResourceBundle.
http://jasperreports.sourceforge.net/sa … .html#i18n

1)Is it compatible with ReportServer? Can I just create the propertie  files in the classpath of reportserver?

2) Also, how can jasperreport  get the locale?  I thought we can set a user variable and set the locale on a onlogin script?

3) Last, how can we get Script Reports internationalized ? I guess I could use the  java.util.ResourceBundle as well? Or do you have another idea?

This has become a very important requirement for us.

Thanks a lot in advance.

Last edited by marcosfilho (2014-12-11 04:34:51)

Offline

#2 2014-12-11 22:49:34

marcosfilho
Member
Registered: 2014-08-04

Re: Internationalized reports?

Hi,

I did a few tests myself.

so, following up my previous questions:

1) Yes, it is supported. I was able to load the messages in the jasper and script reports through a ResourceBundle

2) Still havent figured out how to tell a jasper report how to load the exact locale(according to the reportserver user session) any ideas?

3) I was able to use ResourceBundle for a RS dynamic list report. This dynamic report uses a script as a datasource(this script returns a RSTableModel).  However im getting erros with Chinese language because I try to create the headers of the RsTablModel with Chinese words from the resource bundle.

my main code is like this:

public RSTableModel generateReport(){

		initializeReport();
		doSomeStuff();

                def td = new TableDefinition( headers.toList(),  dataTypes.toList() );

               
		def table = new RSTableModel(td); 

		for(line in this.data) {
			table.addDataRow(line)	
		}

		return table
	}

//my headers are generated like this:

	Locale zhCN = new Locale("zh","CN");
        ResourceBundle bundle = ResourceBundle.getBundle("messages", zhNC);
        //tout.println(bundle.getString("welcome"));
 


        headers[0] =  bundle.getString("welcome") // if i put a english word in this key, it works, but with a chinese word, it doesnt work
        //then the rest of the headers

I think it happens because RS creates a temporaty table to store this report and then displays it later.

Could you please advice how I could fix this? Or chinese words are not supported for headers of Dynamic Lists?


I would appreciate any help.

Thanks

Offline

#3 2014-12-11 22:52:09

marcosfilho
Member
Registered: 2014-08-04

Re: Internationalized reports?

btw, this is the error i get when i have a chinese word in a header of a RSTableModel:

net.datenwerke.gxtdto.client.servercommunication.exceptions.NonFatalException: The report could not be executed: java.lang.IllegalStateException: org.h2.jdbc.JdbcSQLException: Unknown data type: ","; SQL statement:
CREATE TABLE RS_SCR_TAB_15(
VARCHAR,
EMP_ID VARCHAR,
POSITION_TITLE VARCHAR,
REPLACE2 VARCHAR,
NAME VARCHAR,
BRANCH_CODE VARCHAR,
ID_NUM VARCHAR,
DOB VARCHAR,
GENDER VARCHAR,
BANK_ACCOUNT_NAME VARCHAR,
BANK_ACCOUNT_NUM VARCHAR,
EMAIL_ADDR VARCHAR,
SALARY VARCHAR,
GTL_SUM_INSURED VARCHAR,
GTL_PREMIUM VARCHAR,
ADD_SUM_INSURED VARCHAR,
ADD_PREMIUM VARCHAR,
MEDICAL_SUM_INSURED VARCHAR,
MEDICAL_PREMIUM VARCHAR,
GCL_SUM_INSURED VARCHAR,
GCL_PREMIUM VARCHAR,
MCU_SUM_INSURED VARCHAR,
MCU_PREMIUM VARCHAR,
TOTALPREMIUM VARCHAR
); [50004-180]
at net.datenwerke.rs.base.server.table.TableReportUtilityServiceImpl.getReturnedColumns(TableReportUtilityServiceImpl.java:216)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:66)
at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
at net.datenwerke.gf.service.gwtstacktrace.CatchStacktraceInterceptor.invoke(CatchStacktraceInterceptor.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
at net.datenwerke.gf.service.gwtstacktrace.CatchStacktraceInterceptor.invoke(CatchStacktraceInterceptor.java:38)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
at net.datenwerke.gf.service.gwtstacktrace.CatchStacktraceInterceptor.invoke(CatchStacktraceInterceptor.java:38)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
at com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:89)
at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorException: The report could not be executed: java.lang.IllegalStateException: org.h2.jdbc.JdbcSQLException: Unknown data type: ","; SQL statement:
CREATE TABLE RS_SCR_TAB_15(
VARCHAR,
EMP_ID VARCHAR,
POSITION_TITLE VARCHAR,
REPLACE2 VARCHAR,
NAME VARCHAR,
BRANCH_CODE VARCHAR,
ID_NUM VARCHAR,
DOB VARCHAR,
GENDER VARCHAR,
BANK_ACCOUNT_NAME VARCHAR,
BANK_ACCOUNT_NUM VARCHAR,
EMAIL_ADDR VARCHAR,
SALARY VARCHAR,
GTL_SUM_INSURED VARCHAR,
GTL_PREMIUM VARCHAR,
ADD_SUM_INSURED VARCHAR,
ADD_PREMIUM VARCHAR,
MEDICAL_SUM_INSURED VARCHAR,
MEDICAL_PREMIUM VARCHAR,
GCL_SUM_INSURED VARCHAR,
GCL_PREMIUM VARCHAR,
MCU_SUM_INSURED VARCHAR,
MCU_PREMIUM VARCHAR,
TOTALPREMIUM VARCHAR
); [50004-180]
at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:218)
at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:119)
at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:106)
at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:89)
at net.datenwerke.rs.base.service.reportengines.table.TableReportUtilsImpl.getReturnedColumns(TableReportUtilsImpl.java:162)
at net.datenwerke.rs.base.service.reportengines.table.TableReportUtilsImpl.getReturnedPlainColumns(TableReportUtilsImpl.java:138)
at net.datenwerke.rs.base.server.table.TableReportUtilityServiceImpl.getReturnedColumns(TableReportUtilityServiceImpl.java:212)
... 54 more
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: org.h2.jdbc.JdbcSQLException: Unknown data type: ","; SQL statement:
CREATE TABLE RS_SCR_TAB_15(
VARCHAR,
EMP_ID VARCHAR,
POSITION_TITLE VARCHAR,
REPLACE2 VARCHAR,
NAME VARCHAR,
BRANCH_CODE VARCHAR,
ID_NUM VARCHAR,
DOB VARCHAR,
GENDER VARCHAR,
BANK_ACCOUNT_NAME VARCHAR,
BANK_ACCOUNT_NUM VARCHAR,
EMAIL_ADDR VARCHAR,
SALARY VARCHAR,
GTL_SUM_INSURED VARCHAR,
GTL_PREMIUM VARCHAR,
ADD_SUM_INSURED VARCHAR,
ADD_PREMIUM VARCHAR,
MEDICAL_SUM_INSURED VARCHAR,
MEDICAL_PREMIUM VARCHAR,
GCL_SUM_INSURED VARCHAR,
GCL_PREMIUM VARCHAR,
MCU_SUM_INSURED VARCHAR,
MCU_PREMIUM VARCHAR,
TOTALPREMIUM VARCHAR
); [50004-180]
at net.datenwerke.rs.incubator.service.scriptdatasource.transformers.ScriptToInMemoryDb.getConnection(ScriptToInMemoryDb.java:169)
at net.datenwerke.rs.incubator.service.scriptdatasource.hooker.ScriptDatasourceInternalDbConnectionResultTransformer.transform(ScriptDatasourceInternalDbConnectionResultTransformer.java:41)
at net.datenwerke.rs.incubator.service.scriptdatasource.hooker.ScriptDatasourceInternalDbConnectionResultTransformer.transform(ScriptDatasourceInternalDbConnectionResultTransformer.java:1)
at net.datenwerke.rs.incubator.service.scriptdatasource.transformers.ScriptDatasourceTransformer.transform(ScriptDatasourceTransformer.java:84)
at net.datenwerke.rs.core.service.datasourcemanager.datasourcetransformers.DatasourceDefinitionTransformerManager.transform(DatasourceDefinitionTransformerManager.java:49)
at net.datenwerke.rs.base.service.reportengines.table.TableReportEngine.doExecuteNormal(TableReportEngine.java:168)
at net.datenwerke.rs.base.service.reportengines.table.TableReportEngine.doExecuteNormal(TableReportEngine.java:148)
at net.datenwerke.rs.base.service.reportengines.table.TableReportEngine.doExecute(TableReportEngine.java:90)
at net.datenwerke.rs.core.service.reportmanager.engine.ReportEngine.execute(ReportEngine.java:127)
at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:186)
... 60 more
Caused by: java.lang.IllegalStateException: org.h2.jdbc.JdbcSQLException: Unknown data type: ","; SQL statement:
CREATE TABLE RS_SCR_TAB_15(
VARCHAR,
EMP_ID VARCHAR,
POSITION_TITLE VARCHAR,
REPLACE2 VARCHAR,
NAME VARCHAR,
BRANCH_CODE VARCHAR,
ID_NUM VARCHAR,
DOB VARCHAR,
GENDER VARCHAR,
BANK_ACCOUNT_NAME VARCHAR,
BANK_ACCOUNT_NUM VARCHAR,
EMAIL_ADDR VARCHAR,
SALARY VARCHAR,
GTL_SUM_INSURED VARCHAR,
GTL_PREMIUM VARCHAR,
ADD_SUM_INSURED VARCHAR,
ADD_PREMIUM VARCHAR,
MEDICAL_SUM_INSURED VARCHAR,
MEDICAL_PREMIUM VARCHAR,
GCL_SUM_INSURED VARCHAR,
GCL_PREMIUM VARCHAR,
MCU_SUM_INSURED VARCHAR,
MCU_PREMIUM VARCHAR,
TOTALPREMIUM VARCHAR
); [50004-180]
at net.datenwerke.rs.core.service.internaldb.InternalDbServiceImpl.getConnection(InternalDbServiceImpl.java:334)
at net.datenwerke.rs.incubator.service.scriptdatasource.transformers.ScriptToInMemoryDb.getConnection(ScriptToInMemoryDb.java:158)
... 69 more
Caused by: org.h2.jdbc.JdbcSQLException: Unknown data type: ","; SQL statement:
CREATE TABLE RS_SCR_TAB_15(
VARCHAR,
EMP_ID VARCHAR,
POSITION_TITLE VARCHAR,
REPLACE2 VARCHAR,
NAME VARCHAR,
BRANCH_CODE VARCHAR,
ID_NUM VARCHAR,
DOB VARCHAR,
GENDER VARCHAR,
BANK_ACCOUNT_NAME VARCHAR,
BANK_ACCOUNT_NUM VARCHAR,
EMAIL_ADDR VARCHAR,
SALARY VARCHAR,
GTL_SUM_INSURED VARCHAR,
GTL_PREMIUM VARCHAR,
ADD_SUM_INSURED VARCHAR,
ADD_PREMIUM VARCHAR,
MEDICAL_SUM_INSURED VARCHAR,
MEDICAL_PREMIUM VARCHAR,
GCL_SUM_INSURED VARCHAR,
GCL_PREMIUM VARCHAR,
MCU_SUM_INSURED VARCHAR,
MCU_PREMIUM VARCHAR,
TOTALPREMIUM VARCHAR
); [50004-180]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.Parser.parseColumnWithType(Parser.java:3962)
at org.h2.command.Parser.parseColumnForTable(Parser.java:3825)
at org.h2.command.Parser.parseCreateTable(Parser.java:5722)
at org.h2.command.Parser.parseCreate(Parser.java:4121)
at org.h2.command.Parser.parsePrepared(Parser.java:350)
at org.h2.command.Parser.parse(Parser.java:305)
at org.h2.command.Parser.parse(Parser.java:277)
at org.h2.command.Parser.prepareCommand(Parser.java:242)
at org.h2.engine.Session.prepareLocal(Session.java:446)
at org.h2.engine.Session.prepareCommand(Session.java:388)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1189)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:171)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:159)
at net.datenwerke.rs.core.service.internaldb.InternalDbTableCreator.createTable(InternalDbTableCreator.java:113)
at net.datenwerke.rs.core.service.internaldb.InternalDbServiceImpl.getConnection(InternalDbServiceImpl.java:317)
... 70 more

Last edited by marcosfilho (2014-12-12 00:11:22)

Offline

#4 2014-12-12 18:34:41

Thorsten J. Krause
Guest

Re: Internationalized reports?

Hi Marcos,

well it seems the ResourceBundle works smile To pass the current users locale to Jasper, you have to set the REPORT_LOCALE parameter.
This script adds the needed callback:

import net.datenwerke.rs.core.service.reportmanager.hooks.ParameterSetReplacementProviderHook;
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report;
import net.datenwerke.security.service.usermanager.entities.User;
import net.datenwerke.rs.core.service.reportmanager.parameters.*;
import net.datenwerke.rs.utils.localization.LocalizationServiceImpl;

def LocalizationServiceImpl localizationService = GLOBALS.getRsService(LocalizationServiceImpl.class);
replacementProvider = new ParameterSetReplacementProviderHook(){
	@Override
	public Collection<? extends ParameterSetReplacementProvider> getProviders() {
		Set<ParameterSetReplacementProvider> providers = new HashSet<ParameterSetReplacementProvider>();
		def testProvider = new ParameterSetReplacementProviderImpl() {
			@Override
			public Map<String, ParameterValue> provideReplacements(User user, Report report) {
				locale = localizationService.getLocale();
				Map<String, ParameterValue> res = new HashMap<String, ParameterValue>();
				res.put("REPORT_LOCALE", new ParameterValueImpl("REPORT_LOCALE",locale, String.class));
				return res;
			}
		};
		providers.add(testProvider);
		return providers;
	}
};	
GLOBALS.services.callbackRegistry.attachHook("LOCAL_PARAM_PROV", ParameterSetReplacementProviderHook.class, replacementProvider);

With script reports you can choose between a number of different methods to load localised texts, but if you are using ResouceBundles for jasper, it's probably a good idea to use the same mechanism for script reports, too.

Column names may not use special characters: Use ascii characters instead and use the DEFAULT_ALIAS mechanism to provide a localised text instead (dynamic list metadata datasource).

Cheers,
Thorsten

#5 2014-12-14 20:53:07

marcosfilho
Member
Registered: 2014-08-04

Re: Internationalized reports?

Thanks a lot, Thorsten.

Two questions:

1 - where should I place this script? should it go on on filesystem /bin/onlogin.d folder?

2 - please could you give me an example how to use the metadata datasource? imagine that  I have a RSTableModel with the headers: name, description.  those headers need to appear in Chinese on the report. how I can link them to the resourcebundle by using metadata?

thanks a lot.

Offline

#6 2014-12-15 03:52:33

marcosfilho
Member
Registered: 2014-08-04

Re: Internationalized reports?

i was able to create a dynamic list report with the following query:

select branch 北京市工商银行, name from bank

it works fine. the name of the column is that chinese name. interesting. but apparantly if I create the header of the RSTableModel from the datasource script, it doesnt work..

Offline

#7 2022-10-25 12:32:59

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Internationalized reports?

Hi,

pls note that as of ReportServer 4.4.0 the REPORT_LOCALE parameter will be sent automatically to the Jasper engine.

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB