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 71d99ea..1043da4 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 @@ -45,7 +45,9 @@ public class ThreddsInfo { } public DataSet getDataSetFromLocation(String location) { - return getCatalogByFittingLocation(location).getDataSetFromLocation(location); + try{ + return getCatalogByFittingLocation(location).getDataSetFromLocation(location); + }catch(NullPointerException e) {return null;} } public static ThreddsCatalog findById(ThreddsCatalog catalog,String id) { @@ -77,6 +79,8 @@ public class ThreddsInfo { } public static boolean matchesPath(String catalogPath,String toMatchPath) { + if(toMatchPath.endsWith("/")) return toMatchPath.startsWith(catalogPath); + else 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 58e1705..d4e2b0a 100644 --- a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java +++ b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java @@ -50,6 +50,8 @@ import org.gcube.data.transfer.model.utils.DateWrapper; import org.junit.BeforeClass; import org.junit.Test; +import junit.framework.Assert; + public class MarshallUnmarshalTest { static JAXBContext ctx =null; @@ -267,9 +269,9 @@ public class MarshallUnmarshalTest { ThreddsCatalog mainCatalog=new ThreddsCatalog(); mainCatalog.setCatalogFile("catalog.xml"); - mainCatalog.setDeclaredDataSetRoot(new DataSetRoot("public",info.getLocalBasePath()+"/public/genericRoot",1000l)); + mainCatalog.setDeclaredDataSetRoot(new DataSetRoot("public",info.getLocalBasePath()+"/public/genericRoot/",1000l)); mainCatalog.setDeclaredDataSetScan(new HashSet()); - mainCatalog.getDeclaredDataSetScan().add(new DataSetScan("generic scan","/public",info.getLocalBasePath()+"/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"); @@ -291,8 +293,31 @@ public class MarshallUnmarshalTest { info.setCatalog(mainCatalog); info.getById(subCatalog.getID()); - System.out.println(info.getCatalogByFittingLocation("/tmp/public/genericScanned")); - System.out.println(info.getCatalogByFittingLocation("/tmp/more_tuna/anotherfolder/inside/this/one/")); + + + String[] toTestPaths=new String[] { + "/tmp/public/genericScanned", + "/tmp/vres/tunaScanned/anotherfolder/inside/this/one/", + "/tmp/public/genericScanned/notSure", + "/tmp/public/genericScanned/notSure/", + }; + + String[] toTestMissing=new String[] { + "/tmp/public/myCatalog", + "/tmp/some/other/catalog" + + }; + + for(String path:toTestPaths) { + Assert.assertNotNull(info.getCatalogByFittingLocation(path)); + Assert.assertNotNull(info.getDataSetFromLocation(path)); + } + + for(String path:toTestMissing) { + Assert.assertNull(info.getCatalogByFittingLocation(path)); + Assert.assertNull(info.getDataSetFromLocation(path)); + } + return info; }