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:
parent
a161becebb
commit
7099328d5f
|
@ -20,7 +20,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">
|
||||
|
|
|
@ -58,17 +58,25 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
// library util instance
|
||||
private CKanUtilsImpl instance;
|
||||
|
||||
/**
|
||||
* Since it needs the scope, we need to check if it is null or not
|
||||
* @return
|
||||
*/
|
||||
private CKanUtilsImpl getCkanUtilsObj(){
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
// discover the library
|
||||
try {
|
||||
logger.debug("Creating ckan utility lib object");
|
||||
instance = new CKanUtilsImpl(ScopeProvider.instance.get());
|
||||
logger.debug("Created");
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to find ckan information", e);
|
||||
if(instance == null){
|
||||
// retrieve ckan information
|
||||
try{
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
logger.debug("Scope is " + currentScope);
|
||||
instance = new CKanUtilsImpl(currentScope);
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to retrieve ckan information", e);
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +120,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
|
||||
else{
|
||||
|
||||
token = instance.getApiKeyFromUsername(username);
|
||||
token = getCkanUtilsObj().getApiKeyFromUsername(username);
|
||||
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
|
||||
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");
|
||||
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");
|
||||
orgsName = instance.getOrganizationsNames(); // get all organizations' names
|
||||
orgsName = getCkanUtilsObj().getOrganizationsNames(); // get all organizations' names
|
||||
|
||||
}else{
|
||||
|
||||
|
@ -145,7 +153,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
rolesToMatch.add(RolesIntoOrganization.EDITOR);
|
||||
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);
|
||||
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
|
||||
|
||||
|
@ -181,7 +189,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @return
|
||||
*/
|
||||
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");
|
||||
try {
|
||||
List<String> titlesLicenses = instance.getLicenseTitles();
|
||||
List<String> titlesLicenses = getCkanUtilsObj().getLicenseTitles();
|
||||
// return the bean
|
||||
return new LicensesBean(titlesLicenses);
|
||||
} 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,
|
||||
listOfTags, customFields, resources, setPublic);
|
||||
|
||||
|
@ -473,7 +481,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
toCreate.setId(datasetId);
|
||||
|
||||
// retrieve the url
|
||||
String datasetUrl = instance.getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(), datasetId);
|
||||
String datasetUrl = getCkanUtilsObj().getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(), datasetId);
|
||||
|
||||
toCreate.setSource(datasetUrl);
|
||||
return toCreate;
|
||||
|
@ -508,7 +516,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
datasetId,
|
||||
null);
|
||||
|
||||
String resourceId = instance.addResourceToDataset(resourceBean, getUserCKanTokenFromSession());
|
||||
String resourceId = getCkanUtilsObj().addResourceToDataset(resourceBean, getUserCKanTokenFromSession());
|
||||
|
||||
if(resourceId != null){
|
||||
|
||||
|
@ -538,7 +546,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
try{
|
||||
|
||||
deleted = instance.
|
||||
deleted = getCkanUtilsObj().
|
||||
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession());
|
||||
|
||||
if(deleted){
|
||||
|
|
Loading…
Reference in New Issue