From b6e233b64470dfaead168b84bd2bd49aa23d6363 Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Thu, 14 Dec 2017 16:27:50 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-model/1.2@160514 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../model/plugins/thredds/ThreddsInfo.java | 43 +++++++++++++++---- .../transfer/test/MarshallUnmarshalTest.java | 11 +++-- 2 files changed, 41 insertions(+), 13 deletions(-) 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 25f331d..d7e9ef1 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 @@ -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); + } } 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 8039bb2..d370d70 100644 --- a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java +++ b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java @@ -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()); - 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()); - 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; }