use of io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException in project furms by unity-idm.
the class ProjectApplicationsServiceImpl method createForCurrentUser.
@Override
@FurmsAuthorize(capability = AUTHENTICATED)
public void createForCurrentUser(String projectId) {
projectRepository.findById(projectId).ifPresent(project -> {
FURMSUser currentUser = authzService.getCurrentAuthNUser();
if (invitationRepository.findBy(currentUser.email, Role.PROJECT_USER, new ResourceId(projectId, PROJECT)).isPresent())
throw new UserAlreadyInvitedException(String.format("User %s is invited for project %s", currentUser.email, projectId));
FenixUserId fenixUserId = currentUser.fenixUserId.orElseThrow(UserWithoutFenixIdValidationError::new);
applicationRepository.create(projectId, fenixUserId);
projectGroupsDAO.getAllAdmins(project.getCommunityId(), projectId).forEach(usr -> userApplicationNotificationService.notifyAdminAboutApplicationRequest(usr.id.get(), projectId, project.getName(), currentUser.email));
publisher.publishEvent(new ProjectApplicationCreatedEvent(fenixUserId, projectId, new HashSet<>(projectGroupsDAO.getAllAdmins(project.getCommunityId(), projectId))));
LOG.info("User {} application for project ID: {} was created", projectId, currentUser.fenixUserId.get());
});
}
use of io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException in project furms by unity-idm.
the class ProjectsView method createLastColumnContent.
private HorizontalLayout createLastColumnContent(ProjectGridModel project) {
switch(project.status) {
case ACTIVE:
return new GridActionsButtonLayout(new RouterGridLink(PIE_CHART, project.id, ProjectView.class), createContextMenu(project.id, project.name, project.communityId));
case NOT_ACTIVE:
MenuButton applyButton = new MenuButton(PLUS_CIRCLE);
applyButton.addClickListener(x -> {
try {
projectApplicationsService.createForCurrentUser(project.id);
showSuccessNotification(getTranslation("view.user-settings.projects.applied.notification", project.name));
loadGridContent();
} catch (UserAlreadyInvitedException e) {
showErrorNotification(getTranslation("user.already.invited"));
} catch (Exception e) {
showErrorNotification(getTranslation("base.error.message"));
throw e;
}
});
return new GridActionsButtonLayout(addApplyTooltip(applyButton));
case REQUESTED:
MenuButton removeApplicationButton = new MenuButton(TRASH);
removeApplicationButton.addClickListener(x -> {
try {
projectApplicationsService.removeForCurrentUser(project.id);
} catch (ApplicationNotExistingException e) {
showErrorNotification(getTranslation("application.already.not.existing"));
} catch (Exception e) {
showErrorNotification(getTranslation("base.error.message"));
throw e;
}
loadGridContent();
});
return new GridActionsButtonLayout(removeApplicationButton);
default:
throw new RuntimeException("This should not happened");
}
}
Aggregations