diff --git a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/FeatureCollectionService.java b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/FeatureCollectionService.java new file mode 100644 index 0000000000000000000000000000000000000000..e5cb9d5dbedf3396db5b4ae75964df59acdf480c --- /dev/null +++ b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/FeatureCollectionService.java @@ -0,0 +1,50 @@ +package gov.usgs.earthquake.nshmp.netcdf.www; + +import com.google.gson.JsonElement; + +import gov.usgs.earthquake.nshmp.geo.json.FeatureCollection; +import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion; +import gov.usgs.earthquake.nshmp.www.ResponseBody; +import gov.usgs.earthquake.nshmp.www.ResponseMetadata; + +import io.micronaut.http.HttpRequest; +import jakarta.inject.Singleton; + +/** + * Handle feature collection services. + * + * @author U.S. Geological Survey + */ +@Singleton +public class FeatureCollectionService { + + static String handleFeatureCollection( + HttpRequest<?> http, + String name, + FeatureCollection fc, + Boolean raw) { + RequestData requestData = new RequestData(raw); + + if (requestData.raw) { + return fc.toJson(); + } else { + var response = ResponseBody.<RequestData, JsonElement> success() + .name(name) + .url(http.getUri().toString()) + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) + .request(requestData) + .response(fc.toJsonTree()) + .build(); + + return NetcdfWsUtils.GSON.toJson(response); + } + } + + static class RequestData { + public boolean raw; + + RequestData(Boolean raw) { + this.raw = raw == null ? false : raw; + } + } +}