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);
// create the group
CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, "");
if(groupTitle != null){
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
RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organization, catalogue.getApiKeyFromUsername(username)).toUpperCase());
logger.debug("Group exists, going to add the user " + username + " as its admin...");
if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
// retrieve the role to be assigned according the one the user has into the organization of the dataset
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");
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group? " + putIntoGroup);
if(assigned){
if(putIntoGroup)
notifyGroupAdmins(catalogue, groupTitle, username);
logger.debug("Admin/editor role was assigned for this group, going to associate the product to the group");
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);
for (GroupBean groupBean : groups) {
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getGroupTitle(), datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group" + groupBean.getGroupTitle() + "? " + putIntoGroup);
if(groups != null)
for (GroupBean groupBean : groups) {
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getGroupTitle(), datasetId, catalogue.getApiKeyFromUsername(username));
logger.info("Was product put into group" + groupBean.getGroupTitle() + "? " + putIntoGroup);
if(putIntoGroup)
notifyGroupAdmins(catalogue, groupBean.getGroupTitle(), username);
}
if(putIntoGroup)
notifyGroupAdmins(catalogue, groupBean.getGroupTitle(), username);
}
}