git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/sis-geotk-plugin@150799 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
726811b0bd
commit
976494a484
30
pom.xml
30
pom.xml
|
@ -27,6 +27,18 @@
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.distribution</groupId>
|
||||||
|
<artifactId>maven-smartgears-bom</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data.transfer</groupId>
|
<groupId>org.gcube.data.transfer</groupId>
|
||||||
|
@ -34,12 +46,24 @@
|
||||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency> -->
|
||||||
|
<!-- <groupId>org.gcube.spatial.data</groupId> -->
|
||||||
|
<!-- <artifactId>geonetwork</artifactId> -->
|
||||||
|
<!-- <version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version> -->
|
||||||
|
<!-- </dependency> -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.spatial.data</groupId>
|
<groupId>org.gcube.spatial.data</groupId>
|
||||||
<artifactId>geonetwork</artifactId>
|
<artifactId>sdi-library</artifactId>
|
||||||
<version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SMARTGEARS -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-smartgears</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SIS -->
|
<!-- SIS -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.sis.core</groupId>
|
<groupId>org.apache.sis.core</groupId>
|
||||||
|
|
|
@ -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.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 org.gcube.data.transfer.plugin.model.DataTransferContext;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.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";
|
||||||
|
@ -63,7 +67,7 @@ public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SisPlugin createWorker(PluginInvocation arg0) {
|
public SisPlugin createWorker(PluginInvocation arg0) {
|
||||||
return new SisPlugin(arg0);
|
return new SisPlugin(arg0,ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,7 +86,9 @@ public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init() throws PluginInitializationException {
|
public boolean init(DataTransferContext ctx) throws PluginInitializationException {
|
||||||
|
log.trace("Loading configuration .. ");
|
||||||
|
this.ctx=ctx;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,4 +97,7 @@ public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private DataTransferContext ctx;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.data.transfer.plugins.sis;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.sis.storage.DataStoreException;
|
import org.apache.sis.storage.DataStoreException;
|
||||||
import org.apache.sis.storage.DataStores;
|
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.AbstractPlugin;
|
||||||
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.data.transfer.plugin.model.DataTransferContext;
|
||||||
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
|
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
|
||||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
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 org.opengis.metadata.Metadata;
|
||||||
|
|
||||||
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SisPlugin extends AbstractPlugin {
|
public class SisPlugin extends AbstractPlugin {
|
||||||
|
|
||||||
public SisPlugin(PluginInvocation invocation) {
|
File tmp=null;
|
||||||
|
DataTransferContext ctx;
|
||||||
|
|
||||||
|
public SisPlugin(PluginInvocation invocation, DataTransferContext ctx) {
|
||||||
super(invocation);
|
super(invocation);
|
||||||
|
this.ctx=ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanup() throws PluginCleanupException {
|
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
|
@Override
|
||||||
public ExecutionReport run() throws PluginExecutionException {
|
public ExecutionReport run() throws PluginExecutionException {
|
||||||
try{
|
try{
|
||||||
|
|
||||||
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.get(SISPluginFactory.GEONETWORK_CATEGORY);
|
String category=params.get(SISPluginFactory.GEONETWORK_CATEGORY);
|
||||||
String stylesheet=params.get(SISPluginFactory.GEONETWORK_STYLESHEET);
|
String stylesheet=params.get(SISPluginFactory.GEONETWORK_STYLESHEET);
|
||||||
File dataStore=new File(dataStorePath);
|
File dataStore=new File(dataStorePath);
|
||||||
log.debug("Extracting meta from {} ",dataStore.getAbsolutePath());
|
log.debug("Extracting meta from {} ",dataStore.getAbsolutePath());
|
||||||
Metadata meta=getMetaFromFile(dataStore);
|
Metadata meta=getMetaFromFile(dataStore);
|
||||||
// TODO Links from current thredds
|
|
||||||
// TODO Info from infrastructure
|
tmp=File.createTempFile("tmp_meta_", ".xml");
|
||||||
long id=publishMetadata(meta, category, stylesheet);
|
|
||||||
return new ExecutionReport(invocation, "Published meta with id : "+id, ExecutionReportFlag.SUCCESS);
|
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<TemplateInvocation> 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){
|
}catch(DataStoreException e){
|
||||||
log.error("Unable to parse source ",e);
|
log.error("Unable to parse source ",e);
|
||||||
throw new PluginExecutionException("Unable to extract metadata.", 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{
|
public static final Metadata getMetaFromFile(Object dataStore) throws UnsupportedStorageException, DataStoreException{
|
||||||
return DataStores.open(dataStore).getMetadata();
|
return DataStores.open(dataStore).getMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getCatalogFromPath(String path){
|
||||||
public static final long publishMetadata(Metadata meta,String category, String stylesheet) throws Exception{
|
String catalog=path.substring(0, path.lastIndexOf("/")-1);
|
||||||
File tmp=File.createTempFile("tmp_meta_", ".xml");
|
catalog=catalog.substring(catalog.lastIndexOf("/")+1);
|
||||||
|
return catalog;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue