Package org.sonar.server.exceptions

Examples of org.sonar.server.exceptions.BadRequestException


  }

  public static void checkMandatorySizeParameter(String value, String paramName, Integer size) {
    checkMandatoryParameter(value, paramName);
    if (!Strings.isNullOrEmpty(value) && value.length() > size) {
      throw new BadRequestException(Validation.IS_TOO_LONG_MESSAGE, paramName, size);
    }
  }
View Full Code Here


  }

  @Override
  public void validate(String value, @Nullable List<String> options) {
    if (!StringUtils.equalsIgnoreCase(value, "true") && !StringUtils.equalsIgnoreCase(value, "false")) {
      throw new BadRequestException("errors.type.notBoolean", value);
    }
  }
View Full Code Here

    return builder.build();
  }

  public void deactivate(String login) {
    if (Strings.isNullOrEmpty(login)) {
      throw new BadRequestException("Login is missing");
    }
    UserSession userSession = UserSession.get();
    userSession.checkGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
    if (Objects.equal(userSession.login(), login)) {
      throw new BadRequestException("Self-deactivation is not possible");
    }
    dao.deactivateUserByLogin(login);
  }
View Full Code Here

    ActiveRuleChange change;
    if (context.activeRule() == null) {
      return changes;
    }
    if (!force && !isCascade && context.activeRule().getInheritance() != null) {
      throw new BadRequestException("Cannot deactivate inherited rule '" + key.ruleKey() + "'");
    }
    change = ActiveRuleChange.createFor(ActiveRuleChange.Type.DEACTIVATED, key);
    changes.add(change);
    persist(change, context, dbSession);
View Full Code Here

      removeParent(dbSession, profile);

    } else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
      QualityProfileDto parentProfile = db.qualityProfileDao().getNonNullByKey(dbSession, parentKey);
      if (isDescendant(dbSession, profile, parentProfile)) {
        throw new BadRequestException(String.format("Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey));
      }
      removeParent(dbSession, profile);

      // set new parent
      profile.setParentKee(parentKey);
View Full Code Here

        session);
      if (needUpdate) {
        session.commit();
      }
    } catch (IllegalArgumentException e) {
      throw new BadRequestException(e.getMessage());
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
View Full Code Here

    }
  }

  private void checkOptionalSizeParameter(String value, String paramName, Integer size) {
    if (!Strings.isNullOrEmpty(value) && value.length() > size) {
      throw new BadRequestException(Validation.IS_TOO_LONG_MESSAGE, paramName, size);
    }
  }
View Full Code Here

  public Long createComponent(String kee, String name, String qualifier) {
    // Sub view should not be created with provisioning. Will be fixed by http://jira.sonarsource.com/browse/VIEWS-296
    if (!Qualifiers.SUBVIEW.equals(qualifier)) {
      ComponentDto component = (ComponentDto) resourceDao.findByKey(kee);
      if (component != null) {
        throw new BadRequestException(formatMessage("Could not create %s, key already exists: %s", qualifier, kee));
      }
      checkKeyFormat(qualifier, kee);

      String uuid = UUID.randomUUID().toString();
      resourceDao.insertOrUpdate(
        new ResourceDto()
          .setUuid(uuid)
          .setProjectUuid(uuid)
          .setKey(kee)
          .setDeprecatedKey(kee)
          .setName(name)
          .setLongName(name)
          .setScope(Scopes.PROJECT)
          .setQualifier(qualifier)
          .setCreatedAt(new Date()));
      component = (ComponentDto) resourceDao.findByKey(kee);
      if (component == null) {
        throw new BadRequestException(String.format("Component not created: %s", kee));
      }
      resourceIndexerDao.indexResource(component.getId());
      return component.getId();
    }
    return null;
View Full Code Here

    return builder.build();
  }

  private void checkKeyFormat(String qualifier, String kee) {
    if (!ComponentKeys.isValidModuleKey(kee)) {
      throw new BadRequestException(formatMessage("Malformed key for %s: %s. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.",
        qualifier, kee));
    }
  }
View Full Code Here

  @Override
  public void handle(Request request, Response response) {
    String customKey = request.param(PARAM_CUSTOM_KEY);
    String manualKey = request.param(PARAM_MANUAL_KEY);
    if (Strings.isNullOrEmpty(customKey) && Strings.isNullOrEmpty(manualKey)) {
      throw new BadRequestException(String.format("Either '%s' or '%s' parameters should be set", PARAM_CUSTOM_KEY, PARAM_MANUAL_KEY));
    }

    try {
      if (!Strings.isNullOrEmpty(customKey)) {
        NewRule newRule = NewRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY)))
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.