Merge pull request '1.2.0' (#3) from 1.2.0 into master

20760_https
Fabio Sinibaldi 3 years ago
commit ce3f825cb9

@ -79,7 +79,7 @@
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-library</artifactId>
<version>[1.0.0,2.0.0)</version>
<version>[1.0.0,1.0.2]</version>
</dependency>
<!-- SMARTGEARS -->

@ -0,0 +1,45 @@
package org.gcube.data.transfer.plugins.thredds;
import static java.util.Collections.singletonMap;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.xml.bind.JAXBException;
import javax.xml.transform.stream.StreamResult;
import org.apache.sis.xml.MarshallerPool;
import org.apache.sis.xml.XML;
import org.opengis.metadata.Metadata;
import lombok.Synchronized;
public class ISOMetadataMarshalling {
private static MarshallerPool pool=null;
@Synchronized
private static MarshallerPool getPool() throws JAXBException {
if(pool==null)
pool=new MarshallerPool(
singletonMap(XML.METADATA_VERSION,"2007"));
return pool;
}
public static final File asXML(Metadata meta) throws JAXBException, IOException {
File tmp=File.createTempFile("tmp_meta_", ".xml");
try (FileWriter fw=new FileWriter(tmp)){
getPool().acquireMarshaller().marshal(meta,new StreamResult(fw));
// XML.marshal(meta, new StreamResult(fw), singletonMap(XML.METADATA_VERSION,"2007"));
}
return tmp;
}
}

@ -16,6 +16,7 @@ import org.gcube.data.transfer.model.plugins.thredds.ThreddsCatalog;
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.data.transfer.plugins.thredds.ISOMetadataMarshalling;
import org.gcube.data.transfer.plugins.thredds.ThreddsInstanceManager;
import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions;
import org.gcube.spatial.data.sdi.model.metadata.MetadataReport;
@ -69,9 +70,7 @@ public class SisPlugin extends AbstractPlugin {
log.debug("Extracting meta from {} ",dataStore.getAbsolutePath());
Metadata meta=getMetaFromFile(dataStore);
tmp=File.createTempFile("tmp_meta_", ".xml");
XML.marshal(meta,tmp);
tmp=ISOMetadataMarshalling.asXML(meta);
org.gcube.spatial.data.sdi.interfaces.Metadata metadataInterface=SDIAbstractPlugin.metadata().build();

@ -12,24 +12,29 @@ import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.bind.JAXBException;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.UnsupportedStorageException;
import org.apache.sis.xml.XML;
import org.gcube.data.transfer.plugins.thredds.ISOMetadataMarshalling;
import org.gcube.data.transfer.plugins.thredds.sis.SisPlugin;
import org.opengis.metadata.Metadata;
public class TestGetMetadata {
public static void main(String[] args) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException {
public static void main(String[] args) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException, JAXBException {
String[] toCheckFiles=new String[] {
// ********** HDF - NETCDF 4
"/Users/FabioISTI/Downloads/NASA_Precipitations_1950_2100_rcp45.nc",
"/Users/FabioISTI/Downloads/NASA_Surface_Air_Temperature_1950_2100_rcp45.nc",
"https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Precipitations_1950_2100_rcp45.nc",
"https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Precipitations_1950_2100_rcp85.nc",
"https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Surface_Air_Temperature_1950_2100_rcp45.nc",
"https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Surface_Air_Temperature_1950_2100_rcp85.nc",
"https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/hcaf_v6_1950_2100.nc",
// "https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Precipitations_1950_2100_rcp45.nc",
// "https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Precipitations_1950_2100_rcp85.nc",
// "https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Surface_Air_Temperature_1950_2100_rcp45.nc",
// "https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/NASA_Surface_Air_Temperature_1950_2100_rcp85.nc",
// "https://thredds.d4science.org/thredds/fileServer/public/netcdf/ClimateChange/hcaf_v6_1950_2100.nc",
// *********** NETCDF 3
@ -68,7 +73,7 @@ public class TestGetMetadata {
// }
private static void check(boolean checkCopy,String src) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException {
private static void check(boolean checkCopy,String src) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException, JAXBException {
File original=new File(src);
@ -94,14 +99,18 @@ public class TestGetMetadata {
if(dataset.exists())
System.out.println(SisPlugin.getMetaFromFile(dataset));
System.out.println(
ISOMetadataMarshalling.asXML(SisPlugin.getMetaFromFile(dataset)).getAbsolutePath());
else {
System.out.println(SisPlugin.getMetaFromFile(new URL(src)));
System.out.println(
ISOMetadataMarshalling.asXML(SisPlugin.getMetaFromFile(new URL(src))).getAbsolutePath());
}
}
private static String getChecksum(File datafile) throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("SHA1");

Loading…
Cancel
Save