diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..534b5e5
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..9e50a3a
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ geonetwork
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..29abf99
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..60105c1
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..f897a7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/distro/changelog.xml b/distro/changelog.xml
new file mode 100644
index 0000000..10dc79e
--- /dev/null
+++ b/distro/changelog.xml
@@ -0,0 +1,6 @@
+
+
+ First Release
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..6ee5150
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,129 @@
+
+ 4.0.0
+
+ maven-parent
+ org.gcube.tools
+ 1.0.0
+
+ org.gcube.spatial.data
+ geonetwork
+ 1.0.0-SNAPSHOT
+ geonetwork
+
+
+ UTF-8
+ 8.0-M4
+ distro
+
+
+
+
+
+
+ it.geosolutions
+ geonetwork-manager
+ 1.0-SNAPSHOT
+
+
+ org.gcube.core
+ common-gcore-clients
+ [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)
+
+
+ org.gcube.distribution
+ ghn-client-runtime
+ 2.1.0-SNAPSHOT
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+
+ org.geotoolkit
+ geotk-metadata
+ 3.20-geoapi-3.0
+
+
+ org.w3c
+ dom
+ 2.3.0-jaxb-1.0.6
+
+
+ org.geotoolkit
+ geotk-referencing
+ 3.20-geoapi-3.0
+
+
+
+
+
+
+
+
+ maven-compiler-plugin
+
+
+ 1.6
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.5
+
+
+ copy-profile
+ install
+
+ copy-resources
+
+
+ target
+
+
+ ${distroDirectory}
+ true
+
+ profile.xml
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ ${distroDirectory}/descriptor.xml
+
+
+
+
+ servicearchive
+ install
+
+ single
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/GeoNetwork.java b/src/main/java/org/gcube/spatial/data/geonetwork/GeoNetwork.java
new file mode 100644
index 0000000..71d3eab
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/geonetwork/GeoNetwork.java
@@ -0,0 +1,120 @@
+package org.gcube.spatial.data.geonetwork;
+
+import it.geosolutions.geonetwork.GNClient;
+import it.geosolutions.geonetwork.exception.GNLibException;
+import it.geosolutions.geonetwork.exception.GNServerException;
+import it.geosolutions.geonetwork.util.GNInsertConfiguration;
+import it.geosolutions.geonetwork.util.GNPrivConfiguration;
+import it.geosolutions.geonetwork.util.GNSearchRequest;
+import it.geosolutions.geonetwork.util.GNSearchResponse;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBException;
+
+import org.gcube.spatial.data.geonetwork.configuration.AuthorizationException;
+import org.gcube.spatial.data.geonetwork.configuration.Configuration;
+import org.gcube.spatial.data.geonetwork.configuration.ConfigurationManager;
+import org.geotoolkit.xml.XML;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.opengis.metadata.Metadata;
+
+public class GeoNetwork {
+
+ private static XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
+
+ public static GeoNetwork get() throws Exception{
+ return new GeoNetwork();
+ }
+
+ private Configuration config;
+
+ private GeoNetwork() throws Exception {
+ config=ConfigurationManager.get();
+ }
+
+ //************** READ ONLY METHODS, NO NEED TO LOGIN
+
+ public GNSearchResponse query(GNSearchRequest request) throws GNLibException, GNServerException{
+ return getClient().search(request);
+ }
+
+ public GNSearchResponse query(File fileRequest) throws GNLibException, GNServerException{
+ return getClient().search(fileRequest);
+ }
+
+ public Metadata getById(long id) throws GNLibException, GNServerException, JAXBException{
+ String xml=out.outputString(getClient().get(id));
+ return (Metadata) XML.unmarshal(xml);
+ }
+
+ public Metadata getById(String UUID) throws GNLibException, GNServerException, JAXBException{
+ String xml=out.outputString(getClient().get(UUID));
+ return (Metadata) XML.unmarshal(xml);
+ }
+
+ //************** WRITE METHODS, LOGIN REQUIRED
+
+ public void setPrivileges(long metadataId,GNPrivConfiguration cfg) throws GNLibException, GNServerException, AuthorizationException{
+ GNClient client=getClient();
+ if(!client.login(config.getGeoNetworkUser(), config.getGeoNetworkPassword()))throw new AuthorizationException();
+ client.setPrivileges(metadataId, cfg);
+ }
+
+
+ public long insertMetadata(GNInsertConfiguration configuration,File metadataFile) throws GNLibException, GNServerException, AuthorizationException{
+ GNClient client=getClient();
+ if(!client.login(config.getGeoNetworkUser(), config.getGeoNetworkPassword()))throw new AuthorizationException();
+ return client.insertMetadata(configuration, metadataFile);
+ }
+ public long insertMetadata(GNInsertConfiguration configuration,Metadata meta) throws GNLibException, GNServerException, AuthorizationException, IOException, JAXBException{
+ return insertMetadata(configuration, meta2File(meta));
+ }
+
+ public long insertMetadata(File requestFile) throws GNLibException, GNServerException, AuthorizationException{
+ GNClient client=getClient();
+ if(!client.login(config.getGeoNetworkUser(), config.getGeoNetworkPassword()))throw new AuthorizationException();
+ return client.insertRequest(requestFile);
+ }
+ public long insertMetadata(Metadata meta) throws GNLibException, GNServerException, AuthorizationException, IOException, JAXBException{
+ return insertMetadata(meta2File(meta));
+ }
+
+
+ public void updateMetadata(long id,File metadataFile) throws GNLibException, GNServerException, AuthorizationException{
+ GNClient client=getClient();
+ if(!client.login(config.getGeoNetworkUser(), config.getGeoNetworkPassword()))throw new AuthorizationException();
+ client.updateMetadata(id, metadataFile);
+ }
+ public void updateMetadata(long id,Metadata meta) throws GNLibException, GNServerException, AuthorizationException, IOException, JAXBException{
+ updateMetadata(id, meta2File(meta));
+ }
+
+
+ public void deleteMetadata(long id) throws GNLibException, GNServerException, AuthorizationException{
+ GNClient client=getClient();
+ if(!client.login(config.getGeoNetworkUser(), config.getGeoNetworkPassword()))throw new AuthorizationException();
+ client.deleteMetadata(id);
+ }
+
+
+ //************* PRIVATE
+
+ private GNClient getClient(){
+ GNClient client = new GNClient(config.getGeoNetworkEndpoint());
+ return client;
+ }
+
+
+ private static File meta2File(Metadata meta) throws IOException, JAXBException{
+ File temp=File.createTempFile("meta", ".xml");
+ FileWriter writer=new FileWriter(temp);
+ writer.write(XML.marshal(meta));
+ writer.close();
+ return temp;
+ }
+
+}
diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/configuration/AuthorizationException.java b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/AuthorizationException.java
new file mode 100644
index 0000000..2a5ce8d
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/AuthorizationException.java
@@ -0,0 +1,32 @@
+package org.gcube.spatial.data.geonetwork.configuration;
+
+public class AuthorizationException extends Throwable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8639478879076898891L;
+
+ public AuthorizationException() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public AuthorizationException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+ public AuthorizationException(String arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ public AuthorizationException(Throwable arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+
+
+}
diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/configuration/Configuration.java b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/Configuration.java
new file mode 100644
index 0000000..38588c3
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/Configuration.java
@@ -0,0 +1,9 @@
+package org.gcube.spatial.data.geonetwork.configuration;
+
+public interface Configuration {
+
+ public String getGeoNetworkEndpoint();
+ public String getGeoNetworkUser();
+ public String getGeoNetworkPassword();
+
+}
diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/configuration/ConfigurationManager.java b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/ConfigurationManager.java
new file mode 100644
index 0000000..dd03287
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/ConfigurationManager.java
@@ -0,0 +1,14 @@
+package org.gcube.spatial.data.geonetwork.configuration;
+
+public class ConfigurationManager {
+
+ private static Configuration config;
+
+
+ public static synchronized Configuration get() throws Exception{
+ if(config==null)config=new DefaultConfiguration();
+ return config;
+ }
+ public static void setConfiguration(Configuration configuration){config=configuration;}
+
+}
diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/configuration/DefaultConfiguration.java b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/DefaultConfiguration.java
new file mode 100644
index 0000000..c7c17e8
--- /dev/null
+++ b/src/main/java/org/gcube/spatial/data/geonetwork/configuration/DefaultConfiguration.java
@@ -0,0 +1,56 @@
+package org.gcube.spatial.data.geonetwork.configuration;
+
+import java.util.List;
+
+import org.gcube.common.core.contexts.GHNContext;
+import org.gcube.common.core.informationsystem.client.AtomicCondition;
+import org.gcube.common.core.informationsystem.client.ISClient;
+import org.gcube.common.core.informationsystem.client.queries.GCUBERuntimeResourceQuery;
+import org.gcube.common.core.resources.GCUBERuntimeResource;
+import org.gcube.common.core.resources.runtime.AccessPoint;
+import org.gcube.common.core.scope.GCUBEScope;
+import org.gcube.common.scope.api.ScopeProvider;
+
+public class DefaultConfiguration implements Configuration {
+
+private static ISClient client;
+
+ private String url;
+ private String user;
+ private String pwd;
+
+
+ public DefaultConfiguration() throws Exception {
+ client=GHNContext.getImplementation(ISClient.class);
+ GCUBERuntimeResourceQuery runtimeQuery=client.getQuery(GCUBERuntimeResourceQuery.class);
+ runtimeQuery.addAtomicConditions(new AtomicCondition("//Profile/Category", "Gis"));
+ runtimeQuery.addAtomicConditions(new AtomicCondition("//Profile/Platform/Name", "geonetwork"));
+ List list=client.execute(runtimeQuery, GCUBEScope.getScope(ScopeProvider.instance.get()));
+ for(GCUBERuntimeResource rr:list){
+ try{
+ for(AccessPoint access:rr.getAccessPoints())
+ if(access.getEntryname().equals("geonetwork")){
+ url=access.getEndpoint();
+ user=access.getUsername();
+ pwd=access.getPassword();
+ }
+ }catch(Exception e){e.printStackTrace();}
+ }
+ }
+
+ @Override
+ public String getGeoNetworkEndpoint() {
+ return url;
+ }
+
+ @Override
+ public String getGeoNetworkUser() {
+ return user;
+ }
+
+ @Override
+ public String getGeoNetworkPassword() {
+ return pwd;
+ }
+
+}
diff --git a/src/test/java/org/gcube/spatial/data/geonetwork/test/QueryLogger.java b/src/test/java/org/gcube/spatial/data/geonetwork/test/QueryLogger.java
new file mode 100644
index 0000000..73a0169
--- /dev/null
+++ b/src/test/java/org/gcube/spatial/data/geonetwork/test/QueryLogger.java
@@ -0,0 +1,82 @@
+package org.gcube.spatial.data.geonetwork.test;
+
+import it.geosolutions.geonetwork.util.GNSearchRequest;
+import it.geosolutions.geonetwork.util.GNSearchResponse;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.spatial.data.geonetwork.GeoNetwork;
+import org.gcube.spatial.data.geonetwork.configuration.AuthorizationException;
+import org.geotoolkit.metadata.iso.identification.DefaultDataIdentification;
+import org.geotoolkit.metadata.iso.identification.DefaultKeywords;
+import org.geotoolkit.util.DefaultInternationalString;
+import org.geotoolkit.xml.XML;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.junit.Test;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.identification.Identification;
+import org.opengis.metadata.identification.Keywords;
+import org.opengis.util.InternationalString;
+
+public class QueryLogger {
+
+ /**
+ * @param args
+ */
+
+ private static final String defaultScope="/gcube/devsec";
+ private static final boolean printEverything=true;
+ private static XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
+ public static final String CITATION="Kaschner, K., J. S. Ready, E. Agbayani, J. Rius, K. Kesner-Reyes, P. D. Eastwood, A. B. South, "+
+ "S. O. Kullander, T. Rees, C. H. Close, R. Watson, D. Pauly, and R. Froese. 2008 AquaMaps: "+
+ "Predicted range maps for aquatic species. World wide web electronic publication, www.aquamaps.org, Version 10/2008.";
+
+ public static void main(String[] args) throws Exception, AuthorizationException {
+ new QueryLogger().test();
+ }
+
+ @Test
+ public void test() throws Exception, AuthorizationException{
+ System.out.println(System.getenv());
+ ScopeProvider.instance.set(defaultScope);
+ System.out.println("Looking for ANY 'aquamaps'");
+ GNSearchRequest req=new GNSearchRequest();
+ req.addParam(GNSearchRequest.Param.any, "geoserver");
+// req.addConfig(GNSearchRequest.Config.sortBy, "title");
+ GeoNetwork gn=GeoNetwork.get();
+ GNSearchResponse resp=gn.query(req);
+ System.out.println("Found "+resp.getCount()+" items");
+ System.out.println("From "+resp.getFrom());
+ System.out.println("To "+resp.getTo());
+ System.out.println("Summary "+resp.getSummary());
+ System.out.println("Is Complete "+resp.isCompleteResponse());
+ if(resp.getCount()!=0)
+ for(GNSearchResponse.GNMetadata metadata:resp){
+ long id=metadata.getId();
+ System.out.println(out.outputString(metadata.getInfo()));
+ System.out.print(id + (metadata+""));
+ Metadata meta=gn.getById(metadata.getUUID());
+ System.out.println(meta);
+
+// ArrayList key=new ArrayList();
+// key.add(new DefaultInternationalString("AquaMaps"));
+// Keywords keys= new DefaultKeywords(key);
+// Identification ident=new DefaultDataIdentification();
+// ((Collection)ident.getDescriptiveKeywords()).add(keys);
+// ((Collection) meta.getIdentificationInfo()).add(ident);
+//
+// gn.updateMetadata(id, meta);
+// System.out.println("*********************UPDATED************************");
+// System.out.println(gn.getById(id));
+
+
+
+
+ }
+
+ }
+
+}