public void renameProfile(int profileId, String newName, UserSession userSession) { checkPermission(userSession); DbSession session = myBatis.openSession(false); try { QualityProfileDto profileDto = findNotNull(profileId, session); String oldName = profileDto.getName(); QProfile profile = QProfile.from(profileDto); if (!oldName.equals(newName)) { checkNotAlreadyExists(newName, profile.language(), session); } profileDto.setName(newName); dao.update(session, profileDto); List<QProfile> children = profileLookup.children(profile, session); for (QProfile child : children) { dao.update(session, child.setParent(newName).toDto()); } propertiesDao.updateProperties( PROFILE_PROPERTY_PREFIX + profile.language(), oldName, newName, session); session.commit(); } finally { MyBatis.closeQuietly(session); } }
@Test public void findNotificationSubscribers() { when(propertiesDao.findNotificationSubscribers("NewViolations", "Email", "struts")) .thenReturn(Lists.newArrayList("user1", "user2")); when(propertiesDao.findNotificationSubscribers("NewViolations", "Twitter", "struts")) .thenReturn(Lists.newArrayList("user2")); Multimap<String, NotificationChannel> multiMap = manager.findNotificationSubscribers(dispatcher, "struts"); assertThat(multiMap.entries()).hasSize(3); Map<String, Collection<NotificationChannel>> map = multiMap.asMap(); assertThat(map.get("user1")).containsOnly(emailChannel); assertThat(map.get("user2")).containsOnly(emailChannel, twitterChannel); assertThat(map.get("other")).isNull(); }
@Test public void shouldFindSubscribedRecipientForNoResource() { when(propertiesDao.findUsersForNotification("NewViolations", "Email", 45L)) .thenReturn(Lists.newArrayList("user1", "user2")); when(propertiesDao.findUsersForNotification("NewViolations", "Email", null)) .thenReturn(Lists.newArrayList("user1", "user3")); when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", 56L)) .thenReturn(Lists.newArrayList("user2")); when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", null)) .thenReturn(Lists.newArrayList("user3")); when(propertiesDao.findUsersForNotification("NewAlerts", "Twitter", null)) .thenReturn(Lists.newArrayList("user4")); Multimap<String, NotificationChannel> multiMap = manager.findSubscribedRecipientsForDispatcher(dispatcher, (Integer) null); assertThat(multiMap.entries()).hasSize(3); Map<String, Collection<NotificationChannel>> map = multiMap.asMap(); assertThat(map.get("user1")).containsOnly(emailChannel); assertThat(map.get("user3")).containsOnly(emailChannel, twitterChannel); assertThat(map.get("user2")).isNull(); assertThat(map.get("user4")).isNull(); }
@Override public void dispatch(Notification notification, Context context) { // "null" is passed as a 2nd argument because this dispatcher is not a per-project dispatcher Multimap<String, NotificationChannel> subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher(this, null); List<String> userLogins = propertiesDao.findUserIdsForFavouriteResource( Long.parseLong(notification.getFieldValue("projectId"))); for (String userLogin : userLogins) { Collection<NotificationChannel> channels = subscribedRecipients.get(userLogin); for (NotificationChannel channel : channels) { context.addUser(userLogin, channel); } } }
@Test public void test_getDatabaseForDryRun_project_invalidation() throws Exception { when(dryRunDatabaseFactory.createNewDatabaseForDryRun(eq(123L), any(File.class), anyString())) .thenAnswer( new Answer<File>() { public File answer(InvocationOnMock invocation) throws IOException { Object[] args = invocation.getArguments(); File dbFile = new File(new File(dryRunCacheLocation, "123"), (String) args[2] + ".h2.db"); FileUtils.write(dbFile, "fake db content 1"); return dbFile; } }) .thenAnswer( new Answer<File>() { public File answer(InvocationOnMock invocation) throws IOException { Object[] args = invocation.getArguments(); File dbFile = new File(new File(dryRunCacheLocation, "123"), (String) args[2] + ".h2.db"); FileUtils.write(dbFile, "fake db content 2"); return dbFile; } }); when(resourceDao.getRootProjectByComponentId(123L)).thenReturn(new ResourceDto().setId(123L)); byte[] dbContent = dryRunCache.getDatabaseForPreview(123L); assertThat(new String(dbContent)).isEqualTo("fake db content 1"); // Emulate invalidation of cache Thread.sleep(100); when(propertiesDao.selectProjectProperty( 123L, PreviewCache.SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY)) .thenReturn(new PropertyDto().setValue("" + System.currentTimeMillis())); dbContent = dryRunCache.getDatabaseForPreview(123L); assertThat(new String(dbContent)).isEqualTo("fake db content 2"); verify(dryRunDatabaseFactory, times(2)) .createNewDatabaseForDryRun(anyLong(), any(File.class), anyString()); }
public Settings newProjectSettings(DbSession session, long projectId) { List<PropertyDto> propertyList = dao.selectProjectProperties(projectId, session); return new ProjectSettings(settings, getPropertyMap(propertyList)); }