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