Search in sources :

Example 1 with UserAlreadyInvitedException

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());
    });
}
Also used : ResourceId(io.imunity.furms.domain.authz.roles.ResourceId) FenixUserId(io.imunity.furms.domain.users.FenixUserId) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) ProjectApplicationCreatedEvent(io.imunity.furms.domain.applications.ProjectApplicationCreatedEvent) FURMSUser(io.imunity.furms.domain.users.FURMSUser) UserAlreadyInvitedException(io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException) HashSet(java.util.HashSet) FurmsAuthorize(io.imunity.furms.core.config.security.method.FurmsAuthorize)

Example 2 with UserAlreadyInvitedException

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");
    }
}
Also used : RouterGridLink(io.imunity.furms.ui.components.RouterGridLink) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) MenuButton(io.imunity.furms.ui.components.MenuButton) UserAlreadyInvitedException(io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) UserAlreadyInvitedException(io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException)

Aggregations

UserAlreadyInvitedException (io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException)2 ApplicationNotExistingException (io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException)1 UserWithoutFenixIdValidationError (io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError)1 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)1 ProjectApplicationCreatedEvent (io.imunity.furms.domain.applications.ProjectApplicationCreatedEvent)1 ResourceId (io.imunity.furms.domain.authz.roles.ResourceId)1 FURMSUser (io.imunity.furms.domain.users.FURMSUser)1 FenixUserId (io.imunity.furms.domain.users.FenixUserId)1 GridActionsButtonLayout (io.imunity.furms.ui.components.GridActionsButtonLayout)1 MenuButton (io.imunity.furms.ui.components.MenuButton)1 RouterGridLink (io.imunity.furms.ui.components.RouterGridLink)1 HashSet (java.util.HashSet)1