minor fixes
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129676 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
96c214d9fa
commit
d0f8e7e12c
|
@ -58,6 +58,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
public static final String CKAN_LICENSES_KEY = "ckanLicenses";
|
||||
private static final String CKAN_ORGANIZATIONS_KEY = "ckanOrganizations";
|
||||
private static final String CKAN_PROFILES_KEY = "ckanProfiles";
|
||||
private final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810";
|
||||
|
||||
private Object LOCK = new Object();
|
||||
|
||||
|
@ -120,26 +121,39 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
*/
|
||||
private String getUserCKanTokenFromSession(){
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
logger.debug("User in session is " + username);
|
||||
|
||||
if(username.equals(TEST_USER))
|
||||
return null;
|
||||
|
||||
String token = null;
|
||||
if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
|
||||
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
|
||||
else{
|
||||
|
||||
token = getCkanUtilsObj().getApiKeyFromUsername(username);
|
||||
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
|
||||
logger.debug("Ckan token has been set for user " + username);
|
||||
if(!isWithinPortal()){
|
||||
logger.warn("You are running outside the portal");
|
||||
token = TEST_SEC_TOKEN;
|
||||
}else{
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
|
||||
// check if session expired
|
||||
if(username.equals(TEST_USER)){
|
||||
|
||||
logger.warn("Session expired, returning null token");
|
||||
token = null;
|
||||
|
||||
}else{
|
||||
try{
|
||||
logger.debug("User in session is " + username);
|
||||
if(session.getAttribute(CKAN_TOKEN_KEY) != null)
|
||||
token = (String)session.getAttribute(CKAN_TOKEN_KEY);
|
||||
else{
|
||||
token = getCkanUtilsObj().getApiKeyFromUsername(username);
|
||||
session.setAttribute(CKAN_TOKEN_KEY, token);
|
||||
logger.debug("Ckan token has been set for user " + username);
|
||||
}
|
||||
logger.debug("Found ckan token " + token.substring(0, 3) + "************************" + " for user " + username);
|
||||
}catch(Exception e){
|
||||
logger.error("Error while retrieving the key" , e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Found ckan token " + token.substring(0, 3) + "****************" + " for user " + username);
|
||||
return token;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,6 +168,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
List<String> orgsName = new ArrayList<String>();
|
||||
ASLSession session = getASLSession();
|
||||
|
||||
CKanUtilsImpl ckanUtils = getCkanUtilsObj();
|
||||
|
||||
if(session.getAttribute(CKAN_ORGANIZATIONS_KEY) != null){
|
||||
orgsName = (List<String>)session.getAttribute(CKAN_ORGANIZATIONS_KEY);
|
||||
logger.debug("List of organizations was into session");
|
||||
|
@ -162,7 +178,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
if(getCkanUtilsObj().isSysAdmin(username, getUserCKanTokenFromSession())){
|
||||
|
||||
logger.debug("The user " + username + " is a sysadmin. He can publish everywhere");
|
||||
orgsName = getCkanUtilsObj().getOrganizationsNames(); // get all organizations' names
|
||||
orgsName = ckanUtils.getOrganizationsNames(); // get all organizations' names
|
||||
|
||||
}else{
|
||||
|
||||
|
@ -171,13 +187,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
rolesToMatch.add(RolesIntoOrganization.EDITOR);
|
||||
rolesToMatch.add(RolesIntoOrganization.ADMIN);
|
||||
|
||||
Map<String, List<RolesIntoOrganization>> orgsAndRoles = getCkanUtilsObj().getGroupsAndRolesByUser(username, rolesToMatch);
|
||||
Map<String, List<RolesIntoOrganization>> orgsAndRoles = ckanUtils.getGroupsAndRolesByUser(username, rolesToMatch);
|
||||
logger.debug("Result is " + orgsAndRoles);
|
||||
Iterator<Entry<String, List<RolesIntoOrganization>>> iterator = orgsAndRoles.entrySet().iterator();
|
||||
|
||||
// get the names
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, java.util.List<RolesIntoOrganization>> entry = (Map.Entry<String, java.util.List<RolesIntoOrganization>>) iterator
|
||||
Map.Entry<String, List<RolesIntoOrganization>> entry = (Map.Entry<String, List<RolesIntoOrganization>>) iterator
|
||||
.next();
|
||||
orgsName.add(entry.getKey());
|
||||
logger.debug("The user has a role ADMIN/EDITOR into org " + entry.getKey());
|
||||
|
@ -568,60 +584,82 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
logger.debug("Incoming request for creating new resource for dataset with id " + datasetId);
|
||||
logger.debug("Owner is " + owner + " and resource is " + resource);
|
||||
|
||||
try{
|
||||
if(!isWithinPortal()){
|
||||
|
||||
ResourceBean resourceBean = new ResourceBean(
|
||||
resource.getUrl(),
|
||||
resource.getName(),
|
||||
resource.getDescription(),
|
||||
null,
|
||||
owner,
|
||||
datasetId,
|
||||
null);
|
||||
logger.warn("Running outside the portal");
|
||||
return resource;
|
||||
|
||||
String resourceId = getCkanUtilsObj().addResourceToDataset(resourceBean, getUserCKanTokenFromSession());
|
||||
}else{
|
||||
|
||||
if(resourceId != null){
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
|
||||
logger.debug("Resource " + resource.getName() + " is now available");
|
||||
if(username.equals(TEST_USER)){
|
||||
|
||||
// set its id and turn it to the client
|
||||
resource.setId(resourceId);
|
||||
return resource;
|
||||
logger.warn("SESSION EXPIRED! ");
|
||||
return null;
|
||||
|
||||
}else{
|
||||
|
||||
try{
|
||||
|
||||
ResourceBean resourceBean = new ResourceBean(
|
||||
resource.getUrl(),
|
||||
resource.getName(),
|
||||
resource.getDescription(),
|
||||
null,
|
||||
owner,
|
||||
datasetId,
|
||||
null);
|
||||
|
||||
String resourceId = getCkanUtilsObj().addResourceToDataset(resourceBean, getUserCKanTokenFromSession());
|
||||
|
||||
if(resourceId != null){
|
||||
logger.debug("Resource " + resource.getName() + " is now available");
|
||||
// set its id and turn it to the client
|
||||
resource.setId(resourceId);
|
||||
return resource;
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to create new resource", e);
|
||||
}
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to create new resource", e);
|
||||
logger.debug("No resource created");
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.debug("No resource created");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteResourceFromDataset(ResourceBeanWrapper resource,
|
||||
String owner) {
|
||||
logger.debug("Request for deleting resource " + resource);
|
||||
|
||||
logger.debug("Request for deleting resource " + resource);
|
||||
boolean deleted = false;
|
||||
|
||||
try{
|
||||
if(!isWithinPortal()){
|
||||
logger.warn("Running outside the portal");
|
||||
return deleted;
|
||||
}else{
|
||||
|
||||
deleted = getCkanUtilsObj().
|
||||
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession());
|
||||
ASLSession session = getASLSession();
|
||||
String username = session.getUsername();
|
||||
|
||||
if(deleted){
|
||||
logger.debug("Resource described by " + resource + " deleted");
|
||||
}else
|
||||
logger.error("Resource described by " + resource + " NOT deleted");
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||
if(username.equals(TEST_USER)){
|
||||
logger.warn("SESSION EXPIRED! ");
|
||||
return deleted;
|
||||
}else{
|
||||
try{
|
||||
deleted = getCkanUtilsObj().
|
||||
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession());
|
||||
if(deleted){
|
||||
logger.debug("Resource described by " + resource + " deleted");
|
||||
}else
|
||||
logger.error("Resource described by " + resource + " NOT deleted");
|
||||
}catch(Exception e){
|
||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue