From 173d586f8866406aba7ce1f943f6b69a97e94f59 Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Thu, 17 Feb 2022 16:30:05 -0700
Subject: [PATCH] Match dynamic usage

---
 .../nshmp/netcdf/www/NetcdfService.java       | 51 +++++++++++--------
 1 file changed, 29 insertions(+), 22 deletions(-)

diff --git a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java
index 7b14ed1..0453caa 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/netcdf/www/NetcdfService.java
@@ -126,39 +126,24 @@ public abstract class NetcdfService {
   class Metadata {
     final String description;
     final String[] syntax;
-    final String netcdfFile;
-    final Parameters model;
-    final ScienceBaseMetadata scienceBaseMetadata;
+    final SourceModel model;
+    final DoubleParameter longitude;
+    final DoubleParameter latitude;
+    final DoubleParameter vs30;
+    final NetcdfMetadata netcdfMetadata;
 
     Metadata(HttpRequest<?> request, String description) {
       var url = request.getUri().toString();
       url = url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
       this.description = description;
-      scienceBaseMetadata = netcdf().netcdfData().scienceBaseMetadata();
-      var fileName = netcdf.netcdfPath().getFileName();
-      netcdfFile = fileName == null ? netcdf().netcdfPath().toString() : fileName.toString();
       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}",
       };
-      model = new Parameters();
-    }
-  }
-
-  class Parameters {
-    final String name;
-    final DoubleParameter longitude;
-    final DoubleParameter latitude;
-    final Map<NehrpSiteClass, Double> siteClasses;
-    final DoubleParameter vs30;
 
-    Parameters() {
-      var netcdfData = netcdf().netcdfData();
-      var bounds = netcdfData.bounds();
-
-      name = netcdfData.scienceBaseMetadata().label;
+      var bounds = netcdf().netcdfData().bounds();
       longitude = new DoubleParameter(
           "Longitude",
           "°",
@@ -169,12 +154,34 @@ public abstract class NetcdfService {
           "°",
           Maths.round(bounds.min.latitude, 3),
           Maths.round(bounds.max.latitude, 3));
-      siteClasses = netcdfData.vs30Map();
+      model = new SourceModel();
       vs30 = new DoubleParameter(
           "Vs30",
           "m/s",
           150,
           1500);
+      netcdfMetadata = new NetcdfMetadata();
+    }
+  }
+
+  class NetcdfMetadata {
+    final String netcdfFile;
+    final ScienceBaseMetadata scienceBaseMetadata;
+
+    NetcdfMetadata() {
+      var fileName = netcdf.netcdfPath().getFileName();
+      netcdfFile = fileName == null ? netcdf().netcdfPath().toString() : fileName.toString();
+      scienceBaseMetadata = netcdf().netcdfData().scienceBaseMetadata();
+    }
+  }
+
+  class SourceModel {
+    final String name;
+    final Map<NehrpSiteClass, Double> siteClasses;
+
+    SourceModel() {
+      name = netcdf().netcdfData().scienceBaseMetadata().label;
+      siteClasses = netcdf().netcdfData().vs30Map();
     }
   }
 
-- 
GitLab