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";
|
public static final String CKAN_LICENSES_KEY = "ckanLicenses";
|
||||||
private static final String CKAN_ORGANIZATIONS_KEY = "ckanOrganizations";
|
private static final String CKAN_ORGANIZATIONS_KEY = "ckanOrganizations";
|
||||||
private static final String CKAN_PROFILES_KEY = "ckanProfiles";
|
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();
|
private Object LOCK = new Object();
|
||||||
|
|
||||||
|
@ -120,26 +121,39 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
*/
|
*/
|
||||||
private String getUserCKanTokenFromSession(){
|
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;
|
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);
|
if(!isWithinPortal()){
|
||||||
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
|
logger.warn("You are running outside the portal");
|
||||||
logger.debug("Ckan token has been set for user " + username);
|
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;
|
return token;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,6 +168,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
List<String> orgsName = new ArrayList<String>();
|
List<String> orgsName = new ArrayList<String>();
|
||||||
ASLSession session = getASLSession();
|
ASLSession session = getASLSession();
|
||||||
|
|
||||||
|
CKanUtilsImpl ckanUtils = getCkanUtilsObj();
|
||||||
|
|
||||||
if(session.getAttribute(CKAN_ORGANIZATIONS_KEY) != null){
|
if(session.getAttribute(CKAN_ORGANIZATIONS_KEY) != null){
|
||||||
orgsName = (List<String>)session.getAttribute(CKAN_ORGANIZATIONS_KEY);
|
orgsName = (List<String>)session.getAttribute(CKAN_ORGANIZATIONS_KEY);
|
||||||
logger.debug("List of organizations was into session");
|
logger.debug("List of organizations was into session");
|
||||||
|
@ -162,7 +178,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
if(getCkanUtilsObj().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 = getCkanUtilsObj().getOrganizationsNames(); // get all organizations' names
|
orgsName = ckanUtils.getOrganizationsNames(); // get all organizations' names
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
|
@ -171,13 +187,13 @@ 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 = getCkanUtilsObj().getGroupsAndRolesByUser(username, rolesToMatch);
|
Map<String, List<RolesIntoOrganization>> orgsAndRoles = ckanUtils.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();
|
||||||
|
|
||||||
// get the names
|
// get the names
|
||||||
while (iterator.hasNext()) {
|
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();
|
.next();
|
||||||
orgsName.add(entry.getKey());
|
orgsName.add(entry.getKey());
|
||||||
logger.debug("The user has a role ADMIN/EDITOR into org " + 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("Incoming request for creating new resource for dataset with id " + datasetId);
|
||||||
logger.debug("Owner is " + owner + " and resource is " + resource);
|
logger.debug("Owner is " + owner + " and resource is " + resource);
|
||||||
|
|
||||||
try{
|
if(!isWithinPortal()){
|
||||||
|
|
||||||
ResourceBean resourceBean = new ResourceBean(
|
logger.warn("Running outside the portal");
|
||||||
resource.getUrl(),
|
return resource;
|
||||||
resource.getName(),
|
|
||||||
resource.getDescription(),
|
|
||||||
null,
|
|
||||||
owner,
|
|
||||||
datasetId,
|
|
||||||
null);
|
|
||||||
|
|
||||||
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
|
logger.warn("SESSION EXPIRED! ");
|
||||||
resource.setId(resourceId);
|
return null;
|
||||||
return resource;
|
|
||||||
|
|
||||||
|
}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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
logger.debug("No resource created");
|
||||||
}catch(Exception e){
|
return null;
|
||||||
logger.error("Unable to create new resource", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("No resource created");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteResourceFromDataset(ResourceBeanWrapper resource,
|
public boolean deleteResourceFromDataset(ResourceBeanWrapper resource,
|
||||||
String owner) {
|
String owner) {
|
||||||
logger.debug("Request for deleting resource " + resource);
|
|
||||||
|
|
||||||
|
logger.debug("Request for deleting resource " + resource);
|
||||||
boolean deleted = false;
|
boolean deleted = false;
|
||||||
|
|
||||||
try{
|
if(!isWithinPortal()){
|
||||||
|
logger.warn("Running outside the portal");
|
||||||
|
return deleted;
|
||||||
|
}else{
|
||||||
|
|
||||||
deleted = getCkanUtilsObj().
|
ASLSession session = getASLSession();
|
||||||
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession());
|
String username = session.getUsername();
|
||||||
|
|
||||||
if(deleted){
|
if(username.equals(TEST_USER)){
|
||||||
logger.debug("Resource described by " + resource + " deleted");
|
logger.warn("SESSION EXPIRED! ");
|
||||||
}else
|
return deleted;
|
||||||
logger.error("Resource described by " + resource + " NOT deleted");
|
}else{
|
||||||
|
try{
|
||||||
}catch(Exception e){
|
deleted = getCkanUtilsObj().
|
||||||
logger.error("Error while trying to delete resource described by " + resource, e);
|
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