add pentaho reporting (but disabled at the moment)
This commit is contained in:
+25
-10
@@ -19,6 +19,7 @@ import javax.sql.DataSource;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosng.platform.api.data.AdditionalFieldsSet;
|
||||
import org.mifosng.platform.api.data.GenericResultset;
|
||||
import org.mifosng.platform.api.data.ResultsetColumnHeader;
|
||||
@@ -50,13 +51,14 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
|
||||
private final DataSource dataSource;
|
||||
private final String reportingMetaDataDB;
|
||||
private Boolean noPentaho = false;
|
||||
|
||||
@Autowired
|
||||
public ReadExtraDataAndReportingServiceImpl(final DataSource dataSource) {
|
||||
//kick off pentaho reports server
|
||||
ClassicEngineBoot.getInstance().start();
|
||||
|
||||
|
||||
// kick off pentaho reports server
|
||||
// ClassicEngineBoot.getInstance().start();
|
||||
noPentaho = true;
|
||||
|
||||
try {
|
||||
this.dataSource = dataSource;
|
||||
Connection db_connection = dataSource.getConnection();
|
||||
@@ -714,15 +716,28 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
e.getMessage(), "Error closing database connection");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Response processPentahoRequest(String reportName,
|
||||
String outputType, Map<String, String> queryParams) {
|
||||
public Response processPentahoRequest(String reportName, String outputTypeParam,
|
||||
Map<String, String> queryParams) {
|
||||
|
||||
String outputType = "HTML";
|
||||
if (StringUtils.isNotBlank(outputTypeParam)) outputType = outputTypeParam;
|
||||
|
||||
if (!(outputType.equalsIgnoreCase("HTML") || outputType.equalsIgnoreCase("PDF") || outputType.equalsIgnoreCase("XLS") || outputType.equalsIgnoreCase("CSV")))
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.invalid.outputType", "No matching Output Type: "
|
||||
+ outputType);
|
||||
|
||||
if (noPentaho)
|
||||
throw new PlatformDataIntegrityException("error.msg.no.pentaho",
|
||||
"Pentaho is not enabled", "Pentaho is not enabled");
|
||||
|
||||
//TODO - use pentaho location finder like Pawel does in Mifos
|
||||
String reportPath = "C:\\dev\\apache-tomcat-7.0.25\\webapps\\ROOT\\PentahoReports\\"
|
||||
+ reportName + ".prpt";
|
||||
// String reportPath =
|
||||
// "/var/lib/tomcat6/webapps/ROOT/PentahoReports/"
|
||||
// "/var/lib/tomcat7/webapps/ROOT/PentahoReports/"
|
||||
// + reportName + ".prpt";
|
||||
logger.info("Report path: " + reportPath);
|
||||
|
||||
@@ -770,7 +785,7 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
|
||||
if ("HTML".equalsIgnoreCase(outputType)) {
|
||||
HtmlReportUtil.createStreamHTML(masterReport, baos);
|
||||
return Response.ok().entity(baos.toByteArray()).build();
|
||||
return Response.ok().entity(baos.toByteArray()).type("text/html").build();
|
||||
}
|
||||
} catch (ResourceException e) {
|
||||
throw new PlatformDataIntegrityException(
|
||||
@@ -788,5 +803,5 @@ public class ReadExtraDataAndReportingServiceImpl implements
|
||||
+ outputType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -26,6 +27,6 @@ public class PlatformDataIntegrityExceptionMapper implements ExceptionMapper<Pla
|
||||
ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.dataIntegrityError(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(),
|
||||
exception.getParameterName(), exception.getDefaultUserMessageArgs());
|
||||
|
||||
return Response.status(Status.FORBIDDEN).entity(dataIntegrityError).build();
|
||||
return Response.status(Status.FORBIDDEN).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+9
-14
@@ -15,16 +15,11 @@ import org.codehaus.jackson.map.ser.FilterProvider;
|
||||
import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter;
|
||||
import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider;
|
||||
import org.mifosng.platform.exceptions.PlatformInternalServerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(ApiJSONFormattingServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public String convertRequest(Object dataObject, String filterName,
|
||||
String allowedFieldList, String selectedFields,
|
||||
@@ -111,18 +106,18 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
String associationFields, String param, String filterType) {
|
||||
|
||||
if (isPassed(param)) {
|
||||
//logger.info("is associations");
|
||||
// logger.info("is associations");
|
||||
if (param.equalsIgnoreCase("ALL")) {
|
||||
//logger.info("is ALL");
|
||||
// logger.info("is ALL");
|
||||
if (filterType.equals("I")) {
|
||||
//logger.info("is Include");
|
||||
// logger.info("is Include");
|
||||
return fieldList + "," + associationFields;
|
||||
}
|
||||
//logger.info("is Exclude");
|
||||
// logger.info("is Exclude");
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
//logger.info("Not ALL");
|
||||
// logger.info("Not ALL");
|
||||
Set<String> fullAssociationsSet = createSetFromString(associationFields);
|
||||
Set<String> paramAssociationsSet = createSetFromString(param);
|
||||
|
||||
@@ -130,15 +125,15 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
|
||||
String selectedAssociationFields = createIncludedInStringList(
|
||||
paramAssociationsSet, fullAssociationsSet);
|
||||
//logger.info("is Include - selected fields are :"
|
||||
// + selectedAssociationFields);
|
||||
// logger.info("is Include - selected fields are :"
|
||||
// + selectedAssociationFields);
|
||||
return fieldList + "," + selectedAssociationFields;
|
||||
}
|
||||
|
||||
String unSelectedAssociationFields = createNotIncludedInStringList(
|
||||
fullAssociationsSet, paramAssociationsSet);
|
||||
//logger.info("is Exclude - unselected fields are :"
|
||||
// + unSelectedAssociationFields);
|
||||
// logger.info("is Exclude - unselected fields are :"
|
||||
// + unSelectedAssociationFields);
|
||||
|
||||
if (fieldList.equals("")) {
|
||||
return unSelectedAssociationFields;
|
||||
|
||||
-167
@@ -1,167 +0,0 @@
|
||||
package org.mifosng.platform.infrastructure;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
//@Controller
|
||||
public class PentahoReportingController //implements ServletContextAware
|
||||
{
|
||||
|
||||
// private int reportNum = 0; // used for building HTML reports
|
||||
// private ServletContext myServletContext;
|
||||
|
||||
//private final static Logger logger = LoggerFactory.getLogger(PentahoReportingController.class);
|
||||
|
||||
public PentahoReportingController() {
|
||||
|
||||
// JPW commented out for now ClassicEngineBoot.getInstance().start();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pentahoreport", method = RequestMethod.GET)
|
||||
public void handlePentahoReport(final HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException {
|
||||
/* JPW commented out for now
|
||||
try {
|
||||
// load report definition
|
||||
ResourceManager manager = new ResourceManager();
|
||||
manager.registerDefaults();
|
||||
|
||||
// various ways of pointing to the report directory - hardcoded here
|
||||
// for testing so if you put the test.prpt in a directory
|
||||
// c:\dev\PentahoTestReports it should find it
|
||||
|
||||
// String reportPath = "file:" +
|
||||
// this.getServletContext().getRealPath(request.getParameter("pentahoReportName"));
|
||||
// String reportPath = "file:" + request.getServletPath();
|
||||
// String reportPath =
|
||||
// "http://ec2-46-137-17-252.eu-west-1.compute.amazonaws.com:8080/PentahoReports/"
|
||||
// + request.getParameter("pentahoReportName") + ".prpt";
|
||||
// String reportPath = "file:///C:/dev/mifosbiGithub/bi/reports/standardReports/prpts/" + request.getParameter("pentahoReportName") + ".prpt";
|
||||
|
||||
String reportPath = "file:///C:/dev/PentahoTestReports/"
|
||||
+ request.getParameter("pentahoReportName") + ".prpt";
|
||||
|
||||
logger.info("pentahoReportName: "
|
||||
+ request.getParameter("pentahoReportName"));
|
||||
logger.info("Report path: " + reportPath);
|
||||
|
||||
Resource res = manager.createDirectly(new URL(reportPath),
|
||||
MasterReport.class);
|
||||
MasterReport report = (MasterReport) res.getResource();
|
||||
ReportParameterValues rptParamValues = report.getParameterValues();
|
||||
|
||||
String name;
|
||||
String value;
|
||||
@SuppressWarnings("unchecked")
|
||||
Enumeration<String> parms = request.getParameterNames();
|
||||
while (parms.hasMoreElements()) {
|
||||
// Get the name of the request parameter
|
||||
name = (String) parms.nextElement();
|
||||
logger.info("parm name: " + name);
|
||||
|
||||
if (!((name.equals("pentahoReportName")) || (name
|
||||
.equals("output-type")))) {
|
||||
// Get the value of the request parameter
|
||||
value = request.getParameter(name);
|
||||
rptParamValues.put(name, value);
|
||||
logger.info("parm name: " + name + " parm value: "
|
||||
+ value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String outputType = request.getParameter("output-type");
|
||||
|
||||
if ("PDF".equals(outputType)) {
|
||||
response.setContentType("application/pdf");
|
||||
PdfReportUtil.createPDF(report, response.getOutputStream());
|
||||
} else if ("XLS".equals(outputType)) {
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
try {
|
||||
ExcelReportUtil.createXLS(report,
|
||||
response.getOutputStream());
|
||||
} catch (ReportProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if ("HTML".equals(outputType)) {
|
||||
String reportLoc = "report_" + reportNum++;
|
||||
|
||||
logger.info("request context path: " + request.getContextPath());
|
||||
logger.info("request.getServletPath(): "
|
||||
+ request.getServletPath());
|
||||
|
||||
logger.info("hopoe: "
|
||||
+ myServletContext.getRealPath(request.getContextPath()));
|
||||
String path = myServletContext
|
||||
.getRealPath("../ROOT/PentahoHTMLReports/" + reportLoc);
|
||||
logger.info("The path is: " + path);
|
||||
|
||||
File folder = new File(path);
|
||||
folder.mkdir();
|
||||
try {
|
||||
HtmlReportUtil.createDirectoryHTML(report, path
|
||||
+ File.separator + "index.html");
|
||||
} catch (ReportProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String redirectLink = "/PentahoHTMLReports/" + reportLoc
|
||||
+ "/index.html";
|
||||
logger.info(redirectLink);
|
||||
response.sendRedirect(redirectLink);
|
||||
} else {
|
||||
response.setContentType("application/rtf");
|
||||
try {
|
||||
RTFReportUtil.createRTF(report, response.getOutputStream());
|
||||
} catch (ReportProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (ResourceException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
|
||||
/* jpw comment out
|
||||
@Override
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
myServletContext = servletContext;
|
||||
String pentahoHTMLFolderName = myServletContext
|
||||
.getRealPath("../ROOT/PentahoHTMLReports");
|
||||
|
||||
if (pentahoHTMLFolderName == null) {
|
||||
logger.info("pentaho HTML directory doesn't exist for non-Tomcat use");
|
||||
} else {
|
||||
File pentahoHTMLFolder = new File(pentahoHTMLFolderName);
|
||||
if (!(deleteDir(pentahoHTMLFolder)))
|
||||
logger.info("Failed to delete folder: "
|
||||
+ pentahoHTMLFolder.getName());
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
// Deletes all files and subdirectories under dir.
|
||||
// Returns true if all deletions were successful.
|
||||
// If a deletion fails, the method stops attempting to delete and returns
|
||||
// false.
|
||||
// private static boolean deleteDir(File dir) {
|
||||
// if (dir.isDirectory()) {
|
||||
// String[] children = dir.list();
|
||||
// for (int i = 0; i < children.length; i++) {
|
||||
// boolean success = deleteDir(new File(dir, children[i]));
|
||||
// if (!success) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // The directory is now empty so delete it
|
||||
// return dir.delete();
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user