Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nshmp-ws-static
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Seismic Hazard Model Project
nshmp-ws-static
Commits
57de20ff
Commit
57de20ff
authored
2 years ago
by
Clayton, Brandon Scott
Browse files
Options
Downloads
Patches
Plain Diff
move swagger utils to swagger class
parent
4c5845c7
No related branches found
No related tags found
2 merge requests
!128
Production Release | nshmp-ws-static
,
!127
Resolves - Handle Multiple NetCDF Files for AASHTO Service
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java
+0
-83
0 additions, 83 deletions
...a/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java
with
0 additions
and
83 deletions
src/lib/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfWsUtils.java
+
0
−
83
View file @
57de20ff
...
...
@@ -3,29 +3,21 @@ package gov.usgs.earthquake.nshmp.netcdf.www;
import
static
com
.
google
.
common
.
base
.
CaseFormat
.
UPPER_CAMEL
;
import
static
com
.
google
.
common
.
base
.
CaseFormat
.
UPPER_UNDERSCORE
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Optional
;
import
java.util.logging.Logger
;
import
java.util.stream.Collectors
;
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
;
import
io.micronaut.http.HttpRequest
;
import
io.micronaut.http.HttpResponse
;
import
io.swagger.v3.oas.models.OpenAPI
;
import
io.swagger.v3.parser.OpenAPIV3Parser
;
public
class
NetcdfWsUtils
{
static
final
Gson
GSON
;
...
...
@@ -69,33 +61,6 @@ public class NetcdfWsUtils {
return
HttpResponse
.
serverError
(
response
);
}
public
static
OpenAPI
getOpenApi
(
HttpRequest
<?>
request
,
NetcdfData
netcdfData
,
String
serviceSection
)
throws
IOException
{
var
openApi
=
new
OpenAPIV3Parser
().
read
(
"META-INF/swagger/nshmp-ws-static.yml"
);
var
scienceBaseMetadata
=
netcdfData
.
scienceBaseMetadata
();
SwaggerUtils
.
addLocationBounds
(
openApi
,
netcdfData
.
minimumBounds
(),
netcdfData
.
maximumBounds
());
var
components
=
openApi
.
getComponents
();
var
schemas
=
components
.
getSchemas
();
SwaggerUtils
.
siteClassSchema
(
schemas
,
netcdfData
.
siteClasses
());
openApi
.
servers
(
null
);
openApi
.
getInfo
().
setTitle
(
scienceBaseMetadata
.
label
);
// Update description
var
description
=
new
StringBuilder
()
.
append
(
scienceBaseMetadata
.
description
+
"\n"
)
.
append
(
swaggerResponseFormatSection
())
.
append
(
serviceSection
)
.
append
(
swaggerParameterSection
(
netcdfData
))
.
append
(
swaggerScienceBaseSection
(
scienceBaseMetadata
))
.
toString
();
openApi
.
getInfo
().
setDescription
(
description
);
return
openApi
;
}
public
static
enum
Key
{
LATITUDE
,
LONGITUDE
,
...
...
@@ -107,52 +72,4 @@ public class NetcdfWsUtils {
return
UPPER_UNDERSCORE
.
to
(
UPPER_CAMEL
,
name
());
}
}
private
static
String
swaggerParameterSection
(
NetcdfData
netcdfData
)
{
return
new
StringBuilder
()
.
append
(
"<details>\n"
+
"<summary>Parameters</summary>\n"
)
.
append
(
SwaggerUtils
.
locationBoundsInfo
(
netcdfData
.
minimumBounds
(),
netcdfData
.
maximumBounds
(),
Optional
.
of
(
"###"
)))
.
append
(
SwaggerUtils
.
siteClassInfo
(
netcdfData
.
siteClasses
(),
Optional
.
of
(
"###"
)))
.
append
(
"</details>"
)
.
toString
();
}
private
static
String
swaggerResponseFormatSection
()
{
return
new
StringBuilder
()
.
append
(
"<details>\n"
+
"<summary>Response Format: CSV or JSON</summary>\n"
)
.
append
(
"The web service can respond in JSON or CSV format.\n"
+
"<br><br>"
+
"Choose the format type by adding a `format` query to the service call:"
+
"`?format=JSON` or `?format=CSV`\n\n"
+
"<br><br>"
+
"Default: `JSON`"
)
.
append
(
"</details>"
)
.
toString
();
}
private
static
String
swaggerScienceBaseSection
(
ScienceBaseMetadata
scienceBaseMetadata
)
{
return
new
StringBuilder
()
.
append
(
"<details>\n"
+
"<summary>ScienceBase Information</summary>\n"
)
.
append
(
"Data history: "
+
scienceBaseMetadata
.
history
)
.
append
(
"<br><br>"
)
.
append
(
String
.
format
(
"Returned data are spatially interpolated from "
+
"the %s grid data from ScienceBase:\n"
,
scienceBaseMetadata
.
gridStep
))
.
append
(
Arrays
.
stream
(
scienceBaseMetadata
.
scienceBaseInfo
)
.
map
(
info
->
String
.
format
(
"- [%s](%s)"
,
info
.
url
,
info
.
url
))
.
collect
(
Collectors
.
joining
(
"\n"
)))
.
append
(
"</details>"
)
.
toString
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment