use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class BulkApplyTemplateAction method doHandle.
private void doHandle(BulkApplyTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
ComponentQuery componentQuery = ComponentQuery.builder().setNameOrKeyQuery(request.getQuery()).setQualifiers(qualifiers(request.getQualifier())).build();
List<ComponentDto> projects = dbClient.componentDao().selectByQuery(dbSession, template.getOrganizationUuid(), componentQuery, 0, Integer.MAX_VALUE);
permissionTemplateService.apply(dbSession, template, projects);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class DeleteTemplateAction method doHandle.
private void doHandle(DeleteTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = finder.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
DefaultTemplates defaultTemplates = retrieveDefaultTemplates(dbSession, template);
checkTemplateUuidIsNotDefault(template, defaultTemplates);
dbClient.permissionTemplateDao().deleteById(dbSession, template.getId());
updateViewDefaultTemplateWhenGovernanceIsNotInstalled(dbSession, template, defaultTemplates);
dbSession.commit();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class QProfileComparison method compare.
public QProfileComparisonResult compare(String leftKey, String rightKey) {
try (DbSession dbSession = dbClient.openSession(false)) {
QProfileComparisonResult result = new QProfileComparisonResult();
compare(dbSession, leftKey, rightKey, result);
return result;
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class QProfileExporters method wrap.
private RulesProfile wrap(QualityProfileDto profile) {
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
ListMultimap<Integer, ActiveRuleParamDto> activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId);
for (ActiveRuleDto activeRule : activeRuleDtos) {
// TODO all rules should be loaded by using one query with all active rule keys as parameter
Rule rule = ruleFinder.findByKey(activeRule.getKey().ruleKey());
org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId());
for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
}
}
return target;
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class IndexAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
List<ComponentDto> projects = getAuthorizedComponents(dbSession, searchComponents(dbSession, request));
JsonWriter json = response.newJsonWriter();
json.beginArray();
for (ComponentDto project : projects) {
addProject(json, project);
}
json.endArray();
json.close();
}
}
Aggregations