WIP filtering, pretty and templates
This commit is contained in:
@@ -32,6 +32,9 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class OfficeApiResource {
|
||||
|
||||
private String defaultFieldList = "openingDate";
|
||||
private String allowedFieldList = "allowedParents";
|
||||
|
||||
@Autowired
|
||||
private OfficeReadPlatformService readPlatformService;
|
||||
|
||||
@@ -51,11 +54,9 @@ public class OfficeApiResource {
|
||||
|
||||
Collection<OfficeData> offices = this.readPlatformService
|
||||
.retrieveAllOffices();
|
||||
|
||||
String filterType = "E";
|
||||
String templateFields = "allowedParents";
|
||||
return this.jsonFormattingService.convertRequest(offices, filterType,
|
||||
templateFields, uriInfo.getQueryParameters());
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(offices,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -67,11 +68,9 @@ public class OfficeApiResource {
|
||||
OfficeData officeData = this.readPlatformService
|
||||
.retrieveNewOfficeTemplate();
|
||||
|
||||
String filterType = "I";
|
||||
String templateFields = "openingDate,allowedParents";
|
||||
|
||||
String selectedFields = defaultFieldList + "," + allowedFieldList;
|
||||
return this.jsonFormattingService.convertRequest(officeData,
|
||||
filterType, templateFields, uriInfo.getQueryParameters());
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -94,36 +93,18 @@ public class OfficeApiResource {
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retreiveOffice(@PathParam("officeId") final Long officeId,
|
||||
@QueryParam("fields") String fields,
|
||||
@QueryParam("template") String template,
|
||||
@QueryParam("pretty") String pretty) {
|
||||
@QueryParam("template") String template, @Context UriInfo uriInfo) {
|
||||
|
||||
OfficeData office = this.readPlatformService.retrieveOffice(officeId);
|
||||
|
||||
String filterType = "E";
|
||||
String fieldList = "";
|
||||
if (this.jsonFormattingService.isPassed(fields)) {
|
||||
filterType = "I";
|
||||
fieldList = fields;
|
||||
}
|
||||
|
||||
if (this.jsonFormattingService.isTrue(template)) {
|
||||
office.setAllowedParents(this.readPlatformService
|
||||
.retrieveAllowedParents(officeId));
|
||||
|
||||
if (this.jsonFormattingService.isPassed(fields)) {
|
||||
fieldList += ",allowedParents";
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!(this.jsonFormattingService.isPassed(fields))) {
|
||||
fieldList = "allowedParents";
|
||||
}
|
||||
}
|
||||
|
||||
return this.jsonFormattingService.convertDataObjectJSON(office,
|
||||
filterType, fieldList,
|
||||
this.jsonFormattingService.isTrue(pretty));
|
||||
String selectedFields = "";
|
||||
return this.jsonFormattingService.convertRequest(office,
|
||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
public interface ApiJSONFormattingService {
|
||||
|
||||
String convertRequest(Object dataObject, String filterType,
|
||||
String filterFields, MultivaluedMap<String, String> queryParams);
|
||||
String convertRequest(Object dataObject, String allowedFieldList,
|
||||
String selectedFields, MultivaluedMap<String, String> queryParams);
|
||||
|
||||
String convertDataObjectJSON(Object dataObject, String filterType,
|
||||
String fields, boolean prettyOutput);
|
||||
|
||||
+43
-11
@@ -21,22 +21,54 @@ import org.springframework.stereotype.Service;
|
||||
public class ApiJSONFormattingServiceImpl implements ApiJSONFormattingService {
|
||||
|
||||
@Override
|
||||
public String convertRequest(Object dataObject, String filterType, String filterFields,
|
||||
MultivaluedMap<String, String> queryParams) {
|
||||
|
||||
public String convertRequest(Object dataObject, String allowedFieldList,
|
||||
String selectedFields, MultivaluedMap<String, String> queryParams) {
|
||||
|
||||
String filterType = "E";
|
||||
String fieldList = "";
|
||||
String fields = queryParams.getFirst("fields");
|
||||
String calcFilterType = filterType;
|
||||
String fieldList = filterFields;
|
||||
if (isPassed(fields)) {
|
||||
calcFilterType = "I";
|
||||
fieldList = fields;
|
||||
|
||||
if (isPassed(fields) || (!(selectedFields.equals("")))) {
|
||||
filterType = "I";
|
||||
|
||||
if (isPassed(fields)) {
|
||||
if (selectedFields.equals(""))
|
||||
fieldList = fields;
|
||||
else {
|
||||
Set<String> paramFieldsSet = new HashSet<String>();
|
||||
StringTokenizer st = new StringTokenizer(fields, ",");
|
||||
while (st.hasMoreTokens()) {
|
||||
paramFieldsSet.add(st.nextToken().trim());
|
||||
}
|
||||
Set<String> selectedFieldsSet = new HashSet<String>();
|
||||
st = new StringTokenizer(fields, ",");
|
||||
while (st.hasMoreTokens()) {
|
||||
selectedFieldsSet.add(st.nextToken().trim());
|
||||
}
|
||||
|
||||
for (String paramField : paramFieldsSet) {
|
||||
if (selectedFieldsSet.contains(paramField)) fieldList += paramField;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
fieldList = selectedFields;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return convertDataObjectJSON(dataObject,
|
||||
calcFilterType, fieldList,
|
||||
if (isTrue(queryParams.getFirst("template"))) {
|
||||
if (filterType.equals("I"))
|
||||
fieldList += "," + allowedFieldList;
|
||||
} else {
|
||||
if (filterType.equals("E"))
|
||||
fieldList = allowedFieldList;
|
||||
}
|
||||
|
||||
return convertDataObjectJSON(dataObject, filterType, fieldList,
|
||||
isTrue(queryParams.getFirst("pretty")));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String convertDataObjectJSON(Object dataObject, String filterType,
|
||||
String fields, boolean prettyOutput) {
|
||||
|
||||
Reference in New Issue
Block a user