From f7fe5453ebc4d35e35ba45ef5a4fc35950a2fdda Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Thu, 23 Feb 2017 17:55:32 +0000 Subject: [PATCH] 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 --- .../utils/threads/ManageTimeSeriesThread.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java index 843e75b..97a68af 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java @@ -53,7 +53,7 @@ public class ManageTimeSeriesThread extends Thread{ private static CacheInterface vreFolderCache = new CacheImpl(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);