use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ResetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
ResetRequest resetRequest = toWsRequest(request);
Optional<ComponentDto> component = getComponent(dbSession, resetRequest);
checkPermissions(component);
resetRequest.getKeys().forEach(key -> {
SettingData data = new SettingData(key, emptyList(), component.orElse(null));
ImmutableList.of(validations.scope(), validations.qualifier()).forEach(validation -> validation.accept(data));
});
List<String> keys = getKeys(resetRequest);
if (component.isPresent()) {
settingsUpdater.deleteComponentSettings(dbSession, component.get(), keys);
} else {
settingsUpdater.deleteGlobalSettings(dbSession, keys);
}
dbSession.commit();
response.noContent();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class HashAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession session = dbClient.openSession(false)) {
String componentKey = request.mandatoryParam("key");
ComponentDto component = componentFinder.getByKey(session, componentKey);
userSession.checkComponentPermission(UserRole.USER, component);
response.stream().setMediaType("text/plain");
try (OutputStreamWriter writer = new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8)) {
HashFunction hashFunction = new HashFunction(writer, componentKey);
dbClient.fileSourceDao().readLineHashesStream(session, component.uuid(), hashFunction);
if (!hashFunction.hasData()) {
response.noContent();
}
}
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class IndexAction method handle.
@Override
public void handle(Request request, Response response) {
String fileKey = request.mandatoryParam("resource");
int from = request.mandatoryParamAsInt("from");
Integer to = request.paramAsInt("to");
try (DbSession session = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByKey(session, fileKey);
userSession.checkComponentPermission(UserRole.CODEVIEWER, component);
Optional<Iterable<String>> lines = sourceService.getLinesAsRawText(session, component.uuid(), from, to == null ? Integer.MAX_VALUE : to - 1);
JsonWriter json = response.newJsonWriter().beginArray().beginObject();
if (lines.isPresent()) {
int lineCounter = from;
for (String line : lines.get()) {
json.prop(String.valueOf(lineCounter), line);
lineCounter++;
}
}
json.endObject().endArray().close();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class CoveredFilesAction method buildComponentsByUuid.
private Map<String, ComponentDto> buildComponentsByUuid(List<CoveredFileDoc> coveredFiles) {
List<String> sourceFileUuids = Lists.transform(coveredFiles, new CoveredFileToFileUuidFunction());
List<ComponentDto> components;
try (DbSession dbSession = dbClient.openSession(false)) {
components = dbClient.componentDao().selectByUuids(dbSession, sourceFileUuids);
}
return Maps.uniqueIndex(components, ComponentDto::uuid);
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) {
String fileKey = request.mandatoryParam("key");
int from = Math.max(request.paramAsInt("from"), 1);
int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto file = componentFinder.getByKey(dbSession, fileKey);
userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
Iterable<String> linesHtml = checkFoundWithOptional(sourceService.getLinesAsHtml(dbSession, file.uuid(), from, to), "No source found for file '%s'", fileKey);
JsonWriter json = response.newJsonWriter().beginObject();
writeSource(linesHtml, from, json);
json.endObject().close();
}
}
Aggregations