diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/AssociationToGroupThread.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/AssociationToGroupThread.java index faf848e..d288dc8 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/AssociationToGroupThread.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/AssociationToGroupThread.java @@ -19,7 +19,6 @@ public class AssociationToGroupThread extends Thread { private String datasetId; private String username; private DataCatalogue catalogue; - private String organization; /** * @param groupTitle @@ -28,37 +27,31 @@ public class AssociationToGroupThread extends Thread { * @param catalogue */ public AssociationToGroupThread(List groupsTitles, String datasetId, - String username, DataCatalogue catalogue, String organization) { + String username, DataCatalogue catalogue) { this.groupsTitles = groupsTitles; this.datasetId = datasetId; this.username = username; this.catalogue = catalogue; - this.organization = organization; } @Override public void run() { - logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title " + groupsTitles + " for user " + username); - - // create the group + logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title(s) " + groupsTitles + " for user " + username); + + for (String groupTitle : groupsTitles) { - - logger.debug("Group exists, going to add the user " + username + " as its 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(assigned){ - - 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); - + + // check the user has enough privileges to associate it + if(catalogue.checkRoleIntoGroup(username, groupTitle, RolesCkanGroupOrOrg.MEMBER)){ + + logger.warn("The user " + username + " has no enough priviliges to associate the dataset into group " + groupTitle); + continue; } + + boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username)); + logger.info("Was product put into group? " + putIntoGroup); + } }