This commit is contained in:
Fabio Sinibaldi 2013-03-05 17:00:03 +00:00
parent ed6d9eca3e
commit 69da352dd6
10 changed files with 514 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>gis-interface</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=false
version=1

88
pom.xml Normal file
View File

@ -0,0 +1,88 @@
<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>gis-interface</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>gis-interface</name>
<dependencies>
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geonetwork</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
</dependency>
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
</dependency>
</dependencies>
<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,164 @@
package org.gcube.spatial.data.gis;
import it.geosolutions.geoserver.rest.GeoServerRESTManager;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.SortedSet;
import java.util.concurrent.ConcurrentSkipListSet;
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.gis.model.GeoServerDescriptor;
import org.gcube.spatial.data.gis.model.InfrastructureCrawler;
public class GISInterface {
private static final long MAX_GEOSERVER_CACHE_TIME=2*60*1000;
public static GISInterface get() throws Exception{
return new GISInterface();
}
//************ INSTANCE
private GISInterface() throws Exception{
}
//***************** GEONETWORK READ METHODS
// public GNSearchResponse query(GNSearchRequest request)
// throws GNLibException, GNServerException, Exception{
// return getGN().query(request);
// }
//
// public GNSearchResponse query(File request)
// throws GNLibException, GNServerException, Exception{
// return getGN().query(request);
// }
//
// public Metadata getById(long id) throws GNLibException,
// GNServerException, JAXBException, Exception {
// return getGN().getById(id);
// }
//
// public Metadata getById(String UUID) throws GNLibException,
// GNServerException, JAXBException, Exception {
// return getGN().getById(UUID);
// }
//****************** GEONETWORK WRITE METHODS
// public void deleteMetadata(long id) throws GNLibException,
// GNServerException, AuthorizationException, Exception {
// getGN().deleteMetadata(id);
// }
//
// public void setPrivileges(long metadataId, GNPrivConfiguration cfg)
// throws GNLibException, GNServerException, AuthorizationException,Exception{
// getGN().setPrivileges(metadataId, cfg);
// }
//
// public long insertMetadata(GNInsertConfiguration configuration,
// File metadataFile) throws GNLibException, GNServerException,
// AuthorizationException,Exception{
// return getGN().insertMetadata(configuration, metadataFile);
// }
//
// public long insertMetadata(GNInsertConfiguration configuration,
// Metadata meta) throws GNLibException, GNServerException,
// AuthorizationException, IOException, JAXBException,Exception{
// return getGN().insertMetadata(configuration, meta);
// }
//
// public long insertMetadata(File requestFile) throws GNLibException,
// GNServerException, AuthorizationException,Exception{
// return getGN().insertMetadata(requestFile);
// }
//
// public long insertMetadata(Metadata meta) throws GNLibException,
// GNServerException, AuthorizationException, IOException,
// JAXBException,Exception{
// return getGN().insertMetadata(meta);
// }
//
// public void updateMetadata(long id, File metadataFile)
// throws GNLibException, GNServerException, AuthorizationException,Exception{
// getGN().updateMetadata(id, metadataFile);
// }
//
// public void updateMetadata(long id, Metadata meta) throws GNLibException,
// GNServerException, AuthorizationException, IOException,
// JAXBException,Exception{
// getGN().updateMetadata(id, meta);
// }
//*******************READER getter METHODS
public GeoNetworkReader getGeoNetworkReader() throws Exception{
return getGN();
}
public GeoNetworkPublisher getGeoNewtorkPublisher()throws Exception{
return getGN();
}
public GeoServerRESTReader getGeoServerReader(ResearchMethod method,boolean forceRefresh) throws Exception{
GeoServerDescriptor desc=getGeoServerSet(forceRefresh).last();
return getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getReader();
}
public GeoServerRESTReader getGeoServerReader(String url,String user,String password) throws IllegalArgumentException, MalformedURLException{
return getGeoServerManager(url, user, password).getReader();
}
public GeoServerRESTReader getGeoServerReader(String url) throws MalformedURLException{
return new GeoServerRESTReader(url);
}
//******************* Complex logic
public void addGeoTIFF() throws Exception{
GeoServerDescriptor desc=getGeoServerSet(false).last();
GeoServerRESTPublisher publisher=getGeoServerManager(desc.getUrl(), desc.getUser(), desc.getPassword()).getPublisher();
publisher.
}
//************ PRIVATE
private GeoNetworkPublisher geoNetwork=null;
private ConcurrentSkipListSet<GeoServerDescriptor> geoservers=new ConcurrentSkipListSet<GeoServerDescriptor>();
private long lastAccessedTime=0l;
private synchronized SortedSet<GeoServerDescriptor> getGeoServerSet(boolean forceRefresh) throws Exception{
if(forceRefresh||geoservers.size()==0||System.currentTimeMillis()-lastAccessedTime>MAX_GEOSERVER_CACHE_TIME){
geoservers.clear();
geoservers.addAll(InfrastructureCrawler.queryforGeoServer());
lastAccessedTime=System.currentTimeMillis();
}
return geoservers;
}
private synchronized GeoNetworkPublisher getGN() throws Exception{
if(geoNetwork==null) geoNetwork=GeoNetwork.get();
return geoNetwork;
}
private GeoServerRESTManager getGeoServerManager(String url,String user,String password) throws IllegalArgumentException, MalformedURLException{
return new GeoServerRESTManager(new URL(url), user, password);
}
}

View File

@ -0,0 +1,6 @@
package org.gcube.spatial.data.gis;
public enum ResearchMethod {
RANDOM,MOSTUNLOAD
}

View File

@ -0,0 +1,144 @@
package org.gcube.spatial.data.gis.model;
public class GeoServerDescriptor implements Comparable<GeoServerDescriptor>{
private String url;
private String user;
private String password;
private Long hostedLayersCount;
public GeoServerDescriptor(String url, String user, String password,
Long hostedLayersCount) {
super();
this.url = url;
this.user = user;
this.password = password;
this.hostedLayersCount = hostedLayersCount;
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(GeoServerDescriptor o) {
// TODO Auto-generated method stub
return hostedLayersCount.compareTo(o.hostedLayersCount);
}
/**
* @return the url
*/
public String getUrl() {
return url;
}
/**
* @param url the url to set
*/
public void setUrl(String url) {
this.url = url;
}
/**
* @return the user
*/
public String getUser() {
return user;
}
/**
* @param user the user to set
*/
public void setUser(String user) {
this.user = user;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the hostedLayersCount
*/
public Long getHostedLayersCount() {
return hostedLayersCount;
}
/**
* @param hostedLayersCount the hostedLayersCount to set
*/
public void setHostedLayersCount(Long hostedLayersCount) {
this.hostedLayersCount = hostedLayersCount;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((url == null) ? 0 : url.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
GeoServerDescriptor other = (GeoServerDescriptor) obj;
if (url == null) {
if (other.url != null)
return false;
} else if (!url.equals(other.url))
return false;
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoServerDescriptor [url=");
builder.append(url);
builder.append(", user=");
builder.append(user);
builder.append(", password=");
builder.append(password);
builder.append(", hostedLayersCount=");
builder.append(hostedLayersCount);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,38 @@
package org.gcube.spatial.data.gis.model;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
public class InfrastructureCrawler {
public static List<GeoServerDescriptor> queryforGeoServer() throws Exception{
List<GeoServerDescriptor> toReturn=new ArrayList<GeoServerDescriptor>();
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq 'Gis'")
.addCondition("$resource/Profile/Platform/Name/text() eq 'geonetwork'")
.setResult("$resource/Profile/AccessPoint");
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
List<AccessPoint> accesspoints = client.submit(query);
// if(accesspoints.size()==0) throw new Exception("No Resource found under current scope "+ScopeProvider.instance.get());
for (AccessPoint point : accesspoints) {
toReturn.add(new GeoServerDescriptor(point.address(),point.username(),point.password(),0l));
// url=point.address();
// user=point.username();
// pwd=point.password();
}
return toReturn;
}
}