diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.965.js b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.966.js similarity index 99% rename from mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.965.js rename to mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.966.js index 1c708b844..284f3b01a 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.965.js +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/stretchyreporting/stretchyreporting-0.966.js @@ -1104,8 +1104,7 @@ function getExportCSV(inParams) { //paramCount = paramCount + 1; } - //var fullExportUrl = RESTUrl + inQueryParameters + "&exportCSV=true"; - var fullExportUrl = RESTUrl + "/exportjpw" + inQueryParameters; + var fullExportUrl = RESTUrl + inQueryParameters + "&exportCSV=true"; showMsg("full export url: " + fullExportUrl); var loadHTML = ''; diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp index c6ab9283e..dd83cba61 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/common-head-stretchyreporting.jsp @@ -16,6 +16,6 @@ - + diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingService.java b/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingService.java index 33f953d8a..5a360986f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingService.java @@ -1,6 +1,5 @@ package org.mifosng.platform; -import java.io.OutputStream; import java.util.Map; import javax.ws.rs.core.StreamingOutput; @@ -10,13 +9,13 @@ import org.mifosng.data.reports.GenericResultset; public interface ReadExtraDataAndReportingService { - StreamingOutput retrieveReportCSV(String rptDB, String name, - String type, Map extractedQueryParams); - - //@PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')") + StreamingOutput retrieveReportCSV(String rptDB, String name, String type, + Map extractedQueryParams); + + // @PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')") GenericResultset retrieveGenericResultset(String rptDB, String name, String type, Map extractedQueryParams); - + ExtraDatasets retrieveExtraDatasetNames(String datasetType); GenericResultset retrieveExtraData(String datasetType, String datasetName, diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java index b67d643f8..797993d66 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/ReadExtraDataAndReportingServiceImpl.java @@ -44,40 +44,40 @@ public class ReadExtraDataAndReportingServiceImpl implements this.dataSource = dataSource; } - @Override public StreamingOutput retrieveReportCSV(final String rptDB, final String name, final String type, final Map queryParams) { return new StreamingOutput() { - public void write(OutputStream out) throws IOException, WebApplicationException { - try { + public void write(OutputStream out) throws IOException, + WebApplicationException { + try { - GenericResultset result = retrieveGenericResultset(rptDB, name, type, queryParams); - StringBuffer sb = generateCsvFileBuffer(result); + GenericResultset result = retrieveGenericResultset(rptDB, + name, type, queryParams); + StringBuffer sb = generateCsvFileBuffer(result); - InputStream in = new ByteArrayInputStream(sb.toString().getBytes( - "UTF-8")); + InputStream in = new ByteArrayInputStream(sb.toString() + .getBytes("UTF-8")); - byte[] outputByte = new byte[4096]; - Integer readLen = in.read(outputByte, 0, 4096); + byte[] outputByte = new byte[4096]; + Integer readLen = in.read(outputByte, 0, 4096); + + while (readLen != -1) { + out.write(outputByte, 0, readLen); + readLen = in.read(outputByte, 0, 4096); + } + // in.close(); + // out.flush(); + // out.close(); + } catch (Exception e) { + throw new WebApplicationException(e); + } + } + }; - while (readLen != -1) { - out.write(outputByte, 0, readLen); - readLen = in.read(outputByte, 0, 4096); - } - //in.close(); - //out.flush(); - //out.close(); - } catch (Exception e) { - throw new WebApplicationException(e); - } - } - }; - } - private static StringBuffer generateCsvFileBuffer(GenericResultset result) { StringBuffer writer = new StringBuffer(); @@ -125,7 +125,6 @@ public class ReadExtraDataAndReportingServiceImpl implements return writer; } - @Override public GenericResultset retrieveGenericResultset(final String rptDB, final String name, final String type, diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java index 5626ed643..4cfaccdfe 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java @@ -1,48 +1,30 @@ package org.mifosng.platform.api; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.OPTIONS; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; -import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.UriInfo; -import org.mifosng.data.ErrorResponse; -import org.mifosng.data.ErrorResponseList; import org.mifosng.data.reports.GenericResultset; -import org.mifosng.data.reports.ResultsetColumnHeader; -import org.mifosng.data.reports.ResultsetDataRow; import org.mifosng.platform.ReadExtraDataAndReportingService; -import org.mifosng.platform.exceptions.ApplicationDomainRuleException; -import org.mifosng.platform.exceptions.NewDataValidationException; -import org.mifosng.platform.exceptions.UnAuthenticatedUserException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; -import org.springframework.security.access.AccessDeniedException; import org.springframework.stereotype.Component; @Path("/v1/reports") @@ -104,7 +86,7 @@ public class ReportingApiResource { @GET @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @Produces({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload" }) public Response retrieveReport(@Context UriInfo uriInfo, @Context HttpServletResponse httpServletResponse) { @@ -113,6 +95,7 @@ public class ReportingApiResource { String rptDB = queryParams.getFirst("MRP_rptDB"); String name = queryParams.getFirst("MRP_Name"); String type = queryParams.getFirst("MRP_Type"); + String exportCSV = queryParams.getFirst("exportCSV"); Map extractedQueryParams = new HashMap(); @@ -129,47 +112,19 @@ public class ReportingApiResource { } } logger.info("BEGINNING REQUEST FOR: " + name); - GenericResultset result = this.ReadExtraDataAndReportingService - .retrieveGenericResultset(rptDB, name, type, - extractedQueryParams); - return makeCORS(Response.ok().entity(result)); - } + if ((exportCSV == null) || (!(exportCSV.equalsIgnoreCase("true")))) { + GenericResultset result = this.ReadExtraDataAndReportingService + .retrieveGenericResultset(rptDB, name, type, + extractedQueryParams); + return makeCORS(Response.ok().entity(result)); + } else { + StreamingOutput result = this.ReadExtraDataAndReportingService + .retrieveReportCSV(rptDB, name, type, extractedQueryParams); - @GET - @Path("/exportjpw") - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @Produces({ "application/x-msdownload" }) - public Response retrieveReportExport(@Context UriInfo uriInfo, - @Context HttpServletResponse httpServletResponse) { - - MultivaluedMap queryParams = uriInfo - .getQueryParameters(); - String rptDB = queryParams.getFirst("MRP_rptDB"); - String name = queryParams.getFirst("MRP_Name"); - String type = queryParams.getFirst("MRP_Type"); - - Map extractedQueryParams = new HashMap(); - - Set keys = queryParams.keySet(); - String pKey; - String pValue; - for (String k : keys) { - - if (k.startsWith("MRP_")) { - pKey = "${" + k.substring(4) + "}"; - pValue = queryParams.get(k).get(0); - - extractedQueryParams.put(pKey, pValue); - } + return makeCORSExport(Response.ok().entity(result), + name.replaceAll(" ", "") + ".csv"); } - logger.info("BEGINNING Export REQUEST FOR: " + name); - - StreamingOutput result = this.ReadExtraDataAndReportingService - .retrieveReportCSV(rptDB, name, type, extractedQueryParams); - - return makeCORSExport(Response.ok().entity(result), - name.replaceAll(" ", "") + ".csv"); }