<commit_before>package org.innovateuk.ifs.management.controller;

import org.innovateuk.ifs.application.service.CompetitionService;
import org.innovateuk.ifs.assessment.service.CompetitionInviteRestService;
import org.innovateuk.ifs.commons.rest.RestResult;
import org.innovateuk.ifs.commons.service.ServiceResult;
import org.innovateuk.ifs.competition.resource.CompetitionResource;
import org.innovateuk.ifs.controller.ValidationHandler;
import org.innovateuk.ifs.invite.resource.CompetitionInviteResource;
import org.innovateuk.ifs.invite.resource.ExistingUserStagedInviteResource;
import org.innovateuk.ifs.invite.resource.NewUserStagedInviteListResource;
import org.innovateuk.ifs.invite.resource.NewUserStagedInviteResource;
import org.innovateuk.ifs.management.form.InviteNewAssessorsForm;
import org.innovateuk.ifs.management.form.InviteNewAssessorsRowForm;
import org.innovateuk.ifs.management.model.InviteAssessorsFindModelPopulator;
import org.innovateuk.ifs.management.model.InviteAssessorsInviteModelPopulator;
import org.innovateuk.ifs.management.model.InviteAssessorsOverviewModelPopulator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

import static java.lang.String.format;

/**
 * This controller will handle all Competition Management requests related to inviting assessors to a Competition.
 */
@Controller
@RequestMapping("/competition/{competitionId}/assessors")
public class CompetitionManagementInviteAssessorsController {

    private static final String FORM_ATTR_NAME = "form";

    @Autowired
    private CompetitionService competitionService;

    @Autowired
    private CompetitionInviteRestService competitionInviteRestService;

    @Autowired
    private InviteAssessorsFindModelPopulator inviteAssessorsFindModelPopulator;

    @Autowired
    private InviteAssessorsInviteModelPopulator inviteAssessorsInviteModelPopulator;

    @Autowired
    private InviteAssessorsOverviewModelPopulator inviteAssessorsOverviewModelPopulator;

    @RequestMapping(method = RequestMethod.GET)
    public String assessors(@PathVariable("competitionId") Long competitionId) {
        return format("redirect:/competition/%s/assessors/find", competitionId);
    }

    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public String find(Model model, @PathVariable("competitionId") Long competitionId) {
        return doViewFind(model, competitionId);
    }

    @RequestMapping(value = "/find", params = {"add"}, method = RequestMethod.POST)
    public String addInviteFromFindView(Model model, @PathVariable("competitionId") Long competitionId, @RequestParam(name = "add") String email) {
        inviteUser(email, competitionId).getSuccessObjectOrThrowException();
        return doViewFind(model, competitionId);
    }

    @RequestMapping(value = "/find", params = {"remove"}, method = RequestMethod.POST)
    public String removeInviteFromFindView(Model model, @PathVariable("competitionId") Long competitionId, @RequestParam(name = "remove") String email) {
        deleteInvite(email, competitionId).getSuccessObjectOrThrowException();
        return doViewFind(model, competitionId);
    }

    @RequestMapping(value = "/invite", method = RequestMethod.GET)
    public String invite(Model model,
                         @PathVariable("competitionId") Long competitionId,
                         @SuppressWarnings("unused") @ModelAttribute(FORM_ATTR_NAME) InviteNewAssessorsForm form,
                         @SuppressWarnings("unused") BindingResult bindingResult) {
        if (form.getInvites().size() == 0) {<commit_msg>INFUND-7126 - Changes form to check on .isEmpty than size directly<commit_after>package org.innovateuk.ifs.management.controller;

import org.innovateuk.ifs.application.service.CompetitionService;
import org.innovateuk.ifs.assessment.service.CompetitionInviteRestService;
import org.innovateuk.ifs.commons.rest.RestResult;
import org.innovateuk.ifs.commons.service.ServiceResult;
import org.innovateuk.ifs.competition.resource.CompetitionResource;
import org.innovateuk.ifs.controller.ValidationHandler;
import org.innovateuk.ifs.invite.resource.CompetitionInviteResource;
import org.innovateuk.ifs.invite.resource.ExistingUserStagedInviteResource;
import org.innovateuk.ifs.invite.resource.NewUserStagedInviteListResource;
import org.innovateuk.ifs.invite.resource.NewUserStagedInviteResource;
import org.innovateuk.ifs.management.form.InviteNewAssessorsForm;
import org.innovateuk.ifs.management.form.InviteNewAssessorsRowForm;
import org.innovateuk.ifs.management.model.InviteAssessorsFindModelPopulator;
import org.innovateuk.ifs.management.model.InviteAssessorsInviteModelPopulator;
import org.innovateuk.ifs.management.model.InviteAssessorsOverviewModelPopulator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

import static java.lang.String.format;

/**
 * This controller will handle all Competition Management requests related to inviting assessors to a Competition.
 */
@Controller
@RequestMapping("/competition/{competitionId}/assessors")
public class CompetitionManagementInviteAssessorsController {

    private static final String FORM_ATTR_NAME = "form";

    @Autowired
    private CompetitionService competitionService;

    @Autowired
    private CompetitionInviteRestService competitionInviteRestService;

    @Autowired
    private InviteAssessorsFindModelPopulator inviteAssessorsFindModelPopulator;

    @Autowired
    private InviteAssessorsInviteModelPopulator inviteAssessorsInviteModelPopulator;

    @Autowired
    private InviteAssessorsOverviewModelPopulator inviteAssessorsOverviewModelPopulator;

    @RequestMapping(method = RequestMethod.GET)
    public String assessors(@PathVariable("competitionId") Long competitionId) {
        return format("redirect:/competition/%s/assessors/find", competitionId);
    }

    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public String find(Model model, @PathVariable("competitionId") Long competitionId) {
        return doViewFind(model, competitionId);
    }

    @RequestMapping(value = "/find", params = {"add"}, method = RequestMethod.POST)
    public String addInviteFromFindView(Model model, @PathVariable("competitionId") Long competitionId, @RequestParam(name = "add") String email) {
        inviteUser(email, competitionId).getSuccessObjectOrThrowException();
        return doViewFind(model, competitionId);
    }

    @RequestMapping(value = "/find", params = {"remove"}, method = RequestMethod.POST)
    public String removeInviteFromFindView(Model model, @PathVariable("competitionId") Long competitionId, @RequestParam(name = "remove") String email) {
        deleteInvite(email, competitionId).getSuccessObjectOrThrowException();
        return doViewFind(model, competitionId);
    }

    @RequestMapping(value = "/invite", method = RequestMethod.GET)
    public String invite(Model model,
                         @PathVariable("competitionId") Long competitionId,
                         @SuppressWarnings("unused") @ModelAttribute(FORM_ATTR_NAME) InviteNewAssessorsForm form,
                         @SuppressWarnings("unused") BindingResult bindingResult) {
        if (form.getInvites().isEmpty()) {
{'fraction_non_alphanumeric': 0.09062861550327805, 'fraction_numerical': 0.000642756138321121, 'mean_word_length': 5.505016722408027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5717148', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2115, 'n_words': 380}