class ApplicationTeamAddOrganisationController {

    @PostMapping
    @PreAuthorize("hasPermission(#applicationId, 'org.innovateuk.ifs.application.resource.ApplicationCompositeId', 'ADD_NEW_ORGANISATION')")
    public String addOrganisation(@Valid @ModelAttribute(value = "form") ApplicationTeamOrganisationForm form,
                           BindingResult bindingResult,
                           ValidationHandler validationHandler,
                           Model model,
                           @PathVariable long applicationId,
                           @PathVariable long questionId) {
        Supplier<String> failureView = () -> addOrganisationForm(form, bindingResult, model, applicationId, questionId);
        return validationHandler.failNowOrSucceedWith(failureView, () -> {
            validationHandler.addAnyErrors(inviteRestService.createInvitesByInviteOrganisation(
                    form.getOrganisationName(), singletonList(new ApplicationInviteResource(form.getName(), form.getEmail(), applicationId))),
                    mappingErrorKeyToField("email.already.in.invite", "email"),
                    defaultConverters());
            return validationHandler.failNowOrSucceedWith(failureView,
                    () -> redirectToApplicationTeam(applicationId, questionId));

        });
    }

}