Skip to content

Commit

Permalink
refactor: move APIEnums into api module
Browse files Browse the repository at this point in the history
APIEnums are concerned with API code and should not be used by
the engine core. This refactoring removes the last dependencies
of engine code on APIEnums and moves the APIEnums class into
the api module.
  • Loading branch information
Sascha Fendrich committed Dec 20, 2023
1 parent a2055a4 commit 25746d3
Show file tree
Hide file tree
Showing 40 changed files with 59 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ RELEASING:
- update maven repository for dependencies ([#1536](https://github.com/GIScience/openrouteservice/pull/1536))
- spring-boot-starter-parent to v3.1.6 ([#1630](https://github.com/GIScience/openrouteservice/issues/1630))
- fix IN1-JAVA-ORGMOZILLA-1314295 ([#1627](https://github.com/GIScience/openrouteservice/issues/1627))
- move APIEnums into API module ([#1634](https://github.com/GIScience/openrouteservice/issues/1634))

### Deprecated
- JSON configuration and related classes ([#1506](https://github.com/GIScience/openrouteservice/pull/1506))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
* if not, see <https://www.gnu.org/licenses/>.
*/

package org.heigit.ors.routing;
package org.heigit.ors.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.GenericErrorCodes;


public class APIEnums {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.heigit.ors.exceptions.*;
import org.heigit.ors.export.ExportErrorCodes;
import org.heigit.ors.export.ExportResult;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.http.converter.HttpMessageNotReadableException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.heigit.ors.exceptions.*;
import org.heigit.ors.isochrones.IsochroneMapCollection;
import org.heigit.ors.isochrones.IsochronesErrorCodes;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConversionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.heigit.ors.exceptions.*;
import org.heigit.ors.matrix.MatrixErrorCodes;
import org.heigit.ors.matrix.MatrixResult;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConversionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.heigit.ors.api.services.RoutingService;
import org.heigit.ors.api.util.AppConfigMigration;
import org.heigit.ors.exceptions.*;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RouteResult;
import org.heigit.ors.routing.RoutingErrorCodes;
import org.locationtech.jts.geom.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.heigit.ors.api.services.SnappingService;
import org.heigit.ors.api.util.AppConfigMigration;
import org.heigit.ors.exceptions.*;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.snapping.SnappingErrorCodes;
import org.heigit.ors.snapping.SnappingResult;
import org.springframework.core.convert.ConversionFailedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package org.heigit.ors.api.converters;

import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.springframework.core.convert.converter.Converter;

public class APIRequestProfileConverter implements Converter<String, APIEnums.Profile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;

public class APIRequest {
public static final String PARAM_ID = "id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.api.requests.matrix.MatrixRequest;
import org.heigit.ors.api.requests.routing.RequestProfileParams;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RouteRequestParameterNames;
import org.json.simple.JSONObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.api.requests.common.APIRequest;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.heigit.ors.isochrones.IsochroneMapCollection;
import org.heigit.ors.isochrones.IsochroneRequest;
import org.heigit.ors.isochrones.IsochronesErrorCodes;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RoutingProfileType;

import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.heigit.ors.api.requests.common.APIRequest;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.matrix.MatrixErrorCodes;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.api.requests.common.APIRequest;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RouteRequestParameterNames;
import org.heigit.ors.routing.RoutingErrorCodes;
import org.heigit.ors.routing.RoutingProfileType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.api.requests.common.APIRequest;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.heigit.ors.api.responses.routing.json.JSON3DBoundingBox;
import org.heigit.ors.api.responses.routing.json.JSONBoundingBox;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RoutingErrorCodes;

public class BoundingBoxFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import jakarta.xml.bind.annotation.XmlElement;
import org.heigit.ors.api.requests.routing.RouteRequest;
import org.heigit.ors.api.util.AppInfo;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;

public class GPXExtensions {
@XmlElement(name = "attribution")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.heigit.ors.api.requests.routing.RouteRequest;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RouteSegment;
import org.heigit.ors.routing.RouteStep;
import org.heigit.ors.util.FormatUtility;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ors.api.services;

import org.heigit.ors.api.APIEnums;
import org.heigit.ors.api.EndpointsProperties;
import org.heigit.ors.api.requests.common.APIRequest;
import org.heigit.ors.api.requests.common.RequestOptions;
Expand Down Expand Up @@ -326,7 +327,7 @@ private WheelchairParameters convertWheelchairParamRestrictions(RequestProfilePa
if (restrictions.hasTrackType())
params.setTrackType(WheelchairTypesEncoder.getTrackType(restrictions.getTrackType()));
if (restrictions.hasSmoothnessType())
params.setSmoothnessType(WheelchairTypesEncoder.getSmoothnessType(restrictions.getSmoothnessType()));
params.setSmoothnessType(WheelchairTypesEncoder.getSmoothnessType(restrictions.getSmoothnessType().toString()));
if (restrictions.hasMaxSlopedKerb())
params.setMaximumSlopedKerb(restrictions.getMaxSlopedKerb());
if (restrictions.hasMaxIncline())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.heigit.ors.fastisochrones.partitioning.FastIsochroneFactory;
import org.heigit.ors.isochrones.*;
import org.heigit.ors.isochrones.statistics.StatisticsProviderConfiguration;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RouteSearchParameters;
import org.heigit.ors.routing.RoutingProfileManager;
import org.heigit.ors.routing.RoutingProfileType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.heigit.ors.matrix.MatrixMetricsType;
import org.heigit.ors.matrix.MatrixResult;
import org.heigit.ors.matrix.MatrixSearchParameters;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RoutingErrorCodes;
import org.heigit.ors.routing.RoutingProfileManager;
import org.heigit.ors.routing.RoutingProfileType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ors.api.services;

import org.heigit.ors.api.APIEnums;
import org.heigit.ors.api.EndpointsProperties;
import org.heigit.ors.api.requests.routing.RouteRequest;
import org.heigit.ors.api.requests.routing.RouteRequestRoundTripOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.heigit.ors.api.converters;

import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.heigit.ors.api.requests.routing.RouteRequestOptions;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.heigit.ors.api.EndpointsProperties;
import org.heigit.ors.api.util.HelperFunctions;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.heigit.ors.api.requests.routing;

import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.heigit.ors.api.requests.routing;

import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.heigit.ors.matrix.MatrixMetricsType;
import org.heigit.ors.matrix.MatrixResult;
import org.heigit.ors.matrix.ResolvedLocation;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.heigit.ors.matrix.MatrixMetricsType;
import org.heigit.ors.matrix.MatrixResult;
import org.heigit.ors.matrix.ResolvedLocation;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.heigit.ors.matrix.MatrixMetricsType;
import org.heigit.ors.matrix.MatrixResult;
import org.heigit.ors.matrix.ResolvedLocation;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.heigit.ors.api.responses.routing.gpx.GPXBounds;
import org.heigit.ors.api.responses.routing.json.JSON3DBoundingBox;
import org.heigit.ors.api.responses.routing.json.JSONBoundingBox;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.exceptions.StatusCodeException;
import org.heigit.ors.exceptions.UnknownParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.parameters.ProfileParameters;
import org.heigit.ors.routing.parameters.VehicleParameters;
import org.heigit.ors.routing.pathprocessors.BordersExtractor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ors.api.services;

import org.heigit.ors.api.APIEnums;
import org.heigit.ors.api.EndpointsProperties;
import org.heigit.ors.api.requests.isochrones.IsochronesRequest;
import org.heigit.ors.api.requests.isochrones.IsochronesRequestEnums;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.heigit.ors.exceptions.StatusCodeException;
import org.heigit.ors.matrix.MatrixMetricsType;
import org.heigit.ors.matrix.MatrixRequest;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RoutingProfileType;
import org.heigit.ors.routing.WeightingMethod;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.heigit.ors.api.services;

import org.heigit.ors.api.APIEnums;
import org.heigit.ors.api.EndpointsProperties;
import org.heigit.ors.api.requests.routing.*;
import org.heigit.ors.common.DistanceUnit;
Expand Down Expand Up @@ -233,7 +234,7 @@ void TestWheelchairParameters() throws Exception {
RoutingRequest routingRequest = routingService.convertRouteRequest(request);

WheelchairParameters params = (WheelchairParameters) routingRequest.getSearchParameters().getProfileParameters();
assertEquals(WheelchairTypesEncoder.getSmoothnessType(APIEnums.SmoothnessTypes.SMOOTHNESS_GOOD), params.getSmoothnessType());
assertEquals(WheelchairTypesEncoder.getSmoothnessType(APIEnums.SmoothnessTypes.SMOOTHNESS_GOOD.toString()), params.getSmoothnessType());
assertEquals(3.0f, params.getMaximumIncline(), 0);
assertEquals(1.0f, params.getMaximumSlopedKerb(), 0);
assertEquals(2.0f, params.getMinimumWidth(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.heigit.ors.api.requests.matrix.MatrixRequest;
import org.heigit.ors.api.requests.routing.RouteRequest;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.heigit.ors.routing.RoutingRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.heigit.ors.api.util;

import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.api.APIEnums;
import org.junit.jupiter.params.provider.Arguments;

import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*/
package org.heigit.ors.routing.graphhopper.extensions;

import org.heigit.ors.routing.APIEnums;
import org.heigit.ors.exceptions.ParameterValueException;
import org.heigit.ors.routing.GenericErrorCodes;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -154,15 +155,19 @@ public static int getSurfaceType(String value) {

public static int getEncodedType(WheelchairAttributes.Attribute attribute, String value) throws Exception {
return switch (attribute) {
case SMOOTHNESS -> getSmoothnessType(APIEnums.SmoothnessTypes.forValue(value));
case SMOOTHNESS -> { int smoothness = getSmoothnessType(value);
if (smoothness==-1)
throw new ParameterValueException(GenericErrorCodes.INVALID_PARAMETER_VALUE, "surface_type", value);
yield smoothness;
}
case SURFACE -> getSurfaceType(value);
case TRACK -> getTrackType(value);
default -> throw new Exception("Attribute is not a recognised encoded type");
};
}

public static int getSmoothnessType(APIEnums.SmoothnessTypes smoothnessType) {
return SMOOTHNESS_MAP.getOrDefault(smoothnessType.toString(), -1);
public static int getSmoothnessType(String value) {
return SMOOTHNESS_MAP.getOrDefault(value.toLowerCase(), -1);
}

public static int getTrackType(String value) {
Expand Down
Loading

0 comments on commit 25746d3

Please sign in to comment.