use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class SearchUsersAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
SearchQualityProfileUsersRequest wsRequest = buildRequest(request);
try (DbSession dbSession = dbClient.openSession(false)) {
QProfileDto profile = wsSupport.getProfile(dbSession, wsRequest.getQualityProfile(), wsRequest.getLanguage());
wsSupport.checkCanEdit(dbSession, profile);
SearchQualityProfilePermissionQuery query = builder().setProfile(profile).setQuery(wsRequest.getQuery()).setMembership(MEMBERSHIP.get(fromParam(wsRequest.getSelected()))).build();
int total = dbClient.qProfileEditUsersDao().countByQuery(dbSession, query);
List<SearchUserMembershipDto> usersMembership = dbClient.qProfileEditUsersDao().selectByQuery(dbSession, query, forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize()));
Map<String, UserDto> usersById = dbClient.userDao().selectByUuids(dbSession, usersMembership.stream().map(SearchUserMembershipDto::getUserUuid).collect(toList())).stream().collect(uniqueIndex(UserDto::getUuid));
writeProtobuf(SearchUsersResponse.newBuilder().addAllUsers(usersMembership.stream().map(userMembershipDto -> toUser(usersById.get(userMembershipDto.getUserUuid()), userMembershipDto.isSelected())).collect(toList())).setPaging(buildPaging(wsRequest, total)).build(), request, response);
}
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
QProfileDto profile = qProfileWsSupport.getProfile(dbSession, QProfileReference.fromKey(request.mandatoryParam(PARAM_KEY)));
boolean isDefault = dbClient.defaultQProfileDao().isDefault(dbSession, profile.getKee());
ActiveRuleCountQuery.Builder builder = ActiveRuleCountQuery.builder();
long activeRuleCount = countActiveRulesByQuery(dbSession, profile, builder);
long deprecatedActiveRuleCount = countActiveRulesByQuery(dbSession, profile, builder.setRuleStatus(DEPRECATED));
long projectCount = countProjectsByProfiles(dbSession, profile);
CompareToSonarWay compareToSonarWay = getSonarWay(request, dbSession, profile);
writeProtobuf(buildResponse(profile, isDefault, getLanguage(profile), activeRuleCount, deprecatedActiveRuleCount, projectCount, compareToSonarWay), request, response);
}
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class DeactivateRulesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String qualityProfileKey = request.mandatoryParam(PARAM_TARGET_KEY);
userSession.checkLoggedIn();
BulkChangeResult result;
try (DbSession dbSession = dbClient.openSession(false)) {
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
wsSupport.checkCanEdit(dbSession, profile);
RuleQuery ruleQuery = ruleQueryFactory.createRuleQuery(dbSession, request);
ruleQuery.setIncludeExternal(false);
result = ruleActivator.bulkDeactivateAndCommit(dbSession, profile, ruleQuery);
}
writeResponse(result, response);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class ExportAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String name = request.param(PARAM_QUALITY_PROFILE);
String language = request.mandatoryParam(PARAM_LANGUAGE);
try (DbSession dbSession = dbClient.openSession(false)) {
QProfileDto profile = loadProfile(dbSession, language, name);
String exporterKey = exporters.exportersForLanguage(profile.getLanguage()).isEmpty() ? null : request.param(PARAM_EXPORTER_KEY);
writeResponse(dbSession, profile, exporterKey, response);
}
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class ProjectsAction method loadAllProjects.
private List<ProjectQprofileAssociationDto> loadAllProjects(String profileKey, DbSession session, String selected, String query) {
QProfileDto profile = dbClient.qualityProfileDao().selectByUuid(session, profileKey);
if (profile == null) {
throw new NotFoundException("Quality profile not found: " + profileKey);
}
List<ProjectQprofileAssociationDto> projects;
SelectionMode selectionMode = SelectionMode.fromParam(selected);
if (SelectionMode.SELECTED == selectionMode) {
projects = dbClient.qualityProfileDao().selectSelectedProjects(session, profile, query);
} else if (SelectionMode.DESELECTED == selectionMode) {
projects = dbClient.qualityProfileDao().selectDeselectedProjects(session, profile, query);
} else {
projects = dbClient.qualityProfileDao().selectProjectAssociations(session, profile, query);
}
return projects;
}
Aggregations