use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class RemoveProjectAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
RemoveProjectRequest removeProjectRequest = toWsRequest(request);
try (DbSession dbSession = dbClient.openSession(false)) {
String profileKey = projectAssociationFinder.getProfileKey(removeProjectRequest.getLanguage(), removeProjectRequest.getProfileName(), removeProjectRequest.getProfileKey());
ComponentDto project = projectAssociationFinder.getProject(dbSession, removeProjectRequest.getProjectKey(), removeProjectRequest.getProjectUuid());
profileProjectOperations.removeProject(dbSession, profileKey, project);
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class RegisterQualityProfiles method start.
public void start() {
Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register quality profiles");
DbSession session = dbClient.openSession(false);
try {
List<ActiveRuleChange> changes = new ArrayList<>();
ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage();
for (String language : profilesByLanguage.keySet()) {
List<RulesProfile> defs = profilesByLanguage.get(language);
if (verifyLanguage(language, defs)) {
changes.addAll(registerProfilesForLanguage(session, language, defs));
}
}
activeRuleIndexer.index(changes);
profiler.stopDebug();
} finally {
session.close();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class RuleActivator method bulkDeactivate.
BulkChangeResult bulkDeactivate(RuleQuery ruleQuery, String profile) {
DbSession dbSession = db.openSession(false);
BulkChangeResult result = new BulkChangeResult();
try {
Iterator<RuleKey> rules = ruleIndex.searchAll(ruleQuery);
while (rules.hasNext()) {
try {
RuleKey ruleKey = rules.next();
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey);
List<ActiveRuleChange> changes = deactivate(dbSession, key);
result.addChanges(changes);
if (!changes.isEmpty()) {
result.incrementSucceeded();
}
} catch (BadRequestException e) {
// other exceptions stop the bulk activation
result.incrementFailed();
result.getErrors().addAll(e.errors());
}
}
dbSession.commit();
activeRuleIndexer.index(result.getChanges());
return result;
} finally {
dbSession.close();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class DeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
qProfileWsSupport.checkQProfileAdminPermission();
try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
profileFactory.delete(dbSession, profile.getKey(), false);
dbSession.commit();
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ServerUserSession method componentUuidToProjectUuid.
@Override
protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
String projectUuid = projectUuidByComponentUuid.get(componentUuid);
if (projectUuid != null) {
return Optional.of(projectUuid);
}
try (DbSession dbSession = dbClient.openSession(false)) {
com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
if (!component.isPresent()) {
return Optional.empty();
}
projectUuid = component.get().projectUuid();
projectUuidByComponentUuid.put(componentUuid, projectUuid);
return Optional.of(projectUuid);
}
}
Aggregations