diff --git a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceGroundMotions.java b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceGroundMotions.java index 5b1d333ca294a59f5e102c2fcd05c36afa2c50c0..e5ddcae46b8b3fa7c96fc3f7fb12ce30ecb06804 100644 --- a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceGroundMotions.java +++ b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceGroundMotions.java @@ -8,8 +8,11 @@ import gov.usgs.earthquake.nshmp.geo.Location; import gov.usgs.earthquake.nshmp.netcdf.NetcdfGroundMotions; import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion; import gov.usgs.earthquake.nshmp.netcdf.data.StaticData; +import gov.usgs.earthquake.nshmp.netcdf.www.Metadata.ServiceResponseMetadata; import gov.usgs.earthquake.nshmp.netcdf.www.NetcdfWsUtils.Key; import gov.usgs.earthquake.nshmp.netcdf.www.Query.Service; +import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestData; +import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestDataSiteClass; import gov.usgs.earthquake.nshmp.www.ResponseBody; import gov.usgs.earthquake.nshmp.www.ResponseMetadata; import gov.usgs.earthquake.nshmp.www.WsUtils; @@ -26,7 +29,6 @@ import io.micronaut.http.HttpRequest; public class NetcdfServiceGroundMotions extends NetcdfService<Query> { static final String SERVICE_DESCRIPTION = "Get static ground motions from a NetCDF file"; - static final String SERVICE_NAME = "AASHTO-2023 Web Service"; static final String X_LABEL = "Period (s)"; static final String Y_LABEL = "Spectral Acceleration (g)"; @@ -35,12 +37,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { } @Override - ResponseBody<String, Metadata> getMetadataResponse(HttpRequest<?> request) { - var metadata = new Metadata(request, SERVICE_DESCRIPTION); + ResponseBody<String, Metadata<Query>> getMetadataResponse(HttpRequest<?> request) { + var metadata = new Metadata<Query>(request, this, SERVICE_DESCRIPTION); - return ResponseBody.<String, Metadata> usage() + return ResponseBody.<String, Metadata<Query>> usage() .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) - .name(SERVICE_NAME) + .name(getServiceName()) .request(NetcdfWsUtils.getRequestUrl(request)) .response(metadata) .url(NetcdfWsUtils.getRequestUrl(request)) @@ -49,12 +51,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { @Override String getServiceName() { - return SERVICE_NAME; + return getSourceModel().name; } @Override SourceModel getSourceModel() { - return new SourceModel(); + return new SourceModel(netcdf()); } @Override @@ -63,18 +65,18 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { } @Override - ResponseBody<?, ?> processRequest(HttpRequest<?> httpRequest, Query query, Service service) { + String processRequest(HttpRequest<?> httpRequest, Query query, Service service) { var site = Location.create(query.longitude, query.latitude); - var requestData = new RequestData(site); + var requestData = new RequestData(site, query.format); var url = NetcdfWsUtils.getRequestUrl(httpRequest); switch (service) { case CURVES: - return processCurves(requestData, url); + return toResponseFromList(processCurves(requestData, url)); case CURVES_BY_SITE_CLASS: - requestData = new RequestDataSiteClass(site, query.siteClass); - return processCurvesSiteClass( - (RequestDataSiteClass) requestData, url); + requestData = new RequestDataSiteClass(site, query.siteClass, query.format); + return toResponse(processCurvesSiteClass( + (RequestDataSiteClass) requestData, url)); default: throw new RuntimeException("Netcdf service [" + service + "] not found"); } @@ -92,7 +94,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { return ResponseBody.<RequestDataSiteClass, ResponseData<ServiceResponseMetadata>> success() .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) - .name(SERVICE_NAME) + .name(getServiceName()) .request(request) .response(responseData) .url(url) @@ -106,11 +108,11 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { WsUtils.checkValue(Key.LATITUDE, request.latitude); WsUtils.checkValue(Key.LONGITUDE, request.longitude); var curves = netcdf().staticData(request.site); - var responseData = toList(request.site, curves); + var responseData = toList(request, curves); return ResponseBody.<RequestData, List<ResponseData<ServiceResponseMetadata>>> success() .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) - .name(SERVICE_NAME) + .name(getServiceName()) .request(request) .response(responseData) .url(url) @@ -118,11 +120,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { } List<ResponseData<ServiceResponseMetadata>> toList( - Location site, + RequestData requestData, StaticData<XySequence> curves) { return curves.entrySet().stream() .map(entry -> { - var request = new RequestDataSiteClass(site, entry.getKey()); + var request = + new RequestDataSiteClass(requestData.site, entry.getKey(), requestData.format); return toResponseData(request, entry.getValue()); }) .collect(Collectors.toList());