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

Move metadta to own class

parent 11f87dce
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
package gov.usgs.earthquake.nshmp.netcdf.www;
import gov.usgs.earthquake.nshmp.gmm.Imt;
import gov.usgs.earthquake.nshmp.gmm.NehrpSiteClass;
import gov.usgs.earthquake.nshmp.netcdf.Netcdf;
import gov.usgs.earthquake.nshmp.netcdf.data.ScienceBaseMetadata;
import gov.usgs.earthquake.nshmp.netcdf.www.NetcdfService.SourceModel;
import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestData;
import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestDataImt;
import gov.usgs.earthquake.nshmp.netcdf.www.Request.RequestDataSiteClass;
import gov.usgs.earthquake.nshmp.netcdf.www.meta.DoubleParameter;
import io.micronaut.http.HttpRequest;
/**
* Web service metadata.
*
* @author U.S. Geological Survey
*/
public class Metadata<T extends Query> {
public final String description;
public final String[] syntax;
public final SourceModel model;
public final DoubleParameter longitude;
public final DoubleParameter latitude;
public final DoubleParameter vs30;
public final NetcdfMetadata netcdfMetadata;
Metadata(HttpRequest<?> request, NetcdfService<T> netcdfService, String description) {
var netcdf = netcdfService.netcdf();
var url = request.getUri().toString();
url = url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
this.description = description;
syntax = new String[] {
url + "/{longitude:number}/{latitude:number}",
url + "?longitude={number}&latitude={number}",
url + "/{longitude:number}/{latitude:number}/{siteClass:NehrpSiteClass}",
url + "?longitude={number}&latitude={number}&siteClass={NehrpSiteClass}",
};
var min = netcdf.netcdfData().minimumBounds();
var max = netcdf.netcdfData().maximumBounds();
longitude = new DoubleParameter(
"Longitude",
"°",
min.longitude,
max.longitude);
latitude = new DoubleParameter(
"Latitude",
"°",
min.latitude,
max.latitude);
model = netcdfService.getSourceModel();
vs30 = new DoubleParameter(
"Vs30",
"m/s",
150,
1500);
netcdfMetadata = new NetcdfMetadata(netcdf);
}
class NetcdfMetadata {
public final String netcdfFile;
public final ScienceBaseMetadata scienceBaseMetadata;
NetcdfMetadata(Netcdf<?> netcdf) {
var fileName = netcdf.netcdfPath().getFileName();
netcdfFile = fileName == null ? netcdf.netcdfPath().toString() : fileName.toString();
scienceBaseMetadata = netcdf.netcdfData().scienceBaseMetadata();
}
}
interface ServiceMetadata {
RequestData toRequestMetadata(RequestData requestData);
}
static class ServiceResponseMetadata implements ServiceMetadata {
public NehrpSiteClass siteClass;
public String xLabel;
public String yLabel;
ServiceResponseMetadata(
NehrpSiteClass siteClass,
String xLabel,
String yLabel) {
this.siteClass = siteClass;
this.xLabel = xLabel;
this.yLabel = yLabel;
}
@Override
public RequestDataSiteClass toRequestMetadata(RequestData requestData) {
return new RequestDataSiteClass(requestData.site, siteClass, requestData.format);
}
}
static class HazardResponseMetadata extends ServiceResponseMetadata {
public final Imt imt;
HazardResponseMetadata(NehrpSiteClass siteClass, Imt imt, String xLabel, String yLabel) {
super(siteClass, xLabel, yLabel);
this.imt = imt;
}
@Override
public RequestDataImt toRequestMetadata(RequestData requestData) {
return new RequestDataImt(requestData.site, siteClass, imt, requestData.format);
}
}
}
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