use of org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY in project sonarqube by SonarSource.
the class ProjectsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String profileKey = request.mandatoryParam(PARAM_KEY);
try (DbSession session = dbClient.openSession(false)) {
String selected = request.param(Param.SELECTED);
String query = request.param(Param.TEXT_QUERY);
int page = request.mandatoryParamAsInt(Param.PAGE);
int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
List<ProjectQprofileAssociationDto> projects = loadAllProjects(profileKey, session, selected, query).stream().sorted(comparing(ProjectQprofileAssociationDto::getProjectName).thenComparing(ProjectQprofileAssociationDto::getProjectUuid)).collect(MoreCollectors.toList());
Collection<String> projectUuids = projects.stream().map(ProjectQprofileAssociationDto::getProjectUuid).collect(MoreCollectors.toSet());
Set<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedProjectUuids(session, projectUuids, userSession.getUuid(), UserRole.USER);
Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(authorizedProjectUuids.size());
List<ProjectQprofileAssociationDto> authorizedProjects = projects.stream().filter(input -> authorizedProjectUuids.contains(input.getProjectUuid())).skip(paging.offset()).limit(paging.pageSize()).collect(MoreCollectors.toList());
writeProjects(response, authorizedProjects, paging);
}
}
use of org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY in project sonarqube by SonarSource.
the class ShowActionTest method statistics.
@Test
public void statistics() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
// Active rules
range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
// Deprecated rules
range(0, 3).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(XOO1.getKey()).setStatus(DEPRECATED)).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
// Projects
range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()));
assertThat(result.getProfile()).extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount, QualityProfile::getProjectCount).containsExactly(13L, 3L, 7L);
}
use of org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY in project sonarqube by SonarSource.
the class ShowActionTest method compare_to_sonar_way_profile_when_same_active_rules.
@Test
public void compare_to_sonar_way_profile_when_same_active_rules() {
QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
db.qualityProfiles().activateRule(profile, commonRule);
db.qualityProfiles().activateRule(sonarWayProfile, commonRule);
ruleIndexer.indexAll();
activeRuleIndexer.indexAll();
CompareToSonarWay result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")).getCompareToSonarWay();
assertThat(result).extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount).containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName(), 0L);
}
use of org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY in project sonarqube by SonarSource.
the class ShowActionTest method json_example.
@Test
public void json_example() {
Language cs = newLanguage("cs", "C#");
QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setKee("AU-TpxcA-iU5OvuD2FL1").setName("Parent Company Profile").setLanguage(cs.getKey()));
QProfileDto profile = db.qualityProfiles().insert(p -> p.setKee("AU-TpxcA-iU5OvuD2FL3").setName("My Company Profile").setLanguage(cs.getKey()).setIsBuiltIn(false).setRulesUpdatedAt("2016-12-22T19:10:03+0100").setParentKee(parentProfile.getKee()));
// Active rules
range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
// Projects
range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
ws = new WsActionTester(new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession), new Languages(cs), ruleIndex));
String result = ws.newRequest().setParam(PARAM_KEY, profile.getKee()).execute().getInput();
assertJson(result).ignoreFields("rulesUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
}
use of org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY in project sonarqube by SonarSource.
the class ShowActionTest method compare_to_sonar_way_profile.
@Test
public void compare_to_sonar_way_profile() {
QProfileDto sonarWayProfile = db.qualityProfiles().insert(p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto sonarWayRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto sonarWayRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto profileRule1 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto profileRule2 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto profileRule3 = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
db.qualityProfiles().activateRule(profile, commonRule);
db.qualityProfiles().activateRule(profile, profileRule1);
db.qualityProfiles().activateRule(profile, profileRule2);
db.qualityProfiles().activateRule(profile, profileRule3);
db.qualityProfiles().activateRule(sonarWayProfile, commonRule);
db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule1);
db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule2);
ruleIndexer.indexAll();
activeRuleIndexer.indexAll();
CompareToSonarWay result = call(ws.newRequest().setParam(PARAM_KEY, profile.getKee()).setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")).getCompareToSonarWay();
assertThat(result).extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount).containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName(), 2L);
}
Aggregations