diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtil.java b/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtil.java index f6870fde1fdf198723fceaa538b37f9be9050683..bf52c0e8b13e0c38a8a2f1941c0520d5268b5006 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtil.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtil.java @@ -17,7 +17,9 @@ import gov.usgs.earthquake.nshmp.internal.Parsing; import gov.usgs.earthquake.nshmp.internal.Parsing.Delimiter; import gov.usgs.earthquake.nshmp.internal.www.NshmpMicronautServlet.UrlHelper; import gov.usgs.earthquake.nshmp.internal.www.Response; +import gov.usgs.earthquake.nshmp.internal.www.WsUtils; import gov.usgs.earthquake.nshmp.internal.www.meta.Status; +import gov.usgs.earthquake.nshmp.www.services.SourceServices.SourceModel; import io.micronaut.http.HttpResponse; @@ -37,6 +39,45 @@ public class WsUtil { return HttpResponse.serverError(response); } + public static interface ServiceQuery { + boolean isNull(); + + void checkValues(); + } + + public static class ServiceQueryData implements ServiceQuery { + public final Double longitude; + public final Double latitude; + + public ServiceQueryData(Double longitude, Double latitude) { + this.longitude = longitude; + this.latitude = latitude; + } + + @Override + public boolean isNull() { + return longitude == null && latitude == null; + } + + @Override + public void checkValues() { + WsUtils.checkValue(Key.LONGITUDE, longitude); + WsUtils.checkValue(Key.LATITUDE, latitude); + } + } + + public static class ServiceRequestData { + public final SourceModel model; + public final double longitude; + public final double latitude; + + public ServiceRequestData(ServiceQueryData query) { + model = new SourceModel(ServletUtil.installedModel()); + longitude = query.longitude; + latitude = query.latitude; + } + } + /** * Returns the value of a servlet request parameter as a boolean. *