WIP filtering, pretty and templates

This commit is contained in:
John Woodlock
2012-05-25 18:24:32 +10:00
parent 18579bc0b5
commit a0680ee34b
4 changed files with 21 additions and 37 deletions
@@ -13,9 +13,11 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
@@ -42,6 +44,8 @@ public class AdditionalFieldsApiResource {
private final static Logger logger = LoggerFactory private final static Logger logger = LoggerFactory
.getLogger(AdditionalFieldsApiResource.class); .getLogger(AdditionalFieldsApiResource.class);
private String allowedFieldList = "";
@Autowired @Autowired
private ReadExtraDataAndReportingService readExtraDataAndReportingService; private ReadExtraDataAndReportingService readExtraDataAndReportingService;
@@ -52,22 +56,14 @@ public class AdditionalFieldsApiResource {
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String datasets(@QueryParam("type") String type, public String datasets(@QueryParam("type") String type,
@QueryParam("fields") String fields, @Context UriInfo uriInfo) {
@QueryParam("pretty") String pretty) {
List<AdditionalFieldsSet> result = this.readExtraDataAndReportingService List<AdditionalFieldsSet> result = this.readExtraDataAndReportingService
.retrieveExtraDatasetNames(type); .retrieveExtraDatasetNames(type);
String filterType = "E"; String selectedFields = "";
String fieldList = ""; return this.jsonFormattingService.convertRequest(result,
if (this.jsonFormattingService.isPassed(fields)) { allowedFieldList, selectedFields, uriInfo.getQueryParameters());
filterType = "I";
fieldList = fields;
}
return this.jsonFormattingService.convertDataObjectJSON(result,
filterType, fieldList,
this.jsonFormattingService.isTrue(pretty));
} }
@GET @GET
@@ -76,18 +72,16 @@ public class AdditionalFieldsApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String extraData(@PathParam("type") final String type, public String extraData(@PathParam("type") final String type,
@PathParam("set") final String set, @PathParam("id") final Long id, @PathParam("set") final String set, @PathParam("id") final Long id,
@QueryParam("pretty") String pretty) { @Context UriInfo uriInfo) {
try { try {
GenericResultset result = this.readExtraDataAndReportingService GenericResultset result = this.readExtraDataAndReportingService
.retrieveExtraData(type, set, id); .retrieveExtraData(type, set, id);
String filterType = "E"; String selectedFields = "";
String fieldList = ""; return this.jsonFormattingService.convertRequest(result,
allowedFieldList, selectedFields,
return this.jsonFormattingService.convertDataObjectJSON(result, uriInfo.getQueryParameters());
filterType, fieldList,
this.jsonFormattingService.isTrue(pretty));
} catch (InvalidSqlException e) { } catch (InvalidSqlException e) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError( ApiParameterError error = ApiParameterError.parameterError(
@@ -96,8 +96,7 @@ public class OfficeApiResource {
@QueryParam("template") String template, @Context UriInfo uriInfo) { @QueryParam("template") String template, @Context UriInfo uriInfo) {
OfficeData office = this.readPlatformService.retrieveOffice(officeId); OfficeData office = this.readPlatformService.retrieveOffice(officeId);
if (template != null && template.equalsIgnoreCase("true")) {
if (this.jsonFormattingService.isTrue(template)) {
office.setAllowedParents(this.readPlatformService office.setAllowedParents(this.readPlatformService
.retrieveAllowedParents(officeId)); .retrieveAllowedParents(officeId));
} }
@@ -7,11 +7,4 @@ public interface ApiJSONFormattingService {
String convertRequest(Object dataObject, String allowedFieldList, String convertRequest(Object dataObject, String allowedFieldList,
String selectedFields, MultivaluedMap<String, String> queryParams); String selectedFields, MultivaluedMap<String, String> queryParams);
String convertDataObjectJSON(Object dataObject, String filterType,
String fields, boolean prettyOutput);
Boolean isTrue(String param);
Boolean isPassed(String param);
} }
@@ -47,7 +47,8 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
} }
for (String paramField : paramFieldsSet) { for (String paramField : paramFieldsSet) {
if (selectedFieldsSet.contains(paramField)) fieldList += paramField; if (selectedFieldsSet.contains(paramField))
fieldList += paramField;
} }
} }
@@ -69,8 +70,7 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
isTrue(queryParams.getFirst("pretty"))); isTrue(queryParams.getFirst("pretty")));
} }
@Override private String convertDataObjectJSON(Object dataObject, String filterType,
public String convertDataObjectJSON(Object dataObject, String filterType,
String fields, boolean prettyOutput) { String fields, boolean prettyOutput) {
try { try {
@@ -124,16 +124,14 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
} }
} }
@Override private Boolean isTrue(String param) {
public Boolean isTrue(String param) {
if (param != null && param.equalsIgnoreCase("true")) if (param != null && param.equalsIgnoreCase("true"))
return true; return true;
else else
return false; return false;
} }
@Override private Boolean isPassed(String param) {
public Boolean isPassed(String param) {
if (param == null || param.equals("")) if (param == null || param.equals(""))
return false; return false;
else else