use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ValidateProjectStep method execute.
@Override
public void execute() {
try (DbSession dbSession = dbClient.openSession(false)) {
Component root = treeRootHolder.getRoot();
List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey());
Map<String, ComponentDto> baseModulesByKey = from(baseModules).uniqueIndex(ComponentDto::key);
ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
new DepthTraversalTypeAwareCrawler(visitor).visit(root);
if (!visitor.validationMessages.isEmpty()) {
throw MessageException.of("Validation of project failed:\n o " + MESSAGES_JOINER.join(visitor.validationMessages));
}
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class IssueQueryService method createFromRequest.
public IssueQuery createFromRequest(SearchWsRequest request) {
DbSession session = dbClient.openSession(false);
try {
IssueQuery.Builder builder = IssueQuery.builder().issueKeys(request.getIssues()).severities(request.getSeverities()).statuses(request.getStatuses()).resolutions(request.getResolutions()).resolved(request.getResolved()).rules(stringsToRules(request.getRules())).assignees(buildAssignees(request.getAssignees())).languages(request.getLanguages()).tags(request.getTags()).types(request.getTypes()).assigned(request.getAssigned()).createdAt(parseDateOrDateTime(request.getCreatedAt())).createdBefore(parseEndingDateOrDateTime(request.getCreatedBefore())).facetMode(request.getFacetMode());
Set<String> allComponentUuids = Sets.newHashSet();
boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(session, request.getOnComponentOnly(), request.getComponents(), request.getComponentUuids(), request.getComponentKeys(), request.getComponentRootUuids(), request.getComponentRoots(), allComponentUuids);
addComponentParameters(builder, session, effectiveOnComponentOnly, allComponentUuids, request.getProjectUuids(), request.getProjectKeys(), request.getModuleUuids(), request.getDirectories(), request.getFileUuids(), request.getAuthors());
builder.createdAfter(buildCreatedAfterFromRequest(session, request, allComponentUuids));
String sort = request.getSort();
if (!Strings.isNullOrEmpty(sort)) {
builder.sort(sort);
builder.asc(request.getAsc());
}
return builder.build();
} finally {
session.close();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class IssueStorage method update.
/**
* @return the keys of the updated issues
*/
private Collection<String> update(List<DefaultIssue> issuesToUpdate, long now) {
Collection<String> updated = new ArrayList<>();
if (!issuesToUpdate.isEmpty()) {
try (DbSession dbSession = dbClient.openSession(false)) {
IssueChangeMapper issueChangeMapper = dbSession.getMapper(IssueChangeMapper.class);
for (DefaultIssue issue : issuesToUpdate) {
String key = doUpdate(dbSession, now, issue);
updated.add(key);
insertChanges(issueChangeMapper, issue);
}
dbSession.commit();
}
}
return updated;
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class FavoriteFinder method list.
/**
* @return the list of favorite components of the authenticated user. Empty list if the user is not authenticated
*/
public List<ComponentDto> list() {
if (!userSession.isLoggedIn()) {
return emptyList();
}
try (DbSession dbSession = dbClient.openSession(false)) {
PropertyQuery dbQuery = PropertyQuery.builder().setKey(PROP_FAVORITE_KEY).setUserId(userSession.getUserId()).build();
Set<Long> componentIds = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getResourceId).collect(Collectors.toSet());
return dbClient.componentDao().selectByIds(dbSession, componentIds).stream().sorted(Comparator.comparing(ComponentDto::name)).collect(toList());
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class NewIssuesNotification method setStatistics.
public NewIssuesNotification setStatistics(String projectName, NewIssuesStatistics.Stats stats) {
setDefaultMessage(stats.countForMetric(SEVERITY) + " new issues on " + projectName + ".\n");
try (DbSession dbSession = dbClient.openSession(false)) {
setSeverityStatistics(stats);
setAssigneesStatistics(stats);
setTagsStatistics(stats);
setComponentsStatistics(dbSession, stats);
setRuleStatistics(dbSession, stats);
}
return this;
}
Aggregations