use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.
the class NotificationTimerTask method requestForServer.
private void requestForServer(ServerConfiguration serverConfiguration, List<NotificationConfiguration> configs) {
try {
Map<String, ZonedDateTime> request = configs.stream().collect(Collectors.toMap(NotificationConfiguration::projectKey, NotificationTimerTask::getLastNotificationTime, MERGE_TIMES));
NotificationChecker notificationChecker = checkerFactory.create(serverConfiguration);
List<SonarQubeNotification> notifications = notificationChecker.request(request);
for (SonarQubeNotification n : notifications) {
Stream<NotificationConfiguration> matchingConfStream = configs.stream();
if (n.projectKey() != null) {
matchingConfStream = matchingConfStream.filter(c -> c.projectKey().equals(n.projectKey()));
}
matchingConfStream.forEach(c -> {
c.listener().handle(n);
c.lastNotificationTime().set(n.time());
});
}
} catch (Exception e) {
LOG.warn("Failed to request SonarQube events to " + serverConfiguration.getUrl(), e);
}
}
use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.
the class NotificationTimerTaskTest method testRepeatedProject.
@Test
public void testRepeatedProject() {
// return one notification for our project
SonarQubeNotification notif = mock(SonarQubeNotification.class);
when(notif.projectKey()).thenReturn("myproject");
when(notificationChecker.request(Collections.singletonMap("myproject", time))).thenReturn(Collections.singletonList(notif));
// execute with one project
NotificationConfiguration project = createProject("myproject");
NotificationConfiguration project2 = createProject("myproject");
LastNotificationTime notificationTime = mock(LastNotificationTime.class);
when(notificationTime.get()).thenReturn(ZonedDateTime.now().minusHours(2));
when(project2.lastNotificationTime()).thenReturn(notificationTime);
timerTask.setProjects(Collections.singleton(project));
timerTask.run();
// verify checker used once and notification was returned through the listener
verify(notificationCheckerFactory, times(1)).create(any(ServerConfiguration.class));
// should use the most recent time
verify(notificationChecker).request(Collections.singletonMap("myproject", time));
verify(listener).handle(notif);
}
use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-intellij by SonarSource.
the class SonarQubeEventNotifications method register.
private void register(SonarLintProjectSettings settings) {
unregister();
if (settings.isBindingEnabled()) {
SonarQubeServer server;
try {
server = bindingManager.getSonarQubeServer();
} catch (InvalidBindingException e) {
// do nothing
return;
}
if (server.enableNotifications()) {
NotificationConfiguration config = createConfiguration(settings, server);
SonarQubeNotifications.get().register(config);
}
}
}
use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.
the class NotificationTimerTaskTest method createProject.
private NotificationConfiguration createProject(String key, ServerConfiguration config) {
NotificationConfiguration project = mock(NotificationConfiguration.class);
when(project.listener()).thenReturn(listener);
when(project.projectKey()).thenReturn(key);
when(project.serverConfiguration()).thenReturn(config);
when(project.lastNotificationTime()).thenReturn(notificationTime);
return project;
}
use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.
the class NotificationTimerTaskTest method testErrorParsing.
@Test
public void testErrorParsing() {
when(notificationChecker.request(anyMap())).thenThrow(new IllegalStateException());
NotificationConfiguration project = createProject("myproject");
timerTask.setProjects(Collections.singleton(project));
timerTask.run();
verify(notificationCheckerFactory, times(1)).create(any(ServerConfiguration.class));
verify(notificationChecker).request(Collections.singletonMap("myproject", time));
verifyZeroInteractions(listener);
}
Aggregations