use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class UpdateQualityProfilesLastUsedDateStep method execute.
@Override
public void execute() {
try (DbSession dbSession = dbClient.openSession(true)) {
Component root = treeRootHolder.getRoot();
Metric metric = metricRepository.getByKey(QUALITY_PROFILES_KEY);
Set<QualityProfile> qualityProfiles = parseQualityProfiles(measureRepository.getRawMeasure(root, metric));
if (qualityProfiles.isEmpty()) {
return;
}
List<QualityProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
dtos.addAll(getAncestors(dbSession, dtos));
long analysisDate = analysisMetadataHolder.getAnalysisDate();
dtos.forEach(dto -> {
dto.setLastUsed(analysisDate);
dbClient.qualityProfileDao().update(dbSession, dto);
});
dbSession.commit();
}
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class UpdateQualityProfilesLastUsedDateStep method incrementAncestors.
private void incrementAncestors(DbSession session, QualityProfileDto profile, List<QualityProfileDto> ancestors) {
String parentKey = profile.getParentKee();
if (parentKey != null) {
QualityProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByKey(session, parentKey);
ancestors.add(parentDto);
incrementAncestors(session, parentDto, ancestors);
}
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class QProfileFactory method create.
public QualityProfileDto create(DbSession dbSession, QProfileName name) {
QualityProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(name.getName(), name.getLanguage(), dbSession);
checkRequest(dto == null, "Quality profile already exists: %s", name);
return doCreate(dbSession, name);
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class QProfileFactory method doCreate.
private QualityProfileDto doCreate(DbSession dbSession, QProfileName name) {
if (StringUtils.isEmpty(name.getName())) {
throw BadRequestException.create("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()).setOrganizationUuid(defaultOrganizationProvider.get().getUuid()).setLanguage(name.getLanguage()).setRulesUpdatedAtAsDate(now);
if (db.qualityProfileDao().selectByKey(dbSession, dto.getKey()) == null) {
db.qualityProfileDao().insert(dbSession, dto);
return dto;
}
}
throw new IllegalStateException("Failed to create an unique quality profile for " + name);
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class QProfileFactory method rename.
// ------------- RENAME
public boolean rename(String key, String newName) {
checkRequest(StringUtils.isNotBlank(newName), "Name must be set");
checkRequest(newName.length() < 100, String.format("Name is too long (>%d characters)", 100));
DbSession dbSession = db.openSession(false);
try {
QualityProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, key);
if (profile == null) {
throw new NotFoundException("Quality profile not found: " + key);
}
if (!StringUtils.equals(newName, profile.getName())) {
checkRequest(db.qualityProfileDao().selectByNameAndLanguage(newName, profile.getLanguage(), dbSession) == null, "Quality profile already exists: %s", newName);
profile.setName(newName);
db.qualityProfileDao().update(dbSession, profile);
dbSession.commit();
return true;
}
return false;
} finally {
dbSession.close();
}
}
Aggregations