git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/sis-geotk-plugin@149012 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eaa93e3298
commit
f6322591f9
|
@ -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.8">
|
||||
<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>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>sis-geotk-plugin</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>
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=false
|
||||
version=1
|
|
@ -0,0 +1,78 @@
|
|||
<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>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>LATEST</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>sis-geotk-plugin</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Sis/GeoToolkit plugin</name>
|
||||
<description>Apache Sis/Geotk plugin for data-transfer-service</description>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<svnBaseUrl>http://svn.research-infrastructures.eu/d4science/gcube/trunk/data-transfer/${project.artifactId}</svnBaseUrl>
|
||||
<sis.version>0.7</sis.version>
|
||||
<sis.utils.modules>${sis.version}</sis.utils.modules>
|
||||
</properties>
|
||||
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:${svnBaseUrl}/${project.artifactId}</connection>
|
||||
<developerConnection>scm:svn:${svnBaseUrl}/${project.artifactId}</developerConnection>
|
||||
<url>${svnBaseUrl}/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>data-transfer-plugin-framework</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.spatial.data</groupId>
|
||||
<artifactId>geonetwork</artifactId>
|
||||
<version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SIS -->
|
||||
<dependency>
|
||||
<groupId>org.apache.sis.core</groupId>
|
||||
<artifactId>sis-referencing</artifactId>
|
||||
<version>${sis.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.sis.storage</groupId>
|
||||
<artifactId>sis-storage</artifactId>
|
||||
<version>${sis.utils.modules}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.sis.storage</groupId>
|
||||
<artifactId>sis-netcdf</artifactId>
|
||||
<version>${sis.utils.modules}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,69 @@
|
|||
package org.gcube.data.transfer.plugins.sis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.data.transfer.model.PluginInvocation;
|
||||
import org.gcube.data.transfer.plugin.AbstractPluginFactory;
|
||||
import org.gcube.data.transfer.plugin.fails.ParameterException;
|
||||
import org.gcube.data.transfer.plugin.fails.PluginInitializationException;
|
||||
import org.gcube.data.transfer.plugin.fails.PluginShutDownException;
|
||||
|
||||
public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
|
||||
|
||||
static final String PLUGIN_ID="SIS/GEOTK";
|
||||
|
||||
public static final String SOURCE_PARAMETER="SOURCE_FILE";
|
||||
public static final String GEONETWORK_CATEGORY="GEONETWORK_CATEGORY";
|
||||
public static final String GEONETWORK_STYLESHEET="GEONETWORK_STYLESHEET";
|
||||
|
||||
static final Map<String,String> PARAMETERS_DESCRIPTION= new HashMap<String,String>();
|
||||
|
||||
static{
|
||||
PARAMETERS_DESCRIPTION.put(SOURCE_PARAMETER, "[String value] Absolute path of source archive file.");
|
||||
PARAMETERS_DESCRIPTION.put(GEONETWORK_CATEGORY, "[String value] GeoNetwork category for publiehd metadata. Default is 'Dataset'.");
|
||||
PARAMETERS_DESCRIPTION.put(GEONETWORK_STYLESHEET, "[String value] GeoNetwork stylesheet for publiehd metadata. Default is '_none_'.");
|
||||
}
|
||||
|
||||
|
||||
public SISPluginFactory() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkInvocation(PluginInvocation arg0) throws ParameterException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SisPlugin createWorker(PluginInvocation arg0) {
|
||||
return new SisPlugin(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return String.format("Extracts ISO metadata file from <%s> and publishes to GeoNetwork.", SOURCE_PARAMETER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return PLUGIN_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,String> getParameters() {
|
||||
return PARAMETERS_DESCRIPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() throws PluginInitializationException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shutDown() throws PluginShutDownException {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package org.gcube.data.transfer.plugins.sis;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.sis.storage.DataStoreException;
|
||||
import org.apache.sis.storage.DataStores;
|
||||
import org.apache.sis.storage.UnsupportedStorageException;
|
||||
import org.gcube.data.transfer.model.PluginInvocation;
|
||||
import org.gcube.data.transfer.plugin.AbstractPlugin;
|
||||
import org.gcube.data.transfer.plugin.ExecutionReport;
|
||||
import org.gcube.data.transfer.plugin.ExecutionReport.ExecutionReportFlag;
|
||||
import org.gcube.data.transfer.plugin.fails.PluginCleanupException;
|
||||
import org.gcube.data.transfer.plugin.fails.PluginExecutionException;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||
import org.opengis.metadata.Metadata;
|
||||
|
||||
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class SisPlugin extends AbstractPlugin {
|
||||
|
||||
public SisPlugin(PluginInvocation invocation) {
|
||||
super(invocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() throws PluginCleanupException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionReport run() throws PluginExecutionException {
|
||||
try{
|
||||
log.debug("Checking parameters for {} ",invocation);
|
||||
Map<String,String> params=invocation.getParameters();
|
||||
String dataStorePath=params.get(SISPluginFactory.SOURCE_PARAMETER);
|
||||
String category=params.containsKey(SISPluginFactory.GEONETWORK_CATEGORY)?params.get(SISPluginFactory.GEONETWORK_CATEGORY):"Dataset";
|
||||
String stylesheet=params.containsKey(SISPluginFactory.GEONETWORK_STYLESHEET)?params.get(SISPluginFactory.GEONETWORK_STYLESHEET):"_none_";
|
||||
File dataStore=new File(dataStorePath);
|
||||
log.debug("Extracting meta from {} ",dataStore.getAbsolutePath());
|
||||
Metadata meta=getMetaFromFile(dataStore);
|
||||
// TODO Links from current thredds
|
||||
// TODO Info from infrastructure
|
||||
long id=publishMetadata(meta, category, stylesheet);
|
||||
return new ExecutionReport(invocation, "Published meta with id : "+id, ExecutionReportFlag.SUCCESS);
|
||||
|
||||
}catch(DataStoreException e){
|
||||
log.error("Unable to parse source ",e);
|
||||
throw new PluginExecutionException("Unable to extract metadata.", e);
|
||||
}catch(Throwable t){
|
||||
log.error("Unexpected error while generating metadata.",t);
|
||||
throw new PluginExecutionException("Unexpected error while generating meta.",t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final Metadata getMetaFromFile(Object dataStore) throws UnsupportedStorageException, DataStoreException{
|
||||
return DataStores.open(dataStore).getMetadata();
|
||||
}
|
||||
|
||||
|
||||
public static final long publishMetadata(Metadata meta,String category, String stylesheet) throws Exception{
|
||||
GeoNetworkPublisher publisher=GeoNetwork.get();
|
||||
publisher.login(LoginLevel.DEFAULT);
|
||||
GNInsertConfiguration config=publisher.getCurrentUserConfiguration(category, stylesheet);
|
||||
config.setValidate(false);
|
||||
return publisher.insertMetadata(config, meta);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.data.transfer.plugins.sis;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.sis.storage.DataStoreException;
|
||||
import org.apache.sis.storage.UnsupportedStorageException;
|
||||
|
||||
public class TestGetMetadata {
|
||||
|
||||
public static void main(String[] args) throws UnsupportedStorageException, MalformedURLException, DataStoreException {
|
||||
System.out.println(SisPlugin.getMetaFromFile(new URL("https://github.com/opengeospatial/geoapi/raw/master/geoapi-netcdf/src/test/resources/org/opengis/wrapper/netcdf/NCEP-SST.nc")));
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue