diff --git a/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsCatalog.java b/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsCatalog.java index 53a6e21..e297038 100644 --- a/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsCatalog.java +++ b/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsCatalog.java @@ -28,5 +28,14 @@ public class ThreddsCatalog{ private DataSetRoot declaredDataSetRoot; private HashSet declaredDataSetScan; private CatalogCollection subCatalogs; + + public String getPathFromLocation(String location) { + if(declaredDataSetRoot!=null&&declaredDataSetRoot.getLocation()!=null&& + ThreddsInfo.matchesPath(declaredDataSetRoot.getLocation(),location)) return declaredDataSetRoot.getPath(); + for(DataSetScan scan : declaredDataSetScan) + if(scan!=null&&scan.getLocation()!=null&&ThreddsInfo.matchesPath(scan.getLocation(), location)) + return scan.getPath(); + return null; + } } \ No newline at end of file diff --git a/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsInfo.java b/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsInfo.java index d7e9ef1..e720ca9 100644 --- a/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsInfo.java +++ b/src/main/java/org/gcube/data/transfer/model/plugins/thredds/ThreddsInfo.java @@ -40,11 +40,15 @@ public class ThreddsInfo { } - public ThreddsCatalog getByFittingLocation(String toMatchLocation) { + public ThreddsCatalog getCatalogByFittingLocation(String toMatchLocation) { return getByFittingLocation(catalog, toMatchLocation); } - private static ThreddsCatalog findById(ThreddsCatalog catalog,String id) { + public String getPathFromLocation(String location) { + return getCatalogByFittingLocation(location).getPathFromLocation(location); + } + + public static ThreddsCatalog findById(ThreddsCatalog catalog,String id) { if(catalog!=null) { if(catalog.getID()!=null&&catalog.getID().equals(id)) return catalog; if(catalog.getSubCatalogs()!=null&&catalog.getSubCatalogs().getLinkedCatalogs()!=null) @@ -54,7 +58,7 @@ public class ThreddsInfo { return null; } - private static ThreddsCatalog getByFittingLocation(ThreddsCatalog catalog,String toMatchPath) { + public 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; @@ -68,7 +72,7 @@ public class ThreddsInfo { return null; } - private static boolean matchesPath(String catalogPath,String toMatchPath) { + public static boolean matchesPath(String catalogPath,String toMatchPath) { return toMatchPath.startsWith(catalogPath); } } diff --git a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java index d370d70..58e1705 100644 --- a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java +++ b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java @@ -291,8 +291,8 @@ public class MarshallUnmarshalTest { 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/")); + System.out.println(info.getCatalogByFittingLocation("/tmp/public/genericScanned")); + System.out.println(info.getCatalogByFittingLocation("/tmp/more_tuna/anotherfolder/inside/this/one/")); return info; }