diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index f8629176d..ed0637439 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -13419,6 +13419,12 @@ Request Body:
Valid Values are HTML, XLS, CSV and PDF for html, Excel, CSV and PDF formats respectively.
Only applies to Pentaho reports.
+
locale
+
+ optional +
+
Any valid locale Ex: en_US, en_IN, fr_FR etc
+
Only applies to Pentaho reports.

Example Requests:

runreports/Client%20Listing?R_officeId=1
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/ApiParameterHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/ApiParameterHelper.java index f599aa603..adec2c8f7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/ApiParameterHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/ApiParameterHelper.java @@ -9,12 +9,14 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import javax.ws.rs.core.MultivaluedMap; import org.apache.commons.lang.StringUtils; +import org.mifosplatform.infrastructure.core.serialization.JsonParserHelper; public class ApiParameterHelper { @@ -62,6 +64,15 @@ public class ApiParameterHelper { return prettyPrint; } + public static Locale extractLocale(final MultivaluedMap queryParams) { + Locale locale = null; + if (queryParams.getFirst("locale") != null) { + String localeAsString = queryParams.getFirst("locale"); + locale = JsonParserHelper.localeFromString(localeAsString); + } + return locale; + } + public static boolean exportCsv(final MultivaluedMap queryParams) { boolean exportCsv = false; if (queryParams.getFirst("exportCSV") != null) { @@ -128,7 +139,7 @@ public class ApiParameterHelper { public static boolean genericResultSetPassed(MultivaluedMap queryParams) { return queryParams.getFirst("genericResultSet") != null; } - + public static String sqlEncodeString(String str) { String singleQuote = "'"; String twoSingleQuotes = "''"; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/JsonParserHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/JsonParserHelper.java index 875a31202..f3b51db00 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/JsonParserHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/serialization/JsonParserHelper.java @@ -518,7 +518,7 @@ public class JsonParserHelper { } } - private Locale localeFromString(final String localeAsString) { + public static Locale localeFromString(final String localeAsString) { if (StringUtils.isBlank(localeAsString)) { List dataValidationErrors = new ArrayList(); @@ -531,7 +531,7 @@ public class JsonParserHelper { } String languageCode = ""; - String courntryCode = ""; + String countryCode = ""; String variantCode = ""; String[] localeParts = localeAsString.split("_"); @@ -542,19 +542,19 @@ public class JsonParserHelper { if (localeParts != null && localeParts.length == 2) { languageCode = localeParts[0]; - courntryCode = localeParts[1]; + countryCode = localeParts[1]; } if (localeParts != null && localeParts.length == 3) { languageCode = localeParts[0]; - courntryCode = localeParts[1]; + countryCode = localeParts[1]; variantCode = localeParts[2]; } - return localeFrom(languageCode, courntryCode, variantCode); + return localeFrom(languageCode, countryCode, variantCode); } - private Locale localeFrom(final String languageCode, final String courntryCode, final String variantCode) { + private static Locale localeFrom(final String languageCode, final String courntryCode, final String variantCode) { List dataValidationErrors = new ArrayList(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/RunreportsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/RunreportsApiResource.java index bb5c20124..9a9b40dcf 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/RunreportsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/RunreportsApiResource.java @@ -7,6 +7,7 @@ package org.mifosplatform.infrastructure.dataqueries.api; import java.io.File; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -41,158 +42,123 @@ import org.springframework.stereotype.Component; @Scope("singleton") public class RunreportsApiResource { - private final PlatformSecurityContext context; - private final ToApiJsonSerializer toApiJsonSerializer; - private final ReadReportingService readExtraDataAndReportingService; - private final GenericDataService genericDataService; + private final PlatformSecurityContext context; + private final ToApiJsonSerializer toApiJsonSerializer; + private final ReadReportingService readExtraDataAndReportingService; + private final GenericDataService genericDataService; - @Autowired - public RunreportsApiResource(final PlatformSecurityContext context, - final ReadReportingService readExtraDataAndReportingService, - final GenericDataService genericDataService, - final ToApiJsonSerializer toApiJsonSerializer) { - this.context = context; - this.readExtraDataAndReportingService = readExtraDataAndReportingService; - this.genericDataService = genericDataService; - this.toApiJsonSerializer = toApiJsonSerializer; - } + @Autowired + public RunreportsApiResource(final PlatformSecurityContext context, final ReadReportingService readExtraDataAndReportingService, + final GenericDataService genericDataService, final ToApiJsonSerializer toApiJsonSerializer) { + this.context = context; + this.readExtraDataAndReportingService = readExtraDataAndReportingService; + this.genericDataService = genericDataService; + this.toApiJsonSerializer = toApiJsonSerializer; + } - @GET - @Path("{reportName}") - @Consumes({ MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload", - "application/vnd.ms-excel", "application/pdf", "text/html" }) - public Response runReport(@PathParam("reportName") final String reportName, - @Context final UriInfo uriInfo) { + @GET + @Path("{reportName}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload", "application/vnd.ms-excel", "application/pdf", "text/html" }) + public Response runReport(@PathParam("reportName") final String reportName, @Context final UriInfo uriInfo) { - MultivaluedMap queryParams = uriInfo - .getQueryParameters(); + MultivaluedMap queryParams = uriInfo.getQueryParameters(); - boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo - .getQueryParameters()); - boolean exportCsv = ApiParameterHelper.exportCsv(uriInfo - .getQueryParameters()); - boolean parameterType = ApiParameterHelper.parameterType(uriInfo - .getQueryParameters()); - boolean exportPdf = ApiParameterHelper.exportPdf(uriInfo - .getQueryParameters()); + boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); + boolean exportCsv = ApiParameterHelper.exportCsv(uriInfo.getQueryParameters()); + boolean parameterType = ApiParameterHelper.parameterType(uriInfo.getQueryParameters()); + boolean exportPdf = ApiParameterHelper.exportPdf(uriInfo.getQueryParameters()); - checkUserPermissionForReport(reportName, parameterType); + checkUserPermissionForReport(reportName, parameterType); - String parameterTypeValue = null; - if (!parameterType) { - parameterTypeValue = "report"; - if (this.readExtraDataAndReportingService.getReportType(reportName) - .equalsIgnoreCase("Pentaho")) { - Map reportParams = getReportParams(queryParams, - true); - return this.readExtraDataAndReportingService - .processPentahoRequest(reportName, - queryParams.getFirst("output-type"), - reportParams); - } - } else { - parameterTypeValue = "parameter"; - } + String parameterTypeValue = null; + if (!parameterType) { + parameterTypeValue = "report"; + if (this.readExtraDataAndReportingService.getReportType(reportName).equalsIgnoreCase("Pentaho")) { + Map reportParams = getReportParams(queryParams, true); + Locale locale = ApiParameterHelper.extractLocale(queryParams); + return this.readExtraDataAndReportingService.processPentahoRequest(reportName, queryParams.getFirst("output-type"), + reportParams, locale); + } + } else { + parameterTypeValue = "parameter"; + } - // PDF format + // PDF format - if (exportPdf) { - Map reportParams = getReportParams(queryParams, - false); - String pdfFileName = this.readExtraDataAndReportingService - .retrieveReportPDF(reportName, parameterTypeValue, - reportParams); + if (exportPdf) { + Map reportParams = getReportParams(queryParams, false); + String pdfFileName = this.readExtraDataAndReportingService.retrieveReportPDF(reportName, parameterTypeValue, reportParams); - File file = new File(pdfFileName); + File file = new File(pdfFileName); - ResponseBuilder response = Response.ok(file); - response.header("Content-Disposition", "attachment; filename=\"" - + pdfFileName + "\""); - response.header("content-Type", "application/pdf"); + ResponseBuilder response = Response.ok(file); + response.header("Content-Disposition", "attachment; filename=\"" + pdfFileName + "\""); + response.header("content-Type", "application/pdf"); - return response.build(); + return response.build(); - } + } - if (!exportCsv) { - Map reportParams = getReportParams(queryParams, - false); + if (!exportCsv) { + Map reportParams = getReportParams(queryParams, false); - GenericResultsetData result = this.readExtraDataAndReportingService - .retrieveGenericResultset(reportName, parameterTypeValue, - reportParams); + GenericResultsetData result = this.readExtraDataAndReportingService.retrieveGenericResultset(reportName, parameterTypeValue, + reportParams); - String json = ""; - final boolean genericResultSetIsPassed = ApiParameterHelper - .genericResultSetPassed(uriInfo.getQueryParameters()); - final boolean genericResultSet = ApiParameterHelper - .genericResultSet(uriInfo.getQueryParameters()); - if (genericResultSetIsPassed) { - if (genericResultSet) { - json = this.toApiJsonSerializer.serializePretty( - prettyPrint, result); - } else { - json = this.genericDataService - .generateJsonFromGenericResultsetData(result); - } - } else { - json = this.toApiJsonSerializer.serializePretty(prettyPrint, - result); - } + String json = ""; + final boolean genericResultSetIsPassed = ApiParameterHelper.genericResultSetPassed(uriInfo.getQueryParameters()); + final boolean genericResultSet = ApiParameterHelper.genericResultSet(uriInfo.getQueryParameters()); + if (genericResultSetIsPassed) { + if (genericResultSet) { + json = this.toApiJsonSerializer.serializePretty(prettyPrint, result); + } else { + json = this.genericDataService.generateJsonFromGenericResultsetData(result); + } + } else { + json = this.toApiJsonSerializer.serializePretty(prettyPrint, result); + } - return Response.ok().entity(json).type(MediaType.APPLICATION_JSON) - .build(); - } + return Response.ok().entity(json).type(MediaType.APPLICATION_JSON).build(); + } - // CSV Export - Map reportParams = getReportParams(queryParams, false); - StreamingOutput result = this.readExtraDataAndReportingService - .retrieveReportCSV(reportName, parameterTypeValue, reportParams); + // CSV Export + Map reportParams = getReportParams(queryParams, false); + StreamingOutput result = this.readExtraDataAndReportingService.retrieveReportCSV(reportName, parameterTypeValue, reportParams); - return Response - .ok() - .entity(result) - .type("application/x-msdownload") - .header("Content-Disposition", - "attachment;filename=" + reportName.replaceAll(" ", "") - + ".csv").build(); - } + return Response.ok().entity(result).type("application/x-msdownload") + .header("Content-Disposition", "attachment;filename=" + reportName.replaceAll(" ", "") + ".csv").build(); + } - private void checkUserPermissionForReport(final String reportName, - final boolean parameterType) { + private void checkUserPermissionForReport(final String reportName, final boolean parameterType) { - // Anyone can run a 'report' that is simply getting possible parameter - // (dropdown listbox) values. - if (!parameterType) { - AppUser currentUser = context.authenticatedUser(); - if (currentUser.hasNotPermissionForReport(reportName)) { - throw new NoAuthorizationException( - "Not authorised to run report: " + reportName); - } - } - } + // Anyone can run a 'report' that is simply getting possible parameter + // (dropdown listbox) values. + if (!parameterType) { + AppUser currentUser = context.authenticatedUser(); + if (currentUser.hasNotPermissionForReport(reportName)) { throw new NoAuthorizationException("Not authorised to run report: " + + reportName); } + } + } - private Map getReportParams( - final MultivaluedMap queryParams, - final Boolean isPentaho) { + private Map getReportParams(final MultivaluedMap queryParams, final Boolean isPentaho) { - Map reportParams = new HashMap(); - Set keys = queryParams.keySet(); - String pKey; - String pValue; - for (String k : keys) { + Map reportParams = new HashMap(); + Set keys = queryParams.keySet(); + String pKey; + String pValue; + for (String k : keys) { - if (k.startsWith("R_")) { - if (isPentaho) - pKey = k.substring(2); - else - pKey = "${" + k.substring(2) + "}"; + if (k.startsWith("R_")) { + if (isPentaho) + pKey = k.substring(2); + else + pKey = "${" + k.substring(2) + "}"; - pValue = queryParams.get(k).get(0); - reportParams.put(pKey, pValue); - } - } - return reportParams; - } + pValue = queryParams.get(k).get(0); + reportParams.put(pKey, pValue); + } + } + return reportParams; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java index f96e697d5..62c1bb572 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingService.java @@ -6,6 +6,7 @@ package org.mifosplatform.infrastructure.dataqueries.service; import java.util.Collection; +import java.util.Locale; import java.util.Map; import javax.ws.rs.core.Response; @@ -17,23 +18,19 @@ import org.mifosplatform.infrastructure.dataqueries.data.ReportParameterData; public interface ReadReportingService { - StreamingOutput retrieveReportCSV(String name, String type, - Map extractedQueryParams); + StreamingOutput retrieveReportCSV(String name, String type, Map extractedQueryParams); - GenericResultsetData retrieveGenericResultset(String name, String type, - Map extractedQueryParams); + GenericResultsetData retrieveGenericResultset(String name, String type, Map extractedQueryParams); - Response processPentahoRequest(String reportName, String outputType, - Map queryParams); + Response processPentahoRequest(String reportName, String outputType, Map queryParams, Locale locale); - String retrieveReportPDF(String name, String type, - Map extractedQueryParams); + String retrieveReportPDF(String name, String type, Map extractedQueryParams); - String getReportType(String reportName); + String getReportType(String reportName); - Collection retrieveReportList(); + Collection retrieveReportList(); - Collection getAllowedParameters(); + Collection getAllowedParameters(); - ReportData retrieveReport(final Long id); + ReportData retrieveReport(final Long id); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java index cace21ef3..a8c5ddcb6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadReportingServiceImpl.java @@ -19,6 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -41,6 +42,7 @@ import org.mifosplatform.infrastructure.documentmanagement.contentrepository.Fil import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.useradministration.domain.AppUser; import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot; +import org.pentaho.reporting.engine.classic.core.DefaultReportEnvironment; import org.pentaho.reporting.engine.classic.core.MasterReport; import org.pentaho.reporting.engine.classic.core.ReportProcessingException; import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil; @@ -231,7 +233,8 @@ public class ReadReportingServiceImpl implements ReadReportingService { } @Override - public Response processPentahoRequest(final String reportName, final String outputTypeParam, final Map queryParams) { + public Response processPentahoRequest(final String reportName, final String outputTypeParam, final Map queryParams, + final Locale locale) { String outputType = "HTML"; if (StringUtils.isNotBlank(outputTypeParam)) outputType = outputTypeParam; @@ -243,7 +246,8 @@ public class ReadReportingServiceImpl implements ReadReportingService { if (noPentaho) { throw new PlatformDataIntegrityException("error.msg.no.pentaho", "Pentaho is not enabled", "Pentaho is not enabled"); } - final String reportPath = FileSystemContentRepository.MIFOSX_BASE_DIR + File.separator + "pentahoReports" + File.separator + reportName + ".prpt"; + final String reportPath = FileSystemContentRepository.MIFOSX_BASE_DIR + File.separator + "pentahoReports" + File.separator + + reportName + ".prpt"; logger.info("Report path: " + reportPath); // load report definition @@ -254,7 +258,10 @@ public class ReadReportingServiceImpl implements ReadReportingService { try { res = manager.createDirectly(reportPath, MasterReport.class); MasterReport masterReport = (MasterReport) res.getResource(); - + DefaultReportEnvironment reportEnvironment = (DefaultReportEnvironment) masterReport.getReportEnvironment(); + if (locale != null) { + reportEnvironment.setLocale(locale); + } addParametersToReport(masterReport, queryParams); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -336,12 +343,9 @@ public class ReadReportingServiceImpl implements ReadReportingService { // data scoping Connection connection = dataSource.getConnection(); String tenantdb; - try - { + try { tenantdb = connection.getCatalog(); - } - finally - { + } finally { connection.close(); } String userhierarchy = currentUser.getOffice().getHierarchy(); @@ -467,8 +471,8 @@ public class ReadReportingServiceImpl implements ReadReportingService { if (reportParameters == null) { reportParameters = new ArrayList(); } - reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(), rpJoin.getParameterId(), rpJoin.getReportParameterName(), rpJoin - .getParameterName())); + reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(), rpJoin.getParameterId(), rpJoin + .getReportParameterName(), rpJoin.getParameterName())); } else { if (firstReport) { @@ -494,8 +498,8 @@ public class ReadReportingServiceImpl implements ReadReportingService { if (rpJoin.getReportParameterId() != null) { // report has at least one parameter reportParameters = new ArrayList(); - reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(),rpJoin.getParameterId(), rpJoin.getReportParameterName(), rpJoin - .getParameterName())); + reportParameters.add(new ReportParameterData(rpJoin.getReportParameterId(), rpJoin.getParameterId(), rpJoin + .getReportParameterName(), rpJoin.getParameterName())); } else { reportParameters = null; } @@ -509,17 +513,15 @@ public class ReadReportingServiceImpl implements ReadReportingService { return reportList; } + @Override + public Collection getAllowedParameters() { - @Override - public Collection getAllowedParameters() { - ReportParameterMapper rm = new ReportParameterMapper(); String sql = rm.schema(); Collection parameters = this.jdbcTemplate.query(sql, rm, new Object[] {}); return parameters; - } - - + } + private static final class ReportParameterJoinMapper implements RowMapper { public String schema(final Long reportId) { diff --git a/mifosng-provider/src/main/pentahoReports/Balance Sheet.prpt b/mifosng-provider/src/main/pentahoReports/Balance Sheet.prpt index 566149fb6..6d77a583e 100644 Binary files a/mifosng-provider/src/main/pentahoReports/Balance Sheet.prpt and b/mifosng-provider/src/main/pentahoReports/Balance Sheet.prpt differ diff --git a/mifosng-provider/src/main/pentahoReports/Income Statement.prpt b/mifosng-provider/src/main/pentahoReports/Income Statement.prpt index a6f14e818..7bc532dfd 100644 Binary files a/mifosng-provider/src/main/pentahoReports/Income Statement.prpt and b/mifosng-provider/src/main/pentahoReports/Income Statement.prpt differ diff --git a/mifosng-provider/src/main/pentahoReports/Trial Balance.prpt b/mifosng-provider/src/main/pentahoReports/Trial Balance.prpt index 186d2b8dc..749f76105 100644 Binary files a/mifosng-provider/src/main/pentahoReports/Trial Balance.prpt and b/mifosng-provider/src/main/pentahoReports/Trial Balance.prpt differ diff --git a/mifosng-provider/src/main/pentahoReports/balanceSheet.properties b/mifosng-provider/src/main/pentahoReports/balanceSheet.properties index c48f08c4c..5fd8cf174 100644 --- a/mifosng-provider/src/main/pentahoReports/balanceSheet.properties +++ b/mifosng-provider/src/main/pentahoReports/balanceSheet.properties @@ -11,6 +11,3 @@ totalEquities=Total Equities : branchName=Branch : asOn=As On : retainedEarnings=Retained Earnings -PrintedBy\:=Printed by: -On\:=On: -Page=Page \ No newline at end of file diff --git a/mifosng-provider/src/main/pentahoReports/incomeStatement.properties b/mifosng-provider/src/main/pentahoReports/incomeStatement.properties index ed0f68931..1fcfad6d7 100644 --- a/mifosng-provider/src/main/pentahoReports/incomeStatement.properties +++ b/mifosng-provider/src/main/pentahoReports/incomeStatement.properties @@ -8,8 +8,8 @@ expenses=Expenses totalExpenses=Total Expenses : netIncome=Net Income : branchName=Branch : -from=From : -to=To : +period=Period: +to=To PrintedBy\:=Printed by: On\:=On: Page=Page \ No newline at end of file diff --git a/mifosng-provider/src/main/pentahoReports/trialBalance.properties b/mifosng-provider/src/main/pentahoReports/trialBalance.properties index cd8151fc3..1ab1bc42d 100644 --- a/mifosng-provider/src/main/pentahoReports/trialBalance.properties +++ b/mifosng-provider/src/main/pentahoReports/trialBalance.properties @@ -9,4 +9,6 @@ name=Name total=Total : PrintedBy\:=Printed by: On\:=On: -Page=Page \ No newline at end of file +Page=Page +period=Period: +to=To \ No newline at end of file