diff --git a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java index 5bd776c0040d70de43e8e21763d8533b1170b53d..727142bac7070531ce86f38c96a1f6046f8adef5 100644 --- a/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java +++ b/src/aashto/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/SwaggerController.java @@ -1,9 +1,8 @@ package gov.usgs.earthquake.nshmp.netcdf.www; -import java.io.IOException; import java.nio.file.Path; -import gov.usgs.earthquake.nshmp.netcdf.NetcdfGroundMotions; +import gov.usgs.earthquake.nshmp.netcdf.NetcdfDataFilesGroundMotions; import gov.usgs.earthquake.nshmp.www.NshmpMicronautServlet; import io.micronaut.context.annotation.Value; @@ -34,74 +33,30 @@ public class SwaggerController { @Inject private NshmpMicronautServlet servlet; - @Value("${nshmp-ws-static.netcdf-file}") + @Value("${nshmp-ws-static.netcdf-path}") Path netcdfPath; - NetcdfGroundMotions netcdf; + @Value("${nshmp-ws-static.aashto-year}") + int aashtoYear; + + NetcdfServiceGroundMotions service; /** * Read in data type and return the appropriate service to use. */ @EventListener void startup(StartupEvent event) { - netcdf = new NetcdfGroundMotions(netcdfPath); + var netcdfDataFiles = new NetcdfDataFilesGroundMotions(netcdfPath, aashtoYear); + service = new NetcdfServiceGroundMotions(netcdfDataFiles); } @Get(produces = MediaType.TEXT_EVENT_STREAM) public HttpResponse<String> doGet(HttpRequest<?> request) { try { - var openApi = NetcdfWsUtils.getOpenApi( - request, - netcdf.netcdfData(), - servicePatternSection(request)); - return HttpResponse.ok(Yaml.pretty(openApi)); + SwaggerGroundMotions swagger = new SwaggerGroundMotions(request, service); + return HttpResponse.ok(Yaml.pretty(swagger.updateOpenApi())); } catch (Exception e) { return NetcdfWsUtils.handleError(e, "Swagger", request.getUri().getPath()); } } - - private static String servicePatternSection(HttpRequest<?> request) - throws IOException { - var url = NetcdfWsUtils.getRequestUrl(request); - url = url.endsWith("/swagger") ? url.replace("/swagger", "") : url; - - return new StringBuilder() - .append( - "<details>\n" + - "<summary>Service Call Patterns</summary>\n") - .append( - "### Query Pattern\n" + - - "The query based service call is in the form of:\n" + - - "```text\n" + - url + "/spectra?longitude={number}&latitude={number}\n" + - url + "/spectra?longitude={number}&latitude={number}&siteClass={string}\n" + - "````\n" + - - "Example:\n" + - "```text\n" + - url + "/spectra?longitude=-118&latitude=34\n" + - url + "/spectra?longitude=-118&latitude=34&siteClass=BC\n" + - "```\n") - .append( - "### Slash Pattern\n" + - - "The slash based service call is in the form of:\n" + - - "```text\n" + - url + "/spectra/{longitude}/{latitude}\n" + - url + "/spectra/{longitude}/{latitude}/{siteClass}\n" + - "```\n" + - - "Example:\n" + - - "```text\n" + - url + "/spectra/-118/34\n" + - url + "/spectra/-118/34/BC\n" + - "```\n") - .append("</details>") - .toString(); - } - }