Fabio Sinibaldi 2017-12-14 16:27:50 +00:00
parent 064bbcdb32
commit b6e233b644
2 changed files with 41 additions and 13 deletions

View File

@ -23,27 +23,52 @@ public class ThreddsInfo {
private String localBasePath;
private String instanceBaseUrl;
private ThreddsCatalog catalog;
private String adminUser;
private String adminPassword;
private int version;
private int minor;
private int build;
private int revision;
private String ghnId;
public ThreddsCatalog getById(String id) {
return findById(catalog,id);
}
public ThreddsCatalog getByFittingLocation(String toMatchLocation) {
return getByFittingLocation(catalog, toMatchLocation);
}
private static ThreddsCatalog findById(ThreddsCatalog catalog,String id) {
if(catalog!=null&&catalog.getID()!=null&&catalog.getID().equals(id)) return catalog;
for(ThreddsCatalog cat : catalog.getSubCatalogs().getLinkedCatalogs())
return findById(cat,id);
if(catalog!=null) {
if(catalog.getID()!=null&&catalog.getID().equals(id)) return catalog;
if(catalog.getSubCatalogs()!=null&&catalog.getSubCatalogs().getLinkedCatalogs()!=null)
for(ThreddsCatalog cat : catalog.getSubCatalogs().getLinkedCatalogs())
return findById(cat,id);
}
return null;
}
private static ThreddsCatalog getByFittingLocation(ThreddsCatalog catalog,String toMatchPath) {
if(catalog!=null) {
if(catalog.getDeclaredDataSetRoot()!=null&&catalog.getDeclaredDataSetRoot().getLocation()!=null&&
matchesPath(catalog.getDeclaredDataSetRoot().getLocation(),toMatchPath)) return catalog;
for(DataSetScan scan : catalog.getDeclaredDataSetScan())
if(scan!=null&&scan.getLocation()!=null&&matchesPath(scan.getLocation(), toMatchPath))
return catalog;
if(catalog.getSubCatalogs()!=null&&catalog.getSubCatalogs().getLinkedCatalogs()!=null)
for(ThreddsCatalog cat:catalog.getSubCatalogs().getLinkedCatalogs())
getByFittingLocation(cat, toMatchPath);
}
return null;
}
private static boolean matchesPath(String catalogPath,String toMatchPath) {
return toMatchPath.startsWith(catalogPath);
}
}

View File

@ -267,9 +267,9 @@ public class MarshallUnmarshalTest {
ThreddsCatalog mainCatalog=new ThreddsCatalog();
mainCatalog.setCatalogFile("catalog.xml");
mainCatalog.setDeclaredDataSetRoot(new DataSetRoot("public","public/genericRoot",1000l));
mainCatalog.setDeclaredDataSetRoot(new DataSetRoot("public",info.getLocalBasePath()+"/public/genericRoot",1000l));
mainCatalog.setDeclaredDataSetScan(new HashSet<DataSetScan>());
mainCatalog.getDeclaredDataSetScan().add(new DataSetScan("generic scan","/public","public/genericScanned","ROOT-DatasetScan"));
mainCatalog.getDeclaredDataSetScan().add(new DataSetScan("generic scan","/public",info.getLocalBasePath()+"/public/genericScanned","ROOT-DatasetScan"));
CatalogCollection collection=new CatalogCollection();
collection.setID("Catalog_VREs");
@ -282,14 +282,17 @@ public class MarshallUnmarshalTest {
subCatalog.setName("ThreddsCatalog for tuna atlas");
subCatalog.setTitle("This is a catalog bla bla");
//info from catalog file
subCatalog.setDeclaredDataSetRoot(new DataSetRoot("/tuna","vres/tuna",1000l));
subCatalog.setDeclaredDataSetRoot(new DataSetRoot("/tuna",info.getLocalBasePath()+"/vres/tuna",1000l));
subCatalog.setDeclaredDataSetScan(new HashSet<DataSetScan>());
subCatalog.getDeclaredDataSetScan().add(new DataSetScan("tuna scan","/tuna","vres/tunaScanned","TUNA-DatasetScan"));
subCatalog.getDeclaredDataSetScan().add(new DataSetScan("tuna scan","/tuna",info.getLocalBasePath()+"/vres/tunaScanned","TUNA-DatasetScan"));
subCatalog.getDeclaredDataSetScan().add(new DataSetScan("tuna scan2","/more_tuna",info.getLocalBasePath()+"/vres/tunaScanned2","TUNA-DatasetScan2"));
collection.getLinkedCatalogs().add(subCatalog);
mainCatalog.setSubCatalogs(collection);
info.setCatalog(mainCatalog);
info.getById(subCatalog.getID());
System.out.println(info.getByFittingLocation("/tmp/public/genericScanned"));
System.out.println(info.getByFittingLocation("/tmp/more_tuna/anotherfolder/inside/this/one/"));
return info;
}