private QProfileDto getParent(DbSession dbSession, QProfileDto profile) { QProfileDto parent = dbClient.qualityProfileDao().selectByUuid(dbSession, profile.getParentKee()); if (parent == null) { throw new IllegalStateException("Cannot find parent of profile: " + profile.getKee()); } return parent; }
private void incrementAncestors(DbSession session, QProfileDto profile, List<QProfileDto> ancestors) { String parentKey = profile.getParentKee(); if (parentKey != null) { QProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByUuid(session, parentKey); ancestors.add(parentDto); incrementAncestors(session, parentDto, ancestors); } }
private void setProfile(DbSession dbSession, RuleQuery query, Request request) { String profileUuid = request.param(PARAM_QPROFILE); if (profileUuid == null) { return; } QProfileDto profileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, profileUuid); QProfileDto profile = checkFound(profileOptional, "The specified qualityProfile '%s' does not exist", profileUuid); query.setQProfile(profile); }
private QProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, QProfileDto sourceProfile, String toName) { QProfileName toProfileName = new QProfileName(sourceProfile.getLanguage(), toName); verify(sourceProfile, toProfileName); QProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, toProfileName.getName(), toProfileName.getLanguage()); if (toProfile == null) { toProfile = factory.checkAndCreateCustom(dbSession, organization, toProfileName); toProfile.setParentKee(sourceProfile.getParentKee()); db.qualityProfileDao().update(dbSession, toProfile); dbSession.commit(); } return toProfile; }
@Override public QProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) { requireNonNull(organization); QProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name.getName(), name.getLanguage()); if (profile == null) { profile = doCreate(dbSession, organization, name, false, false); } else { checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s' with language '%s'", profile.getName(), profile.getLanguage()); } return profile; }
private void assertThatProfileIsNotMarkedAsUpdated(RulesProfileDto dto) { RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectBuiltInRuleProfiles(db.getSession()) .stream() .filter(p -> p.getKee().equals(dto.getKee())) .findFirst() .get(); assertThat(reloaded.getRulesUpdatedAt()).isNull(); }
private void assertThatProfileIsMarkedAsUpdated(RulesProfileDto dto) { RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectBuiltInRuleProfiles(db.getSession()) .stream() .filter(p -> p.getKee().equals(dto.getKee())) .findFirst() .get(); assertThat(reloaded.getRulesUpdatedAt()).isNotEmpty(); }
@Test public void selectQProfilesByRuleProfileUuid_returns_empty_list_if_rule_profile_does_not_exist() { List<QProfileDto> result = db.getDbClient().qualityProfileDao().selectQProfilesByRuleProfile(db.getSession(), new RulesProfileDto().setKee("unknown")); assertThat(result).isEmpty(); }
/** * Create a profile with random field values on the specified organization. */ public QProfileDto insert(OrganizationDto organization, Consumer<QProfileDto> consumer) { QProfileDto profile = QualityProfileTesting.newQualityProfileDto() .setOrganizationUuid(organization.getUuid()); consumer.accept(profile); dbClient.qualityProfileDao().insert(dbSession, profile); dbSession.commit(); return profile; }
@Test public void rename() { logInAsQProfileAdministrator(); String qualityProfileKey = createNewValidQualityProfileKey(); call(qualityProfileKey, "the new name"); QProfileDto reloaded = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), qualityProfileKey); assertThat(reloaded.getName()).isEqualTo("the new name"); }
private RulesProfileDto insertRulesProfile(DbSession dbSession, BuiltInQProfile builtIn, Date now) { RulesProfileDto dto = new RulesProfileDto() .setKee(uuidFactory.create()) .setName(builtIn.getName()) .setLanguage(builtIn.getLanguage()) .setIsBuiltIn(true) .setRulesUpdatedAtAsDate(now); dbClient.qualityProfileDao().insert(dbSession, dto); return dto; }
private void assertThatProfileIsUpdatedBySystem(QProfileDto profile) { QProfileDto loaded = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), profile.getKee()); assertThat(loaded.getUserUpdatedAt()).isNull(); assertThat(loaded.getRulesUpdatedAt()).isNotEmpty(); }
@Test public void delete_builtin_profile() { RulesProfileDto builtInProfile = createBuiltInProfile(); OrganizationDto org = db.organizations().insert(); QProfileDto profile = associateBuiltInProfileToOrganization(builtInProfile, org); underTest.delete(dbSession, asList(profile)); verifyNoCallsActiveRuleIndexerDelete(); // remove only from org_qprofiles assertThat(db.getDbClient().qualityProfileDao().selectOrderedByOrganizationUuid(dbSession, org)).isEmpty(); assertThatRulesProfileExists(builtInProfile); }
@Test public void update_built_in_profile_if_it_already_exists() { RulesProfileDto ruleProfile = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Sonar way").setLanguage(FOO_LANGUAGE.getKey())); db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile); db.commit(); BuiltInQProfile builtIn = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfile.getName(), false); builtInQProfileRepositoryRule.initialize(); underTest.start(); assertThat(insert.callLogs).isEmpty(); assertThat(update.callLogs).containsExactly(builtIn); assertThat(logTester.logs(LoggerLevel.INFO)).contains("Update profile foo/Sonar way"); }
private RulesProfileDto insertBuiltInProfile(String language) { RulesProfileDto ruleProfileDto = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setLanguage(language)); db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfileDto); db.commit(); return ruleProfileDto; }
@Test public void commitDeletionOfProfiles() { ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1); ActiveRuleDto ar2 = db.qualityProfiles().activateRule(profile2, rule1); ActiveRuleDto ar3 = db.qualityProfiles().activateRule(profile2, rule2); indexAll(); db.getDbClient().qualityProfileDao().deleteRulesProfilesByUuids(db.getSession(), singletonList(profile2.getRulesProfileUuid())); underTest.commitDeletionOfProfiles(db.getSession(), singletonList(profile2)); verifyOnlyIndexed(ar1); }
@Test public void flag_profile_as_default_on_organization_if_declared_as_default_by_api() { OrganizationDto org = db.organizations().insert(); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("the name", "xoo").setDefault(true); newQp.done(); BuiltInQProfile builtIn = builtInQProfileRepository.create(context.profile("xoo", "the name")); call(builtIn); QProfileDto profile = verifyProfileInDb(org, builtIn); QProfileDto defaultProfile = db.getDbClient().qualityProfileDao().selectDefaultProfile(dbSession, org, "xoo"); assertThat(defaultProfile.getKee()).isEqualTo(profile.getKee()); }
@Before public void setUp() { persistedProfile = newRuleProfileDto(rp -> rp .setIsBuiltIn(true) .setLanguage("xoo") .setRulesUpdatedAt(null)); db.getDbClient().qualityProfileDao().insert(db.getSession(), persistedProfile); db.commit(); }
private QProfileDto associateBuiltInProfileToOrganization(RulesProfileDto rulesProfile, OrganizationDto organization) { OrgQProfileDto orgQProfileDto = new OrgQProfileDto() .setUuid(Uuids.createFast()) .setRulesProfileUuid(rulesProfile.getKee()) .setOrganizationUuid(organization.getUuid()); db.getDbClient().qualityProfileDao().insert(dbSession, orgQProfileDto); db.commit(); return QProfileDto.from(orgQProfileDto, rulesProfile); }
private void insertRulesProfile(BuiltInQProfile builtIn) { RulesProfileDto dto = new RulesProfileDto() .setIsBuiltIn(true) .setKee(RandomStringUtils.randomAlphabetic(40)) .setLanguage(builtIn.getLanguage()) .setName(builtIn.getName()); dbClient.qualityProfileDao().insert(db.getSession(), dto); db.commit(); }