added hashmap which stores couple <organization name, scope>
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@132811 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
169974e09b
commit
a7c24dc919
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
@ -52,6 +53,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
public static final String TEST_USER = "test.user";
|
public static final String TEST_USER = "test.user";
|
||||||
private final static String TEST_SEC_TOKEN = "a1e19695-467f-42b8-966d-bf83dd2382ef";
|
private final static String TEST_SEC_TOKEN = "a1e19695-467f-42b8-966d-bf83dd2382ef";
|
||||||
|
|
||||||
|
// map <orgName, scope>
|
||||||
|
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an instance of the library for the scope
|
* Retrieve an instance of the library for the scope
|
||||||
* @param scope if it is null it is evaluated from the session
|
* @param scope if it is null it is evaluated from the session
|
||||||
|
@ -200,10 +204,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String findLicenseIdByLicense(String chosenLicense) {
|
private String findLicenseIdByLicense(String chosenLicense) {
|
||||||
|
|
||||||
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||||
return getCatalogue(scope).findLicenseIdByLicenseTitle(chosenLicense);
|
return getCatalogue(scope).findLicenseIdByLicenseTitle(chosenLicense);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -478,7 +482,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
|
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
|
||||||
String scope = Utils.retrieveScopeFromOrganizationName(organizationNameOrId);
|
String scope = getScopeFromOrgName(organizationNameOrId);
|
||||||
DataCatalogue utils = getCatalogue(scope);
|
DataCatalogue utils = getCatalogue(scope);
|
||||||
|
|
||||||
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(scope), title, organizationNameOrId, author,
|
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(scope), title, organizationNameOrId, author,
|
||||||
|
@ -493,15 +497,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
// retrieve the url
|
// retrieve the url
|
||||||
String datasetUrl = utils.getPortletUrl() + "?path=" + utils.getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(scope), datasetId, true);
|
String datasetUrl = utils.getPortletUrl() + "?path=" + utils.getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(scope), datasetId, true);
|
||||||
toCreate.setSource(datasetUrl);
|
toCreate.setSource(datasetUrl);
|
||||||
|
|
||||||
// start a thread that will associate this dataset with the group
|
// start a thread that will associate this dataset with the group
|
||||||
if(toCreate.getChosenProfile() != null){
|
if(toCreate.getChosenProfile() != null){
|
||||||
|
|
||||||
AssociationToGroupThread thread = new AssociationToGroupThread(toCreate.getChosenProfile(), datasetId, userName, utils, organizationNameOrId);
|
AssociationToGroupThread thread = new AssociationToGroupThread(toCreate.getChosenProfile(), datasetId, userName, utils, organizationNameOrId);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return toCreate;
|
return toCreate;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
@ -552,7 +556,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
null);
|
null);
|
||||||
|
|
||||||
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
||||||
String scope = Utils.retrieveScopeFromOrganizationName(resource.getOrganizationNameDatasetParent());
|
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
||||||
String resourceId = getCatalogue(scope).addResourceToDataset(resourceBean, getUserCKanTokenFromSession(scope));
|
String resourceId = getCatalogue(scope).addResourceToDataset(resourceBean, getUserCKanTokenFromSession(scope));
|
||||||
|
|
||||||
if(resourceId != null){
|
if(resourceId != null){
|
||||||
|
@ -590,7 +594,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
}else{
|
}else{
|
||||||
try{
|
try{
|
||||||
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
||||||
String scope = Utils.retrieveScopeFromOrganizationName(resource.getOrganizationNameDatasetParent());
|
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
||||||
deleted = getCatalogue(scope).
|
deleted = getCatalogue(scope).
|
||||||
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession(scope));
|
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession(scope));
|
||||||
if(deleted){
|
if(deleted){
|
||||||
|
@ -612,7 +616,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
|
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
|
||||||
try{
|
try{
|
||||||
String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName);
|
String evaluatedScope = getScopeFromOrgName(orgName);
|
||||||
logger.debug("Evaluated scope is " + evaluatedScope);
|
logger.debug("Evaluated scope is " + evaluatedScope);
|
||||||
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession());
|
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession());
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -640,4 +644,37 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method tries to retrieve the scope related to the organization using the map first,
|
||||||
|
* if no match is found, it retrieves such information by using liferay
|
||||||
|
*/
|
||||||
|
private String getScopeFromOrgName(String orgName){
|
||||||
|
|
||||||
|
logger.debug("Request for scope related to orgName " + orgName + "[ map that will be used is " + mapOrganizationScope.toString() + " ]");
|
||||||
|
|
||||||
|
if(orgName == null || orgName.isEmpty())
|
||||||
|
throw new IllegalArgumentException("orgName cannot be empty or null!");
|
||||||
|
|
||||||
|
String toReturn = null;
|
||||||
|
|
||||||
|
if(mapOrganizationScope.containsKey(orgName))
|
||||||
|
toReturn = mapOrganizationScope.get(orgName);
|
||||||
|
else{
|
||||||
|
try{
|
||||||
|
|
||||||
|
String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName);
|
||||||
|
mapOrganizationScope.put(orgName, evaluatedScope);
|
||||||
|
toReturn = evaluatedScope;
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logger.debug("Returning scope " + toReturn);
|
||||||
|
return toReturn;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue