@NotNull
  public synchronized List<TagRule> getRules(@NotNull SProject project) {
    SProject cur = project;
    List<TagRule> allRules = new ArrayList<TagRule>();
    while (cur != null) {
      List<TagRule> rules = myProjectRules.get(cur.getProjectId());
      if (rules != null) {
        allRules.addAll(rules);
      }

      cur = cur.getParentProject();
    }

    return allRules;
  }
 @Override
 protected void doProcess(
     @NotNull final HttpServletRequest request,
     @NotNull final HttpServletResponse response,
     @NotNull final Element ajaxResponse) {
   final String resourceId =
       request.getParameter(SharedResourcesPluginConstants.WEB.PARAM_RESOURCE_ID);
   final String projectId =
       request.getParameter(SharedResourcesPluginConstants.WEB.PARAM_PROJECT_ID);
   final SProject project = myProjectManager.findProjectById(projectId);
   if (project != null) {
     myProjectFeatures.removeFeature(project, resourceId);
     // todo: resource name
     project.persist(
         myConfigActionFactory.createAction(
             project, "'" + resourceId + "' shared resource was removed"));
     addMessage(request, "Resource " + resourceId + " was deleted");
   } else {
     LOG.error("Project [" + projectId + "] no longer exists!");
   }
 }
  public ProjectMonitorViewState(SProject project, UserGroup userGroup) {
    this.project = project;

    builds = new ArrayList<BuildTypeMonitorViewState>();
    for (SBuildType buildType : project.getBuildTypes()) {
      if (hasAtLeastOneBuild(buildType)) {
        if (buildType.isAllowExternalStatus()) {
          builds.add(new BuildTypeMonitorViewState(buildType, userGroup));
        }
      }
    }

    for (BuildTypeMonitorViewState build : builds) {
      committers.addAll(build.getCommitters());
    }
  }
 public String getProjectName() {
   return project.getName();
 }
 public synchronized void setRules(@NotNull SProject project, @NotNull List<TagRule> rules) {
   myProjectRules.put(project.getProjectId(), rules);
 }
  @Nullable
  protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    HashMap<String, Object> params = new HashMap<String, Object>();

    SUser myUser = SessionUser.getUser(request);
    SProject myProject = null;
    SlackNotificationProjectSettings projSettings = null;

    if (request.getMethod().equalsIgnoreCase("post")) {
      if ((request.getParameter("projectId") != null)
          && request.getParameter("projectId").startsWith("project")) {
        projSettings =
            (SlackNotificationProjectSettings)
                mySettings.getSettings(request.getParameter("projectId"), "slackNotifications");
        myProject =
            this.myServer.getProjectManager().findProjectById(request.getParameter("projectId"));

        if ((projSettings != null)
            && (myProject != null)
            && (myUser.isPermissionGrantedForProject(
                myProject.getProjectId(), Permission.EDIT_PROJECT))) {
          if ((request.getParameter("submitAction") != null)
              && (request.getParameter("submitAction").equals("removeSlackNotification"))
              && (request.getParameter("removedSlackNotificationId") != null)) {
            projSettings.deleteSlackNotification(
                request.getParameter("removedSlackNotificationId"), myProject.getProjectId());
            if (projSettings.updateSuccessful()) {
              myProject.persist();
              params.put("messages", "<errors />");
            } else {
              params.put(
                  "messages",
                  "<errors><error id=\"messageArea\">The slacknotifications was not found. Have the SlackNotifications been edited on disk or by another user?</error></errors>");
            }

          } else if ((request.getParameter("submitAction") != null)
              && (request.getParameter("submitAction").equals("updateSlackNotification"))) {
            if ((request.getParameter("channel") != null)
                && (request.getParameter("channel").length() > 0)) {

              if (request.getParameter("slackNotificationId") != null) {
                Boolean enabled = false;
                Boolean mentionChannelEnabled = false;
                Boolean mentionSlackUserEnabled = false;
                Boolean buildTypeAll = false;
                Boolean buildTypeSubProjects = false;
                SlackNotificationContentConfig content = new SlackNotificationContentConfig();
                Set<String> buildTypes = new HashSet<String>();
                if ((request.getParameter("slackNotificationsEnabled") != null)
                    && (request.getParameter("slackNotificationsEnabled").equalsIgnoreCase("on"))) {
                  enabled = true;
                }
                if ((request.getParameter("mentionChannelEnabled") != null)
                    && (request.getParameter("mentionChannelEnabled").equalsIgnoreCase("on"))) {

                  mentionChannelEnabled = true;
                }
                if ((request.getParameter("mentionSlackUserEnabled") != null)
                    && (request.getParameter("mentionSlackUserEnabled").equalsIgnoreCase("on"))) {
                  mentionSlackUserEnabled = true;
                }

                content.setEnabled(
                    (request.getParameter("customContentEnabled") != null)
                        && (request.getParameter("customContentEnabled").equalsIgnoreCase("on")));

                if (content.isEnabled()) {

                  if ((request.getParameter("maxCommitsToDisplay") != null)
                      && (request.getParameter("maxCommitsToDisplay").length() > 0)) {
                    content.setMaxCommitsToDisplay(
                        convertToInt(
                            request.getParameter("maxCommitsToDisplay"),
                            SlackNotificationContentConfig.DEFAULT_MAX_COMMITS));
                  }

                  content.setShowBuildAgent(
                      (request.getParameter("showBuildAgent") != null)
                          && (request.getParameter("showBuildAgent").equalsIgnoreCase("on")));

                  content.setShowCommits(
                      (request.getParameter("showCommits") != null)
                          && (request.getParameter("showCommits").equalsIgnoreCase("on")));

                  content.setShowCommitters(
                      (request.getParameter("showCommitters") != null)
                          && (request.getParameter("showCommitters").equalsIgnoreCase("on")));

                  content.setShowElapsedBuildTime(
                      (request.getParameter("showElapsedBuildTime") != null)
                          && (request.getParameter("showElapsedBuildTime").equalsIgnoreCase("on")));

                  content.setShowFailureReason(
                      (request.getParameter("showFailureReason") != null)
                          && (request.getParameter("showFailureReason").equalsIgnoreCase("on")));

                  if ((request.getParameter("botName") != null)
                      && (request.getParameter("botName").length() > 0)) {
                    content.setBotName(request.getParameter("botName"));
                  }

                  if ((request.getParameter("iconUrl") != null)
                      && (request.getParameter("iconUrl").length() > 0)) {
                    content.setIconUrl(request.getParameter("iconUrl"));
                  }
                }

                BuildState states = new BuildState();

                checkAndAddBuildState(
                    request, states, BuildStateEnum.BUILD_SUCCESSFUL, BUILD_SUCCESSFUL);
                checkAndAddBuildState(request, states, BuildStateEnum.BUILD_FAILED, BUILD_FAILED);
                checkAndAddBuildState(request, states, BuildStateEnum.BUILD_FIXED, BUILD_FIXED);
                checkAndAddBuildState(request, states, BuildStateEnum.BUILD_BROKEN, BUILD_BROKEN);
                checkAndAddBuildState(request, states, BuildStateEnum.BUILD_STARTED, BUILD_STARTED);
                checkAndAddBuildState(
                    request, states, BuildStateEnum.BUILD_INTERRUPTED, BUILD_INTERRUPTED);
                checkAndAddBuildState(
                    request, states, BuildStateEnum.BEFORE_BUILD_FINISHED, BEFORE_FINISHED);
                checkAndAddBuildStateIfEitherSet(
                    request, states, BuildStateEnum.BUILD_FINISHED, BUILD_SUCCESSFUL, BUILD_FAILED);
                checkAndAddBuildState(
                    request,
                    states,
                    BuildStateEnum.RESPONSIBILITY_CHANGED,
                    "ResponsibilityChanged");

                if ((request.getParameter("buildTypeSubProjects") != null)
                    && (request.getParameter("buildTypeSubProjects").equalsIgnoreCase("on"))) {
                  buildTypeSubProjects = true;
                }
                if ((request.getParameter("buildTypeAll") != null)
                    && (request.getParameter("buildTypeAll").equalsIgnoreCase("on"))) {
                  buildTypeAll = true;
                } else {
                  if (request.getParameterValues("buildTypeId") != null) {
                    String[] types = request.getParameterValues("buildTypeId");
                    for (String string : types) {
                      buildTypes.add(string);
                    }
                  }
                }

                if (request.getParameter("slackNotificationId").equals("new")) {
                  projSettings.addNewSlackNotification(
                      myProject.getProjectId(),
                      request.getParameter("channel"),
                      request.getParameter("team"),
                      enabled,
                      states,
                      buildTypeAll,
                      buildTypeSubProjects,
                      buildTypes,
                      mentionChannelEnabled,
                      mentionSlackUserEnabled);
                  if (projSettings.updateSuccessful()) {
                    myProject.persist();
                    params.put("messages", "<errors />");
                  } else {
                    params.put(
                        "message",
                        "<errors><error id=\"\">" + projSettings.getUpdateMessage() + "</error>");
                  }
                } else {
                  projSettings.updateSlackNotification(
                      myProject.getProjectId(),
                      request.getParameter("slackNotificationId"),
                      request.getParameter("channel"),
                      enabled,
                      states,
                      buildTypeAll,
                      buildTypeSubProjects,
                      buildTypes,
                      mentionChannelEnabled,
                      mentionSlackUserEnabled,
                      content);
                  if (projSettings.updateSuccessful()) {
                    myProject.persist();
                    params.put("messages", "<errors />");
                  } else {
                    params.put(
                        "message",
                        "<errors><error id=\"\">" + projSettings.getUpdateMessage() + "</error>");
                  }
                }
              } // TODO Need to handle slackNotificationId being null

            } else {
              if ((request.getParameter("channel") == null)
                  || (request.getParameter("channel").length() == 0)) {
                params.put(
                    "messages",
                    "<errors><error id=\"emptySlackNotificationChannel\">Please enter a channel.</error></errors>");
              }
            }
          }
        } else {
          params.put(
              "messages",
              "<errors><error id=\"messageArea\">You do not appear to have permission to edit SlackNotifications.</error></errors>");
        }
      }
    }

    if (request.getMethod().equalsIgnoreCase("get")
        && request.getParameter("projectId") != null
        && request.getParameter("projectId").startsWith("project")) {

      SlackNotificationProjectSettings projSettings1 =
          (SlackNotificationProjectSettings)
              mySettings.getSettings(request.getParameter("projectId"), "slackNotifications");
      SProject project =
          this.myServer.getProjectManager().findProjectById(request.getParameter("projectId"));

      String message = projSettings1.getSlackNotificationsAsString();

      params.put("haveProject", "true");
      params.put("messages", message);
      params.put("projectId", project.getProjectId());
      params.put("projectExternalId", TeamCityIdResolver.getExternalProjectId(project));
      params.put("projectName", project.getName());

      params.put("slackNotificationCount", projSettings1.getSlackNotificationsCount());
      if (projSettings1.getSlackNotificationsCount() == 0) {
        params.put("noSlackNotifications", "true");
        params.put("slackNotifications", "false");
      } else {
        params.put("noSlackNotifications", "false");
        params.put("slackNotifications", "true");
        params.put("slackNotificationList", projSettings.getSlackNotificationsAsList());
        params.put("slackNotificationsDisabled", !projSettings.isEnabled());
        params.put("slackNotificationsEnabledAsChecked", projSettings.isEnabledAsChecked());
        params.put(
            "projectSlackNotificationsAsJson",
            ProjectSlackNotificationsBeanJsonSerialiser.serialise(
                ProjectSlackNotificationsBean.build(projSettings, project, myMainSettings)));
      }
    } else {
      params.put("haveProject", "false");
    }

    return new ModelAndView(myPluginPath + "SlackNotification/ajaxEdit.jsp", params);
  }