<commit_before>package org.innovateuk.ifs.project.grants.controller;

import org.innovateuk.ifs.commons.security.SecuredBySpring;
import org.innovateuk.ifs.controller.ValidationHandler;
import org.innovateuk.ifs.filter.CookieFlashMessageFilter;
import org.innovateuk.ifs.grants.service.GrantsInviteRestService;
import org.innovateuk.ifs.project.grants.form.ResendInvitationForm;
import org.innovateuk.ifs.project.grants.populator.ManageInvitationsModelPopulator;
import org.innovateuk.ifs.project.grants.viewmodel.ManageInvitationsViewModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.function.Supplier;

@Controller
@RequestMapping("/project/{projectId}")
public class ManageInvitationsController {

    @Autowired
    private GrantsInviteRestService grantsInviteRestService;

    @Autowired
    private ManageInvitationsModelPopulator manageInvitationsModelPopulator;

    @Autowired
    private CookieFlashMessageFilter cookieFlashMessageFilter;

    @SecuredBySpring(value = "MANAGE_INVITATIONS", description = "Only project finance users can manage invitations")
    @PreAuthorize("hasAnyAuthority('project_finance')")
    @GetMapping("/grants/invite")
    public String viewInvitations(
            Model model,
            @PathVariable("projectId") long projectId, @ModelAttribute("form") ResendInvitationForm form) {

        ManageInvitationsViewModel viewModel = manageInvitationsModelPopulator.populateManageInvitationsViewModel(projectId);

        model.addAttribute("model", viewModel);
        return "project/manage-invitations";
    }

    @SecuredBySpring(value = "MANAGE_INVITATIONS", description = "Only project finance users can manage invitations")
    @PreAuthorize("hasAnyAuthority('project_finance')")
    @PostMapping("/grants/invite/resend")
    public String resendInvitation(Model model, @PathVariable long projectId, @ModelAttribute("form") ResendInvitationForm form,
                                   ValidationHandler validationHandler, HttpServletResponse response) {

        Supplier<String> failureView = () -> viewInvitations(model, projectId, form);
        Supplier<String> successView = () -> String.format("redirect:/project/%d/grants/invite", projectId);

        validationHandler.addAnyErrors(grantsInviteRestService.resendInvite(form.getProjectId(), form.getInviteId()));
        if (!validationHandler.hasErrors()) {
            cookieFlashMessageFilter.setFlashMessage(response, "emailSent");
        }
        return validationHandler.failNowOrSucceedWith(failureView, successView);
    }

}
<commit_msg>IFS-7318 review feedback - moving success logic into successView lambda<commit_after>package org.innovateuk.ifs.project.grants.controller;

import org.innovateuk.ifs.commons.security.SecuredBySpring;
import org.innovateuk.ifs.controller.ValidationHandler;
import org.innovateuk.ifs.filter.CookieFlashMessageFilter;
import org.innovateuk.ifs.grants.service.GrantsInviteRestService;
import org.innovateuk.ifs.project.grants.form.ResendInvitationForm;
import org.innovateuk.ifs.project.grants.populator.ManageInvitationsModelPopulator;
import org.innovateuk.ifs.project.grants.viewmodel.ManageInvitationsViewModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.function.Supplier;

@Controller
@RequestMapping("/project/{projectId}")
public class ManageInvitationsController {

    @Autowired
    private GrantsInviteRestService grantsInviteRestService;

    @Autowired
    private ManageInvitationsModelPopulator manageInvitationsModelPopulator;

    @Autowired
    private CookieFlashMessageFilter cookieFlashMessageFilter;

    @SecuredBySpring(value = "MANAGE_INVITATIONS", description = "Only project finance users can manage invitations")
    @PreAuthorize("hasAnyAuthority('project_finance')")
    @GetMapping("/grants/invite")
    public String viewInvitations(
            Model model,
            @PathVariable("projectId") long projectId, @ModelAttribute("form") ResendInvitationForm form) {

        ManageInvitationsViewModel viewModel = manageInvitationsModelPopulator.populateManageInvitationsViewModel(projectId);

        model.addAttribute("model", viewModel);
        return "project/manage-invitations";
    }

    @SecuredBySpring(value = "MANAGE_INVITATIONS", description = "Only project finance users can manage invitations")
    @PreAuthorize("hasAnyAuthority('project_finance')")
    @PostMapping("/grants/invite/resend")
    public String resendInvitation(Model model, @PathVariable long projectId, @ModelAttribute("form") ResendInvitationForm form,
                                   ValidationHandler validationHandler, HttpServletResponse response) {

        Supplier<String> failureView = () -> viewInvitations(model, projectId, form);
        Supplier<String> successView = () -> {
            cookieFlashMessageFilter.setFlashMessage(response, "emailSent");
            return String.format("redirect:/project/%d/grants/invite", projectId);
        };

        validationHandler.addAnyErrors(grantsInviteRestService.resendInvite(form.getProjectId(), form.getInviteId()));
        return validationHandler.failNowOrSucceedWith(failureView, successView);
    }

}

{'fraction_non_alphanumeric': 0.09429671098670399, 'fraction_numerical': 0.0006997900629811056, 'mean_word_length': 5.214130434782609, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837245', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1545, 'n_words': 249}