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