diff --git a/pom.xml b/pom.xml
index ed6121d..196de49 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,6 +27,18 @@
+
+
+
+ org.gcube.distribution
+ maven-smartgears-bom
+ LATEST
+ pom
+ import
+
+
+
+
org.gcube.data.transfer
@@ -34,12 +46,24 @@
[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)
+
+
+
+
+
+
org.gcube.spatial.data
- geonetwork
- [3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)
+ sdi-library
+ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)
-
+
+
+
+ org.gcube.core
+ common-smartgears
+
+
org.apache.sis.core
diff --git a/src/main/java/org/gcube/data/transfer/plugins/sis/SISPluginFactory.java b/src/main/java/org/gcube/data/transfer/plugins/sis/SISPluginFactory.java
index 57f82f5..3653b0c 100644
--- a/src/main/java/org/gcube/data/transfer/plugins/sis/SISPluginFactory.java
+++ b/src/main/java/org/gcube/data/transfer/plugins/sis/SISPluginFactory.java
@@ -9,12 +9,16 @@ 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;
+import org.gcube.data.transfer.plugin.model.DataTransferContext;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SISPluginFactory extends AbstractPluginFactory {
+
+
+
static final String PLUGIN_ID="SIS/GEOTK";
public static final String SOURCE_PARAMETER="SOURCE_FILE";
@@ -63,7 +67,7 @@ public class SISPluginFactory extends AbstractPluginFactory {
@Override
public SisPlugin createWorker(PluginInvocation arg0) {
- return new SisPlugin(arg0);
+ return new SisPlugin(arg0,ctx);
}
@Override
@@ -82,7 +86,9 @@ public class SISPluginFactory extends AbstractPluginFactory {
}
@Override
- public boolean init() throws PluginInitializationException {
+ public boolean init(DataTransferContext ctx) throws PluginInitializationException {
+ log.trace("Loading configuration .. ");
+ this.ctx=ctx;
return true;
}
@@ -91,4 +97,7 @@ public class SISPluginFactory extends AbstractPluginFactory {
return true;
}
+
+ private DataTransferContext ctx;
+
}
diff --git a/src/main/java/org/gcube/data/transfer/plugins/sis/SisPlugin.java b/src/main/java/org/gcube/data/transfer/plugins/sis/SisPlugin.java
index b1d862b..0d18b58 100644
--- a/src/main/java/org/gcube/data/transfer/plugins/sis/SisPlugin.java
+++ b/src/main/java/org/gcube/data/transfer/plugins/sis/SisPlugin.java
@@ -2,6 +2,7 @@ package org.gcube.data.transfer.plugins.sis;
import java.io.File;
import java.util.Map;
+import java.util.Set;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.DataStores;
@@ -13,42 +14,88 @@ import org.gcube.data.transfer.model.PluginInvocation;
import org.gcube.data.transfer.plugin.AbstractPlugin;
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.gcube.data.transfer.plugin.model.DataTransferContext;
+import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
+import org.gcube.spatial.data.sdi.model.metadata.MetadataReport;
+import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation;
+import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder;
+import org.gcube.spatial.data.sdi.plugins.SDIAbstractPlugin;
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) {
+ File tmp=null;
+ DataTransferContext ctx;
+
+ public SisPlugin(PluginInvocation invocation, DataTransferContext ctx) {
super(invocation);
+ this.ctx=ctx;
}
@Override
public void cleanup() throws PluginCleanupException {
-
+ try{
+ if(tmp!=null) tmp.delete();
+ }catch(Throwable t){
+ throw new PluginCleanupException("Unable to delete tmp file "+(tmp==null?tmp:tmp.getAbsolutePath()), t);
+ }
}
@Override
- public ExecutionReport run() throws PluginExecutionException {
+ public ExecutionReport run() throws PluginExecutionException {
try{
-
- Map params=invocation.getParameters();
- String dataStorePath=params.get(SISPluginFactory.SOURCE_PARAMETER);
- String category=params.get(SISPluginFactory.GEONETWORK_CATEGORY);
- String stylesheet=params.get(SISPluginFactory.GEONETWORK_STYLESHEET);
- 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);
-
+
+ Map params=invocation.getParameters();
+ String dataStorePath=params.get(SISPluginFactory.SOURCE_PARAMETER);
+ String category=params.get(SISPluginFactory.GEONETWORK_CATEGORY);
+ String stylesheet=params.get(SISPluginFactory.GEONETWORK_STYLESHEET);
+ File dataStore=new File(dataStorePath);
+ log.debug("Extracting meta from {} ",dataStore.getAbsolutePath());
+ Metadata meta=getMetaFromFile(dataStore);
+
+ tmp=File.createTempFile("tmp_meta_", ".xml");
+
+ XML.marshal(meta,tmp);
+
+ org.gcube.spatial.data.sdi.interfaces.Metadata metadataInterface=SDIAbstractPlugin.metadata().build();
+
+ String hostname=ctx.getCtx().container().configuration().hostname();
+ String filename=dataStore.getName();
+ String catalog=getCatalogFromPath(dataStorePath);
+
+ Set invocations=new TemplateInvocationBuilder().
+ threddsOnlineResources(hostname,filename, catalog).get();
+
+ MetadataPublishOptions options=new MetadataPublishOptions(invocations);
+ options.setGeonetworkCategory(category);
+ options.setGeonetworkStyleSheet(stylesheet);
+
+
+ MetadataReport report=metadataInterface.pushMetadata(tmp, options);
+ log.debug("Metadata report is {} ",report);
+ return new ExecutionReport(invocation,
+ "Published/Updated meta with id : "+report.getPublishedID()+" , UUID "+report.getPublishedUUID(),ExecutionReportFlag.SUCCESS);
+
+//// TemplateManager.getTHREDDSLinks(new ThreddsLinkRequest(hostname, filename, catalog, gisViewerLink))
+// // TODO Info from infrastructure
+// try{
+// long id=publishMetadata(tmp, category, stylesheet,getGNPublisher());
+// return new ExecutionReport(invocation, "Published meta with id : "+id, ExecutionReportFlag.SUCCESS);
+// }catch(GNServerException e){
+// //Fail can be due to already existing uuid.
+// log.debug("Trying to update existing uuid");
+//
+// MetadataHandler metaHandler=new MetadataHandler(tmp);
+// String uuid=metaHandler.getUUID();
+// long id= updateMetadata(tmp, uuid, category, stylesheet,getGNPublisher());
+// return new ExecutionReport(invocation, "Updated meta with id : "+id+", UUID : "+uuid, ExecutionReportFlag.SUCCESS);
+// }
+
+
+
}catch(DataStoreException e){
log.error("Unable to parse source ",e);
throw new PluginExecutionException("Unable to extract metadata.", e);
@@ -58,23 +105,45 @@ public class SisPlugin extends AbstractPlugin {
}
}
+// public GeoNetworkPublisher getGNPublisher() throws Exception{
+// if(publisher==null){
+// publisher=GeoNetwork.get();
+// publisher.login(LoginLevel.DEFAULT);
+// }
+// return publisher;
+// }
+//
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{
- File tmp=File.createTempFile("tmp_meta_", ".xml");
-
- XML.marshal(meta,tmp);
-
- GeoNetworkPublisher publisher=GeoNetwork.get();
- publisher.login(LoginLevel.DEFAULT);
- GNInsertConfiguration config=publisher.getCurrentUserConfiguration(category, stylesheet);
- config.setValidate(false);
- long toReturn= publisher.insertMetadata(config, tmp);
- tmp.delete();
- return toReturn;
+
+ private String getCatalogFromPath(String path){
+ String catalog=path.substring(0, path.lastIndexOf("/")-1);
+ catalog=catalog.substring(catalog.lastIndexOf("/")+1);
+ return catalog;
}
+
+
+
+//
+// public long publishMetadata(File toPublish,String category, String stylesheet, GeoNetworkPublisher publisher) throws Exception{
+// GNInsertConfiguration config=publisher.getCurrentUserConfiguration(category, stylesheet);
+// config.setValidate(false);
+// long toReturn= publisher.insertMetadata(config, toPublish);
+// return toReturn;
+// }
+//
+// public long updateMetadata(File toPublish,String uuid,String category,String styleSheet, GeoNetworkPublisher publisher)throws Exception{
+// long id=0l;
+// if(publisher.getConfiguration().getGeoNetworkVersion().equals(Version.DUE)){
+// GNSearchRequest req=new GNSearchRequest();
+// req.addParam(GNSearchRequest.Param.any,uuid);
+//
+// GNSearchResponse resp=publisher.query(req);
+// id=resp.iterator().next().getId();
+// }else id=publisher.getInfo(uuid).getId();
+// publisher.updateMetadata(id, toPublish);
+// return id;
+// }
}