Fabio Sinibaldi 7 years ago
parent 976494a484
commit b89dc09428

@ -30,8 +30,8 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-smartgears-bom</artifactId>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>data-transfer-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
@ -43,7 +43,13 @@
<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.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<scope>provided</scope>
</dependency>
<!-- <dependency> -->
@ -57,13 +63,14 @@
<artifactId>sdi-library</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- SMARTGEARS -->
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
<scope>provided</scope>
</dependency>
<!-- SIS -->
<dependency>
<groupId>org.apache.sis.core</groupId>
@ -87,16 +94,80 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-assembly-plugin</artifactId> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <phase>package</phase> -->
<!-- <goals> -->
<!-- <goal>single</goal> -->
<!-- </goals> -->
<!-- <configuration> -->
<!-- <descriptorRefs> -->
<!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
<!-- </descriptorRefs> -->
<!-- </configuration> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-uberjar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>src/assemble/uber-jar-assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- <pluginRepositories> -->
<!-- <pluginRepository> -->
<!-- <id>onejar-maven-plugin.googlecode.com</id> -->
<!-- <name>onejar-plugin-repo</name> -->
<!-- <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo-snapshot</url> -->
<!-- <releases> -->
<!-- <enabled>false</enabled> -->
<!-- </releases> -->
<!-- <snapshots> -->
<!-- <enabled>true</enabled> -->
<!-- </snapshots> -->
<!-- </pluginRepository> -->
<!-- </pluginRepositories> -->
</project>

@ -0,0 +1,20 @@
<assembly>
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
</assembly>

@ -10,6 +10,7 @@ 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 org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import lombok.extern.slf4j.Slf4j;
@ -33,10 +34,16 @@ public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
}
public SISPluginFactory() {
//INSTANCE
public SISPluginFactory() {
}
String publicCatalogLocation=null;
@Override
public PluginInvocation checkInvocation(PluginInvocation arg0,String transferredFile) throws ParameterException {
log.debug("Setting default parameters for {} ",arg0);
@ -67,7 +74,7 @@ public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
@Override
public SisPlugin createWorker(PluginInvocation arg0) {
return new SisPlugin(arg0,ctx);
return new SisPlugin(arg0,ctx,publicCatalogLocation);
}
@Override
@ -89,6 +96,23 @@ public class SISPluginFactory extends AbstractPluginFactory<SisPlugin> {
public boolean init(DataTransferContext ctx) throws PluginInitializationException {
log.trace("Loading configuration .. ");
this.ctx=ctx;
String threddsContentRoot=null;
// String threddsContentRoot=System.getenv("THREDDS_CONTENT_ROOT")+File.separator+"thredds";
// log.info("Thredds catalog base path from ENV is {} ",threddsContentRoot);
for(ApplicationConfiguration app:ctx.getCtx().container().configuration().apps()) {
log.debug("Found app {} ",app.context());
if(app.context().equals("thredds")||app.context().equals("/thredds")) {
threddsContentRoot=app.persistence().location();
log.info("Thredds catalog base path from Context is {} ",threddsContentRoot);
// Found thredds
// Get catalog base folder
// app.persistence().
}
}
if(threddsContentRoot==null) throw new PluginInitializationException("No Thredds instance found in context");
publicCatalogLocation=threddsContentRoot+"/public/netcdf/";
return true;
}

@ -29,10 +29,11 @@ public class SisPlugin extends AbstractPlugin {
File tmp=null;
DataTransferContext ctx;
public SisPlugin(PluginInvocation invocation, DataTransferContext ctx) {
String publicCatalogLocation;
public SisPlugin(PluginInvocation invocation, DataTransferContext ctx, String publicCatalogLocation) {
super(invocation);
this.ctx=ctx;
this.publicCatalogLocation=publicCatalogLocation;
}
@Override
@ -72,6 +73,7 @@ public class SisPlugin extends AbstractPlugin {
MetadataPublishOptions options=new MetadataPublishOptions(invocations);
options.setGeonetworkCategory(category);
options.setGeonetworkStyleSheet(stylesheet);
options.setValidate(false);
MetadataReport report=metadataInterface.pushMetadata(tmp, options);
@ -119,12 +121,21 @@ public class SisPlugin extends AbstractPlugin {
}
private String getCatalogFromPath(String path){
String catalog=path.substring(0, path.lastIndexOf("/")-1);
catalog=catalog.substring(catalog.lastIndexOf("/")+1);
return catalog;
return getCatalogFromPath(path, publicCatalogLocation);
}
public static String getCatalogFromPath(String path, String publicCatalogLocation) {
log.debug("Getting catalog from path {} ",path);
String catalog=path.substring(publicCatalogLocation.length());
if(catalog.contains("/")) {
catalog=catalog.substring(0, catalog.lastIndexOf("/"));
log.debug("Subcatalog found {} ",catalog);
}else {
log.debug("No catalog found");
catalog=null;
}
return catalog;
}
//
// public long publishMetadata(File toPublish,String category, String stylesheet, GeoNetworkPublisher publisher) throws Exception{

@ -0,0 +1,11 @@
package org.gcube.data.transfer.plugins.sis;
public class TestGetCatalog {
public static void main(String[] args) {
String path="/home/gcube/tomcat/content/thredds/public/netcdf/myCatalog/CERSAT-GLO-CLIM_WIND_L4-OBS_FULL_TIME_SERIE_CLIMATOLOGY_METEOROLOGY_ATMOSPHERE_1366217956317.nc";
String publicLocation="/home/gcube/tomcat/content/thredds/public/netcdf/";
System.out.println(SisPlugin.getCatalogFromPath(path, publicLocation));
}
}

@ -1,16 +1,84 @@
package org.gcube.data.transfer.plugins.sis;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.UnsupportedStorageException;
import org.gcube.data.transfer.model.TransferTicket.Status;
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")));
public static void main(String[] args) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException {
File temp=File.createTempFile("temp", ".temp");
File original=new File("/home/fabio/Downloads/oscar_vel2011_180.nc");
File copied=File.createTempFile("copied", ".nc");
transferStream(new FileInputStream(original),new FileOutputStream(temp));
System.out.println("copied. Moving..");
System.out.println("Checksum original : "+getChecksum(original));
System.out.println("Checksum temp : "+getChecksum(temp));
Files.move(temp.toPath(), copied.toPath(),StandardCopyOption.ATOMIC_MOVE,StandardCopyOption.REPLACE_EXISTING);
if(copied.length()<original.length()) throw new RuntimeException("Different size after moving");
System.out.println(SisPlugin.getMetaFromFile(copied));
}
private static String getChecksum(File datafile) throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("SHA1");
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
};
byte[] mdbytes = md.digest();
//convert the byte to hex format
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
private static void transferStream(InputStream in, OutputStream out){
long receivedTotal=0l;
try{
byte[] internalBuf=new byte[1024];
int received=0;
while ((received=in.read(internalBuf))!=-1){
out.write(internalBuf,0,received);
receivedTotal+=received;
}
out.flush();
}catch(IOException e){
throw new RuntimeException("Unable to read from source.");
}
}
}

Loading…
Cancel
Save