Title: Message Title
|
|
|
Currently the Pentaho reports work in a multi-tenant environment as follows.
Code located at https://github.com/openMF/mifosx/blob/develop/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java#L241
1) Tenant Database name is passed into the report along with user hierarchy for datascoping. Global scripting is used within the pentaho report to form the right URL for the tenant database ( since the host and port are not passed to the pentaho report, global scripting assumes that tenant database is located on localhost on port 3306 ) 2) The default data source configured in the report has the right default credentials for connecting to this tenant database. The same are is used for connecting to the tenant database.
All 4 parameters need to be passed to the report (port, host,username and password)
I took a quick stab at the same, but seem to be running into issues with the Global Configuration in pentaho . ..
The changes made were as follows
Passing in host , port, username and password from the java class (No issues here)
{code:title=ReadReportingServiceImpl.java|borderStyle=solid} for (final ParameterDefinitionEntry paramDefEntry : paramsDefinition.getParameterDefinitions()) { final String paramName = paramDefEntry.getName(); if (!((paramName.equals("tenantdb")) || (paramName.equals("userhierarchy")) || (paramName.equals("host")) || (paramName.equals("port")) || (paramName.equals("username")) || (paramName.equals("password")))) { logger.info("paramName:" + paramName); final String pValue = queryParams.get(paramName); if (StringUtils.isBlank(pValue)) { throw new PlatformDataIntegrityException("error.msg.reporting.error", "Pentaho Parameter: " + paramName + " - not Provided"); }
final Class<?> clazz = paramDefEntry.getValueType(); logger.info("addParametersToReport(" + paramName + " : " + pValue + " : " + clazz.getCanonicalName() + ")"); if (clazz.getCanonicalName().equalsIgnoreCase("java.lang.Integer")) { rptParamValues.put(paramName, Integer.parseInt(pValue)); } else if (clazz.getCanonicalName().equalsIgnoreCase("java.lang.Long")) { rptParamValues.put(paramName, Long.parseLong(pValue)); } else if (clazz.getCanonicalName().equalsIgnoreCase("java.sql.Date")) { rptParamValues.put(paramName, Date.valueOf(pValue)); } else { rptParamValues.put(paramName, pValue); } }
}
/** * tenant database name and current user's office hierarchy passed * as parameters to allow multitenant penaho reporting and data * scoping **/ final Connection connection = this.dataSource.getConnection(); String tenantdb; try { tenantdb = connection.getCatalog(); } finally { connection.close(); } final String userhierarchy = currentUser.getOffice().getHierarchy(); logger.info("db name:" + tenantdb + " userhierarchy:" + userhierarchy); rptParamValues.put("tenantdb", tenantdb); rptParamValues.put("userhierarchy", userhierarchy);
// Also pass in all Tenant Properties to pentaho report final MifosPlatformTenant tenant = ThreadLocalContextUtil.getTenant(); rptParamValues.put("host", tenant.getSchemaServer()); rptParamValues.put("port", tenant.getSchemaServerPort()); rptParamValues.put("username", tenant.getSchemaUsername()); rptParamValues.put("password", tenant.getSchemaPassword()); {code}
Updating Global scripting in Pentaho report
{code} function init(dataRow) { // place all initialization logic here. This is the right space to // prepare complex lookup tables or to fill global variables.
// this method is called once when the data-source is first used. var tenantdb = dataRow.get("tenantdb"); var host = dataRow.get("host"); var port = dataRow.get("port"); var user = dataRow.get("username"); var password = dataRow.get("password"); var tenantUrl = "jdbc:mysql://"+ host +":"+ port + "/" + tenantdb; dataFactory.getConnectionProvider().setProperty("user", user); dataFactory.getConnectionProvider().setProperty("password", password); dataFactory.getConnectionProvider().setUrl(tenantUrl); }
function shutdown() { // place all shutdown logic here. If you use any persistent resources // like files or connections make sure you close them here.
// this method is called once during the data-source shut-down. It // will be called after all query scripts have been shut down.
}
{code}
Also parameters for the 4 new String properties were added to Pentaho
Ended up getting this error.......Wonder why the port number isn't being passed correctly (there isnt isn't any issue with the java bit. need to have a relook at the Global Scripting changes in Pentaho...
{noformat}
ParentException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "null"'. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
{noformat}
|
|
|
|
|
|
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Mifos-issues mailing list
Mifos-issues@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mifos-issues