git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/sis-geotk-plugin@149159 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ca51f00a70
commit
66a55976c4
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.data.transfer</groupId>
|
<groupId>org.gcube.data.transfer</groupId>
|
||||||
<artifactId>sis-geotk-plugin</artifactId>
|
<artifactId>sis-geotk-plugin</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<name>Sis/GeoToolkit plugin</name>
|
<name>Sis/GeoToolkit plugin</name>
|
||||||
<description>Apache Sis/Geotk plugin for data-transfer-service</description>
|
<description>Apache Sis/Geotk plugin for data-transfer-service</description>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.data.transfer.plugins.sis;
|
package org.gcube.data.transfer.plugins.sis;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -9,31 +11,47 @@ import org.gcube.data.transfer.plugin.fails.ParameterException;
|
||||||
import org.gcube.data.transfer.plugin.fails.PluginInitializationException;
|
import org.gcube.data.transfer.plugin.fails.PluginInitializationException;
|
||||||
import org.gcube.data.transfer.plugin.fails.PluginShutDownException;
|
import org.gcube.data.transfer.plugin.fails.PluginShutDownException;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
|
public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
|
||||||
|
|
||||||
static final String PLUGIN_ID="SIS/GEOTK";
|
static final String PLUGIN_ID="SIS/GEOTK";
|
||||||
|
|
||||||
public static final String SOURCE_PARAMETER="SOURCE_FILE";
|
public static final String SOURCE_PARAMETER="SOURCE_FILE";
|
||||||
public static final String GEONETWORK_CATEGORY="GEONETWORK_CATEGORY";
|
public static final String GEONETWORK_CATEGORY="GEONETWORK_CATEGORY";
|
||||||
public static final String GEONETWORK_STYLESHEET="GEONETWORK_STYLESHEET";
|
public static final String GEONETWORK_STYLESHEET="GEONETWORK_STYLESHEET";
|
||||||
|
|
||||||
static final Map<String,String> PARAMETERS_DESCRIPTION= new HashMap<String,String>();
|
static final Map<String,String> PARAMETERS_DESCRIPTION= new HashMap<String,String>();
|
||||||
|
|
||||||
static{
|
static{
|
||||||
PARAMETERS_DESCRIPTION.put(SOURCE_PARAMETER, "[String value] Absolute path of source archive file.");
|
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_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_'.");
|
PARAMETERS_DESCRIPTION.put(GEONETWORK_STYLESHEET, "[String value] GeoNetwork stylesheet for publiehd metadata. Default is '_none_'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SISPluginFactory() {
|
public SISPluginFactory() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkInvocation(PluginInvocation arg0) throws ParameterException {
|
public void checkInvocation(PluginInvocation arg0) throws ParameterException {
|
||||||
// TODO Auto-generated method stub
|
log.debug("Checking parameters for {} ",arg0);
|
||||||
|
Map<String,String> params=arg0.getParameters();
|
||||||
|
if(params==null||params.isEmpty()||(!params.containsKey(SOURCE_PARAMETER)))
|
||||||
|
throw new ParameterException(SOURCE_PARAMETER+" is mandatory");
|
||||||
|
String source=params.get(SOURCE_PARAMETER);
|
||||||
|
if(source==null||source.length()==0) throw new ParameterException(SOURCE_PARAMETER+" cannot be null.");
|
||||||
|
try{
|
||||||
|
File f=new File(source);
|
||||||
|
if(!f.exists()) throw new ParameterException(SOURCE_PARAMETER+" ["+source+"] not found.");
|
||||||
|
if(!f.canRead()) throw new ParameterException("Cannot read "+SOURCE_PARAMETER+" ["+source+"].");
|
||||||
|
}catch(ParameterException e){
|
||||||
|
throw e;
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new ParameterException("Unable to access source file ",e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,10 +6,11 @@ import java.util.Map;
|
||||||
import org.apache.sis.storage.DataStoreException;
|
import org.apache.sis.storage.DataStoreException;
|
||||||
import org.apache.sis.storage.DataStores;
|
import org.apache.sis.storage.DataStores;
|
||||||
import org.apache.sis.storage.UnsupportedStorageException;
|
import org.apache.sis.storage.UnsupportedStorageException;
|
||||||
|
import org.apache.sis.xml.XML;
|
||||||
|
import org.gcube.data.transfer.model.ExecutionReport;
|
||||||
|
import org.gcube.data.transfer.model.ExecutionReport.ExecutionReportFlag;
|
||||||
import org.gcube.data.transfer.model.PluginInvocation;
|
import org.gcube.data.transfer.model.PluginInvocation;
|
||||||
import org.gcube.data.transfer.plugin.AbstractPlugin;
|
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.PluginCleanupException;
|
||||||
import org.gcube.data.transfer.plugin.fails.PluginExecutionException;
|
import org.gcube.data.transfer.plugin.fails.PluginExecutionException;
|
||||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||||
|
@ -35,7 +36,7 @@ public class SisPlugin extends AbstractPlugin {
|
||||||
@Override
|
@Override
|
||||||
public ExecutionReport run() throws PluginExecutionException {
|
public ExecutionReport run() throws PluginExecutionException {
|
||||||
try{
|
try{
|
||||||
log.debug("Checking parameters for {} ",invocation);
|
|
||||||
Map<String,String> params=invocation.getParameters();
|
Map<String,String> params=invocation.getParameters();
|
||||||
String dataStorePath=params.get(SISPluginFactory.SOURCE_PARAMETER);
|
String dataStorePath=params.get(SISPluginFactory.SOURCE_PARAMETER);
|
||||||
String category=params.containsKey(SISPluginFactory.GEONETWORK_CATEGORY)?params.get(SISPluginFactory.GEONETWORK_CATEGORY):"Dataset";
|
String category=params.containsKey(SISPluginFactory.GEONETWORK_CATEGORY)?params.get(SISPluginFactory.GEONETWORK_CATEGORY):"Dataset";
|
||||||
|
@ -64,10 +65,16 @@ public class SisPlugin extends AbstractPlugin {
|
||||||
|
|
||||||
|
|
||||||
public static final long publishMetadata(Metadata meta,String category, String stylesheet) throws Exception{
|
public static final long publishMetadata(Metadata meta,String category, String stylesheet) throws Exception{
|
||||||
|
File tmp=File.createTempFile("tmp_meta_", ".xml");
|
||||||
|
|
||||||
|
XML.marshal(meta,tmp);
|
||||||
|
|
||||||
GeoNetworkPublisher publisher=GeoNetwork.get();
|
GeoNetworkPublisher publisher=GeoNetwork.get();
|
||||||
publisher.login(LoginLevel.DEFAULT);
|
publisher.login(LoginLevel.DEFAULT);
|
||||||
GNInsertConfiguration config=publisher.getCurrentUserConfiguration(category, stylesheet);
|
GNInsertConfiguration config=publisher.getCurrentUserConfiguration(category, stylesheet);
|
||||||
config.setValidate(false);
|
config.setValidate(false);
|
||||||
return publisher.insertMetadata(config, meta);
|
long toReturn= publisher.insertMetadata(config, tmp);
|
||||||
|
tmp.delete();
|
||||||
|
return toReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue