fixed association thread

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@139936 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-12-12 16:56:49 +00:00
parent 7ea5014870
commit 031896c371
1 changed files with 33 additions and 25 deletions

View File

@ -68,46 +68,54 @@ public class AssociationToGroupAndNotifyThread extends Thread {
logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username); logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username);
// create the group if(groupTitle != null){
CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, ""); try{
if(group == null){ // create the group
CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, "");
logger.warn("The group doesn't exist! Unable to perform such association"); if(group == null){
}else{ logger.warn("The group doesn't exist! Unable to perform such association");
logger.debug("Group exists, going to add the user " + username + " as its admin..."); }else{
// retrieve the role to be assigned according the one the user has into the organization of the dataset logger.debug("Group exists, going to add the user " + username + " as its admin...");
RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organization, catalogue.getApiKeyFromUsername(username)).toUpperCase());
if(!role.equals(RolesCkanGroupOrOrg.ADMIN)) // retrieve the role to be assigned according the one the user has into the organization of the dataset
role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organization, catalogue.getApiKeyFromUsername(username)).toUpperCase());
boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, role); if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
if(assigned){ boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, role);
logger.debug("Admin/editor role was assigned for this group, going to associate the product to the group"); if(assigned){
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group? " + putIntoGroup);
if(putIntoGroup) logger.debug("Admin/editor role was assigned for this group, going to associate the product to the group");
notifyGroupAdmins(catalogue, groupTitle, username); boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group? " + putIntoGroup);
if(putIntoGroup)
notifyGroupAdmins(catalogue, groupTitle, username);
}
}
}catch(Exception e){
logger.warn("Something went wrong when tried to add the group " + groupTitle, e);
} }
} }
logger.info("Other groups to which the product should be associate are " + groups); logger.info("Other groups to which the product should be associate are " + groups);
for (GroupBean groupBean : groups) { if(groups != null)
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getGroupTitle(), datasetId, catalogue.getApiKeyFromUsername(username)); for (GroupBean groupBean : groups) {
logger.info("Was product put into group" + groupBean.getGroupTitle() + "? " + putIntoGroup); boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getGroupTitle(), datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group" + groupBean.getGroupTitle() + "? " + putIntoGroup);
if(putIntoGroup) if(putIntoGroup)
notifyGroupAdmins(catalogue, groupBean.getGroupTitle(), username); notifyGroupAdmins(catalogue, groupBean.getGroupTitle(), username);
} }
} }