Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix standard services for nested datasets #496

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading