use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.
the class RepositoriesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String query = request.param(Param.TEXT_QUERY);
String languageKey = request.param(LANGUAGE);
JsonWriter json = response.newJsonWriter().beginObject().name("repositories").beginArray();
for (RuleRepositoryDto repo : listMatchingRepositories(query, languageKey)) {
json.beginObject().prop("key", repo.getKey()).prop("name", repo.getName()).prop(LANGUAGE, repo.getLanguage()).endObject();
}
json.endArray().endObject().close();
}
use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.
the class RepositoriesActionTest method setUp.
@Before
public void setUp() {
DbSession dbSession = dbTester.getSession();
RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
RuleRepositoryDto repo3 = new RuleRepositoryDto("common-ws", "ws", "SonarQube Common");
dbTester.getDbClient().ruleRepositoryDao().insert(dbSession, asList(repo1, repo2, repo3));
dbSession.commit();
wsTester = new WsTester(new RulesWs(new RepositoriesAction(dbTester.getDbClient())));
}
use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.
the class AppActionTest method should_generate_app_init_info.
@Test
public void should_generate_app_init_info() throws Exception {
AppAction app = new AppAction(languages, db.getDbClient(), i18n, userSessionRule, defaultOrganizationProvider);
WsTester tester = new WsTester(new RulesWs(app));
userSessionRule.addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
db.commit();
Language xoo = mock(Language.class);
when(xoo.getKey()).thenReturn("xoo");
when(xoo.getName()).thenReturn("Xoo");
Language whitespace = mock(Language.class);
when(whitespace.getKey()).thenReturn("ws");
when(whitespace.getName()).thenReturn("Whitespace");
when(languages.get("xoo")).thenReturn(xoo);
when(languages.all()).thenReturn(new Language[] { xoo, whitespace });
RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
db.getDbClient().ruleRepositoryDao().insert(db.getSession(), asList(repo1, repo2));
db.getSession().commit();
when(i18n.message(isA(Locale.class), anyString(), anyString())).thenAnswer(invocation -> invocation.getArguments()[1]);
tester.newGetRequest("api/rules", "app").execute().assertJson(this.getClass(), "app.json");
}
use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.
the class RegisterRulesTest method delete_repositories_that_have_been_uninstalled.
@Test
public void delete_repositories_that_have_been_uninstalled() {
RuleRepositoryDto repository = new RuleRepositoryDto("findbugs", "java", "Findbugs");
DbSession dbSession = dbTester.getSession();
dbTester.getDbClient().ruleRepositoryDao().insert(dbSession, asList(repository));
dbSession.commit();
execute(new FakeRepositoryV1());
assertThat(dbTester.getDbClient().ruleRepositoryDao().selectAll(dbSession)).extracting(RuleRepositoryDto::getKey).containsOnly("fake");
}
use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.
the class CompareAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String leftKey = request.mandatoryParam(PARAM_LEFT_KEY);
String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);
QProfileComparisonResult result = comparator.compare(leftKey, rightKey);
try (DbSession dbSession = dbClient.openSession(false)) {
List<RuleDto> referencedRules = dbClient.ruleDao().selectByKeys(dbSession, new ArrayList<>(result.collectRuleKeys()));
Map<RuleKey, RuleDto> rulesByKey = Maps.uniqueIndex(referencedRules, RuleDtoToRuleKey.INSTANCE);
Map<String, RuleRepositoryDto> repositoriesByKey = Maps.uniqueIndex(dbClient.ruleRepositoryDao().selectAll(dbSession), RuleRepositoryDto::getKey);
writeResult(response.newJsonWriter(), result, rulesByKey, repositoriesByKey);
}
}
Aggregations