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.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
@@ -42,6 +44,8 @@ public class AdditionalFieldsApiResource {
private final static Logger logger = LoggerFactory
.getLogger(AdditionalFieldsApiResource.class);
private String allowedFieldList = "";
@Autowired
private ReadExtraDataAndReportingService readExtraDataAndReportingService;
@@ -52,22 +56,14 @@ public class AdditionalFieldsApiResource {
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
public String datasets(@QueryParam("type") String type,
@QueryParam("fields") String fields,
@QueryParam("pretty") String pretty) {
@Context UriInfo uriInfo) {
List<AdditionalFieldsSet> result = this.readExtraDataAndReportingService
.retrieveExtraDatasetNames(type);
String filterType = "E";
String fieldList = "";
if (this.jsonFormattingService.isPassed(fields)) {
filterType = "I";
fieldList = fields;
}
return this.jsonFormattingService.convertDataObjectJSON(result,
filterType, fieldList,
this.jsonFormattingService.isTrue(pretty));
String selectedFields = "";
return this.jsonFormattingService.convertRequest(result,
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
}
@GET
@@ -76,18 +72,16 @@ public class AdditionalFieldsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
public String extraData(@PathParam("type") final String type,
@PathParam("set") final String set, @PathParam("id") final Long id,
@QueryParam("pretty") String pretty) {
@Context UriInfo uriInfo) {
try {
GenericResultset result = this.readExtraDataAndReportingService
.retrieveExtraData(type, set, id);
String filterType = "E";
String fieldList = "";
return this.jsonFormattingService.convertDataObjectJSON(result,
filterType, fieldList,
this.jsonFormattingService.isTrue(pretty));
String selectedFields = "";
return this.jsonFormattingService.convertRequest(result,
allowedFieldList, selectedFields,
uriInfo.getQueryParameters());
} catch (InvalidSqlException e) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError(
@@ -96,8 +96,7 @@ public class OfficeApiResource {
@QueryParam("template") String template, @Context UriInfo uriInfo) {
OfficeData office = this.readPlatformService.retrieveOffice(officeId);
if (this.jsonFormattingService.isTrue(template)) {
if (template != null && template.equalsIgnoreCase("true")) {
office.setAllowedParents(this.readPlatformService
.retrieveAllowedParents(officeId));
}
@@ -7,11 +7,4 @@ public interface ApiJSONFormattingService {
String convertRequest(Object dataObject, String allowedFieldList,
String selectedFields, MultivaluedMap<String, String> queryParams);
String convertDataObjectJSON(Object dataObject, String filterType,
String fields, boolean prettyOutput);
Boolean isTrue(String param);
Boolean isPassed(String param);
}
@@ -45,11 +45,12 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
while (st.hasMoreTokens()) {
selectedFieldsSet.add(st.nextToken().trim());
}
for (String paramField : paramFieldsSet) {
if (selectedFieldsSet.contains(paramField)) fieldList += paramField;
if (selectedFieldsSet.contains(paramField))
fieldList += paramField;
}
}
} else {
fieldList = selectedFields;
@@ -69,8 +70,7 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
isTrue(queryParams.getFirst("pretty")));
}
@Override
public String convertDataObjectJSON(Object dataObject, String filterType,
private String convertDataObjectJSON(Object dataObject, String filterType,
String fields, boolean prettyOutput) {
try {
@@ -124,16 +124,14 @@ public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
}
}
@Override
public Boolean isTrue(String param) {
private Boolean isTrue(String param) {
if (param != null && param.equalsIgnoreCase("true"))
return true;
else
return false;
}
@Override
public Boolean isPassed(String param) {
private Boolean isPassed(String param) {
if (param == null || param.equals(""))
return false;
else