Skip to content

Commit

Permalink
Merge pull request #57 from GIScience/lombok
Browse files Browse the repository at this point in the history
Introducing Lombok
closes #50
  • Loading branch information
FabiKo117 authored Nov 6, 2020
2 parents 2ab129c + 47ecb46 commit 7c04e84
Show file tree
Hide file tree
Showing 34 changed files with 306 additions and 767 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ These instructions will get you a copy of the project up and running on your loc

* [Java 11](https://openjdk.java.net/projects/jdk/11/) or higher
* [Apache Maven 3.5](https://maven.apache.org/download.cgi) or higher
* [Lombok 1.18.16](https://projectlombok.org/download) or higher. Please check the [requirements](https://projectlombok.org/setup/overview) for your IDE
* data: [download](http://downloads.ohsome.org/) it directly, or work through a guide on [how to prepare a new OSHDB extract](https://github.com/GIScience/oshdb/blob/master/oshdb-tool/etl/README.md)

### Setting-up/Running
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ public class AreaController {
* @param servletResponse <code>HttpServletResponse</code> of the outgoing response
* @return {@link org.heigit.ohsome.ohsomeapi.output.dataaggregationresponse.Response Response}
* @throws Exception thrown by
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregate() aggregate}
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregate()
* aggregate}
*/
@ApiOperation(value = "Area of OSM elements", nickname = "area",
response = DefaultAggregationResponse.class)
@RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.POST},
produces = {"application/json", "text/csv"})
public Response area(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception
{
public Response area(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
throws Exception {
AggregateRequestExecutor executor =
new AggregateRequestExecutor(RequestResource.AREA, servletRequest, servletResponse, false);
return executor.aggregate();
Expand Down Expand Up @@ -77,7 +78,8 @@ public Response areaGroupByType(HttpServletRequest servletRequest,
* @param servletResponse <code>HttpServletResponse</code> of the outgoing response
* @return {@link org.heigit.ohsome.ohsomeapi.output.dataaggregationresponse.Response Response}
* @throws Exception thrown by
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregateGroupByBoundary() aggregateGroupByBoundary}
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregateGroupByBoundary()
* aggregateGroupByBoundary}
*/
@ApiOperation(
value = "Area of OSM elements grouped by the boundary (bboxes, bcircles, or bpolys)",
Expand Down Expand Up @@ -174,7 +176,8 @@ public Response areaGroupByTag(HttpServletRequest servletRequest,
* @param servletResponse <code>HttpServletResponse</code> of the outgoing response
* @return {@link org.heigit.ohsome.ohsomeapi.output.dataaggregationresponse.Response Response}
* @throws Exception thrown by
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregate() aggregate}
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregate()
* aggregate}
*/
@ApiOperation(
value = "Density of OSM elements (area of elements divided "
Expand Down Expand Up @@ -217,7 +220,8 @@ public Response areaDensityGroupByType(HttpServletRequest servletRequest,
* @param servletResponse <code>HttpServletResponse</code> of the outgoing response
* @return {@link org.heigit.ohsome.ohsomeapi.output.dataaggregationresponse.Response Response}
* @throws Exception thrown by
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregateGroupByBoundary() aggregateGroupByBoundary}
* {@link org.heigit.ohsome.ohsomeapi.executor.AggregateRequestExecutor#aggregateGroupByBoundary()
* aggregateGroupByBoundary}
*/
@ApiOperation(
value = "Density of OSM elements grouped by the boundary (bboxes, bcircles, or bpolys)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Response aggregate() throws Exception {
* computeCountLengthPerimeterAreaGbB}
*/
public Response aggregateGroupByBoundary() throws Exception {
processingData.setIsGroupByBoundary(true);
processingData.setGroupByBoundary(true);
RequestParameters requestParameters = processingData.getRequestParameters();
MapReducer<OSMEntitySnapshot> mapRed = inputProcessor.processParameters();
InputProcessingUtils utils = inputProcessor.getUtils();
Expand Down Expand Up @@ -285,7 +285,7 @@ private ImmutablePair<List<String>, List<String[]>> createCsvResponseForElements
List<String[]> rows = new LinkedList<>();
for (int i = 0; i < resultSet.length; i++) {
GroupByResult groupByResult = (GroupByResult) resultSet[i];
Object groupByObject = groupByResult.getGroupByObject();
Object groupByObject = groupByResult.getGroupByObjectId();
if (groupByObject instanceof Object[]) {
Object[] groupByObjectArr = (Object[]) groupByObject;
columnNames.add(groupByObjectArr[0].toString() + "_" + groupByObjectArr[1].toString());
Expand Down Expand Up @@ -349,7 +349,7 @@ private ElementsResult[] fillElementsResult(SortedMap<OSHDBTimestamp, ? extends
.collect(Collectors.toMap(idx -> idx, idx -> (P) arrGeoms.get(idx)));
MapAggregator<OSHDBCombinedIndex<OSHDBTimestamp, Integer>, OSMEntitySnapshot> mapAgg =
mapRed.aggregateByTimestamp().aggregateByGeometry(geoms);
if (processingData.containsSimpleFeatureTypes()) {
if (processingData.isContainingSimpleFeatureTypes()) {
mapAgg = inputProcessor.filterOnSimpleFeatures(mapAgg);
}
Optional<FilterExpression> filter = processingData.getFilterExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public DataRequestExecutor(RequestResource requestResource, ElementsGeometry ele
* streamElementsResponse}
*/
public void extract() throws Exception {
inputProcessor.getProcessingData().setIsFullHistory(true);
inputProcessor.getProcessingData().setFullHistory(true);
InputProcessor snapshotInputProcessor = new InputProcessor(servletRequest, true, false);
snapshotInputProcessor.getProcessingData().setIsFullHistory(true);
snapshotInputProcessor.getProcessingData().setFullHistory(true);
MapReducer<OSMEntitySnapshot> mapRedSnapshot = null;
MapReducer<OSMContribution> mapRedContribution = null;
if (DbConnData.db instanceof OSHDBIgnite) {
Expand Down Expand Up @@ -269,7 +269,7 @@ private boolean addEntityToOutput(ProcessingData processingData, InputProcessing
final Set<SimpleFeatureType> simpleFeatureTypes, final boolean requiresGeometryTypeCheck,
FilterExpression filterExpression, Geometry currentGeom, OSMEntity currentEntity) {
boolean addToOutput;
if (processingData.containsSimpleFeatureTypes()) {
if (processingData.isContainingSimpleFeatureTypes()) {
addToOutput = utils.checkGeometryOnSimpleFeatures(currentGeom, simpleFeatureTypes);
} else if (requiresGeometryTypeCheck) {
addToOutput = filterExpression.applyOSMGeometry(currentEntity, currentGeom);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.heigit.ohsome.ohsomeapi.executor;

import java.text.DecimalFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -10,6 +11,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
Expand All @@ -25,13 +27,16 @@
import org.heigit.bigspatialdata.oshdb.api.generic.function.SerializableFunction;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.MapAggregator;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer;
import org.heigit.bigspatialdata.oshdb.api.object.OSMContribution;
import org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMType;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTag;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTimestamp;
import org.heigit.bigspatialdata.oshdb.util.celliterator.ContributionType;
import org.heigit.bigspatialdata.oshdb.util.geometry.Geo;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.TagTranslator;
import org.heigit.bigspatialdata.oshdb.util.time.ISODateTimeParser;
import org.heigit.bigspatialdata.oshdb.util.time.TimestampFormatter;
import org.heigit.ohsome.filter.FilterExpression;
import org.heigit.ohsome.filter.FilterParser;
Expand Down Expand Up @@ -167,7 +172,7 @@ public static <P extends Geometry & Polygonal> Response aggregateGroupByBoundary
final long startTime = System.currentTimeMillis();
MapReducer<OSMEntitySnapshot> mapRed = null;
InputProcessor inputProcessor = new InputProcessor(servletRequest, isSnapshot, isDensity);
inputProcessor.getProcessingData().setIsGroupByBoundary(true);
inputProcessor.getProcessingData().setGroupByBoundary(true);
String[] groupByKey = inputProcessor.splitParamOnComma(
inputProcessor.createEmptyArrayIfNull(servletRequest.getParameterValues("groupByKey")));
if (groupByKey.length != 1) {
Expand All @@ -193,7 +198,7 @@ public static <P extends Geometry & Polygonal> Response aggregateGroupByBoundary
Map<Integer, P> geoms = IntStream.range(0, arrGeoms.size()).boxed()
.collect(Collectors.toMap(idx -> idx, idx -> (P) arrGeoms.get(idx)));
MapAggregator<Integer, OSMEntitySnapshot> mapAgg = mapRed.aggregateByGeometry(geoms);
if (processingData.containsSimpleFeatureTypes()) {
if (processingData.isContainingSimpleFeatureTypes()) {
mapAgg = inputProcessor.filterOnSimpleFeatures(mapAgg);
}
Optional<FilterExpression> filter = processingData.getFilterExpression();
Expand Down Expand Up @@ -516,7 +521,7 @@ public static Response aggregateBasicFiltersRatio(RequestResource requestResourc
final boolean isSnapshot = true;
final boolean isDensity = false;
InputProcessor inputProcessor = new InputProcessor(servletRequest, isSnapshot, isDensity);
inputProcessor.getProcessingData().setIsRatio(true);
inputProcessor.getProcessingData().setRatio(true);
final MapReducer<OSMEntitySnapshot> intermediateMapRed = inputProcessor.processParameters();
ProcessingData processingData = inputProcessor.getProcessingData();
RequestParameters requestParameters = processingData.getRequestParameters();
Expand Down Expand Up @@ -666,7 +671,7 @@ public static Response aggregateRatio(RequestResource requestResource,
final boolean isSnapshot = true;
final boolean isDensity = false;
InputProcessor inputProcessor = new InputProcessor(servletRequest, isSnapshot, isDensity);
inputProcessor.getProcessingData().setIsRatio(true);
inputProcessor.getProcessingData().setRatio(true);
inputProcessor.processParameters();
ProcessingData processingData = inputProcessor.getProcessingData();
ExecutionUtils exeUtils = new ExecutionUtils(processingData);
Expand Down Expand Up @@ -767,8 +772,8 @@ public static <P extends Geometry & Polygonal> Response aggregateBasicFiltersRat
final boolean isSnapshot = true;
final boolean isDensity = false;
InputProcessor inputProcessor = new InputProcessor(servletRequest, isSnapshot, isDensity);
inputProcessor.getProcessingData().setIsGroupByBoundary(true);
inputProcessor.getProcessingData().setIsRatio(true);
inputProcessor.getProcessingData().setGroupByBoundary(true);
inputProcessor.getProcessingData().setRatio(true);
final MapReducer<OSMEntitySnapshot> intermediateMapRed = inputProcessor.processParameters();
ProcessingData processingData = inputProcessor.getProcessingData();
RequestParameters requestParameters = processingData.getRequestParameters();
Expand Down Expand Up @@ -965,8 +970,8 @@ public static <P extends Geometry & Polygonal> Response aggregateRatioGroupByBou
final boolean isSnapshot = true;
final boolean isDensity = false;
InputProcessor inputProcessor = new InputProcessor(servletRequest, isSnapshot, isDensity);
inputProcessor.getProcessingData().setIsGroupByBoundary(true);
inputProcessor.getProcessingData().setIsRatio(true);
inputProcessor.getProcessingData().setGroupByBoundary(true);
inputProcessor.getProcessingData().setRatio(true);
inputProcessor.processParameters();
ProcessingData processingData = inputProcessor.getProcessingData();
if (processingData.getBoundaryType() == BoundaryType.NOBOUNDARY) {
Expand All @@ -991,8 +996,8 @@ public static <P extends Geometry & Polygonal> Response aggregateRatioGroupByBou
InputProcessor inputProcessorCombined =
new InputProcessor(servletRequest, isSnapshot, isDensity);
inputProcessorCombined.setProcessingData(processingDataCombined);
inputProcessorCombined.getProcessingData().setIsRatio(true);
inputProcessorCombined.getProcessingData().setIsGroupByBoundary(true);
inputProcessorCombined.getProcessingData().setRatio(true);
inputProcessorCombined.getProcessingData().setGroupByBoundary(true);
MapReducer<OSMEntitySnapshot> mapRed = inputProcessorCombined.processParameters();
ArrayList<Geometry> arrGeoms = new ArrayList<>(processingData.getBoundaryList());
// intentionally as check for P on Polygonal is already performed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.stream.Stream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.geojson.GeoJsonObject;
Expand Down Expand Up @@ -93,6 +94,7 @@
import org.wololo.jts2geojson.GeoJSONWriter;

/** Holds helper methods that are used by the executor classes. */
@RequiredArgsConstructor
public class ExecutionUtils {
private AtomicReference<Boolean> isFirst;
private final ProcessingData processingData;
Expand All @@ -101,10 +103,6 @@ public class ExecutionUtils {
private static final LineString emptyLine = new LineString(new double[0][0]);
private static final Polygon emptyPolygon = new Polygon(new double[0][0][0]);

public ExecutionUtils(ProcessingData processingData) {
this.processingData = processingData;
}

/** Applies a filter on the given MapReducer object using the given parameters. */
public MapReducer<OSMEntitySnapshot> snapshotFilter(MapReducer<OSMEntitySnapshot> mapRed,
Set<OSMType> osmTypes1, Set<OSMType> osmTypes2, Set<SimpleFeatureType> simpleFeatureTypes1,
Expand Down Expand Up @@ -780,7 +778,7 @@ private ImmutablePair<List<String>, List<String[]>> createCsvResponseForElements
List<String[]> rows = new LinkedList<>();
for (int i = 0; i < resultSet.length; i++) {
GroupByResult groupByResult = (GroupByResult) resultSet[i];
Object groupByObject = groupByResult.getGroupByObject();
Object groupByObject = groupByResult.getGroupByObjectId();
if (groupByObject instanceof Object[]) {
Object[] groupByObjectArr = (Object[]) groupByObject;
columnNames.add(groupByObjectArr[0].toString() + "_" + groupByObjectArr[1].toString());
Expand Down Expand Up @@ -816,9 +814,9 @@ private ImmutablePair<List<String>, List<String[]>> createCsvResponseForElements
List<String[]> rows = new LinkedList<>();
for (int i = 0; i < resultSet.length; i++) {
RatioGroupByResult ratioGroupByResult = (RatioGroupByResult) resultSet[i];
columnNames.add(ratioGroupByResult.getGroupByObject() + "_value");
columnNames.add(ratioGroupByResult.getGroupByObject() + "_value2");
columnNames.add(ratioGroupByResult.getGroupByObject() + "_ratio");
columnNames.add(ratioGroupByResult.getGroupByObjectId() + "_value");
columnNames.add(ratioGroupByResult.getGroupByObjectId() + "_value2");
columnNames.add(ratioGroupByResult.getGroupByObjectId() + "_ratio");
for (int j = 0; j < ratioGroupByResult.getRatioResult().length; j++) {
RatioResult ratioResult = ratioGroupByResult.getRatioResult()[j];
if (i == 0) {
Expand Down Expand Up @@ -854,7 +852,7 @@ private ImmutablePair<List<String>, List<String[]>> createCsvResponseForUsersGro
List<String[]> rows = new LinkedList<>();
for (int i = 0; i < resultSet.length; i++) {
GroupByResult groupByResult = (GroupByResult) resultSet[i];
columnNames.add(groupByResult.getGroupByObject().toString());
columnNames.add(groupByResult.getGroupByObjectId().toString());
for (int j = 0; j < groupByResult.getResult().length; j++) {
UsersResult usersResult = (UsersResult) groupByResult.getResult()[j];
if (i == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
import java.text.DecimalFormat;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.heigit.ohsome.ohsomeapi.oshdb.ExtractMetadata;
import org.heigit.ohsome.ohsomeapi.output.dataaggregationresponse.Attribution;

@RequiredArgsConstructor
public abstract class RequestExecutor {

protected static final String URL = ExtractMetadata.attributionUrl;
protected static final String TEXT = ExtractMetadata.attributionShort;
protected static final Attribution ATTRIBUTION = new Attribution(URL, TEXT);
public static final DecimalFormat df = ExecutionUtils.defineDecimalFormat("#.##");
protected final HttpServletRequest servletRequest;
protected final HttpServletResponse servletResponse;

public RequestExecutor(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
this.servletRequest = servletRequest;
this.servletResponse = servletResponse;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package org.heigit.ohsome.ohsomeapi.executor;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

/** Holds those parameters, which are relevant for every request. */
@Getter
@Setter
@AllArgsConstructor
public class RequestParameters {

private String requestMethod;
Expand All @@ -17,80 +24,4 @@ public class RequestParameters {
private String showMetadata;
private double timeout;
private String filter;

public RequestParameters(String requestMethod, boolean isSnapshot, boolean isDensity,
String bboxes, String bcircles, String bpolys, String[] types, String[] keys, String[] values,
String[] time, String format, String showMetadata, double timeout, String filter) {

this.requestMethod = requestMethod;
this.isDensity = isDensity;
this.isSnapshot = isSnapshot;
this.bboxes = bboxes;
this.bcircles = bcircles;
this.bpolys = bpolys;
this.types = types;
this.keys = keys;
this.values = values;
this.time = time;
this.format = format;
this.showMetadata = showMetadata;
this.timeout = timeout;
this.filter = filter;
}

public String getRequestMethod() {
return requestMethod;
}

public boolean isSnapshot() {
return isSnapshot;
}

public boolean isDensity() {
return isDensity;
}

public String getBboxes() {
return bboxes;
}

public String getBcircles() {
return bcircles;
}

public String getBpolys() {
return bpolys;
}

public String[] getTypes() {
return types;
}

public String[] getKeys() {
return keys;
}

public String[] getValues() {
return values;
}

public String[] getTime() {
return time;
}

public String getFormat() {
return format;
}

public String getShowMetadata() {
return showMetadata;
}

public double getTimeout() {
return timeout;
}

public String getFilter() {
return filter;
}
}
Loading

0 comments on commit 7c04e84

Please sign in to comment.