This commit is contained in:
Fabio Sinibaldi 2013-03-01 11:05:53 +00:00
parent 873da34025
commit da02580f9a
13 changed files with 522 additions and 0 deletions

36
.classpath Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>geonetwork</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -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/<project>=UTF-8

View File

@ -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

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

6
distro/changelog.xml Normal file
View File

@ -0,0 +1,6 @@
<ReleaseNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="xsd/changelog.xsd">
<Changeset component="org.gcube.spatial-data.geonetowrk.1-0-0" date="2013-03-01">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

129
pom.xml Normal file
View File

@ -0,0 +1,129 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geonetwork</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>geonetwork</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<geotools.version>8.0-M4</geotools.version>
<distroDirectory>distro</distroDirectory>
</properties>
<dependencies>
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geonetwork-manager</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcore-clients</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>ghn-client-runtime</artifactId>
<version>2.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotoolkit</groupId>
<artifactId>geotk-metadata</artifactId>
<version>3.20-geoapi-3.0</version>
</dependency>
<dependency>
<groupId>org.w3c</groupId>
<artifactId>dom</artifactId>
<version>2.3.0-jaxb-1.0.6</version>
</dependency>
<dependency>
<groupId>org.geotoolkit</groupId>
<artifactId>geotk-referencing</artifactId>
<version>3.20-geoapi-3.0</version>
</dependency>
</dependencies>
<!-- <repositories>
<repository>
<id>geo-solutions</id>
<name>geo-solutions</name>
<url>http://maven.geo-solutions.it/</url>
</repository>
</repositories> -->
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

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

View File

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

View File

@ -0,0 +1,9 @@
package org.gcube.spatial.data.geonetwork.configuration;
public interface Configuration {
public String getGeoNetworkEndpoint();
public String getGeoNetworkUser();
public String getGeoNetworkPassword();
}

View File

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

View File

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

View File

@ -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<InternationalString> key=new ArrayList<InternationalString>();
// key.add(new DefaultInternationalString("AquaMaps"));
// Keywords keys= new DefaultKeywords(key);
// Identification ident=new DefaultDataIdentification();
// ((Collection<Keywords>)ident.getDescriptiveKeywords()).add(keys);
// ((Collection<Identification>) meta.getIdentificationInfo()).add(ident);
//
// gn.updateMetadata(id, meta);
// System.out.println("*********************UPDATED************************");
// System.out.println(gn.getById(id));
}
}
}