Skip to content
Snippets Groups Projects
Commit 81255dc2 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

get service name from netcdf file

parent bd568499
No related branches found
No related tags found
2 merge requests!124Production Release | nshmp-ws-static,!123Resolves - Remove GITLAB_TOKEN Requirement and AASHTO-2023 web service -- add CSV response
...@@ -8,8 +8,11 @@ import gov.usgs.earthquake.nshmp.geo.Location; ...@@ -8,8 +8,11 @@ import gov.usgs.earthquake.nshmp.geo.Location;
import gov.usgs.earthquake.nshmp.netcdf.NetcdfGroundMotions; import gov.usgs.earthquake.nshmp.netcdf.NetcdfGroundMotions;
import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion; import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion;
import gov.usgs.earthquake.nshmp.netcdf.data.StaticData; 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.NetcdfWsUtils.Key;
import gov.usgs.earthquake.nshmp.netcdf.www.Query.Service; 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.ResponseBody;
import gov.usgs.earthquake.nshmp.www.ResponseMetadata; import gov.usgs.earthquake.nshmp.www.ResponseMetadata;
import gov.usgs.earthquake.nshmp.www.WsUtils; import gov.usgs.earthquake.nshmp.www.WsUtils;
...@@ -26,7 +29,6 @@ import io.micronaut.http.HttpRequest; ...@@ -26,7 +29,6 @@ import io.micronaut.http.HttpRequest;
public class NetcdfServiceGroundMotions extends NetcdfService<Query> { public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
static final String SERVICE_DESCRIPTION = "Get static ground motions from a NetCDF file"; 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 X_LABEL = "Period (s)";
static final String Y_LABEL = "Spectral Acceleration (g)"; static final String Y_LABEL = "Spectral Acceleration (g)";
...@@ -35,12 +37,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { ...@@ -35,12 +37,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
} }
@Override @Override
ResponseBody<String, Metadata> getMetadataResponse(HttpRequest<?> request) { ResponseBody<String, Metadata<Query>> getMetadataResponse(HttpRequest<?> request) {
var metadata = new Metadata(request, SERVICE_DESCRIPTION); 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())) .metadata(new ResponseMetadata(NetcdfVersion.appVersions()))
.name(SERVICE_NAME) .name(getServiceName())
.request(NetcdfWsUtils.getRequestUrl(request)) .request(NetcdfWsUtils.getRequestUrl(request))
.response(metadata) .response(metadata)
.url(NetcdfWsUtils.getRequestUrl(request)) .url(NetcdfWsUtils.getRequestUrl(request))
...@@ -49,12 +51,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { ...@@ -49,12 +51,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
@Override @Override
String getServiceName() { String getServiceName() {
return SERVICE_NAME; return getSourceModel().name;
} }
@Override @Override
SourceModel getSourceModel() { SourceModel getSourceModel() {
return new SourceModel(); return new SourceModel(netcdf());
} }
@Override @Override
...@@ -63,18 +65,18 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { ...@@ -63,18 +65,18 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
} }
@Override @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 site = Location.create(query.longitude, query.latitude);
var requestData = new RequestData(site); var requestData = new RequestData(site, query.format);
var url = NetcdfWsUtils.getRequestUrl(httpRequest); var url = NetcdfWsUtils.getRequestUrl(httpRequest);
switch (service) { switch (service) {
case CURVES: case CURVES:
return processCurves(requestData, url); return toResponseFromList(processCurves(requestData, url));
case CURVES_BY_SITE_CLASS: case CURVES_BY_SITE_CLASS:
requestData = new RequestDataSiteClass(site, query.siteClass); requestData = new RequestDataSiteClass(site, query.siteClass, query.format);
return processCurvesSiteClass( return toResponse(processCurvesSiteClass(
(RequestDataSiteClass) requestData, url); (RequestDataSiteClass) requestData, url));
default: default:
throw new RuntimeException("Netcdf service [" + service + "] not found"); throw new RuntimeException("Netcdf service [" + service + "] not found");
} }
...@@ -92,7 +94,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { ...@@ -92,7 +94,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
return ResponseBody.<RequestDataSiteClass, ResponseData<ServiceResponseMetadata>> success() return ResponseBody.<RequestDataSiteClass, ResponseData<ServiceResponseMetadata>> success()
.metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .metadata(new ResponseMetadata(NetcdfVersion.appVersions()))
.name(SERVICE_NAME) .name(getServiceName())
.request(request) .request(request)
.response(responseData) .response(responseData)
.url(url) .url(url)
...@@ -106,11 +108,11 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { ...@@ -106,11 +108,11 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
WsUtils.checkValue(Key.LATITUDE, request.latitude); WsUtils.checkValue(Key.LATITUDE, request.latitude);
WsUtils.checkValue(Key.LONGITUDE, request.longitude); WsUtils.checkValue(Key.LONGITUDE, request.longitude);
var curves = netcdf().staticData(request.site); var curves = netcdf().staticData(request.site);
var responseData = toList(request.site, curves); var responseData = toList(request, curves);
return ResponseBody.<RequestData, List<ResponseData<ServiceResponseMetadata>>> success() return ResponseBody.<RequestData, List<ResponseData<ServiceResponseMetadata>>> success()
.metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .metadata(new ResponseMetadata(NetcdfVersion.appVersions()))
.name(SERVICE_NAME) .name(getServiceName())
.request(request) .request(request)
.response(responseData) .response(responseData)
.url(url) .url(url)
...@@ -118,11 +120,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { ...@@ -118,11 +120,12 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> {
} }
List<ResponseData<ServiceResponseMetadata>> toList( List<ResponseData<ServiceResponseMetadata>> toList(
Location site, RequestData requestData,
StaticData<XySequence> curves) { StaticData<XySequence> curves) {
return curves.entrySet().stream() return curves.entrySet().stream()
.map(entry -> { .map(entry -> {
var request = new RequestDataSiteClass(site, entry.getKey()); var request =
new RequestDataSiteClass(requestData.site, entry.getKey(), requestData.format);
return toResponseData(request, entry.getValue()); return toResponseData(request, entry.getValue());
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment