|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package org.gcube.data_catalogue.grsf_publish_ws.utils.csv;
|
|
|
|
|
|
|
|
|
|
import java.beans.IntrospectionException;
|
|
|
|
|
import java.beans.PropertyDescriptor;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
@ -8,18 +7,11 @@ import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.TimeSeries;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
|
|
|
|
@ -42,13 +34,15 @@ public class ManageTimeSeriesThread extends Thread{
|
|
|
|
|
|
|
|
|
|
private static final String PATH_SEPARATOR = "/";
|
|
|
|
|
|
|
|
|
|
private static final String CATALOGUE_FOLDER = ".catalogue";
|
|
|
|
|
|
|
|
|
|
// Logger
|
|
|
|
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ManageTimeSeriesThread.class);
|
|
|
|
|
|
|
|
|
|
// try to attach the source at most CHANCES times ..
|
|
|
|
|
private static final int CHANCES = 10;
|
|
|
|
|
|
|
|
|
|
private static CacheInterface<String, WorkspaceCatalogue> vreFolderCache = new CacheImpl<String, WorkspaceCatalogue>(1000 * 60 * 60 * 24);
|
|
|
|
|
private static CacheInterface<String, FolderContainer> vreFolderCache = new CacheImpl<String, FolderContainer>(1000 * 60 * 60 * 24);
|
|
|
|
|
|
|
|
|
|
private static final int MAX_NAME_CSV_FILE_WITHOUT_MEASURE = 50;
|
|
|
|
|
|
|
|
|
@ -96,17 +90,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (WorkspaceFolderNotFoundException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (ItemNotFoundException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (IntrospectionException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (HomeNotFoundException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (UserNotFoundException e) {
|
|
|
|
|
} catch (StorageHubException e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error was " + e.getMessage());
|
|
|
|
@ -130,17 +114,26 @@ public class ManageTimeSeriesThread extends Thread{
|
|
|
|
|
if(record == null)
|
|
|
|
|
throw new IllegalArgumentException("The given record is null!!");
|
|
|
|
|
|
|
|
|
|
StorageHubClient shClient = new StorageHubClient();
|
|
|
|
|
|
|
|
|
|
String token = SecurityTokenProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
WorkspaceCatalogue catalogueFolder = null;
|
|
|
|
|
FolderContainer catalogueFolder = null;
|
|
|
|
|
|
|
|
|
|
//WorkspaceCatalogue catalogueFolder = null;
|
|
|
|
|
if((catalogueFolder = vreFolderCache.get(token)) == null){
|
|
|
|
|
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome().getWorkspace();
|
|
|
|
|
WorkspaceSharedFolder vreFolder = ws.getVREFolderByScope(ScopeProvider.instance.get());
|
|
|
|
|
catalogueFolder = vreFolder.getVRECatalogue();
|
|
|
|
|
//Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome().getWorkspace();
|
|
|
|
|
FolderContainer vreFolder = shClient.openVREFolder();
|
|
|
|
|
try {
|
|
|
|
|
catalogueFolder = vreFolder.openByRelativePath(CATALOGUE_FOLDER).asFolder();
|
|
|
|
|
}catch (StorageHubException e) {
|
|
|
|
|
catalogueFolder = vreFolder.newHiddenFolder(CATALOGUE_FOLDER, "catalogue folder");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vreFolderCache.insert(token, catalogueFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.debug("Catalogue folder in vre has path " + catalogueFolder.getPath());
|
|
|
|
|
logger.debug("Catalogue folder in vre has path " + catalogueFolder.get().getPath());
|
|
|
|
|
|
|
|
|
|
// the structure under the .catalogue will be as follows:
|
|
|
|
|
// .catalogue:
|
|
|
|
@ -167,7 +160,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|
|
|
|
// the whole path of the directory is going to be...
|
|
|
|
|
String csvDirectoryForThisProduct = recordTypeFolderName + PATH_SEPARATOR + firstLetter + PATH_SEPARATOR + replaceIllegalChars(uuidKB, "_") + PATH_SEPARATOR + CSVUtils.CSV_EXTENSION.replace(".", "");
|
|
|
|
|
logger.debug("The path under which the time series are going to be saved is " + csvDirectoryForThisProduct);
|
|
|
|
|
WorkspaceFolder csvFolder = HelperMethods.createOrGetSubFoldersByPath(catalogueFolder, csvDirectoryForThisProduct);
|
|
|
|
|
FolderContainer csvFolder = HelperMethods.createOrGetSubFoldersByPath(catalogueFolder, csvDirectoryForThisProduct);
|
|
|
|
|
|
|
|
|
|
if(csvFolder == null)
|
|
|
|
|
logger.error("Failed to create directory where csv files will be deployed in the workspace!!");
|
|
|
|
@ -192,7 +185,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|
|
|
|
String resourceToAttachOnCkanDescription = productName;
|
|
|
|
|
|
|
|
|
|
CkanResourceBase ckanResource = null;
|
|
|
|
|
ExternalFile createdFileOnWorkspace = null;
|
|
|
|
|
FileContainer createdFileOnWorkspace = null;
|
|
|
|
|
String[] relevantSources = new String[1];
|
|
|
|
|
File csvFile = CSVUtils.listToCSV(asList, relevantSources);
|
|
|
|
|
if(csvFile != null){
|
|
|
|
@ -212,7 +205,7 @@ public class ManageTimeSeriesThread extends Thread{
|
|
|
|
|
+ customAnnotation.key() + CSVUtils.CSV_EXTENSION, resourceToAttachOnCkanDescription, csvFile);
|
|
|
|
|
|
|
|
|
|
if(createdFileOnWorkspace != null){
|
|
|
|
|
String publicUrlToSetOnCkan = createdFileOnWorkspace.getPublicLink(true);
|
|
|
|
|
String publicUrlToSetOnCkan = createdFileOnWorkspace.getPublicLink().toString();
|
|
|
|
|
|
|
|
|
|
// wait for patching..
|
|
|
|
|
Thread.sleep(1500);
|
|
|
|
|