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
This commit is contained in:
Costantino Perciante 2016-12-16 20:31:52 +00:00
parent ceca8a5497
commit bf3d0675ce
1 changed files with 15 additions and 5 deletions

View File

@ -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<String, WorkspaceCatalogue> vreFolderCache = new CacheImpl<String, WorkspaceCatalogue>(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);