Fabio Sinibaldi 2018-03-15 15:12:08 +00:00
parent f873f73b8e
commit be340c3b1d
2 changed files with 34 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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<DataSetScan>());
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;
}