Class InputProcessor

java.lang.Object
org.heigit.ohsome.ohsomeapi.inputprocessing.InputProcessor

public class InputProcessor extends Object
Holds general input processing and validation methods and validates specific parameters given by the request. Uses geometry methods from GeometryBuilder and inputProcessingUtils from InputProcessingUtils. Throws exceptions depending on their validity.
  • Field Details

    • COMPUTE_MODE_THRESHOLD

      public static final int COMPUTE_MODE_THRESHOLD
      See Also:
  • Constructor Details

    • InputProcessor

      public InputProcessor(ProcessingData processingData)
    • InputProcessor

      public InputProcessor(javax.servlet.http.HttpServletRequest servletRequest, boolean isSnapshot, boolean isDensity)
  • Method Details

    • processParameters

      public <T extends org.heigit.ohsome.oshdb.util.mappable.OSHDBMapReducible> org.heigit.ohsome.oshdb.api.mapreducer.MapReducer<T> processParameters() throws Exception
      Throws:
      Exception - thrown by #processParameters(ComputeMode) processParameters
    • processParameters

      public <T extends org.heigit.ohsome.oshdb.util.mappable.OSHDBMapReducible> org.heigit.ohsome.oshdb.api.mapreducer.MapReducer<T> processParameters(org.heigit.ohsome.oshdb.api.db.OSHDBIgnite.ComputeMode forceComputeMode) throws Exception
      Processes the input parameters from the given request.
      Returns:
      MapReducer object including the settings derived from the given parameters.
      Throws:
      BadRequestException - if the boundary parameter is not defined or it has an invalid format, if the geometry of given boundary cannot be parsed for the creation of the response GeoJSON or if the keys, values and types parameters are not empty, while the filter parameter is set.
      Exception - thrown by #extractTime(MapReducer, String[], boolean) extractTime
    • defineTypes

      public <T extends org.heigit.ohsome.oshdb.util.mappable.OSHDBMapReducible> org.heigit.ohsome.oshdb.api.mapreducer.MapReducer<T> defineTypes(String[] types, org.heigit.ohsome.oshdb.api.mapreducer.MapReducer<T> mapRed)
      Defines the type(s) out of the given String[].
      Parameters:
      types - String array containing one, two, or all 3 OSM types (node, way, relation), or simple feature types (point, line, polygon, other). If the array is empty, all three OSM types are used.
    • defineSimpleFeatureTypes

      public EnumSet<SimpleFeatureType> defineSimpleFeatureTypes(String[] types)
      Defines the simple feature types and corresponding OSM types out of the given String array.
    • splitParamOnComma

      public String[] splitParamOnComma(String[] param)
      Splits the given input parameter on ',' if it has a length of 1 and contains ',' at [0]. Returns a String array containing the splits.
      Parameters:
      param - String array containing the content to split
      Returns:
      String array containing the split parameter content
    • createEmptyArrayIfNull

      public String[] createEmptyArrayIfNull(String[] toCheck)
      Creates an empty array if an input parameter of a POST request is null.
      Parameters:
      toCheck - String array, which is checked.
      Returns:
      String array, which is empty.
    • createEmptyStringIfNull

      public String createEmptyStringIfNull(String toCheck)
      Creates an empty String, if a given input parameter is null.
      Parameters:
      toCheck - String, which is checked.
      Returns:
      String, which may be empty but not null.
    • checkKeysValues

      public void checkKeysValues(String[] keys, String[] values)
      Checks the given keys and values String[] on their length.
      Throws:
      BadRequestException - if values_n doesn't fit to keys_n. There cannot be more input values in the values|values2 than in the keys|keys2 parameter.
    • compareKeysValues

      public boolean compareKeysValues(String[] keys, String[] keys2, String[] values, String[] values2)
      Compares the keys and values arrays with each other. Returns true only if keys=keys2 and values=values2.
    • processKeys2Vals2

      public org.apache.commons.lang3.tuple.Pair<String[],String[]> processKeys2Vals2(String[] keys2, String[] values2)
      Used in /ratio requests.
    • processPropertiesParam

      public void processPropertiesParam()
      Processes the properties parameter used in data-extraction resources and sets the respective boolean values includeTags, includeOSMMetadata, unclippedGeometries, and includeContributionTypes (only for the /contributions endpoints).
      Throws:
      BadRequestException - if the properties parameter contains invalid values
    • processIsUnclippedParam

      public void processIsUnclippedParam()
      Processes the clipGeometry parameter used in data-extraction resources and sets the respective boolean value 'clipGeometry'. Note: this method is called after processPropertiesParam() so it could overwrite the previously defined value of 'clipGeometry'.
    • getRequestUrlIfGetRequest

      public String getRequestUrlIfGetRequest(javax.servlet.http.HttpServletRequest servletRequest)
      Returns the request URL if a GET request was sent.
    • filterOnSimpleFeatures

      public <T extends org.heigit.ohsome.oshdb.api.mapreducer.Mappable<? extends org.heigit.ohsome.oshdb.util.mappable.OSHDBMapReducible>> T filterOnSimpleFeatures(T mapRed)
      Applies respective Puntal|Lineal|Polygonal filter(s) on features of the given MapReducer.
      Returns:
      MapReducer with filtered geometries
      Throws:
      RuntimeException - if #filterOnSimpleFeatures(Mappable) filterOnSimpleFeatures was called on mapped entries
    • checkFilter

      public void checkFilter(String filter)
      Checks the given filter parameter if it's null or blank. Currently used for filter2 parameter of /ratio processing.
      Parameters:
      filter - parameter to be checked
      Throws:
      BadRequestException - if the given filter parameter is null or blank.
    • getGeometry

      public org.locationtech.jts.geom.Geometry getGeometry()
      Gets the geometry from the currently in-use boundary object(s).
      Returns:
      Geometry object of the used boundary parameter.
    • getGeomBuilder

      public GeometryBuilder getGeomBuilder()
    • getUtils

      public InputProcessingUtils getUtils()
    • setUtils

      public void setUtils(InputProcessingUtils utils)
    • getProcessingData

      public ProcessingData getProcessingData()
    • setProcessingData

      public void setProcessingData(ProcessingData processingData)
    • getRequestUrl

      public String getRequestUrl()
    • includeTags

      public boolean includeTags()
    • includeOSMMetadata

      public boolean includeOSMMetadata()
    • includeContributionTypes

      public boolean includeContributionTypes()
    • isClipGeometry

      public boolean isClipGeometry()