From 22faf023768e0117f02e08b2c05e2fd35d688c5b Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Fri, 11 May 2012 18:13:01 +1000 Subject: [PATCH] WIP reporting exportcsv refactor --- .../mifosng/ui/CommonRestOperationsImpl.java | 2 +- .../api/FlexibleReportingApiResourceOLD.java | 107 ------------ .../ProtectedFlexibleReportingResource.java | 155 ------------------ 3 files changed, 1 insertion(+), 263 deletions(-) delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResourceOLD.java delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java diff --git a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/CommonRestOperationsImpl.java b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/CommonRestOperationsImpl.java index 4ac3de662..01ce7fea5 100644 --- a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/CommonRestOperationsImpl.java +++ b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/CommonRestOperationsImpl.java @@ -1202,7 +1202,7 @@ public class CommonRestOperationsImpl implements CommonRestOperations { try { StringBuilder uriAsString = new StringBuilder(getBaseServerUrl()) - .append("api/protected/reporting/exportcsv/") + .append("api/v1/flexiblereporting/exportcsv/") .append(encodeURIComponent(rptDB)) .append('/') .append(encodeURIComponent(name)) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResourceOLD.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResourceOLD.java deleted file mode 100644 index 1048d2057..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/FlexibleReportingApiResourceOLD.java +++ /dev/null @@ -1,107 +0,0 @@ -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 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); - } - } - 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 extractedQueryParams = new HashMap(); - - 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) {*/ -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java deleted file mode 100644 index 765a8c7b1..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/rest/ProtectedFlexibleReportingResource.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.mifosng.platform.rest; - -import java.io.IOException; -import java.util.Arrays; -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; -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.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.UnAuthenticatedUserException; -import org.mifosng.platform.exceptions.NewDataValidationException; -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/flexiblereportingxxxyyy") -@Component -@Scope("singleton") -public class ProtectedFlexibleReportingResource { - - private final static Logger logger = LoggerFactory.getLogger(ProtectedFlexibleReportingResource.class); - - @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 - @Path("/flexireport") - 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, @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); - } - } - logger.info("BEGINNING REQUEST FOR: " + name); - GenericResultset result = this.readPlatformService.retrieveGenericResultset(rptDB, name, type, extractedQueryParams); - -// JSONWithPadding paddedResult = new JSONWithPadding(result, -// callbackName); - - return makeCORS(Response.ok().entity(result)); - } - - @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 extractedQueryParams = new HashMap(); - - 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) { - ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id"); - ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse)); - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build()); - } catch (ApplicationDomainRuleException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build()); - } catch (NewDataValidationException e) { - throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build()); - } - } - - @GET - @Path("forceauth") - public Response hackToForceAuthentication() { - return Response.ok().build(); - } -} \ No newline at end of file