Skip to content

Commit

Permalink
massive reduction of code
Browse files Browse the repository at this point in the history
combining processing of incoming GET and POST requests
  • Loading branch information
kowatsch committed Aug 28, 2018
1 parent ce93760 commit 9aa0511
Show file tree
Hide file tree
Showing 9 changed files with 689 additions and 3,992 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class ElementsRequestExecutor {
* Performs a count|length|perimeter|area calculation.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCount(String, String, String, String[], String[], String[], String[], String[], String)
* getCount} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#count(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest)
* count} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand All @@ -76,7 +76,7 @@ public static Response executeCountLengthPerimeterArea(RequestResource requestRe
InputProcessor iP = new InputProcessor();
String requestURL = null;
DecimalFormat df = exeUtils.defineDecimalFormat("#.##");
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
mapRed = iP.processParameters(mapRed, rPs);
switch (requestResource) {
Expand Down Expand Up @@ -123,8 +123,8 @@ public static Response executeCountLengthPerimeterArea(RequestResource requestRe
* Performs a count|length|perimeter|area calculation grouped by the boundary.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCount(String, String, String, String[], String[], String[], String[], String[], String)
* getCount} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#count(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest)
* count} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand All @@ -145,7 +145,7 @@ public static Response executeCountLengthPerimeterAreaGroupByBoundary(
InputProcessor iP = new InputProcessor();
String requestURL = null;
DecimalFormat df = exeUtils.defineDecimalFormat("#.##");
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
mapRed = iP.processParameters(mapRed, rPs);
switch (requestResource) {
Expand Down Expand Up @@ -199,8 +199,8 @@ public static Response executeCountLengthPerimeterAreaGroupByBoundary(
* Performs a count|length|perimeter|area calculation grouped by the user.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCount(String, String, String, String[], String[], String[], String[], String[], String)
* getCount} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#count(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest)
* count} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand All @@ -222,7 +222,7 @@ public static Response executeCountLengthPerimeterAreaGroupByUser(RequestResourc
String requestURL = null;
DecimalFormat df = exeUtils.defineDecimalFormat("#.##");
ArrayList<Integer> useridsInt = new ArrayList<Integer>();
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
mapRed = iP.processParameters(mapRed, rPs);
if (rPs.getUserids() != null)
Expand Down Expand Up @@ -261,8 +261,8 @@ public static Response executeCountLengthPerimeterAreaGroupByUser(RequestResourc
* Performs a count|length|perimeter|area calculation grouped by the tag.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCountGroupByTag(String, String, String, String[], String[], String[], String[], String[], String, String[], String[])
* getCountGroupByTag} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#countGroupByTag(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest, String[], String[])
* countGroupByTag} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand All @@ -286,7 +286,7 @@ public static Response executeCountLengthPerimeterAreaGroupByTag(RequestResource
InputProcessor iP = new InputProcessor();
String requestURL = null;
DecimalFormat df = exeUtils.defineDecimalFormat("#.##");
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
if (groupByValues == null)
groupByValues = new String[0];
Expand Down Expand Up @@ -360,8 +360,8 @@ public static Response executeCountLengthPerimeterAreaGroupByTag(RequestResource
* Performs a count|perimeter|area calculation grouped by the OSM type.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCount(String, String, String, String[], String[], String[], String[], String[], String)
* getCount} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#count(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest)
* count} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand All @@ -382,7 +382,7 @@ public static Response executeCountPerimeterAreaGroupByType(RequestResource requ
InputProcessor iP = new InputProcessor();
String requestURL = null;
DecimalFormat df = exeUtils.defineDecimalFormat("#.##");
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
mapRed = iP.processParameters(mapRed, rPs);
preResult = mapRed.aggregateByTimestamp()
Expand Down Expand Up @@ -417,8 +417,8 @@ public static Response executeCountPerimeterAreaGroupByType(RequestResource requ
* Performs a count|length|perimeter|area calculation grouped by the key.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCountGroupByKey(String, String, String, String[], String[], String[], String[], String[], String, String[])
* groupByKey} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#countGroupByKey(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest, String[])
* countGroupByKey} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand All @@ -441,7 +441,7 @@ public static Response executeCountLengthPerimeterAreaGroupByKey(RequestResource
InputProcessor iP = new InputProcessor();
String requestURL = null;
DecimalFormat df = exeUtils.defineDecimalFormat("#.##");
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
TagTranslator tt = DbConnData.tagTranslator;
Integer[] keysInt = new Integer[groupByKeys.length];
Expand Down Expand Up @@ -499,8 +499,8 @@ public static Response executeCountLengthPerimeterAreaGroupByKey(RequestResource
* Performs a count|length|perimeter|area-share|ratio calculation.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCountRatio(String, String, String, String[], String[], String[], String[], String[], String, String[], String[], String[])
* getCountRatio} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#countRatio(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest, String[], String[], String[])
* countRatio} method.
*
* @param requestResource <code>Enum</code> defining the request type (COUNT, LENGTH, PERIMETER,
* AREA).
Expand Down Expand Up @@ -554,7 +554,7 @@ public static Response executeCountLengthPerimeterAreaRatio(RequestResource requ
Integer[] valuesInt1 = new Integer[rPs.getValues().length];
Integer[] keysInt2 = new Integer[keys2.length];
Integer[] valuesInt2 = new Integer[values2.length];
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
for (int i = 0; i < rPs.getKeys().length; i++) {
keysInt1[i] = tt.getOSHDBTagKeyOf(rPs.getKeys()[i]).toInt();
Expand All @@ -574,9 +574,9 @@ public static Response executeCountLengthPerimeterAreaRatio(RequestResource requ
osmTypes.stream().map(OSMType::toString).map(String::toLowerCase).toArray(String[]::new);
if (!iP.compareKeysValues(rPs.getKeys(), keys2, rPs.getValues(), values2)) {
mapRed = iP.processParameters(mapRed,
new RequestParameters(rPs.isPost(), rPs.isSnapshot(), rPs.isDensity(), rPs.getBboxes(),
rPs.getBcircles(), rPs.getBpolys(), osmTypesString, new String[] {}, new String[] {},
rPs.getUserids(), rPs.getTime(), rPs.getShowMetadata()));
new RequestParameters(rPs.getRequestMethod(), rPs.isSnapshot(), rPs.isDensity(),
rPs.getBboxes(), rPs.getBcircles(), rPs.getBpolys(), osmTypesString, new String[] {},
new String[] {}, rPs.getUserids(), rPs.getTime(), rPs.getShowMetadata()));
mapRed = mapRed.osmEntityFilter(entity -> {
if (!exeUtils.entityMatches(entity, osmTypes1, keysInt1, valuesInt1))
return exeUtils.entityMatches(entity, osmTypes2, keysInt2, valuesInt2);
Expand Down Expand Up @@ -639,8 +639,8 @@ else if (matches2)
* Performs a count|length|perimeter|area-ratio calculation grouped by the boundary.
* <p>
* The other parameters are described in the
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#getCountRatio(String, String, String, String[], String[], String[], String[], String[], String, String[], String[], String[])
* getCountRatio} method.
* {@link org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.dataAggregation.CountController#countRatio(String, String, String, String[], String[], String[], String[], String[], String, HttpServletRequest, String[], String[], String[])
* countRatio} method.
*
* @param rPs <code>RequestParameters</code> object, which holds those parameters that are used in
* every request.
Expand Down Expand Up @@ -697,7 +697,7 @@ public static Response executeCountLengthPerimeterAreaRatioGroupByBoundary(
Integer[] valuesInt1 = new Integer[rPs.getValues().length];
Integer[] keysInt2 = new Integer[keys2.length];
Integer[] valuesInt2 = new Integer[values2.length];
if (!rPs.isPost())
if (!rPs.getRequestMethod().equalsIgnoreCase("post"))
requestURL = RequestInterceptor.requestUrl;
for (int i = 0; i < rPs.getKeys().length; i++) {
keysInt1[i] = tt.getOSHDBTagKeyOf(rPs.getKeys()[i]).toInt();
Expand All @@ -717,9 +717,9 @@ public static Response executeCountLengthPerimeterAreaRatioGroupByBoundary(
osmTypes.stream().map(OSMType::toString).map(String::toLowerCase).toArray(String[]::new);
if (!iP.compareKeysValues(rPs.getKeys(), keys2, rPs.getValues(), values2)) {
mapRed = iP.processParameters(mapRed,
new RequestParameters(rPs.isPost(), rPs.isSnapshot(), rPs.isDensity(), rPs.getBboxes(),
rPs.getBcircles(), rPs.getBpolys(), osmTypesString, new String[] {}, new String[] {},
rPs.getUserids(), rPs.getTime(), rPs.getShowMetadata()));
new RequestParameters(rPs.getRequestMethod(), rPs.isSnapshot(), rPs.isDensity(),
rPs.getBboxes(), rPs.getBcircles(), rPs.getBpolys(), osmTypesString, new String[] {},
new String[] {}, rPs.getUserids(), rPs.getTime(), rPs.getShowMetadata()));
mapRed = mapRed.osmEntityFilter(entity -> {
boolean matches1 = exeUtils.entityMatches(entity, osmTypes1, keysInt1, valuesInt1);
boolean matches2 = exeUtils.entityMatches(entity, osmTypes2, keysInt2, valuesInt2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** Holds those parameters, which are relevant for every request. */
public class RequestParameters {

private boolean isPost;
private String requestMethod;
private boolean isSnapshot;
private boolean isDensity;
private String bboxes;
Expand All @@ -21,11 +21,11 @@ private RequestParameters() {

}

public RequestParameters(boolean isPost, boolean isSnapshot, boolean isDensity, String bboxes, String bcircles,
public RequestParameters(String requestMethod, boolean isSnapshot, boolean isDensity, String bboxes, String bcircles,
String bpolys, String[] types, String[] keys, String[] values, String[] userids,
String[] time, String showMetadata) {

this.isPost = isPost;
this.requestMethod = requestMethod;
this.isSnapshot = isSnapshot;
this.isDensity = isDensity;
this.bboxes = bboxes;
Expand All @@ -39,12 +39,12 @@ public RequestParameters(boolean isPost, boolean isSnapshot, boolean isDensity,
this.showMetadata = showMetadata;
}

public static RequestParameters of(boolean isPost, boolean isSnapshot, boolean isDensity, String bboxes, String bcircles,
public static RequestParameters of(String requestMethod, boolean isSnapshot, boolean isDensity, String bboxes, String bcircles,
String bpolys, String[] types, String[] keys, String[] values, String[] userids,
String[] time, String format, String showMetadata) {

RequestParameters rPs = new RequestParameters();
rPs.isPost = isPost;
rPs.requestMethod = requestMethod;
rPs.isSnapshot = isSnapshot;
rPs.isDensity = isDensity;
rPs.bboxes = bboxes;
Expand All @@ -61,8 +61,8 @@ public static RequestParameters of(boolean isPost, boolean isSnapshot, boolean i
return rPs;
}

public boolean isPost() {
return isPost;
public String getRequestMethod() {
return requestMethod;
}

public boolean isSnapshot() {
Expand Down
Loading

0 comments on commit 9aa0511

Please sign in to comment.