diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/ResponseBody.java b/src/main/java/gov/usgs/earthquake/nshmp/www/ResponseBody.java deleted file mode 100644 index 0e10375315a5a716f3de429e0c5ce6853f687078..0000000000000000000000000000000000000000 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/ResponseBody.java +++ /dev/null @@ -1,213 +0,0 @@ -package gov.usgs.earthquake.nshmp.www; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.time.ZonedDateTime; - -import gov.usgs.earthquake.nshmp.www.meta.Status; - -/** - * Generic wrapper around a web service response object that is typically - * serialized to JSON and sent back to requestor as an HttpResponse 'body'. - * - * <p>To create a response, use one of the three static builder methods: - * {@link Builder#error()}, {@link Builder#success()}, or - * {@link Builder#usage()}. - * - * @author U.S. Geological Survey - * - * @param <T> The request type - * @param <V> The response type - */ -public class ResponseBody<T, V> { - - private final String name; - private final String date; - private final String status; - private final String url; - private final T request; - private final V response; - private final ResponseMetadata metadata; - - private ResponseBody(Builder<T, V> builder) { - name = builder.name; - date = ZonedDateTime.now().format(WsUtils.DATE_FMT); - status = builder.status; - url = builder.url; - request = builder.request; - response = builder.response; - metadata = builder.metadata; - } - - protected ResponseBody() { - date = null; - metadata = null; - name = null; - request = null; - response = null; - status = null; - url = null; - } - - /** - * The date and time this request/response. - */ - public String getDate() { - return date; - } - - /** - * The metadata. - */ - public ResponseMetadata getMetadata() { - return metadata; - } - - /** - * The name of the service. - */ - public String getName() { - return name; - } - - /** - * The request object. - */ - public T getRequest() { - return request; - } - - /** - * The response object. - */ - public V getResponse() { - return response; - } - - /** - * The response status. - */ - public String getStatus() { - return status; - } - - /** - * The URL used to call the service - */ - public String getUrl() { - return url; - } - - /** - * Create a new builder initialized to an error response. - * - * @param <T> The request type - * @param <V> The response type - */ - public static <T, V> Builder<T, V> error() { - return new Builder<T, V>(Status.ERROR); - } - - /** - * Create a new builder initialized to a success response. - * - * @param <T> The request type - * @param <V> The response type - */ - public static <T, V> Builder<T, V> success() { - return new Builder<T, V>(Status.SUCCESS); - } - - /** - * Create a new builder initialized to a usage response. - * - * @param <T> The request type - * @param <V> The response type - */ - public static <T, V> Builder<T, V> usage() { - return new Builder<T, V>(Status.USAGE); - } - - /** - * A {@code ResponseBody} builder. - * - * @param <T> The request type - * @param <V> The response type - */ - public static class Builder<T, V> { - - private String name; - private String status; - private String url; - private ResponseMetadata metadata; - private T request; - private V response; - - private Builder(String status) { - this.status = status; - } - - /** - * Set the metadata. - * - * @param metadata The servie metadata - */ - public Builder<T, V> metadata(ResponseMetadata metadata) { - this.metadata = metadata; - return this; - } - - /** - * Set the service name. - * - * @param name of the service being called - */ - public Builder<T, V> name(String name) { - this.name = name; - return this; - } - - /** - * Set the request object. - * - * @param request object - */ - public Builder<T, V> request(T request) { - this.request = request; - return this; - } - - /** - * Set the response object. - * - * @param response object - */ - public Builder<T, V> response(V response) { - this.response = response; - return this; - } - - /** - * Set the url used to call the service. - * - * @param url used to generate this response - */ - public Builder<T, V> url(String url) { - this.url = url; - return this; - } - - /** - * Returns a new Response - */ - public ResponseBody<T, V> build() { - checkNotNull(metadata); - checkNotNull(name); - checkNotNull(request); - checkNotNull(response); - checkNotNull(url); - checkNotNull(status); - return new ResponseBody<T, V>(this); - } - } -} diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtils.java b/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtils.java deleted file mode 100644 index 1e0d6939a995fea473a307235794717c33b1db16..0000000000000000000000000000000000000000 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/WsUtils.java +++ /dev/null @@ -1,100 +0,0 @@ -package gov.usgs.earthquake.nshmp.www; - -import java.lang.reflect.Type; -import java.time.format.DateTimeFormatter; -import java.util.Optional; - -import com.google.common.collect.Range; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import gov.usgs.earthquake.nshmp.gmm.GmmInput; -import gov.usgs.earthquake.nshmp.gmm.GmmInput.Field; - -/** - * Web service utilities. - * - * @author U.S. Geological Survey - */ -public class WsUtils { - - public static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern( - "yyyy-MM-dd'T'HH:mm:ssXXX"); - - public static <T, E extends Enum<E>> T checkValue(E key, T value) { - if (value == null) { - throw new IllegalStateException("Missing [" + key.toString() + "]"); - } - - return value; - } - - /* Constrain all doubles to 8 decimal places */ - public static final class DoubleSerializer implements JsonSerializer<Double> { - @Override - public JsonElement serialize(Double d, Type type, JsonSerializationContext context) { - double dOut = Double.valueOf(String.format("%.8g", d)); - return new JsonPrimitive(dOut); - } - } - - /* Convert NaN to null */ - public static final class NaNSerializer implements JsonSerializer<Double> { - @Override - public JsonElement serialize(Double d, Type type, JsonSerializationContext context) { - return Double.isNaN(d) ? null : new JsonPrimitive(d); - } - } - - public static final class ConstraintsSerializer implements JsonSerializer<GmmInput.Constraints> { - @Override - public JsonElement serialize( - GmmInput.Constraints constraints, - Type type, - JsonSerializationContext context) { - JsonArray json = new JsonArray(); - - for (Field field : Field.values()) { - Optional<?> opt = constraints.get(field); - if (opt.isPresent()) { - Range<?> value = (Range<?>) opt.orElseThrow(); - Constraint constraint = new Constraint( - field.id, - value.lowerEndpoint(), - value.upperEndpoint()); - json.add(context.serialize(constraint)); - } - } - - return json; - } - } - - public static final class EnumSerializer<E extends Enum<E>> implements JsonSerializer<E> { - @Override - public JsonElement serialize(E src, Type type, JsonSerializationContext context) { - JsonObject jObj = new JsonObject(); - jObj.addProperty("value", src.name()); - jObj.addProperty("display", src.toString()); - - return jObj; - } - } - - @SuppressWarnings("unused") - private static class Constraint { - final String id; - final Object min; - final Object max; - - Constraint(String id, Object min, Object max) { - this.id = id; - this.min = min; - this.max = max; - } - } -} diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/meta/EnumParameter.java b/src/main/java/gov/usgs/earthquake/nshmp/www/meta/EnumParameter.java deleted file mode 100644 index 154bedc45e213eca83bd954c7936b25bec59903b..0000000000000000000000000000000000000000 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/meta/EnumParameter.java +++ /dev/null @@ -1,22 +0,0 @@ -package gov.usgs.earthquake.nshmp.www.meta; - -import java.util.Set; - -/** - * An enum parameter. - * - * @author U.S. Geological Survey - * - * @param <E> The enum type - */ -public final class EnumParameter<E extends Enum<E>> { - - private final String label; - private final Set<E> values; - - public EnumParameter(String label, Set<E> values) { - this.label = label; - this.values = values; - } - -} diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/meta/Status.java b/src/main/java/gov/usgs/earthquake/nshmp/www/meta/Status.java deleted file mode 100644 index 9511b464d8101fe317e31784006f2945dab9bade..0000000000000000000000000000000000000000 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/meta/Status.java +++ /dev/null @@ -1,18 +0,0 @@ -package gov.usgs.earthquake.nshmp.www.meta; - -/** - * Service request status identifier. - * - * @author U.S. Geological Survey - */ -public class Status { - - /** Error reponse status. */ - public static final String ERROR = "error"; - - /** Success reponse status. */ - public static final String SUCCESS = "success"; - - /** Usage reponse status. */ - public static final String USAGE = "usage"; -} diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/meta/StringParameter.java b/src/main/java/gov/usgs/earthquake/nshmp/www/meta/StringParameter.java deleted file mode 100644 index d8262749207c60ed72b4aedd2dc1ddcb16354ee8..0000000000000000000000000000000000000000 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/meta/StringParameter.java +++ /dev/null @@ -1,20 +0,0 @@ -package gov.usgs.earthquake.nshmp.www.meta; - -import java.util.Set; - -/** - * A string parameter. - * - * @author U.S. Geological Survey - */ -public class StringParameter { - - public final String label; - public final Set<String> values; - - public StringParameter(String label, Set<String> values) { - this.label = label; - this.values = values; - } - -}