protected ModelAndView doHandle()

in src/main/java/jetbrains/buildServer/investigationsAutoAssigner/representation/AssignInvestigationController.java [55:119]


  protected ModelAndView doHandle(@NotNull final HttpServletRequest request,
                                  @NotNull final HttpServletResponse response) throws IllegalAccessException {
    final long userId;
    final long testNameId;
    final int buildId;
    try {
      userId = Long.parseLong(request.getParameter("userId"));
      testNameId = Long.parseLong(request.getParameter("testNameId"));
      buildId = Integer.parseInt(request.getParameter("buildId"));
    } catch (NumberFormatException ex) {
      throw new IllegalArgumentException("Provided parameter is not valid", ex);
    }

    final String description = request.getParameter("description");
    if (description == null) {
      throw new IllegalArgumentException("Description is not specified");
    }


    AuthorityHolder authorityHolder = mySecurityContext.getAuthorityHolder();

    @Nullable
    User reporterUser = authorityHolder.getAssociatedUser();

    if (reporterUser == null) {
      reporterUser = SessionUser.getUser(request);
    }

    @Nullable final SBuild build = myServer.findBuildInstanceById(buildId);
    if (build == null) throw new IllegalStateException("Build was not found by provided buildId");

    @Nullable String projectId = build.getProjectId();
    if (projectId == null) throw new IllegalStateException("ProjectId is not specified on the build");
    final SProject project = myProjectManager.findProjectById(projectId);
    if (project == null) throw new IllegalStateException("Cannot find project by ID " + projectId);

    @Nullable
    User responsibleUser = myUserModel.findUserById(userId);
    if (responsibleUser == null) throw new IllegalStateException("Investigator was not found in the model by his id");

    @Nullable
    STest sTest = myTestManager.findTest(testNameId, projectId);
    if (sTest == null) throw new IllegalStateException("Test was not found by provided testNameId");


    if (!authorityHolder.getPermissionsGrantedForProject(projectId).contains(Permission.ASSIGN_INVESTIGATION)) {
      throw new IllegalAccessException("Current user doesn't have permissions to assign investigations");
    }

    if (reporterUser instanceof SUser) {
      SProject preferredProject =
        myTargetProjectFinder.getPreferredInvestigationProject(project, (SUser)reporterUser);
      if (preferredProject != null) {
        projectId = preferredProject.getProjectId();
      }
    }

    myTestNameResponsibilityFacade.setTestNameResponsibility(
      sTest.getName(), projectId,
      new ResponsibilityEntryEx(
        ResponsibilityEntry.State.TAKEN, responsibleUser, reporterUser, Dates.now(),
        description, ResponsibilityEntry.RemoveMethod.WHEN_FIXED));

    return null;
  }