Package org.sonar.server.exceptions

Examples of org.sonar.server.exceptions.BadRequestException


    }
  }

  private void validatePermission(String permission) {
    if (permission == null || !ComponentPermissions.ALL.contains(permission)) {
      throw new BadRequestException("Invalid permission: " + permission);
    }
  }
View Full Code Here


  }

  private Long getTemplateId(String key) {
    PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectTemplateByKey(key);
    if (permissionTemplateDto == null) {
      throw new BadRequestException("Unknown template: " + key);
    }
    return permissionTemplateDto.getId();
  }
View Full Code Here

    validateUserGroup();
  }

  private void validateUserGroup() {
    if (StringUtils.isBlank(user) && StringUtils.isBlank(group)) {
      throw new BadRequestException("Missing user or group parameter");
    }
    if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(group)) {
      throw new BadRequestException("Only one of user or group parameter should be provided");
    }
  }
View Full Code Here

    }
  }

  private void validatePermission() {
    if (StringUtils.isBlank(permission)) {
      throw new BadRequestException("Missing permission parameter");
    }
    if (Strings.isNullOrEmpty(component)){
      if (!GlobalPermissions.ALL.contains(permission)) {
        throw new BadRequestException(String.format("Invalid global permission key %s. Valid values are %s", permission, GlobalPermissions.ALL));
      }
    } else {
      if (!ComponentPermissions.ALL.contains(permission)) {
        throw new BadRequestException(String.format("Invalid component permission key %s. Valid values are %s", permission, ComponentPermissions.ALL));
      }
    }
  }
View Full Code Here

  }

  public QualityProfileDto create(DbSession dbSession, QProfileName name) {
    QualityProfileDto dto = db.qualityProfileDao().getByNameAndLanguage(name.getName(), name.getLanguage(), dbSession);
    if (dto != null) {
      throw new BadRequestException("Quality profile already exists: " + name);
    }
    return doCreate(dbSession, name);
  }
View Full Code Here

    return doCreate(dbSession, name);
  }

  private QualityProfileDto doCreate(DbSession dbSession, QProfileName name) {
    if (StringUtils.isEmpty(name.getName())) {
      throw new BadRequestException("quality_profiles.profile_name_cant_be_blank");
    }
    Date now = new Date();
    for (int i = 0; i < 20; i++) {
      String key = Slug.slugify(String.format("%s %s %s", name.getLanguage(), name.getName(), RandomStringUtils.randomNumeric(5)));
      QualityProfileDto dto = QualityProfileDto.createFor(key)
View Full Code Here

    return db.qualityProfileDao().getByNameAndLanguage(name, language, session);
  }

  private void checkNotDefault(@Nullable QualityProfileDto defaultProfile, QualityProfileDto p) {
    if (defaultProfile != null && defaultProfile.getKey().equals(p.getKey())) {
      throw new BadRequestException("The profile marked as default can not be deleted: " + p.getKey());
    }
  }
View Full Code Here

    DbSession dbSession = db.openSession(false);
    try {
      QualityProfileDto profile = db.qualityProfileDao().getNonNullByKey(dbSession, key);
      if (!StringUtils.equals(newName, profile.getName())) {
        if (db.qualityProfileDao().getByNameAndLanguage(newName, profile.getLanguage(), dbSession) != null) {
          throw new BadRequestException("Quality profile already exists: " + newName);
        }
        String previousName = profile.getName();
        profile.setName(newName);
        db.qualityProfileDao().update(dbSession, profile);
        db.propertiesDao().updateProperties(PROFILE_PROPERTY_PREFIX + profile.getLanguage(), previousName, newName, dbSession);
View Full Code Here

  }

  private void validateTemplateName(@Nullable Long templateId, String templateName) {
    if (StringUtils.isEmpty(templateName)) {
      String errorMsg = "Name can't be blank";
      throw new BadRequestException(errorMsg);
    }
    List<PermissionTemplateDto> existingTemplates = permissionTemplateDao.selectAllPermissionTemplates();
    if (existingTemplates != null) {
      for (PermissionTemplateDto existingTemplate : existingTemplates) {
        if ((templateId == null || !existingTemplate.getId().equals(templateId)) && (existingTemplate.getName().equals(templateName))) {
          String errorMsg = "A template with that name already exists";
          throw new BadRequestException(errorMsg);
        }
      }
    }
  }
View Full Code Here

    }
    try {
      Pattern.compile(keyPattern);
    } catch (PatternSyntaxException e) {
      String errorMsg = "Invalid pattern: " + keyPattern + ". Should be a valid Java regular expression.";
      throw new BadRequestException(errorMsg);
    }
  }
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.