Package org.sonar.server.exceptions

Examples of org.sonar.server.exceptions.BadRequestException


    return selectedComponents;
  }

  public void validate() {
    if(StringUtils.isBlank(templateKey)) {
      throw new BadRequestException("Permission template is mandatory");
    }
    if(selectedComponents == null || selectedComponents.isEmpty()) {
      throw new BadRequestException("Please provide at least one entry to which the permission template should be applied");
    }
  }
View Full Code Here


  RuleActivatorContext create(String profileKey, RuleKey ruleKey, DbSession session) {
    RuleActivatorContext context = new RuleActivatorContext();
    QualityProfileDto profile = db.qualityProfileDao().getByKey(session, profileKey);
    if (profile == null) {
      throw new BadRequestException("Quality profile not found: " + profileKey);
    }
    context.setProfile(profile);
    return create(ruleKey, session, context);
  }
View Full Code Here

  RuleActivatorContext create(QProfileName profileName, RuleKey ruleKey, DbSession session) {
    RuleActivatorContext context = new RuleActivatorContext();
    QualityProfileDto profile = db.qualityProfileDao().getByNameAndLanguage(profileName.getName(), profileName.getLanguage(), session);
    if (profile == null) {
      throw new BadRequestException("Quality profile not found: " + profileName);
    }
    context.setProfile(profile);
    return create(ruleKey, session, context);
  }
View Full Code Here

  }

  private RuleDto initRule(RuleKey ruleKey, RuleActivatorContext context, DbSession dbSession) {
    RuleDto rule = db.ruleDao().getNullableByKey(dbSession, ruleKey);
    if (rule == null) {
      throw new BadRequestException("Rule not found: " + ruleKey);
    }
    context.setRule(rule);
    context.setRuleParams(db.ruleDao().findRuleParamsByRuleKey(dbSession, rule.getKey()));
    return rule;
  }
View Full Code Here

  }

  public IssueComment addComment(String issueKey, String text, UserSession userSession) {
    verifyLoggedIn(userSession);
    if (StringUtils.isBlank(text)) {
      throw new BadRequestException("Cannot add empty comments to an issue");
    }

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = issueService.getByKeyForUpdate(session, issueKey).toDefaultIssue();
      IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login());
      updater.addComment(issue, text, context);

      issueService.saveIssue(session, issue, context, text);
      session.commit();

      List<DefaultIssueComment> comments = findComments(issueKey);
      if (comments.isEmpty()) {
        throw new BadRequestException(String.format("Fail to add a comment on issue %s", issueKey));
      }
      return comments.get(comments.size() - 1);
    } finally {
      session.close();
    }
View Full Code Here

  }

  public IssueComment editComment(String commentKey, String text, UserSession userSession) {
    DefaultIssueComment comment = changeDao.selectCommentByKey(commentKey);
    if (StringUtils.isBlank(text)) {
      throw new BadRequestException("Cannot add empty comments to an issue");
    }
    if (comment == null) {
      throw new NotFoundException("Comment not found: " + commentKey);
    }
    if (Strings.isNullOrEmpty(comment.userLogin()) || !Objects.equal(comment.userLogin(), userSession.login())) {
View Full Code Here

  @Override
  public void validate(String value, @Nullable List<String> options) {
    try {
      Double.parseDouble(value);
    } catch (NumberFormatException e) {
      throw new BadRequestException("errors.type.notFloat", value);
    }
  }
View Full Code Here

  @Override
  public void validate(String value, @Nullable List<String> options) {
    try {
      Integer.parseInt(value);
    } catch (NumberFormatException e) {
      throw new BadRequestException("errors.type.notInteger", value);
    }
  }
View Full Code Here

  }

  private WebService.Action getAction(String controllerPath, String actionKey) {
    WebService.Controller controller = context.controller(controllerPath);
    if (controller == null) {
      throw new BadRequestException(String.format("Unknown web service: %s", controllerPath));
    }
    WebService.Action action = controller.action(actionKey);
    if (action == null) {
      throw new BadRequestException(String.format("Unknown action: %s/%s", controllerPath, actionKey));
    }
    return action;
  }
View Full Code Here

    // only static methods
  }

  public static void checkMandatoryParameter(String value, String paramName) {
    if (Strings.isNullOrEmpty(value)) {
      throw new BadRequestException(Validation.CANT_BE_EMPTY_MESSAGE, paramName);
    }
  }
View Full Code Here

TOP

Related Classes of org.sonar.server.exceptions.BadRequestException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.