From 031896c37109caf557cc745dbe57784bf54a2de2 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 12 Dec 2016 16:56:49 +0000 Subject: [PATCH] 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 --- .../AssociationToGroupAndNotifyThread.java | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java index 0dfeb0f..646c742 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java @@ -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); + } }