diff --git a/src/test/java/GeonetworkQueryTest.java b/src/test/java/GeonetworkQueryTest.java index cf4ab56..90518b0 100644 --- a/src/test/java/GeonetworkQueryTest.java +++ b/src/test/java/GeonetworkQueryTest.java @@ -1,6 +1,3 @@ -import it.geosolutions.geonetwork.util.GNSearchRequest; -import it.geosolutions.geonetwork.util.GNSearchResponse; - import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.spatial.data.geonetwork.GeoNetwork; @@ -12,6 +9,9 @@ import org.gcube.spatial.data.geonetwork.model.Account; import org.gcube.spatial.data.geonetwork.model.Account.Type; import org.opengis.metadata.Metadata; +import it.geosolutions.geonetwork.util.GNSearchRequest; +import it.geosolutions.geonetwork.util.GNSearchResponse; + /** * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it diff --git a/src/test/java/GeonetworkResolverTest.java b/src/test/java/GeonetworkResolverTest.java index 67b2eb7..58daebb 100644 --- a/src/test/java/GeonetworkResolverTest.java +++ b/src/test/java/GeonetworkResolverTest.java @@ -1,128 +1,128 @@ -//import java.io.ByteArrayInputStream; -//import java.io.IOException; -//import java.io.InputStream; -//import java.io.UnsupportedEncodingException; -//import java.nio.file.Files; -//import java.nio.file.Path; -//import java.nio.file.Paths; -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.Map; -// -//import org.gcube.common.scope.api.ScopeProvider; -//import org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver; -//import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils; -//import org.gcube.datatransfer.resolver.gis.util.GetResponseRecordFilter; -//import org.gcube.spatial.data.geonetwork.GeoNetwork; -//import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; -//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; -// -// -///** -// * -// */ -///** -// * -// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it -// * Sep 8, 2016 -// */ -//public class GeonetworkResolverTest { -// -// private static String scope = "/d4science.research-infrastructures.eu"; -// -// private static LoginLevel loginLevel = LoginLevel.SCOPE; -// -// private static Type accountType = Type.CKAN; -// -// /** -// * The main method. -// * -// * @param args the arguments -// * @throws UnsupportedEncodingException the unsupported encoding exception -// */ -// public static void main(String[] args) throws UnsupportedEncodingException { -// -// /*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", "", ""); -// -// String newQueryString = purgeScopeFromQueryString(scopeValue, queryString); -// logger.info("Purged query string from "+scopeValue+" is: "+newQueryString); -// -// String baseURL = remainValue==null ||remainValue.isEmpty()?geonetworkParams.getUrl()+"/"+CSW_SERVER:geonetworkParams.getUrl()+"/"+CSW_SERVER+remainValue; -// logger.info("New base URL "+baseURL); -// newQueryString = purgeRemainFromQueryString(remainValue, newQueryString); -// logger.info("Purged query string from "+remainValue+" is: "+newQueryString); -// -// String gnGetlURL = newQueryString==null || newQueryString.isEmpty()? baseURL : baseURL+"?"+newQueryString; -// logger.info("Sending get request to URL: "+gnGetlURL);*/ -// -// try{ -// HTTPCallsUtils httpUtils = new HTTPCallsUtils(); -// String data =""; -// -// ScopeProvider.instance.set(scope); -// GeoNetworkPublisher reader=GeoNetwork.get(); -// -// -// Configuration config = reader.getConfiguration(); -// Account account=config.getScopeConfiguration().getAccounts().get(accountType); -// reader.login(loginLevel); -// -// String contentType = "application/xml ; charset=\"UTF-8\""; -// String uuid = "c15ae8e5-71c0-4b8b-aa29-304cc4e97238"; -// String gnCSWlURL = "http://geonetwork.d4science.org/geonetwork/srv/en/csw"; -//// String gnCSWlURL = "http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork/srv/en//srv/en/mef.export"; -// -// /*File file = File.createTempFile(uuid, ".xml"); -// InputStream response = httpUtils.post(gnCSWlURL, file, contentType);*/ -// -// //MAP -// Map map = new HashMap(); -// String[] value = new String[1]; -// value[0]=uuid; -// map.put(GeonetworkResolver.UUID, value); -//// data = ""+uuid+""; -// -// data = "" + -// ""+ -// ""+uuid+"" + -// "full" + -// ""; -// -// byte[] byteArray = data.getBytes(); -// InputStream response = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray), contentType, map); -// -//// String respToString = IOUtils.toString(response); -//// System.out.println("Response returned by request: \n"+respToString); -//// InputStream responseToIs = IOUtils.toInputStream(respToString); -// if(response!=null){ -// try { -// -// InputStream re = GetResponseRecordFilter.overrideResponseIdsByListIds(response, new ArrayList(), "Replaced UUID"); -//// String theString = IOUtils.toString(re); -//// System.out.println("Response returned after overriding: \n"+theString); -// -// final Path destination = Paths.get("test.xml"); -// Files.copy(re, destination); -// } -// catch (IOException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } -// -// }catch (Exception e1) { -// // TODO Auto-generated catch block -// e1.printStackTrace(); -// } -// -// } -//} +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datatransfer.resolver.services.GeonetworkResolver; +import org.gcube.datatransfer.resolver.util.GetResponseRecordFilter; +import org.gcube.datatransfer.resolver.util.HTTPCallsUtils; +import org.gcube.spatial.data.geonetwork.GeoNetwork; +import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; +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; + + +/** + * + */ +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Sep 8, 2016 + */ +public class GeonetworkResolverTest { + + private static String scope = "/d4science.research-infrastructures.eu"; + + private static LoginLevel loginLevel = LoginLevel.SCOPE; + + private static Type accountType = Type.CKAN; + + /** + * The main method. + * + * @param args the arguments + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + public static void main(String[] args) throws UnsupportedEncodingException { + + /*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", "", ""); + + String newQueryString = purgeScopeFromQueryString(scopeValue, queryString); + logger.info("Purged query string from "+scopeValue+" is: "+newQueryString); + + String baseURL = remainValue==null ||remainValue.isEmpty()?geonetworkParams.getUrl()+"/"+CSW_SERVER:geonetworkParams.getUrl()+"/"+CSW_SERVER+remainValue; + logger.info("New base URL "+baseURL); + newQueryString = purgeRemainFromQueryString(remainValue, newQueryString); + logger.info("Purged query string from "+remainValue+" is: "+newQueryString); + + String gnGetlURL = newQueryString==null || newQueryString.isEmpty()? baseURL : baseURL+"?"+newQueryString; + logger.info("Sending get request to URL: "+gnGetlURL);*/ + + try{ + HTTPCallsUtils httpUtils = new HTTPCallsUtils(); + String data =""; + + ScopeProvider.instance.set(scope); + GeoNetworkPublisher reader=GeoNetwork.get(); + + + Configuration config = reader.getConfiguration(); + Account account=config.getScopeConfiguration().getAccounts().get(accountType); + reader.login(loginLevel); + + String contentType = "application/xml ; charset=\"UTF-8\""; + String uuid = "c15ae8e5-71c0-4b8b-aa29-304cc4e97238"; + String gnCSWlURL = "http://geonetwork.d4science.org/geonetwork/srv/en/csw"; +// String gnCSWlURL = "http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork/srv/en//srv/en/mef.export"; + + /*File file = File.createTempFile(uuid, ".xml"); + InputStream response = httpUtils.post(gnCSWlURL, file, contentType);*/ + + //MAP + Map map = new HashMap(); + String[] value = new String[1]; + value[0]=uuid; + map.put(GeonetworkResolver.UUID, value); +// data = ""+uuid+""; + + data = "" + + ""+ + ""+uuid+"" + + "full" + + ""; + + byte[] byteArray = data.getBytes(); + InputStream response = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray), contentType, map); + +// String respToString = IOUtils.toString(response); +// System.out.println("Response returned by request: \n"+respToString); +// InputStream responseToIs = IOUtils.toInputStream(respToString); + if(response!=null){ + try { + + InputStream re = GetResponseRecordFilter.overrideResponseIdsByListIds(response, new ArrayList(), "Replaced UUID"); +// String theString = IOUtils.toString(re); +// System.out.println("Response returned after overriding: \n"+theString); + + final Path destination = Paths.get("test.xml"); + Files.copy(re, destination); + } + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + }catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } +} diff --git a/src/test/java/GetAllInfrastructureScopesFromIS.java b/src/test/java/GetAllInfrastructureScopesFromIS.java index b8010a3..5c75910 100644 --- a/src/test/java/GetAllInfrastructureScopesFromIS.java +++ b/src/test/java/GetAllInfrastructureScopesFromIS.java @@ -2,9 +2,7 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client; import java.io.StringReader; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.ExecutionException; import javax.xml.parsers.DocumentBuilder; diff --git a/src/test/java/GisResolverTest.java b/src/test/java/GisResolverTest.java index b209b06..c42100d 100644 --- a/src/test/java/GisResolverTest.java +++ b/src/test/java/GisResolverTest.java @@ -1,5 +1,6 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem; +import org.gcube.datatransfer.resolver.gis.entity.ServerParameters; import org.gcube.datatransfer.resolver.services.GisResolver; /** @@ -26,29 +27,30 @@ public class GisResolverTest { } -// public void resolve(){ -// GisResolver gisResolver = new GisResolver(); -// String scope = "/gcube/devsec/devVRE"; -// String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8"; -// try { -// ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope); -// String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams); -// System.out.println("Final url is: " + wmsRequest); -// wmsRequest = URLEncoder.encode(wmsRequest, UTF_8); -// System.out.println("Encoded WMS request is: " + wmsRequest); -// String gisPortletUrl = gisResolver.getGisViewerApplicationURL(scope); -// System.out.println("Gis Viewer Application url is: " + gisPortletUrl); -//// logger.info("WmsRequest is: " + wmsRequest); -//// wmsRequest = encodeURLWithParamDelimiter(wmsRequest); -//// logger.info("Encoded url is: " + wmsRequest); -//// wmsRequest = appendParamReplacement(wmsRequest); -// gisPortletUrl+="?wmsrequest="+wmsRequest; -// -// System.out.println(gisPortletUrl); -//// urlRedirect(req, resp, gisPortletUrl); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } + /*//TODO TO BE MOVED + * public void resolve(){ + GisResolver gisResolver = new GisResolver(); + String scope = "/gcube/devsec/devVRE"; + String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8"; + try { + ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope); + String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams); + System.out.println("Final url is: " + wmsRequest); + wmsRequest = URLEncoder.encode(wmsRequest, UTF_8); + System.out.println("Encoded WMS request is: " + wmsRequest); + String gisPortletUrl = gisResolver.getGisViewerApplicationURL(scope); + System.out.println("Gis Viewer Application url is: " + gisPortletUrl); +// logger.info("WmsRequest is: " + wmsRequest); +// wmsRequest = encodeURLWithParamDelimiter(wmsRequest); +// logger.info("Encoded url is: " + wmsRequest); +// wmsRequest = appendParamReplacement(wmsRequest); + gisPortletUrl+="?wmsrequest="+wmsRequest; + + System.out.println(gisPortletUrl); +// urlRedirect(req, resp, gisPortletUrl); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }*/ }