use of de.ids_mannheim.korap.entity.UserGroupMember in project Kustvakt by KorAP.
the class UserGroupService method retrieveUserGroupDto.
public List<UserGroupDto> retrieveUserGroupDto(String username) throws KustvaktException {
List<UserGroup> userGroups = retrieveUserGroup(username);
ArrayList<UserGroupDto> dtos = new ArrayList<>(userGroups.size());
UserGroupMember userAsMember;
List<UserGroupMember> members;
UserGroupDto groupDto;
for (UserGroup group : userGroups) {
members = retrieveMembers(group.getId(), username);
userAsMember = groupMemberDao.retrieveMemberById(username, group.getId());
groupDto = converter.createUserGroupDto(group, members, userAsMember.getStatus(), userAsMember.getRoles());
dtos.add(groupDto);
}
return dtos;
}
use of de.ids_mannheim.korap.entity.UserGroupMember in project Kustvakt by KorAP.
the class UserGroupService method retrieveMembers.
private List<UserGroupMember> retrieveMembers(int groupId, String username) throws KustvaktException {
List<UserGroupMember> groupAdmins = groupMemberDao.retrieveMemberByRole(groupId, PredefinedRole.USER_GROUP_ADMIN.getId());
List<UserGroupMember> members = null;
for (UserGroupMember admin : groupAdmins) {
if (admin.getUserId().equals(username)) {
members = groupMemberDao.retrieveMemberByGroupId(groupId);
break;
}
}
return members;
}
use of de.ids_mannheim.korap.entity.UserGroupMember in project Kustvakt by KorAP.
the class UserGroupService method addMemberRoles.
public void addMemberRoles(String username, String groupName, String memberUsername, List<Integer> roleIds) throws KustvaktException {
ParameterChecker.checkStringValue(username, "username");
ParameterChecker.checkStringValue(groupName, "groupName");
ParameterChecker.checkStringValue(memberUsername, "memberUsername");
UserGroup userGroup = userGroupDao.retrieveGroupByName(groupName, true);
UserGroupStatus groupStatus = userGroup.getStatus();
if (groupStatus == UserGroupStatus.DELETED) {
throw new KustvaktException(StatusCodes.GROUP_DELETED, "Usergroup has been deleted.");
} else if (isUserGroupAdmin(username, userGroup) || adminDao.isAdmin(username)) {
UserGroupMember member = groupMemberDao.retrieveMemberById(memberUsername, userGroup.getId());
if (!member.getStatus().equals(GroupMemberStatus.ACTIVE)) {
throw new KustvaktException(StatusCodes.GROUP_MEMBER_INACTIVE, memberUsername + " has status " + member.getStatus(), memberUsername, member.getStatus().name());
}
Set<Role> roles = member.getRoles();
for (int i = 0; i < roleIds.size(); i++) {
roles.add(roleDao.retrieveRoleById(roleIds.get(i)));
}
member.setRoles(roles);
groupMemberDao.updateMember(member);
} else {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED, "Unauthorized operation for user: " + username, username);
}
}
use of de.ids_mannheim.korap.entity.UserGroupMember in project Kustvakt by KorAP.
the class UserGroupService method acceptInvitation.
/**
* Updates the {@link GroupMemberStatus} of a pending member
* to {@link GroupMemberStatus#ACTIVE} and add default member
* roles.
*
* @param groupId
* groupId
* @param username
* the username of the group member
* @throws KustvaktException
*/
public void acceptInvitation(String groupName, String username) throws KustvaktException {
ParameterChecker.checkStringValue(username, "userId");
ParameterChecker.checkStringValue(groupName, "groupId");
UserGroup userGroup = userGroupDao.retrieveGroupByName(groupName, false);
if (userGroup.getStatus() == UserGroupStatus.DELETED) {
throw new KustvaktException(StatusCodes.GROUP_DELETED, "Group " + userGroup.getName() + " has been deleted.", userGroup.getName());
}
UserGroupMember member = groupMemberDao.retrieveMemberById(username, userGroup.getId());
GroupMemberStatus status = member.getStatus();
if (status.equals(GroupMemberStatus.DELETED)) {
throw new KustvaktException(StatusCodes.GROUP_MEMBER_DELETED, username + " has already been deleted from the group " + userGroup.getName(), username, userGroup.getName());
} else if (member.getStatus().equals(GroupMemberStatus.ACTIVE)) {
throw new KustvaktException(StatusCodes.GROUP_MEMBER_EXISTS, "Username " + username + " with status " + status + " exists in the user-group " + userGroup.getName(), username, status.name(), userGroup.getName());
} else // status pending
{
if (DEBUG) {
jlog.debug("status: " + member.getStatusDate());
}
ZonedDateTime expiration = member.getStatusDate().plusMinutes(30);
ZonedDateTime now = ZonedDateTime.now();
if (DEBUG) {
jlog.debug("expiration: " + expiration + ", now: " + now);
}
if (expiration.isAfter(now)) {
member.setStatus(GroupMemberStatus.ACTIVE);
setMemberRoles();
member.setRoles(memberRoles);
groupMemberDao.updateMember(member);
} else {
throw new KustvaktException(StatusCodes.INVITATION_EXPIRED);
}
}
}
use of de.ids_mannheim.korap.entity.UserGroupMember in project Kustvakt by KorAP.
the class UserGroupService method doDeleteMember.
/**
* Updates the {@link GroupMemberStatus} of a member to
* {@link GroupMemberStatus#DELETED}
*
* @param userId
* user to be deleted
* @param groupId
* user-group id
* @param deletedBy
* user that issue the delete
* @param isSoftDelete
* true if database entry is to be deleted
* permanently, false otherwise
* @throws KustvaktException
*/
private void doDeleteMember(String username, int groupId, String deletedBy, boolean isSoftDelete) throws KustvaktException {
UserGroup group = userGroupDao.retrieveGroupById(groupId);
UserGroupMember member = groupMemberDao.retrieveMemberById(username, groupId);
GroupMemberStatus status = member.getStatus();
if (isSoftDelete && status.equals(GroupMemberStatus.DELETED)) {
throw new KustvaktException(StatusCodes.GROUP_MEMBER_DELETED, username + " has already been deleted from the group " + group.getName(), username, group.getName());
}
groupMemberDao.deleteMember(member, deletedBy, isSoftDelete);
}
Aggregations