From 80e550dec834506014901faab442c8db422ef3dd Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Wed, 20 Apr 2022 17:06:55 -0600 Subject: [PATCH] add metadata --- .../www/NetcdfServiceGroundMotions.java | 19 ++++++++++++------- .../netcdf/www/NetcdfServiceHazardCurves.java | 8 +++++++- .../nshmp/netcdf/www/NetcdfService.java | 6 +++--- .../nshmp/netcdf/www/NetcdfWsUtils.java | 3 +++ 4 files changed, 25 insertions(+), 11 deletions(-) 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 ddf9aa2..5b1d333 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 @@ -6,10 +6,12 @@ import java.util.stream.Collectors; import gov.usgs.earthquake.nshmp.data.XySequence; 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.NetcdfWsUtils.Key; import gov.usgs.earthquake.nshmp.netcdf.www.Query.Service; import gov.usgs.earthquake.nshmp.www.ResponseBody; +import gov.usgs.earthquake.nshmp.www.ResponseMetadata; import gov.usgs.earthquake.nshmp.www.WsUtils; import io.micronaut.http.HttpRequest; @@ -37,6 +39,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { var metadata = new Metadata(request, SERVICE_DESCRIPTION); return ResponseBody.<String, Metadata> usage() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(NetcdfWsUtils.getRequestUrl(request)) .response(metadata) @@ -78,7 +81,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { } @Override - ResponseBody<RequestDataSiteClass, ResponseData<ResponseMetadata>> processCurvesSiteClass( + ResponseBody<RequestDataSiteClass, ResponseData<ServiceResponseMetadata>> processCurvesSiteClass( RequestDataSiteClass request, String url) { WsUtils.checkValue(Key.LATITUDE, request.latitude); @@ -87,7 +90,8 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { var curves = netcdf().staticData(request.site, request.siteClass); var responseData = toResponseData(request, curves); - return ResponseBody.<RequestDataSiteClass, ResponseData<ResponseMetadata>> success() + return ResponseBody.<RequestDataSiteClass, ResponseData<ServiceResponseMetadata>> success() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(request) .response(responseData) @@ -96,7 +100,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { } @Override - ResponseBody<RequestData, List<ResponseData<ResponseMetadata>>> processCurves( + ResponseBody<RequestData, List<ResponseData<ServiceResponseMetadata>>> processCurves( RequestData request, String url) { WsUtils.checkValue(Key.LATITUDE, request.latitude); @@ -104,7 +108,8 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { var curves = netcdf().staticData(request.site); var responseData = toList(request.site, curves); - return ResponseBody.<RequestData, List<ResponseData<ResponseMetadata>>> success() + return ResponseBody.<RequestData, List<ResponseData<ServiceResponseMetadata>>> success() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(request) .response(responseData) @@ -112,7 +117,7 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { .build(); } - List<ResponseData<ResponseMetadata>> toList( + List<ResponseData<ServiceResponseMetadata>> toList( Location site, StaticData<XySequence> curves) { return curves.entrySet().stream() @@ -123,10 +128,10 @@ public class NetcdfServiceGroundMotions extends NetcdfService<Query> { .collect(Collectors.toList()); } - ResponseData<ResponseMetadata> toResponseData( + ResponseData<ServiceResponseMetadata> toResponseData( RequestDataSiteClass request, XySequence curves) { - var metadata = new ResponseMetadata( + var metadata = new ServiceResponseMetadata( request.siteClass, X_LABEL, Y_LABEL); diff --git a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java index b223f4e..94a1d74 100644 --- a/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java +++ b/src/hazard/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfServiceHazardCurves.java @@ -8,11 +8,13 @@ import gov.usgs.earthquake.nshmp.geo.Location; import gov.usgs.earthquake.nshmp.gmm.Imt; import gov.usgs.earthquake.nshmp.gmm.NehrpSiteClass; import gov.usgs.earthquake.nshmp.netcdf.NetcdfHazardCurves; +import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion; import gov.usgs.earthquake.nshmp.netcdf.data.StaticData; import gov.usgs.earthquake.nshmp.netcdf.data.StaticDataHazardCurves; import gov.usgs.earthquake.nshmp.netcdf.www.NetcdfWsUtils.Key; import gov.usgs.earthquake.nshmp.netcdf.www.Query.Service; import gov.usgs.earthquake.nshmp.www.ResponseBody; +import gov.usgs.earthquake.nshmp.www.ResponseMetadata; import gov.usgs.earthquake.nshmp.www.WsUtils; import io.micronaut.http.HttpRequest; @@ -39,6 +41,7 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { ResponseBody<String, Metadata> getMetadataResponse(HttpRequest<?> request) { var metadata = new Metadata(request, SERVICE_DESCRIPTION); return ResponseBody.<String, Metadata> usage() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(NetcdfWsUtils.getRequestUrl(request)) .response(metadata) @@ -82,6 +85,7 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { var curvesAsList = toList(request.site, curves); return ResponseBody.<RequestData, List<List<ResponseData<HazardResponseMetadata>>>> success() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(request) .response(curvesAsList) @@ -100,6 +104,7 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { var curvesAsList = toList(request, curves); return ResponseBody.<RequestDataSiteClass, List<ResponseData<HazardResponseMetadata>>> success() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(request) .response(curvesAsList) @@ -117,6 +122,7 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { var curves = netcdf().staticData(request.site, request.siteClass); return ResponseBody.<RequestDataSiteClass, ResponseData<HazardResponseMetadata>> success() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(SERVICE_NAME) .request(request) .response(toResponseData(request, request.imt, curves.get(request.imt))) @@ -182,7 +188,7 @@ public class NetcdfServiceHazardCurves extends NetcdfService<HazardQuery> { } } - static class HazardResponseMetadata extends ResponseMetadata { + static class HazardResponseMetadata extends ServiceResponseMetadata { public final Imt imt; HazardResponseMetadata(NehrpSiteClass siteClass, Imt imt, String xLabel, String yLabel) { diff --git a/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java b/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java index e487f79..c6f12eb 100644 --- a/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java +++ b/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java @@ -197,12 +197,12 @@ public abstract class NetcdfService<T extends Query> { } } - static class ResponseMetadata { + static class ServiceResponseMetadata { public NehrpSiteClass siteClass; public String xLabel; public String yLabel; - ResponseMetadata( + ServiceResponseMetadata( NehrpSiteClass siteClass, String xLabel, String yLabel) { @@ -212,7 +212,7 @@ public abstract class NetcdfService<T extends Query> { } } - static class ResponseData<T extends ResponseMetadata> { + static class ResponseData<T extends ServiceResponseMetadata> { final T metadata; final XySequence data; diff --git a/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java b/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java index 83ac0be..7021620 100644 --- a/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java +++ b/src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java @@ -13,9 +13,11 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import gov.usgs.earthquake.nshmp.gmm.Imt; +import gov.usgs.earthquake.nshmp.netcdf.NetcdfVersion; import gov.usgs.earthquake.nshmp.netcdf.data.NetcdfData; import gov.usgs.earthquake.nshmp.netcdf.data.ScienceBaseMetadata; import gov.usgs.earthquake.nshmp.www.ResponseBody; +import gov.usgs.earthquake.nshmp.www.ResponseMetadata; import gov.usgs.earthquake.nshmp.www.SwaggerUtils; import gov.usgs.earthquake.nshmp.www.WsUtils.EnumSerializer; import gov.usgs.earthquake.nshmp.www.WsUtils.NaNSerializer; @@ -55,6 +57,7 @@ public class NetcdfWsUtils { String url) { var msg = e.getMessage() + " (see logs)"; var svcResponse = ResponseBody.error() + .metadata(new ResponseMetadata(NetcdfVersion.appVersions())) .name(name) .request(url) .response(msg) -- GitLab