WIP reporting refactor
This commit is contained in:
+1
-1
@@ -42,7 +42,7 @@ public class ReportingRestOperationsImpl implements ReportingRestOperations {
|
||||
public void hackToForceAuthentication() {
|
||||
try {
|
||||
URI restUri = URI
|
||||
.create(getBaseServerUrl().concat("api/protected/reporting/forceauth"));
|
||||
.create(getBaseServerUrl().concat("api/v1/flexiblereporting/forceauth"));
|
||||
|
||||
this.oauthRestServiceTemplate.exchange(restUri, HttpMethod.GET, emptyRequest(), null);
|
||||
} catch (HttpStatusCodeException e) {
|
||||
|
||||
+6
-2
@@ -1076,10 +1076,14 @@ function getReportDataNoAuth(inParams, successFunction) {
|
||||
$.ajax({
|
||||
url: RESTUrl,
|
||||
type:'GET',
|
||||
dataType: 'jsonp',
|
||||
dataType: 'json',
|
||||
data: inQueryParameters,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
crossDomain: true,
|
||||
crossDomain: false,
|
||||
//cache: true,
|
||||
beforeSend: function( xhr ) {
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
},
|
||||
success: successFunction,
|
||||
error:function(jqXHR, textStatus, errorThrown){
|
||||
showMsgE("getReportDataNoAuth: ");
|
||||
+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.95.js"></script>
|
||||
<script type="text/javascript" src="${resValue}/stretchyreporting/stretchyreporting-0.96.js"></script>
|
||||
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
|
||||
+7
-6
@@ -91,7 +91,8 @@ function selectNewThousandsSep(selectedVal) {
|
||||
|
||||
var reportingParams = {
|
||||
rptDB: "mifosngprovider",
|
||||
RESTUrl: "${baseUrl}api/protected/reporting/flexireport",
|
||||
//old link RESTUrl: "${baseUrl}api/protected/reporting/flexireport",
|
||||
RESTUrl: "${baseUrl}api/v1/flexiblereporting",
|
||||
pentahoUrl: "${baseUrl}pentahoreport",
|
||||
exportUrl: "${rootContext}/exportcsv",
|
||||
bundleDir: "${resValue}/stretchyreporting/mifosngbundle/",
|
||||
@@ -103,13 +104,13 @@ var reportingParams = {
|
||||
indianFormat: false,
|
||||
highlightMissingXlations: "N",
|
||||
loadingImg: "${resValue}/stretchyreporting/dots64.gif",
|
||||
resValue: "${resValue}/stretchyreporting/",
|
||||
resValue: "${resValue}/stretchyreporting/"
|
||||
|
||||
//OAuth 1.0a parameters
|
||||
apiKey: "${consumerKey}",
|
||||
sharedSecret: "${consumerSecret}",
|
||||
accessToken: "${accessToken}",
|
||||
tokenSecret: "${tokenSecret}"
|
||||
//apiKey: "${consumerKey}",
|
||||
//sharedSecret: "${consumerSecret}",
|
||||
//accessToken: "${accessToken}",
|
||||
//tokenSecret: "${tokenSecret}"
|
||||
};
|
||||
|
||||
jQuery.stretchyReporting.initialise(reportingParams);
|
||||
|
||||
@@ -81,7 +81,7 @@ public interface ReadPlatformService {
|
||||
|
||||
Collection<PermissionData> retrieveAllPermissions();
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')")
|
||||
//@PreAuthorize(value = "hasAnyRole('REPORTING_SUPER_USER_ROLE')")
|
||||
GenericResultset retrieveGenericResultset(String rptDB, String name,
|
||||
String type, Map<String, String> extractedQueryParams);
|
||||
|
||||
|
||||
+40
-4
@@ -6,8 +6,11 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
@@ -16,6 +19,7 @@ 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.UriInfo;
|
||||
|
||||
@@ -24,8 +28,8 @@ import org.mifosng.data.ErrorResponseList;
|
||||
import org.mifosng.data.reports.GenericResultset;
|
||||
import org.mifosng.platform.ReadPlatformService;
|
||||
import org.mifosng.platform.exceptions.ApplicationDomainRuleException;
|
||||
import org.mifosng.platform.exceptions.NewDataValidationException;
|
||||
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
|
||||
import org.mifosng.platform.exceptions.NewDataValidationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -43,11 +47,37 @@ public class FlexibleReportingApiResource {
|
||||
@Autowired
|
||||
private ReadPlatformService readPlatformService;
|
||||
|
||||
private String _corsHeaders;
|
||||
|
||||
private Response makeCORS(ResponseBuilder req, String returnMethod) {
|
||||
ResponseBuilder rb = req
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
||||
|
||||
if (!"".equals(returnMethod)) {
|
||||
rb.header("Access-Control-Allow-Headers", returnMethod);
|
||||
}
|
||||
|
||||
return rb.build();
|
||||
}
|
||||
|
||||
private Response makeCORS(ResponseBuilder req) {
|
||||
return makeCORS(req, _corsHeaders);
|
||||
}
|
||||
|
||||
// This OPTIONS request/response is necessary
|
||||
// if you consumes other format than text/plain or
|
||||
// if you use other HTTP verbs than GET and POST
|
||||
@OPTIONS
|
||||
public Response corsMyResource(@HeaderParam("Access-Control-Request-Headers") String requestH) {
|
||||
_corsHeaders = requestH;
|
||||
return makeCORS(Response.ok(), requestH);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("flexireport")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public Response retrieveReport(@Context UriInfo uriInfo) {
|
||||
public Response retrieveReport(@Context UriInfo uriInfo, @Context HttpServletResponse httpServletResponse) {
|
||||
|
||||
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
|
||||
String rptDB = queryParams.getFirst("MRP_rptDB");
|
||||
@@ -75,7 +105,7 @@ public class FlexibleReportingApiResource {
|
||||
// JSONWithPadding paddedResult = new JSONWithPadding(result,
|
||||
// callbackName);
|
||||
|
||||
return Response.ok().entity(result).build();
|
||||
return makeCORS(Response.ok().entity(result));
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -114,4 +144,10 @@ public class FlexibleReportingApiResource {
|
||||
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("forceauth")
|
||||
public Response hackToForceAuthentication() {
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package org.mifosng.platform.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
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.Status;
|
||||
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.platform.ReadPlatformService;
|
||||
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/flexiblereportingxxx")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class FlexibleReportingApiResourceOLD {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(FlexibleReportingApiResourceOLD.class);
|
||||
|
||||
@Autowired
|
||||
private ReadPlatformService readPlatformService;
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({ MediaType.APPLICATION_JSON})
|
||||
public Response retrieveReport(@Context UriInfo uriInfo) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
logger.info("BEGINNING REQUEST FOR: " + name);
|
||||
GenericResultset result = this.readPlatformService.retrieveGenericResultset(rptDB, name, type, extractedQueryParams);
|
||||
|
||||
// JSONWithPadding paddedResult = new JSONWithPadding(result,
|
||||
// callbackName);
|
||||
|
||||
return Response.ok().entity(result).build();
|
||||
}
|
||||
/*
|
||||
@GET
|
||||
@Path("/exportcsv/{reportDb}/{reportName}/{reportType}/office/{officeId}/currency/{currencyId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public Response exportCsvReport(
|
||||
@PathParam("reportDb") String rptDB,
|
||||
@PathParam("reportName") String name,
|
||||
@PathParam("reportType") String type,
|
||||
@PathParam("officeId") Long officeId, @PathParam("currencyId") Long currencyId) throws IOException {
|
||||
|
||||
try {
|
||||
Map<String, String> extractedQueryParams = new HashMap<String, String>();
|
||||
|
||||
if (officeId != null && officeId > 0) {
|
||||
extractedQueryParams.put("${officeId}", officeId.toString());
|
||||
}
|
||||
|
||||
if (currencyId != null) {
|
||||
extractedQueryParams.put("${currencyId}", currencyId.toString());
|
||||
}
|
||||
|
||||
GenericResultset result = this.readPlatformService.retrieveGenericResultset(rptDB, name, type, extractedQueryParams);
|
||||
|
||||
return Response.ok().entity(result).build();
|
||||
} catch (UnAuthenticatedUserException e) {
|
||||
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
|
||||
} catch (AccessDeniedException e) {*/
|
||||
}
|
||||
+1
-1
@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/protected/reporting")
|
||||
@Path("/v1/flexiblereportingxxxyyy")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class ProtectedFlexibleReportingResource {
|
||||
|
||||
Reference in New Issue
Block a user