From bf3d0675ced863272873aa20e54bafe020d56c6b Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Fri, 16 Dec 2016 20:31:52 +0000 Subject: [PATCH] added another cache for VRE catalogue folder git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@140059 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../utils/threads/ManageTimeSeriesThread.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 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 3868c8f..cdf755b 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 @@ -27,6 +27,8 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord; import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVHelpers; import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods; +import org.gcube.data_catalogue.grsf_publish_ws.utils.cache.CacheImpl; +import org.gcube.data_catalogue.grsf_publish_ws.utils.cache.CacheInterface; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.slf4j.LoggerFactory; @@ -48,6 +50,8 @@ public class ManageTimeSeriesThread extends Thread{ // try to attach the source at most CANCHES times .. private static final int CANCHES = 3; + private static CacheInterface vreFolderCache = new CacheImpl(1000 * 60 * 30); + private Common record; private String packageName; private String username; @@ -129,9 +133,15 @@ public class ManageTimeSeriesThread extends Thread{ if(record == null) throw new IllegalArgumentException("The given record is null!!"); - Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome().getWorkspace(); - WorkspaceSharedFolder vreFolder = ws.getVREFolderByScope(ScopeProvider.instance.get()); - WorkspaceCatalogue catalogueFolder = vreFolder.getVRECatalogue(); + String token = SecurityTokenProvider.instance.get(); + + 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(); + vreFolderCache.insert(token, catalogueFolder); + } logger.debug("Catalogue folder in vre has path " + catalogueFolder.getPath()); @@ -193,10 +203,10 @@ public class ManageTimeSeriesThread extends Thread{ //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); - + if(createdFileOnWorkspace != null){ String publicUrlToSetOnCkan = createdFileOnWorkspace.getPublicLink(true);