Package org.sonar.core.qualityprofile.db

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


    return activeRule;
  }

  private ActiveRuleDto doUpdate(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
    ActiveRuleDao dao = db.activeRuleDao();
    ActiveRuleDto activeRule = context.activeRule();
    String severity = change.getSeverity();
    if (severity != null) {
      activeRule.setSeverity(severity);
    }
    ActiveRule.Inheritance inheritance = change.getInheritance();
    if (inheritance != null) {
      activeRule.setInheritance(inheritance.name());
    }
    dao.update(dbSession, activeRule);

    for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
      ActiveRuleParamDto activeRuleParamDto = context.activeRuleParamsAsMap().get(param.getKey());
View Full Code Here


   * @deprecated do not use ids but keys
   */
  @CheckForNull
  @Deprecated
  public ActiveRuleDto getById(DbSession session, int activeRuleId) {
    ActiveRuleDto activeRule = mapper(session).selectById(activeRuleId);
    if (activeRule != null) {
      QualityProfileDto profile = profileDao.getById(activeRule.getProfileId(), session);
      RuleDto rule = ruleDao.getById(session, activeRule.getRuleId());
      if (profile != null && rule != null) {
        activeRule.setKey(ActiveRuleKey.of(profile.getKey(), rule.getKey()));
        return activeRule;
      }
    }
    return null;
  }
View Full Code Here

    return item;
  }

  @Override
  protected void doDeleteByKey(DbSession session, ActiveRuleKey key) {
    ActiveRuleDto activeRule = getNullableByKey(session, key);
    if (activeRule != null) {
      mapper(session).deleteParameters(activeRule.getId());
      mapper(session).delete(activeRule.getId());
    }
  }
View Full Code Here

    return activeRuleParam;
  }

  public void removeParamByKeyAndName(DbSession session, ActiveRuleKey key, String param) {
    // TODO SQL rewrite to delete by key
    ActiveRuleDto activeRule = getNullableByKey(session, key);
    if (activeRule != null) {
      ActiveRuleParamDto activeRuleParam = mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), param);
      if (activeRuleParam != null) {
        mapper(session).deleteParameter(activeRuleParam.getId());
      }
    }
  }
View Full Code Here

   * Finder methods for ActiveRuleParams
   */

  public List<ActiveRuleParamDto> findParamsByActiveRuleKey(DbSession session, ActiveRuleKey key) {
    Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL);
    ActiveRuleDto activeRule = this.getByKey(session, key);
    return mapper(session).selectParamsByActiveRuleId(activeRule.getId());
  }
View Full Code Here

  @CheckForNull
  public ActiveRuleParamDto getParamByKeyAndName(ActiveRuleKey key, String name, DbSession session) {
    Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL);
    Preconditions.checkNotNull(name, PARAMETER_NAME_CANNOT_BE_NULL);
    ActiveRuleDto activeRule = getNullableByKey(session, key);
    if (activeRule != null) {
      return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), name);
    }
    return null;
  }
View Full Code Here

    db.qualityProfileDao().insert(dbSession, profile1);

    RuleDto rule1 = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR);
    db.ruleDao().insert(dbSession, rule1);

    ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile1, rule1).setSeverity("BLOCKER");
    db.activeRuleDao().insert(dbSession, activeRule);
    dbSession.commit();

    // 1. Synchronize since 0
    tester.clearIndexes();
    assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull();
    db.activeRuleDao().synchronizeAfter(dbSession, new Date(0L));
    dbSession.commit();
    assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull();

    // 2. Synchronize since beginning
    tester.clearIndexes();
    assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull();
    db.activeRuleDao().synchronizeAfter(dbSession, beginning);
    dbSession.commit();
    assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull();

    // 3. Assert startup picks it up
    tester.clearIndexes();
    assertThat(index.get(ActiveRuleIndex.class).getLastSynchronization()).isNull();
    tester.get(Platform.class).executeStartupTasks();
    assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull();
    assertThat(index.get(ActiveRuleIndex.class).getLastSynchronization()).isNotNull();
  }
View Full Code Here

    db.qualityProfileDao().insert(dbSession, profileDto);
    RuleKey ruleKey = RuleTesting.XOO_X1;
    RuleDto ruleDto = newRuleDto(ruleKey);
    db.ruleDao().insert(dbSession, ruleDto);

    ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto)
      .setInheritance(ActiveRule.Inheritance.INHERITED.name())
      .setSeverity(Severity.BLOCKER);
    db.activeRuleDao().insert(dbSession, activeRule);
    dbSession.commit();

    // verify db
    assertThat(db.activeRuleDao().getByKey(dbSession, activeRule.getKey())).isNotNull();
    List<ActiveRuleDto> persistedDtos = db.activeRuleDao().findByRule(dbSession, ruleDto);
    assertThat(persistedDtos).hasSize(1);

    // verify es
    ActiveRule hit = index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey());
    assertThat(hit).isNotNull();
    assertThat(hit.key()).isEqualTo(activeRule.getKey());
    assertThat(hit.inheritance().name()).isEqualTo(activeRule.getInheritance());
    assertThat(hit.parentKey()).isNull();
    assertThat(hit.severity()).isEqualTo(activeRule.getSeverityString());
  }
View Full Code Here

    RuleParamDto maxParam = new RuleParamDto()
      .setName("max")
      .setType("STRING");
    db.ruleDao().addRuleParam(dbSession, ruleDto, maxParam);

    ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto)
      .setInheritance(ActiveRule.Inheritance.INHERITED.name())
      .setSeverity(Severity.BLOCKER);
    db.activeRuleDao().insert(dbSession, activeRule);

    ActiveRuleParamDto activeRuleMinParam = ActiveRuleParamDto.createFor(minParam)
      .setValue("minimum");
    db.activeRuleDao().addParam(dbSession, activeRule, activeRuleMinParam);

    ActiveRuleParamDto activeRuleMaxParam = ActiveRuleParamDto.createFor(maxParam)
      .setValue("maximum");
    db.activeRuleDao().addParam(dbSession, activeRule, activeRuleMaxParam);

    dbSession.commit();

    // verify db
    List<ActiveRuleParamDto> persistedDtos =
      db.activeRuleDao().findParamsByActiveRuleKey(dbSession, activeRule.getKey());
    assertThat(persistedDtos).hasSize(2);

    // verify es
    ActiveRule rule = index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey());
    assertThat(rule).isNotNull();
    assertThat(rule.params()).hasSize(2);
    assertThat(rule.params().keySet()).containsOnly("min", "max");
    assertThat(rule.params().values()).containsOnly("minimum", "maximum");
    assertThat(rule.params().get("min")).isEqualTo("minimum");
View Full Code Here

    int nb = 100;
    for (int i = 0; i < nb; i++) {
      RuleDto rule = newRuleDto(RuleKey.of("xoo", "S00" + i));
      db.ruleDao().insert(dbSession, rule);

      ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, rule).setSeverity(Severity.MAJOR);
      db.activeRuleDao().insert(dbSession, activeRule);
    }
    dbSession.commit();
    dbSession.clearCache();
View Full Code Here

TOP

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

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.