From 6a6f01368958fd84fd61d718a3a7fa18c8478d2e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 17 Mar 2023 14:30:11 +0100 Subject: [PATCH] Added Test classes --- .settings/org.eclipse.wst.common.component | 29 +- src/test/java/gis/GeonetworkQueryTest.java | 381 ++++++++++++++++++ src/test/java/gis/ICCATQueryTest.java | 267 ++++++++++++ src/test/java/gis/LayersMatchingGN_CKAN.java | 169 ++++++++ src/test/java/gis/RuntimeResourceReader.java | 166 ++++++++ src/test/java/gis/SE_Harvester_from_IS.java | 167 ++++++++ src/test/java/gis/ServiceEndpointBean.java | 60 +++ .../test/GeonetworkResolverTest.java | 2 +- .../datatransfer/test/GisResolverTest.java | 4 +- .../test/ServiceEndpointReader.java | 2 +- src/test/resources/.gitignore | 6 + 11 files changed, 1239 insertions(+), 14 deletions(-) create mode 100644 src/test/java/gis/GeonetworkQueryTest.java create mode 100644 src/test/java/gis/ICCATQueryTest.java create mode 100644 src/test/java/gis/LayersMatchingGN_CKAN.java create mode 100644 src/test/java/gis/RuntimeResourceReader.java create mode 100644 src/test/java/gis/SE_Harvester_from_IS.java create mode 100644 src/test/java/gis/ServiceEndpointBean.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 43b83d7..068f0a5 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + @@ -10,8 +10,10 @@ - - + + + + @@ -23,7 +25,8 @@ - + + @@ -35,7 +38,8 @@ - + + @@ -47,7 +51,8 @@ - + + @@ -59,7 +64,8 @@ - + + @@ -71,7 +77,8 @@ - + + @@ -83,7 +90,8 @@ - + + @@ -95,7 +103,8 @@ - + + diff --git a/src/test/java/gis/GeonetworkQueryTest.java b/src/test/java/gis/GeonetworkQueryTest.java new file mode 100644 index 0000000..08d3dda --- /dev/null +++ b/src/test/java/gis/GeonetworkQueryTest.java @@ -0,0 +1,381 @@ +package gis; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.gcube.common.encryption.StringEncrypter; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.spatial.data.geonetwork.GeoNetwork; +import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; +import org.gcube.spatial.data.geonetwork.GeoNetworkReader; +import org.gcube.spatial.data.geonetwork.LoginLevel; +import org.gcube.spatial.data.geonetwork.configuration.Configuration; +import org.gcube.spatial.data.geonetwork.model.Account; +import org.gcube.spatial.data.geonetwork.model.Account.Type; +import org.junit.Test; + +import it.geosolutions.geonetwork.util.GNSearchRequest; +import it.geosolutions.geonetwork.util.GNSearchResponse; +import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata; + +/** + * The Class GeonetworkQueryTest. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 31, 2016 + */ +public class GeonetworkQueryTest { + + private static final int MAX = 30; + + //private String[] scopes = {"/gcube/devsec/devVRE"}; + + //private String[] scopes = {"/gcube/devsec/StaTabTest"}; + + //private String[] scopes = {"/gcube/devsec/devVRE"}; + + //private String[] scopes = {"/pred4s/preprod/preVRE"}; + + //private String[] scopes = {"/d4science.research-infrastructures.eu"}; + + //private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"}; + + //private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"}; + + //private String[] scopesProd = {"/d4science.research-infrastructures.eu"}; + + //private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject"}; + + //private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration"}; + + //private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/FrenchTropicalTunaAtlas"}; + + private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"}; + + //private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"}; + + //private String[] scopes = {"/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E"}; + + + + private LoginLevel loginLevel = LoginLevel.CKAN; + + private Type accountType = Type.CKAN; + + private String textToSearch = "geo_fea"; + + /** + * Gets the count. + * + * @return the count + * @throws Exception the exception + */ + //@Test + public void getCount() throws Exception{ + + try{ + for(String scope:scopes){ + ScopeProvider.instance.set(scope); + GeoNetworkPublisher reader=GeoNetwork.get(); + + Configuration config = reader.getConfiguration(); + Account account=config.getScopeConfiguration().getAccounts().get(accountType); + +// Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration(); +// Account account = config.getScopeConfiguration().getAccounts().get(Type.CKAN); + + //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword()); + System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword()); + System.out.println("USER: "+account.getUser()+", Pwd: "+account.getPassword()); + System.out.println("GN: "+config.getGeoNetworkEndpoint()); + try{ + String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword()); + System.out.println("Decrypted Password: "+decryptedPassword); + }catch(Exception e){ + System.out.println("ignoring exception during pwd decrypting"); + } + + + // req.addParam("keyword", "Thredds"); + final GNSearchRequest req=new GNSearchRequest(); +// req.addParam(GNSearchRequest.Param.any,"Thredds"); + GNSearchResponse resp = reader.query(req); + int publicCount=resp.getCount(); + System.out.println("Public UUIDs are: "+publicCount); + Map publicUUIDs = getUUIDs(resp); + System.out.println("Filled list of Public UUIDs with: "+publicUUIDs.size()); + System.out.println("Public layers are: "); + printLayers(publicUUIDs); + + reader.login(loginLevel); + resp = reader.query(req); + int totalCount=resp.getCount(); + System.out.println("All UUIDs are: "+totalCount); + Map allUUIDs = getUUIDs(resp); + System.out.println("Filled list of All UUIDs with: "+allUUIDs.size()); + + System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")"); + + System.out.println("Private layers are: "); + allUUIDs.keySet().removeAll(publicUUIDs.keySet()); + printLayers(allUUIDs); + + /*if(totalCount==0) + return; + try{ + int last = totalCount layersUUIDs) { + int index = 0; + + for (Long key : layersUUIDs.keySet()) { + index++; + System.out.println(index+") ID: "+key+" - UUID: "+layersUUIDs.get(key)); + } + } + + + /** + * Gets the UUI ds. + * + * @param resp the resp + * @return the UUI ds + */ + public static Map getUUIDs(GNSearchResponse resp){ + + Map listUUIDs = new HashMap(); + Iterator iterator = resp.iterator(); + while(iterator.hasNext()) { + GNMetadata meta = iterator.next(); + //listUUIDs.add(new GN_META_REF(meta.getId(), meta.getUUID())); + listUUIDs.put(meta.getId(), meta.getUUID()); + //System.out.println("Added: "+meta.getUUID()); + } + + return listUUIDs; + } + + + /** + * Gets the layers by search. + * + * @return the layers by search + * @throws Exception the exception + */ + //@Test + public void getLayersBySearch() throws Exception{ + try{ + for(String scope:scopes){ + ScopeProvider.instance.set(scope); + GeoNetworkPublisher reader=GeoNetwork.get(); + + + + Configuration config = reader.getConfiguration(); + Account account=config.getScopeConfiguration().getAccounts().get(accountType); + + //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword()); + System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword()); + + try{ + String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword()); + System.out.println("Decrypted Password: "+decryptedPassword); + }catch(Exception e){ + System.out.println("ignoring exception during pwd decrypting"); + } + + + // req.addParam("keyword", "Thredds"); + //final GNSearchRequest req=new GNSearchRequest(); + final GNSearchRequest req = getRequest(true, textToSearch); +// req.addParam(GNSearchRequest.Param.any,"Thredds"); + GNSearchResponse resp = reader.query(req); + int publicCount=resp.getCount(); + reader.login(loginLevel); + int totalCount=reader.query(req).getCount(); + System.out.println("QUERY "+textToSearch); + System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")"); + +// if(totalCount==0) +// return; +// try{ +// int last = totalCount>MAX?totalCount:MAX; +// +// for(int i=0; i getLayers(LAYER_TYPE type) throws Exception{ +// +// try{ +// for(String scope:scopesProd){ +// ScopeProvider.instance.set(scope); +// GeoNetworkPublisher reader=GeoNetwork.get(); +// +// Configuration config = reader.getConfiguration(); +// Account account=config.getScopeConfiguration().getAccounts().get(accountType); +// +// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword()); +// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword()); +// +// try{ +// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword()); +// System.out.println("Decrypted Password: "+decryptedPassword); +// }catch(Exception e){ +// System.out.println("ignoring exception during pwd decrypting"); +// } +// +// +// // req.addParam("keyword", "Thredds"); +// final GNSearchRequest req=new GNSearchRequest(); +//// req.addParam(GNSearchRequest.Param.any,"Thredds"); +// GNSearchResponse resp = reader.query(req); +// int publicCount=resp.getCount(); +// +// List publicLayers = new ArrayList(); +// for(int i=0; i privateLayers = new ArrayList(); +// for(int i=0; i list +// NodeList nodes = doc.getElementsByTagName("gmd:MD_Metadata"); +// logger.debug("gmd:MD_Metadata are: " + nodes.getLength()); +// for (int i = 0; i < nodes.getLength(); i++) { +// Element mdMetadata = (Element) nodes.item(i); +// +// // +// NodeList fileIdentifierLst = mdMetadata.getElementsByTagName("gmd:fileIdentifier"); +// if(fileIdentifierLst==null || fileIdentifierLst.getLength()==0 || fileIdentifierLst.item(0)==null){ +// logger.info("skipping, it has not fileidentifier"); +// return null; +// } +// +// Element id = (Element) fileIdentifierLst.item(0); +// +// NodeList gcoLst = id.getElementsByTagName("gco:CharacterString"); +// if(gcoLst==null || gcoLst.getLength()==0 || gcoLst.item(0)==null){ +// logger.info("skipping, it has not gco:CharacterString"); +// return null; +// } +// +// Element gco = (Element) gcoLst.item(0); +// String idValue = gco.getTextContent(); +// logger.trace("Summary gmd:fileIdentifier is: " + idValue); +// return idValue; +// } +// +// return null; +// } +// +// /** +// * Removes the summary ids by list ids. +// * +// * @param getRecordsResponse the get records response +// * @param idsToRemove the ids to remove +// * @return the input stream +// * @throws IOException Signals that an I/O exception has occurred. +// */ +// public static String toGetFileIdentifier(InputStream getRecordResponse) throws IOException { +// +// try { +// // logger.trace("getRecordsResponse is: "+IOUtils.toString(getRecordsResponse)); +// BufferedInputStream bis = new BufferedInputStream(getRecordResponse); +// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); +// dbf.setValidating(false); +// DocumentBuilder db = dbf.newDocumentBuilder(); +// Document doc = db.parse(bis); +// return getFileIdentifierValue(doc); +// } +// catch (Exception e) { +// logger.error("An error occurred during removing IDS by List: ", e); +// return null; +// } +// } +// +// +// public static List fileReader() throws FileNotFoundException{ +// +// String fileName = "iccat_name_catalogue.csv"; +// +//// //read file into stream, try-with-resources +//// try (Stream stream = Files.lines(Paths.get(fileName))) { +//// +//// stream.forEach(System.out::println); +//// +//// } catch (IOException e) { +//// e.printStackTrace(); +//// } +// +// FileReader reportReader = new FileReader(fileName); +// //Stream stream = reportBW.lines(); +// List list = new ArrayList<>(); +// try (BufferedReader reportBW = new BufferedReader(reportReader)){ +// +// list = reportBW.lines().collect(Collectors.toList()); +// +// }catch (Exception e) { +// e.printStackTrace(); +// } +// +// return list; +// } +// +// +// public static void main(String[] args) { +// +// List listCKAN; +// try { +// listCKAN = fileReader(); +// System.out.println("CKAN Layers are: "+listCKAN.size()); +//// for (String line : listCKAN) { +//// System.out.println("CKAN UUID: "+line); +//// } +// +// List listLayersUUID = getLayers(LAYER_TYPE.PUBLIC); +// System.out.println("List Layers UUID are: "+listLayersUUID.size()); +//// for (String line : listLayersUUID) { +//// System.out.println("PRIVATE GN UUID: "+line); +//// } +// +// +// listCKAN.removeAll(listLayersUUID); +// +// System.out.println("\n\n\nCKAN contains other: "+listCKAN.size()); +// for (String line : listCKAN) { +// System.out.println("CKAN UUID: "+line); +// } +// +// }catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// +// +// +// } +//} diff --git a/src/test/java/gis/LayersMatchingGN_CKAN.java b/src/test/java/gis/LayersMatchingGN_CKAN.java new file mode 100644 index 0000000..29b57c3 --- /dev/null +++ b/src/test/java/gis/LayersMatchingGN_CKAN.java @@ -0,0 +1,169 @@ +/** + * + */ +package gis; + +import it.geosolutions.geonetwork.util.GNSearchRequest; +import it.geosolutions.geonetwork.util.GNSearchResponse; +import resources.GetAllInfrastructureScopes; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.spatial.data.geonetwork.GeoNetwork; +import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; +import org.gcube.spatial.data.geonetwork.LoginLevel; +import org.junit.Test; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Mar 10, 2017 + */ +public class LayersMatchingGN_CKAN { + + //GN CONFIGURATIONS + public static String rootScope = "/d4science.research-infrastructures.eu"; + //static String rootScope = "/pred4s"; +// static String rootScope = "/gcube"; + public static String platformName = "geonetwork"; + public static LoginLevel loginLevel = LoginLevel.ADMIN; + //static Type accountType = Type.SCOPE; + public static String textToSearch = "geo_fea"; + + public static PrintWriter reportPrintWriter; + public static PrintWriter errorPrintWriter; + + public static void main(String[] args) { + + try{ + FileWriter reportWriter = new FileWriter(rootScope.substring(1,rootScope.length())+"_report_matching_gn_catalogue.csv", true); + FileWriter errorWriter = new FileWriter(rootScope.substring(1,rootScope.length())+"_error_matching_gn_catalogue.csv", true); + BufferedWriter reportBW = new BufferedWriter(reportWriter); + BufferedWriter errorBW = new BufferedWriter(errorWriter); + reportPrintWriter = new PrintWriter(reportBW); + reportPrintWriter.println("NB.; SCOPE; GN Endpoint; TOTAL LAYERS; PUBLIC LAYERS; PRIVATE LAYERS"); + errorPrintWriter = new PrintWriter(errorBW); + errorPrintWriter.println("SCOPE;"); + }catch(Exception e){ + e.printStackTrace(); + } + +// final Path destination = Paths.get("report_matching_gn_catalogue.csv"); +// Files.w(re, destination); + + List scopesProd = new ArrayList(); + + //RuntimeResourceReader readerRR; + try { + //MODE-1 +// readerRR = new RuntimeResourceReader(rootScope, platformName, null); +// System.out.println(readerRR.toString()); +// System.out.println("Using GN: "+readerRR.getParameters()); +// System.out.println("Scopes are: "+readerRR.getScopes().size()); +// scopesProd.addAll(readerRR.getScopes()); + + //MODE-2 + Map mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope); + scopesProd.addAll(mapScopes.values()); + } + catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Read "+scopesProd.size() +" VREs from root scope: "+rootScope); + int i = 0; + for (String vre : scopesProd) { + System.out.println(++i +"; "+vre); + } + + System.out.println("Scope found: "+scopesProd.size()); + + int count = 0; + try{ + + for(String scope:scopesProd){ + count++; + System.out.println("\n\n#"+count+" of "+scopesProd.size()+ " - Fetching scope: "+scope); + ScopeProvider.instance.set(scope); + GeoNetworkPublisher reader = null; + String gnEP = null; + try{ + reader=GeoNetwork.get(); + gnEP = reader.getConfiguration().getGeoNetworkEndpoint(); + + }catch (Exception e) { + System.out.println("GeoNetwork not instanciable in the scope: "+scope); + writeError(count+"; "+scope+" ; "+e.getMessage()); + } + + if(reader!=null){ +// Configuration config = reader.getConfiguration(); +// Account account=config.getScopeConfiguration().getAccounts().get(accountType); +// +// //System.out.println("User: "+account.getUser()+", Pwd: "+account.getPassword()); +// System.out.println("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword()); +// +// try{ +// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(account.getPassword()); +// System.out.println("Decrypted Password: "+decryptedPassword); +// }catch(Exception e){ +// System.out.println("ignoring exception during pwd decrypting"); +// } + + + // req.addParam("keyword", "Thredds"); + final GNSearchRequest req=new GNSearchRequest(); + // req.addParam(GNSearchRequest.Param.any,"Thredds"); + GNSearchResponse resp = reader.query(req); + int publicCount=resp.getCount(); + reader.login(loginLevel); + int totalCount=reader.query(req).getCount(); + //System.out.println("SCOPE "+scope+" ; found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")"); + writeReport(count+"; "+scope+" ; "+gnEP+"; "+totalCount+" ; "+publicCount+"; "+(totalCount-publicCount)); + if(totalCount==0) + return; +// try{ +// int last = totalCount>MAX?totalCount:MAX; +// for(int i=0; i scopes = new ArrayList(); + + private List listSE = new ArrayList(); + + /** + * Instantiates a new runtime resource reader. + * + * @param scope the scope + * @param platformName the platform name + * @param endPoint the end point + * @throws Exception the exception + */ + public RuntimeResourceReader(String scope, String platformName, String category, String endPoint) throws Exception { + read(scope, platformName, category, endPoint); + } + + /** + * Read. + * + * @param scope the scope + * @param platformName the platform name + * @param endPoint the end point + * @return the server parameters + * @throws Exception the exception + */ + private List read(String scope, String platformName, String category, String endPoint) + throws Exception { + + String originalScope = null; + try { + + originalScope = ScopeProvider.instance.get(); + + ScopeProvider.instance.set(scope); + + SimpleQuery query = queryFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Platform/Name/text() eq '" + platformName + "'"); + query.addCondition("$resource/Profile/Category/text() eq '" + category + "'"); + if (endPoint != null && !endPoint.isEmpty()) + query.addCondition("$resource/Profile/AccessPoint/Interface/Endpoint/text() eq '" + endPoint + "'"); + +// query.addVariable("$prop", "$resource/Profile/AccessPoint/Properties/Property") +// .addCondition("$prop/Name/text() eq 'priority'") +// .addCondition("$prop/Value/text() eq '1'"); + + logger.info("GeoRuntimeReader, using scope: " + scope + ", to get resource: " + platformName); + + DiscoveryClient client = clientFor(ServiceEndpoint.class); + + List listServiceEndpoint = client.submit(query); + if (listServiceEndpoint == null || listServiceEndpoint.isEmpty()) + throw new Exception("Cannot retrieve the runtime resource: " + platformName); + + for (ServiceEndpoint serviceEndpoint : listServiceEndpoint) { + + ServiceEndpointBean seb = new ServiceEndpointBean(); + + seb.setRuntime(serviceEndpoint.profile().runtime()); + + List listAp = new ArrayList(); + try { + for (AccessPoint accessPoint : serviceEndpoint.profile().accessPoints()) { + listAp.add(accessPoint); + } + } catch (Exception e) { + System.err.println("Error on reading Access point not found"); + } + + System.out.println("sono qui"); + + seb.setListAP(listAp); + listSE.add(seb); + } + + } catch (Exception e) { + logger.error("Sorry, an error occurred on reading parameters in Runtime Resources", e); + } finally { + if (originalScope != null && !originalScope.isEmpty()) { + ScopeProvider.instance.set(originalScope); + logger.info("scope provider setted to orginal scope: " + originalScope); + } else { + ScopeProvider.instance.reset(); + logger.info("scope provider reset"); + } + } + + return listSE; + } + + public List getListSE() { + return listSE; + } + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + String scope = "/gcube/devsec/devVRE"; + String platformName = "GeoServer"; + + //scope = "/pred4s/preprod/preVRE"; + + RuntimeResourceReader reader; + try { + ScopeProvider.instance.set(scope); + reader = new RuntimeResourceReader(scope, "postgis", "Database", null); + + for (ServiceEndpointBean seb : reader.getListSE()) { + System.out.println("Found: " + seb); + + List listAp = seb.getListAP(); + + for (AccessPoint ap : listAp) { + System.out.println("username: " + ap.username()); + System.out.println("password: " + ap.password()); + try{ + String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password()); + System.out.println("Decrypted Password: "+decryptedPassword); + }catch(Exception e){ + System.out.println("ignoring exception during pwd decrypting"); + } + + + } + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} diff --git a/src/test/java/gis/SE_Harvester_from_IS.java b/src/test/java/gis/SE_Harvester_from_IS.java new file mode 100644 index 0000000..b6eec61 --- /dev/null +++ b/src/test/java/gis/SE_Harvester_from_IS.java @@ -0,0 +1,167 @@ +/** + * + */ +package gis; + +import it.geosolutions.geonetwork.util.GNSearchRequest; +import it.geosolutions.geonetwork.util.GNSearchResponse; +import resources.GetAllInfrastructureScopes; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.spatial.data.geonetwork.GeoNetwork; +import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; +import org.gcube.spatial.data.geonetwork.LoginLevel; +import org.junit.Test; + +import com.itextpdf.text.log.SysoCounter; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Mar 10, 2017 + */ +public class SE_Harvester_from_IS { + + // GN CONFIGURATIONS + public static String rootScope = "/d4science.research-infrastructures.eu"; + // static String rootScope = "/pred4s"; +// static String rootScope = "/gcube"; + public static final String platformName = "geoserver"; + public static final String category = "Gis"; + public static LoginLevel loginLevel = LoginLevel.ADMIN; + + public static PrintWriter reportPrintWriter; + public static PrintWriter errorPrintWriter; + + public static HashSet uniqueGNs = new HashSet(); + + public static void main(String[] args) { + + try { + FileWriter reportWriter = new FileWriter( + rootScope.substring(1, rootScope.length()) + "_report_" + platformName + "_harvester.csv", true); + FileWriter errorWriter = new FileWriter( + rootScope.substring(1, rootScope.length()) + "_error_" + platformName + "_harvester.csv", true); + BufferedWriter reportBW = new BufferedWriter(reportWriter); + BufferedWriter errorBW = new BufferedWriter(errorWriter); + reportPrintWriter = new PrintWriter(reportBW); + reportPrintWriter.println("NB.; SCOPE; SE Hosted_On; SE AccessPoint;"); + errorPrintWriter = new PrintWriter(errorBW); + errorPrintWriter.println("SCOPE;"); + } catch (Exception e) { + e.printStackTrace(); + } + +// final Path destination = Paths.get("report_matching_gn_catalogue.csv"); +// Files.w(re, destination); + + List listScopes = new ArrayList(); + + // RuntimeResourceReader readerRR; + try { + // MODE-1 +// readerRR = new RuntimeResourceReader(rootScope, platformName, null); +// System.out.println(readerRR.toString()); +// System.out.println("Using GN: "+readerRR.getParameters()); +// System.out.println("Scopes are: "+readerRR.getScopes().size()); +// scopesProd.addAll(readerRR.getScopes()); + + // MODE-2 + Map mapScopes = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(rootScope); + listScopes.addAll(mapScopes.values()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Read " + listScopes.size() + " VREs from root scope: " + rootScope); + int i = 0; + for (String vre : listScopes) { + System.out.println(++i + "; " + vre); + } + + System.out.println("Scope found: " + listScopes.size()); + try { + + searchFor(listScopes, platformName, category); + searchFor(listScopes, "GeoServer", category); + + System.out.println("\n\nUnique " + platformName + " addresses"); + uniqueGNs.stream().forEach(s -> System.out.println(s)); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (reportPrintWriter != null) + reportPrintWriter.close(); + + if (errorPrintWriter != null) + errorPrintWriter.close(); + + System.out.println("Performed fetching from " + listScopes.size() + " scopes"); + System.out.println("FINISHED!!!"); + } + } + + private static void searchFor(List listScopes, String platformName, String category) { + + int count = 0; + int writerCount = 0; + try { + + for (String scope : listScopes) { + count++; + System.out.println("\n\n#" + count + " of " + listScopes.size() + " - Fetching scope: " + scope); + + RuntimeResourceReader rrr = new RuntimeResourceReader(scope, platformName, category, null); + + List listSE = rrr.getListSE(); + + for (ServiceEndpointBean seb : listSE) { + + StringBuilder sb = new StringBuilder(); + for (AccessPoint ap : seb.getListAP()) { + sb.append(ap.address()); + sb.append(", "); + + uniqueGNs.add(ap.address()); + } + + sb.toString(); + writerCount++; + writeReport( + writerCount + "; " + scope + " ; " + seb.getRuntime().hostedOn() + "; " + sb.toString()); + + } + + Thread.sleep(200); + +// if(count==10) +// break; + + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void writeReport(String newline) { + + reportPrintWriter.println(newline); + } + + private static void writeError(String newline) { + + errorPrintWriter.println(newline); + } + +} diff --git a/src/test/java/gis/ServiceEndpointBean.java b/src/test/java/gis/ServiceEndpointBean.java new file mode 100644 index 0000000..a085d6d --- /dev/null +++ b/src/test/java/gis/ServiceEndpointBean.java @@ -0,0 +1,60 @@ +package gis; + +import java.io.Serializable; +import java.util.List; + +import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; + +/** + * The Class ServerParameters. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 16, 2017 + */ +public class ServiceEndpointBean implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 2459971193655529274L; + + protected org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime; + protected List listAP; + + public ServiceEndpointBean() { + // TODO Auto-generated constructor stub + } + + public ServiceEndpointBean(org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime, List listAP) { + super(); + this.runtime = runtime; + this.listAP = listAP; + } + + public org.gcube.common.resources.gcore.ServiceEndpoint.Runtime getRuntime() { + return runtime; + } + + public List getListAP() { + return listAP; + } + + public void setRuntime(org.gcube.common.resources.gcore.ServiceEndpoint.Runtime runtime2) { + this.runtime = runtime2; + } + + public void setListAP(List listAP) { + this.listAP = listAP; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ServiceEndpoint [runtime="); + builder.append(runtime); + builder.append(", listAP="); + builder.append(listAP); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/org/gcube/datatransfer/test/GeonetworkResolverTest.java b/src/test/java/org/gcube/datatransfer/test/GeonetworkResolverTest.java index 3611ff1..5ee18fb 100644 --- a/src/test/java/org/gcube/datatransfer/test/GeonetworkResolverTest.java +++ b/src/test/java/org/gcube/datatransfer/test/GeonetworkResolverTest.java @@ -49,7 +49,7 @@ public class GeonetworkResolverTest { /*String scopeValue ="/gcube/devsec/devVRE"; String remainValue = "/srv/en/mef.export"; String queryString = "scope=/gcube/devsec/devVRE&remainPath=/srv/en/mef.export&version=2.0.2&request=GetCapabilities&service=CSW"; - ServerParameters geonetworkParams = new ServerParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", ""); + ServiceEndpointParameters geonetworkParams = new ServiceEndpointParameters("http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork", "", ""); String newQueryString = purgeScopeFromQueryString(scopeValue, queryString); logger.info("Purged query string from "+scopeValue+" is: "+newQueryString); diff --git a/src/test/java/org/gcube/datatransfer/test/GisResolverTest.java b/src/test/java/org/gcube/datatransfer/test/GisResolverTest.java index f56673b..3489dbf 100644 --- a/src/test/java/org/gcube/datatransfer/test/GisResolverTest.java +++ b/src/test/java/org/gcube/datatransfer/test/GisResolverTest.java @@ -18,7 +18,7 @@ public class GisResolverTest { public static void main(String[] args) { GisResolver gisResolver = new GisResolver(); ScopeProvider.instance.set(scope); - //ServerParameters geonetworkParams = getCachedServerParameters(scope); + //ServiceEndpointParameters geonetworkParams = getCachedServerParameters(scope); try { GisLayerItem gisLayerItem = gisResolver.getGisLayerForLayerUUID(null, scope, gisUUID); } catch (Exception e) { @@ -33,7 +33,7 @@ public class GisResolverTest { String scope = "/gcube/devsec/devVRE"; String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8"; try { - ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope); + ServiceEndpointParameters geonetworkParams = gisResolver.getCachedServerParameters(scope); String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams); System.out.println("Final url is: " + wmsRequest); wmsRequest = URLEncoder.encode(wmsRequest, UTF_8); diff --git a/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java b/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java index 8f5c0ce..da5de17 100644 --- a/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java +++ b/src/test/java/org/gcube/datatransfer/test/ServiceEndpointReader.java @@ -84,7 +84,7 @@ public class ServiceEndpointReader { if (accessPointPwd != null) { accessPointPwd = StringEncrypter.getEncrypter().decrypt(accessPointPwd); LOG.info("Decrypted pwd registered into Access Point '" + accessPoint.name() + "' is: " - + accessPointPwd.substring(0,accessPointPwd.length()/2)+"..."); + + accessPointPwd+"..."); System.out.println("AccessPoint pwd is: "+accessPointPwd); } diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore index 91f56a4..ad4e9b2 100644 --- a/src/test/resources/.gitignore +++ b/src/test/resources/.gitignore @@ -12,3 +12,9 @@ /preprod.gcubekey /pred4s.gcubekey /log4j.properties +/D4OS.gcubekey +/D4Research.gcubekey +/OpenAIRE.gcubekey +/ParthenosVO.gcubekey +/SmartArea.gcubekey +/SoBigData.gcubekey