Fixed invalid scope bug when creating the ckanutils library

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129453 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-27 09:12:15 +00:00
parent a161becebb
commit 7099328d5f
2 changed files with 27 additions and 20 deletions

View File

@ -20,7 +20,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">

View File

@ -59,18 +59,26 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// library util instance // library util instance
private CKanUtilsImpl instance; private CKanUtilsImpl instance;
@Override /**
public void init(){ * Since it needs the scope, we need to check if it is null or not
// discover the library * @return
*/
private CKanUtilsImpl getCkanUtilsObj(){
if(instance == null){
// retrieve ckan information
try{ try{
logger.debug("Creating ckan utility lib object"); String currentScope = ScopeProvider.instance.get();
instance = new CKanUtilsImpl(ScopeProvider.instance.get()); logger.debug("Scope is " + currentScope);
logger.debug("Created"); instance = new CKanUtilsImpl(currentScope);
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to find ckan information", e); logger.error("Unable to retrieve ckan information", e);
} }
} }
return instance;
}
/** /**
* the current ASLSession * the current ASLSession
* @return the session * @return the session
@ -112,7 +120,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY); token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
else{ else{
token = instance.getApiKeyFromUsername(username); token = getCkanUtilsObj().getApiKeyFromUsername(username);
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token); this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
logger.debug("Ckan token has been set for user " + username); logger.debug("Ckan token has been set for user " + username);
} }
@ -133,10 +141,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("Request for user " + username + " organizations list"); logger.debug("Request for user " + username + " organizations list");
List<String> orgsName = new ArrayList<String>(); List<String> orgsName = new ArrayList<String>();
if(instance.isSysAdmin(username, getUserCKanTokenFromSession())){ if(getCkanUtilsObj().isSysAdmin(username, getUserCKanTokenFromSession())){
logger.debug("The user " + username + " is a sysadmin. He can publish everywhere"); logger.debug("The user " + username + " is a sysadmin. He can publish everywhere");
orgsName = instance.getOrganizationsNames(); // get all organizations' names orgsName = getCkanUtilsObj().getOrganizationsNames(); // get all organizations' names
}else{ }else{
@ -145,7 +153,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
rolesToMatch.add(RolesIntoOrganization.EDITOR); rolesToMatch.add(RolesIntoOrganization.EDITOR);
rolesToMatch.add(RolesIntoOrganization.ADMIN); rolesToMatch.add(RolesIntoOrganization.ADMIN);
Map<String, List<RolesIntoOrganization>> orgsAndRoles = instance.getGroupsAndRolesByUser(username, rolesToMatch); Map<String, List<RolesIntoOrganization>> orgsAndRoles = getCkanUtilsObj().getGroupsAndRolesByUser(username, rolesToMatch);
logger.debug("Result is " + orgsAndRoles); logger.debug("Result is " + orgsAndRoles);
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator(); Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
@ -181,7 +189,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @return * @return
*/ */
private String findLicenseIdByLicense(String chosenLicense) { private String findLicenseIdByLicense(String chosenLicense) {
return instance.findLicenseIdByLicense(chosenLicense); return getCkanUtilsObj().findLicenseIdByLicense(chosenLicense);
} }
/** /**
@ -248,7 +256,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("Request for CKAN licenses"); logger.info("Request for CKAN licenses");
try { try {
List<String> titlesLicenses = instance.getLicenseTitles(); List<String> titlesLicenses = getCkanUtilsObj().getLicenseTitles();
// return the bean // return the bean
return new LicensesBean(titlesLicenses); return new LicensesBean(titlesLicenses);
} catch (Exception e) { } catch (Exception e) {
@ -463,7 +471,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
String datasetId = instance.createCKanDataset(getUserCKanTokenFromSession(), withId, title, organizationNameOrId, author, String datasetId = getCkanUtilsObj().createCKanDataset(getUserCKanTokenFromSession(), withId, title, organizationNameOrId, author,
authorMail, maintainer, maintainerMail, version, description, licenseId, authorMail, maintainer, maintainerMail, version, description, licenseId,
listOfTags, customFields, resources, setPublic); listOfTags, customFields, resources, setPublic);
@ -473,7 +481,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
toCreate.setId(datasetId); toCreate.setId(datasetId);
// retrieve the url // retrieve the url
String datasetUrl = instance.getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(), datasetId); String datasetUrl = getCkanUtilsObj().getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(), datasetId);
toCreate.setSource(datasetUrl); toCreate.setSource(datasetUrl);
return toCreate; return toCreate;
@ -508,7 +516,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
datasetId, datasetId,
null); null);
String resourceId = instance.addResourceToDataset(resourceBean, getUserCKanTokenFromSession()); String resourceId = getCkanUtilsObj().addResourceToDataset(resourceBean, getUserCKanTokenFromSession());
if(resourceId != null){ if(resourceId != null){
@ -538,7 +546,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try{ try{
deleted = instance. deleted = getCkanUtilsObj().
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession()); deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession());
if(deleted){ if(deleted){