Skip to content

Commit

Permalink
Fix standard services for nested datasets (#496)
Browse files Browse the repository at this point in the history
* Add test for a nested dataset with a service type inferred from dataType

* When adding standard services for a dataType, recursively check child datasets
  • Loading branch information
tdrwenski authored May 3, 2024
1 parent 44056ec commit 4835f99
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package thredds.server.catalog;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -42,6 +44,18 @@ public void testStandardServices() throws IOException {
Assert.assertEquals(7, s.getNestedServices().size());
}

@Test
public void testStandardServicesForNestedDataset() {
String catalog = "/catalog/catalogs5/testServices.xml";
Catalog cat = TdsLocalCatalog.open(catalog);
Dataset ds = cat.findDatasetByID("testInnerGridDataset");
assertThat(ds.getFeatureType()).isEqualTo(FeatureType.GRID);

Service service = ds.getServiceDefault();
assertThat(service.getType()).isEqualTo(ServiceType.Compound);
assertThat(service.getNestedServices().size()).isEqualTo(7);
}

// Relies on:
// <datasetScan name="Test Scan Grid Dataset" location="${cdmUnitTest}/ncss/CONUS_80km_nc/"
// path="datasetScan/ncss/CONUS_80km_nc/" dataType="Grid"/>
Expand Down Expand Up @@ -80,6 +94,9 @@ public void testUserDefinedServices() throws IOException {
Assert.assertEquals(ServiceType.OPENDAP, localServices.getType());

for (Dataset ds : cat.getDatasetsLocal()) {
if (ds.getId() != null && ds.getId().equals("testNestedGridDataset")) {
continue;
}
if (!(ds instanceof CatalogRef)) {
Assert.assertTrue(ds.hasAccess());

Expand Down
25 changes: 16 additions & 9 deletions tds/src/main/java/thredds/core/CatalogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,24 @@ private void addGlobalServices(CatalogBuilder cat) {

// look for datasets that want to use standard services
for (DatasetBuilder node : cat.getDatasets()) {
String sname = (String) node.getFldOrInherited(Dataset.ServiceName);
String urlPath = (String) node.get(Dataset.UrlPath);
String ftypeS = (String) node.getFldOrInherited(Dataset.FeatureType);
if (sname == null && urlPath != null && ftypeS != null) {
Service s = globalServices.getStandardServices(ftypeS);
if (s != null) {
node.put(Dataset.ServiceName, s.getName());
cat.addService(s);
}
addStandardServices(cat, node);
}
}

private void addStandardServices(CatalogBuilder cat, DatasetBuilder node) {
String sname = (String) node.getFldOrInherited(Dataset.ServiceName);
String urlPath = (String) node.get(Dataset.UrlPath);
String ftypeS = (String) node.getFldOrInherited(Dataset.FeatureType);
if (sname == null && urlPath != null && ftypeS != null) {
Service s = globalServices.getStandardServices(ftypeS);
if (s != null) {
node.put(Dataset.ServiceName, s.getName());
cat.addService(s);
}
}
for (DatasetBuilder child : node.getDatasets()) {
addStandardServices(cat, child);
}
}

private void findServices(Iterable<DatasetBuilder> datasets, Set<String> serviceNames) {
Expand Down
7 changes: 7 additions & 0 deletions tds/src/test/content/thredds/catalogs5/testServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<!--- test using default -->
<dataset name="Test Single Grid Dataset" ID="testSingleGridDataset" urlPath="cdmUnitTest/ncss/CONUS_80km_nc/GFS_CONUS_80km_20120419_0000.nc" dataType="Grid"/>

<dataset name="Test Nested Grid Dataset" ID="testNestedGridDataset">
<metadata inherited="true">
<dataType>Grid</dataType>
</metadata>
<dataset name="Test Inner Grid Dataset" ID="testInnerGridDataset" urlPath="localContent/testData.nc"/>
</dataset>

<!--- test using global -->
<dataset name="Test sst" ID="TESTsst" serviceName="all" urlPath="cdmUnitTest/conventions/coards/sst.mnmean.nc" dataType="Grid"/>

Expand Down

0 comments on commit 4835f99

Please sign in to comment.