Implementing service

This commit is contained in:
Luca Frosini 2023-05-29 16:09:29 +02:00
parent 7f3c34acb9
commit e1849dec8a
3 changed files with 28 additions and 14 deletions

View File

@ -111,7 +111,7 @@
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>storagehub-application-persistence</artifactId>
<version>[3.0.0,4.0.0-SNAPSHOT)</version>
<version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version>
</dependency>
<!-- Added to support Java 11 JDK -->

View File

@ -18,6 +18,8 @@ public class GRSFInitializator implements ApplicationManager {
*/
private static Logger logger = LoggerFactory.getLogger(GRSFInitializator.class);
public static final String NAME = "GRSF Publisher";
/**
* {@inheritDoc}
* The method discover the plugins available on classpath and their own
@ -38,9 +40,9 @@ public class GRSFInitializator implements ApplicationManager {
logger.trace(
"\n-------------------------------------------------------\n"
+ "GRSF Publisher is Starting on context {}\n"
+ "{} is Starting on context {}\n"
+ "-------------------------------------------------------",
context);
NAME, context);
/*
ApplicationContext applicationContext = ContextProvider.get();
@ -49,9 +51,9 @@ public class GRSFInitializator implements ApplicationManager {
logger.trace(
"\n-------------------------------------------------------\n"
+ "GRSF Publisher Started Successfully on context {}\n"
+ "{} Started Successfully on context {}\n"
+ "-------------------------------------------------------",
context);
NAME, context);
}
@ -74,9 +76,9 @@ public class GRSFInitializator implements ApplicationManager {
logger.trace(
"\n-------------------------------------------------------\n"
+ "GRSF Publisher is Stopping on context {}\n"
+ "{} is Stopping on context {}\n"
+ "-------------------------------------------------------",
context);
NAME, context);
/*
* We don't delete the relation.
@ -89,8 +91,8 @@ public class GRSFInitializator implements ApplicationManager {
logger.trace(
"\n-------------------------------------------------------\n"
+ "GRSF Publisher Stopped Successfully on context {}\n"
+ "{} Stopped Successfully on context {}\n"
+ "-------------------------------------------------------",
context);
NAME, context);
}
}

View File

@ -26,7 +26,9 @@ import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.gcat.persistence.ckan.CKANPackage;
import org.gcube.gcat.persistence.ckan.CKANUserCache;
import org.gcube.grsf.publisher.GRSFInitializator;
import org.gcube.grsf.publisher.freemarker.FreeMarker;
import org.gcube.storagehub.MetadataMatcher;
import org.gcube.storagehub.StorageHubManagement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -101,6 +103,15 @@ public abstract class Record extends CKANPackage {
return null;
}
protected Metadata getTimeSeriesMetadata() {
Map<String,Object> map = new HashMap<>();
map.put(MetadataMatcher.GENERATING_APPLICATION_NAME, GRSFInitializator.NAME);
map.put(MetadataMatcher.GENERATING_APPLICATION_METADATA_VERSION, "1.0.0");
map.put(Record.GRSF_UUID_PROPERTY, grsfUUID);
Metadata metadata = new Metadata(map);
return metadata;
}
/**
* Save the file in the workspace using storagehub-application-persistence
* @param file the file to persist in the workspace
@ -110,11 +121,10 @@ public abstract class Record extends CKANPackage {
protected FileContainer persistFile(File file) throws Exception{
StorageHubManagement shm = new StorageHubManagement();
FileInputStream fis = new FileInputStream(file);
Map<String,Object> map = new HashMap<>();
map.put(Record.GRSF_UUID_PROPERTY, grsfUUID);
Metadata metadata = new Metadata(map);
Metadata metadata = getTimeSeriesMetadata();
shm.persistFile(fis, file.getName(), "text/csv", metadata);
FileContainer fileContainer = shm.getPersistedFile();
logger.debug("File {} has been persisted in StorageHub with ID:{}", file.getName(), fileContainer.getId());
return fileContainer;
}
@ -175,8 +185,8 @@ public abstract class Record extends CKANPackage {
timeseriesFiles.add(tsOut);
/*
* Removing the property form the map keep clean the map
* generated using the input json
* Removing the property from the map to keep it
* as generated using the input json
*/
map.remove(Record.TIMESERIES_PROPERTY);
@ -239,7 +249,9 @@ public abstract class Record extends CKANPackage {
private void deleteUploadedFiles() {
for(FileContainer fileContainer : wsUploadedFiles) {
try {
logger.debug("Going to delete from StorageHub the file with ID:{}", fileContainer.getId());
fileContainer.delete();
logger.debug("StorageHub file with ID:{} has been properly removed", fileContainer.getId());
} catch (StorageHubException e) {
logger.warn("Unable to delete from StorageHub the file with ID:{}", fileContainer.getId());
}