minor fix for csv creation on shared vre folder: the creation failed on too long name files

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@144226 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-02-23 17:55:32 +00:00
parent 3c7eb108a9
commit f7fe5453eb
1 changed files with 19 additions and 19 deletions

View File

@ -53,7 +53,7 @@ public class ManageTimeSeriesThread extends Thread{
private static CacheInterface<String, WorkspaceCatalogue> vreFolderCache = new CacheImpl<String, WorkspaceCatalogue>(1000 * 60 * 120);
private Common record;
private String packageName;
private String uuidKB;
private String username;
private DataCatalogue catalogue;
private String context;
@ -70,7 +70,7 @@ public class ManageTimeSeriesThread extends Thread{
String username, DataCatalogue catalogue, String context, String token) {
super();
this.record = record;
this.packageName = packageName;
this.uuidKB = packageName;
this.username = username;
this.catalogue = catalogue;
this.context = context;
@ -85,7 +85,7 @@ public class ManageTimeSeriesThread extends Thread{
SecurityTokenProvider.instance.set(token);
try {
manageTimeSeries(record, packageName, username, catalogue);
manageTimeSeries(record, uuidKB, username, catalogue);
logger.info("The time series manager thread ended correctly");
return;
} catch (IllegalAccessException e) {
@ -129,7 +129,7 @@ public class ManageTimeSeriesThread extends Thread{
* @throws ItemNotFoundException
*/
@SuppressWarnings("rawtypes")
public static void manageTimeSeries(Common record, String packageName, String username, DataCatalogue catalogue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
public static void manageTimeSeries(Common record, String uuidKB, String username, DataCatalogue catalogue) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
if(record == null)
throw new IllegalArgumentException("The given record is null!!");
@ -149,22 +149,22 @@ public class ManageTimeSeriesThread extends Thread{
// the structure under the .catalogue will be as follows:
// .catalogue:
// - stock:
// - first_letter_of_the_product
// - product_name
// - first_letter_of_the_product (knowledge base uuid)
// - knowledge base uuid
// - type of files (e.g., csv)
// -files (csv)
// -files (e.g, kbuuid.csv)
// - fishery
// - first_letter_of_the_product
// - product_name
// - first_letter_of_the_product (knowledge base uuid)
// - knowledge base uuid
// - type of files (e.g., csv)
// -files (csv)
// -files (e.g, kbuuid.csv)
String recordTypeFolderName = record.getGrsfType().toLowerCase();
String productName = record.getClass().equals(StockRecord.class) ? ((StockRecord)record).getStockName() : ((FisheryRecord)record).getFisheryName();
char firstLetter = productName.charAt(0);
char firstLetter = uuidKB.charAt(0);
// the whole path of the directory is going to be...
String csvDirectoryForThisProduct = recordTypeFolderName + PATH_SEPARATOR + firstLetter + PATH_SEPARATOR + replaceIllegalChars(productName) + PATH_SEPARATOR + "csv";
String csvDirectoryForThisProduct = recordTypeFolderName + PATH_SEPARATOR + firstLetter + PATH_SEPARATOR + replaceIllegalChars(uuidKB) + PATH_SEPARATOR + "csv";
logger.debug("The path under which the time series are going to be saved is " + csvDirectoryForThisProduct);
WorkspaceFolder csvFolder = HelperMethods.createOrGetSubFoldersByPath(catalogueFolder, csvDirectoryForThisProduct);
@ -187,8 +187,8 @@ public class ManageTimeSeriesThread extends Thread{
CustomField customAnnotation = field.getAnnotation(CustomField.class);
logger.debug("A time series has been just found (from field " + customAnnotation.key() + ")");
String resourceToAttachName = (replaceIllegalChars(productName) + "_" + customAnnotation.key()).replaceAll("\\s", "_").replaceAll("[_]+", "_") + CSV_FILE_FORMAT;
String resourceToAttachDescription = productName + " : " + customAnnotation.key() + " time series";
String resourceToAttachOnCkanName = (replaceIllegalChars(productName) + "_" + customAnnotation.key()).replaceAll("\\s", "_").replaceAll("[_]+", "_") + CSV_FILE_FORMAT;
String resourceToAttachOnCkanDescription = productName + " : " + customAnnotation.key() + " time series";
File csvFile = CSVHelpers.listToCSV(asList);
@ -200,19 +200,19 @@ public class ManageTimeSeriesThread extends Thread{
// upload this file on ckan
if(ckanResource == null)
ckanResource = uploadFileOnCatalogue(csvFile, packageName, catalogue, username, resourceToAttachName, resourceToAttachDescription, apiKeyUser);
ckanResource = uploadFileOnCatalogue(csvFile, uuidKB, catalogue, username, resourceToAttachOnCkanName, resourceToAttachOnCkanDescription, apiKeyUser);
//upload this file on the folder of the vre (under .catalogue) and change the url of the resource
if(ckanResource != null){
if(createdFileOnWorkspace == null)
createdFileOnWorkspace = HelperMethods.uploadExternalFile(csvFolder, resourceToAttachName, resourceToAttachDescription, csvFile);
createdFileOnWorkspace = HelperMethods.uploadExternalFile(csvFolder, uuidKB + CSV_FILE_FORMAT, resourceToAttachOnCkanDescription, csvFile);
if(createdFileOnWorkspace != null){
String publicUrlToSetOnCkan = createdFileOnWorkspace.getPublicLink(true);
logger.info("going to patch the created resource with id " + ckanResource.getId() + " with url " + publicUrlToSetOnCkan);
boolean updated = catalogue.patchResource(ckanResource.getId(), publicUrlToSetOnCkan, resourceToAttachName, resourceToAttachDescription, "", apiKeyUser);
boolean updated = catalogue.patchResource(ckanResource.getId(), publicUrlToSetOnCkan, resourceToAttachOnCkanName, resourceToAttachOnCkanDescription, "", apiKeyUser);
if(updated){
logger.info("Resource has been updated with the new url");
@ -256,11 +256,11 @@ public class ManageTimeSeriesThread extends Thread{
* @return a ckan resource on success, null otherwise
*/
private static CkanResourceBase uploadFileOnCatalogue(File csvFile,
String packageName, DataCatalogue catalogue, String username,
String uuidKB, DataCatalogue catalogue, String username,
String resourceToAttachName, String description, String apiKey) {
return catalogue.uploadResourceFile(
csvFile,
packageName,
uuidKB,
apiKey,
resourceToAttachName,
description);