Package org.sonar.core.qualityprofile.db

Examples of org.sonar.core.qualityprofile.db.ActiveRuleKey


    request.setParam(RuleActivationActions.SEVERITY, "MINOR");
    WsTester.Result result = request.execute();
    session.clearCache();

    // 2. Assert ActiveRule in DAO
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey());

    assertThat(db.activeRuleDao().getNullableByKey(session, activeRuleKey).getSeverityString())
      .isEqualTo("MINOR");
  }
View Full Code Here


    context.setRuleParams(db.ruleDao().findRuleParamsByRuleKey(dbSession, rule.getKey()));
    return rule;
  }

  private void initActiveRules(String profileKey, RuleKey ruleKey, RuleActivatorContext context, DbSession session, boolean parent) {
    ActiveRuleKey key = ActiveRuleKey.of(profileKey, ruleKey);
    ActiveRuleDto activeRule = db.activeRuleDao().getNullableByKey(session, key);
    Collection<ActiveRuleParamDto> activeRuleParams = null;
    if (activeRule != null) {
      activeRuleParams = db.activeRuleDao().findParamsByActiveRuleKey(session, key);
    }
View Full Code Here

    // get all inherited profiles
    List<QualityProfileDto> profiles = db.qualityProfileDao().findChildren(dbSession, key.qProfile());

    for (QualityProfileDto profile : profiles) {
      ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), key.ruleKey());
      changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true, force));
    }

    if (!changes.isEmpty()) {
      updateProfileDate(dbSession, context);
View Full Code Here

        .setFieldsToReturn(Arrays.asList(RuleNormalizer.RuleField.KEY.field())));
      Iterator<Rule> rules = ruleSearchResult.scroll();
      while (rules.hasNext()) {
        try {
          Rule rule = rules.next();
          ActiveRuleKey key = ActiveRuleKey.of(profile, rule.key());
          List<ActiveRuleChange> changes = deactivate(dbSession, key);
          result.addChanges(changes);
          if (!changes.isEmpty()) {
            result.incrementSucceeded();
          }
View Full Code Here

    json
      .beginObject()
      .prop("qProfile", activeRule.key().qProfile().toString())
      .prop("inherit", activeRule.inheritance().toString())
      .prop("severity", activeRule.severity());
    ActiveRuleKey parentKey = activeRule.parentKey();
    if (parentKey != null) {
      json.prop("parent", parentKey.toString());
    }
    json.name("params").beginArray();
    for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
      json
        .beginObject()
View Full Code Here

    dbSession.close();
  }

  @Test
  public void insert_find_active_rule_change() {
    ActiveRuleKey key = ActiveRuleKey.of("XOO_P1", RuleKey.of("xoo", "X1"));
    ActiveRuleChange change = ActiveRuleChange
      .createFor(ActiveRuleChange.Type.ACTIVATED, key)
      .setInheritance(ActiveRule.Inheritance.INHERITED)
      .setSeverity("BLOCKER")
      .setParameter("param1", "value1");

    service.write(dbSession, Activity.Type.QPROFILE, change);
    dbSession.commit();

    // 0. AssertBase case
    assertThat(index.findAll().getHits()).hasSize(1);

    Activity activity = Iterables.getFirst(index.findAll().getHits(), null);
    assertThat(activity).isNotNull();
    assertThat(activity.details().get("key")).isEqualTo(key.toString());
  }
View Full Code Here

  @Override
  public List<UpdateRequest> normalize(ActiveRuleDto activeRuleDto) {

    List<UpdateRequest> requests = new ArrayList<UpdateRequest>();

    ActiveRuleKey key = activeRuleDto.getKey();
    Preconditions.checkArgument(key != null, "Cannot normalize ActiveRuleDto with null key");

    Map<String, Object> newRule = new HashMap<String, Object>();
    newRule.put("_parent", key.ruleKey().toString());
    newRule.put(ActiveRuleField.RULE_KEY.field(), key.ruleKey().toString());
    newRule.put(ActiveRuleField.KEY.field(), key.toString());
    newRule.put(ActiveRuleField.INHERITANCE.field(),
      (activeRuleDto.getInheritance() != null) ?
        activeRuleDto.getInheritance() :
        ActiveRule.Inheritance.NONE.name());
    newRule.put(ActiveRuleField.SEVERITY.field(), activeRuleDto.getSeverityString());
    newRule.put(ActiveRuleField.KEY.field(), key.toString());

    newRule.put(ActiveRuleField.CREATED_AT.field(), activeRuleDto.getCreatedAt());
    newRule.put(ActiveRuleField.UPDATED_AT.field(), activeRuleDto.getUpdatedAt());

    DbSession session = db.openSession(false);
    try {
      // TODO because DTO uses legacy ID pattern
      QualityProfileDto profile = db.qualityProfileDao().getById(activeRuleDto.getProfileId(), session);
      if (profile == null) {
        throw new IllegalStateException("Profile is null : " + activeRuleDto.getProfileId());
      }
      newRule.put(ActiveRuleField.PROFILE_KEY.field(), profile.getKey());

      // TODO this should be generated by RegisterRule and modified in DTO.
      String parentKey = null;
      Integer parentId = activeRuleDto.getParentId();
      if (parentId != null) {
        ActiveRuleDto parentDto = db.activeRuleDao().getById(session, parentId);
        if (parentDto != null) {
          parentKey = parentDto.getKey().toString();
        }
      }

      /* Creating updateRequest */
      requests.add(new UpdateRequest()
        .replicationType(ReplicationType.ASYNC)
        .routing(key.ruleKey().toString())
        .id(activeRuleDto.getKey().toString())
        .parent(activeRuleDto.getKey().ruleKey().toString())
        .doc(newRule)
        .upsert(getUpsertFor(ActiveRuleField.ALL_FIELDS, newRule)));

View Full Code Here

  }

  @Test
  public void update_activation_but_new_parameter() throws Exception {
    // initial activation
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
    activation.setSeverity(Severity.BLOCKER);
    activate(activation, XOO_P1_KEY);

    assertThat(db.activeRuleDao().getParamByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull();
View Full Code Here

  }

  @Test
  public void do_not_change_severity_and_params_if_unset_and_already_activated() throws Exception {
    // initial activation
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
    activation.setSeverity(Severity.BLOCKER);
    activation.setParameter("max", "7");
    activate(activation, XOO_P1_KEY);
View Full Code Here

  }

  @Test
  public void revert_activation_to_default_severity_and_parameters() throws Exception {
    // initial activation
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1);
    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
    activation.setSeverity(Severity.BLOCKER);
    activation.setParameter("max", "7");
    activation.setParameter("min", "3");
    activate(activation, XOO_P1_KEY);
View Full Code Here

TOP

Related Classes of org.sonar.core.qualityprofile.db.ActiveRuleKey

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.