Search in sources :

Example 1 with DefaultSonarQubeNotification

use of org.sonarsource.sonarlint.core.container.model.DefaultSonarQubeNotification in project sonarlint-core by SonarSource.

the class NotificationChecker method parseResponse.

private static List<SonarQubeNotification> parseResponse(String contents) {
    List<SonarQubeNotification> notifications = new ArrayList<>();
    try {
        JsonParser parser = new JsonParser();
        JsonObject root = parser.parse(contents).getAsJsonObject();
        JsonArray events = root.get("events").getAsJsonArray();
        for (JsonElement el : events) {
            JsonObject event = el.getAsJsonObject();
            String category = getOrFail(event, "category");
            String message = getOrFail(event, "message");
            String link = getOrFail(event, "link");
            String projectKey = getOrFail(event, "project");
            String dateTime = getOrFail(event, "date");
            ZonedDateTime time = ZonedDateTime.parse(dateTime, TIME_FORMATTER);
            notifications.add(new DefaultSonarQubeNotification(category, message, link, projectKey, time));
        }
    } catch (Exception e) {
        LOG.error("Failed to parse SonarQube notifications response", e);
        return Collections.emptyList();
    }
    return notifications;
}
Also used : JsonArray(com.google.gson.JsonArray) ZonedDateTime(java.time.ZonedDateTime) JsonElement(com.google.gson.JsonElement) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) DefaultSonarQubeNotification(org.sonarsource.sonarlint.core.container.model.DefaultSonarQubeNotification) DefaultSonarQubeNotification(org.sonarsource.sonarlint.core.container.model.DefaultSonarQubeNotification) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 SonarQubeNotification (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification)1 DefaultSonarQubeNotification (org.sonarsource.sonarlint.core.container.model.DefaultSonarQubeNotification)1