WIP refactor api - export csv refactorings so its just an extra parameter to reports resource (looking very nice)
This commit is contained in:
+1
-2
@@ -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 = '<iframe id=rptLoadingFrame src="' + fullExportUrl + '" frameborder="0" onload="jQuery.stretchyReporting.clearLoadingImg();" width="100%" height="600px" style="background:url(';
|
||||
loadHTML += "'" + loadingImg + "'" + ') no-repeat scroll 50% 100px;"><p>Your browser does not support iframes.</p></iframe>';
|
||||
+1
-1
@@ -16,6 +16,6 @@
|
||||
<script type="text/javascript" src="${resValue}/libs/DataTables-1.8.2/extras/TableTools/media/js/TableTools.min.js"></script>
|
||||
<script type="text/javascript" src="${resValue}/libs/jquery.i18n.properties-min-1.0.9.js"></script>
|
||||
<script type="text/javascript" src="${resValue}/libs/OAuthSimple.js"></script>
|
||||
<script type="text/javascript" src="${resValue}/stretchyreporting/stretchyreporting-0.965.js"></script>
|
||||
<script type="text/javascript" src="${resValue}/stretchyreporting/stretchyreporting-0.966.js"></script>
|
||||
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
|
||||
+5
-6
@@ -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<String, String> extractedQueryParams);
|
||||
|
||||
//@PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')")
|
||||
StreamingOutput retrieveReportCSV(String rptDB, String name, String type,
|
||||
Map<String, String> extractedQueryParams);
|
||||
|
||||
// @PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')")
|
||||
GenericResultset retrieveGenericResultset(String rptDB, String name,
|
||||
String type, Map<String, String> extractedQueryParams);
|
||||
|
||||
|
||||
ExtraDatasets retrieveExtraDatasetNames(String datasetType);
|
||||
|
||||
GenericResultset retrieveExtraData(String datasetType, String datasetName,
|
||||
|
||||
+23
-24
@@ -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<String, String> 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,
|
||||
|
||||
@@ -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<String, String> extractedQueryParams = new HashMap<String, String>();
|
||||
|
||||
@@ -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<String, String> queryParams = uriInfo
|
||||
.getQueryParameters();
|
||||
String rptDB = queryParams.getFirst("MRP_rptDB");
|
||||
String name = queryParams.getFirst("MRP_Name");
|
||||
String type = queryParams.getFirst("MRP_Type");
|
||||
|
||||
Map<String, String> extractedQueryParams = new HashMap<String, String>();
|
||||
|
||||
Set<String> 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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user