Github user bbende commented on the pull request:
https://github.com/apache/nifi/pull/452#issuecomment-220121052
@alopresto The intent was for the relationship to be bi-directional,
meaning you could add a user to a group by adding/updating a User with a new
group id in the set of groups, or by adding/updating a Group with a new user id
in the set of users.
The overall idea was to retrieve an object, make a copy of it with the
desired changes, and then call update. So for the example scenarios...
- You could do this two different ways, but one would be to create a new
Group instance with name "Admins" and no users and call addGroup(), then create
a new User instance with name "Bryan Bende" and a set of group ids containing
the id of the "Admins" group and call addUser()
- Same as above to create the group and user and place the user in the
group... then you would retrieve the User instance for "Andrew LoPresto", make
a copy of that User instance with the name set to "Andy LoPrestro" and call
updateUser(...)
- Same as scenario 1 to create the group and users and place the users in
the group, although to add both users to the group in one action you could
retrieve the Group, make a copy of the Group and add both user ids to the set
of users, and call updateGroup(). Removing "Bryan Bende" from "Admins" could be
done by copying the Group without "Bryan Bende"s id in the set of users and
calling updateGroup, or by copying the User for "Bryan Bende" without the id of
the "Admin" group in the set of groups and calling updateUser().
After thinking about all of these, it seems like it would nice to have
builders that made it convenient for updating a User or Group... So something
like...
```
User user = authorizer.getUser(id);
User updatedUser = new User.UserBuilder().fromUser(user).name("New
Name").build();
authorizer.updateUser(updatedUser);
```
Also easily removing entries, so something like this for removing a user
from a group:
```
User user = authorizer.getUser(id);
User updatedUser = new
User.UserBuilder().fromUser(user).removeGroup(groupId).build();
authorizer.updateUser(updatedUser);
```
Thoughts?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---