Package org.sonar.core.qualityprofile.db

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


    // Create custom rule
    RuleDto customRule = RuleTesting.newCustomRule(templateRule).setLanguage("xoo");
    dao.insert(dbSession, customRule);

    // Create a quality profile
    QualityProfileDto profileDto = QProfileTesting.newXooP1();
    db.qualityProfileDao().insert(dbSession, profileDto);
    dbSession.commit();
    dbSession.clearCache();

    // Activate the custom rule
    activate(new RuleActivation(customRule.getKey()).setSeverity(Severity.BLOCKER), QProfileTesting.XOO_P1_KEY);

    // Delete custom rule
    deleter.delete(customRule.getKey());

    // Verify custom rule have status REMOVED
    Rule customRuleReloaded = index.getByKey(customRule.getKey());
    assertThat(customRuleReloaded).isNotNull();
    assertThat(customRuleReloaded.status()).isEqualTo(RuleStatus.REMOVED);

    // Verify there's no more active rule from custom rule
    List<ActiveRule> activeRules = tester.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey());
    assertThat(activeRules).isEmpty();
  }
View Full Code Here


    }
  }

  @CheckForNull
  public QProfile profile(int id, DbSession session) {
    QualityProfileDto dto = findQualityProfile(id, session);
    if (dto != null) {
      return QProfile.from(dto);
    }
    return null;
  }
View Full Code Here

    }
    return null;
  }

  public QProfile profile(String name, String language, DbSession session) {
    QualityProfileDto dto = findQualityProfile(name, language, session);
    if (dto != null) {
      return QProfile.from(dto);
    }
    return null;
  }
View Full Code Here

  public QProfile parent(QProfile profile) {
    DbSession session = db.openSession(false);
    try {
      String parent = profile.parent();
      if (parent != null) {
        QualityProfileDto parentDto = findQualityProfile(parent, profile.language(), session);
        if (parentDto != null) {
          return QProfile.from(parentDto);
        }
      }
      return null;
View Full Code Here

    return ancestors;
  }

  private void incrementAncestors(QProfile profile, List<QProfile> ancestors, DbSession session) {
    if (profile.parent() != null) {
      QualityProfileDto parentDto = db.qualityProfileDao().getParentById(profile.id(), session);
      if (parentDto == null) {
        throw new IllegalStateException("Cannot find parent of profile : " + profile.id());
      }
      QProfile parent = QProfile.from(parentDto);
      ancestors.add(parent);
View Full Code Here

    return exporter.getMimeType();
  }

  public void export(String profileKey, String exporterKey, Writer writer) {
    ProfileExporter exporter = findExporter(exporterKey);
    QualityProfileDto profile = loader.getByKey(profileKey);
    if (profile == null) {
      throw new NotFoundException("Unknown Quality profile: " + profileKey);
    }
    exporter.exportProfile(wrap(profile), writer);
  }
View Full Code Here

  }

  // ------------- CREATION

  QualityProfileDto getOrCreate(DbSession dbSession, QProfileName name) {
    QualityProfileDto profile = db.qualityProfileDao().getByNameAndLanguage(name.getName(), name.getLanguage(), dbSession);
    if (profile == null) {
      profile = doCreate(dbSession, name);
    }
    return profile;
  }
View Full Code Here

    }
    return profile;
  }

  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

      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)
        .setName(name.getName())
        .setLanguage(name.getLanguage())
        .setRulesUpdatedAtAsDate(now);
      if (db.qualityProfileDao().getByKey(dbSession, dto.getKey()) == null) {
        db.qualityProfileDao().insert(dbSession, dto);
        return dto;
      }
    }
View Full Code Here

  /**
   * Session is NOT committed. Profiles marked as "default" for a language can't be deleted,
   * except if the parameter <code>force</code> is true.
   */
  void delete(DbSession session, String key, boolean force) {
    QualityProfileDto profile = db.qualityProfileDao().getNonNullByKey(session, key);
    List<QualityProfileDto> descendants = db.qualityProfileDao().findDescendants(session, key);
    if (!force) {
      QualityProfileDto defaultProfile = getDefault(session, profile.getLanguage());
      checkNotDefault(defaultProfile, profile);
      for (QualityProfileDto descendant : descendants) {
        checkNotDefault(defaultProfile, descendant);
      }
    }
View Full Code Here

TOP

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

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.