From e548b9ee22373fa419b669875a448cac245d59be Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Tue, 13 Feb 2018 15:58:40 +0100 Subject: [PATCH 01/12] Implemented public statuspage API --- .gitattributes | 2 + build.gradle | 2 + gradle/wrapper/gradle-wrapper.properties | 19 +- settings.gradle | 2 +- statuspage/README.md | 3 + statuspage/build.gradle | 20 + .../jdautilities/statuspage/Statuspage.java | 468 ++++++++++++++++++ .../statuspage/data/Component.java | 158 ++++++ .../statuspage/data/Incident.java | 260 ++++++++++ .../jdautilities/statuspage/data/Page.java | 65 +++ .../statuspage/data/ScheduledMaintenance.java | 50 ++ .../jdautilities/statuspage/data/Status.java | 74 +++ .../statuspage/endpoints/Components.java | 132 +++++ .../statuspage/endpoints/Incidents.java | 132 +++++ .../endpoints/ScheduledMaintenances.java | 132 +++++ .../statuspage/endpoints/ServiceStatus.java | 49 ++ .../statuspage/endpoints/Summary.java | 76 +++ .../jdautilities/statuspage/package-info.java | 19 + 18 files changed, 1645 insertions(+), 18 deletions(-) create mode 100644 statuspage/README.md create mode 100644 statuspage/build.gradle create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Page.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ServiceStatus.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java create mode 100644 statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java diff --git a/.gitattributes b/.gitattributes index 4d98b206..97828ed2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,6 @@ gradlew binary +gradlew.bat binary +/gradle/wrapper/gradle-wrapper.properties binary .gitattributes text eol=crlf diff --git a/build.gradle b/build.gradle index 545bf8df..d79c42eb 100644 --- a/build.gradle +++ b/build.gradle @@ -38,11 +38,13 @@ allprojects { slf4jVersion = '1.7.25' okhttpVersion = '3.9.1' findbugsVersion = '3.0.2' + jsonVersion = '20180130' jda = { project.dependencies.compileOnly group: 'net.dv8tion', name: 'JDA', version: jdaVersion } slf4j = { project.dependencies.compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion } okhttp = { project.dependencies.compile group: 'com.squareup.okhttp3', name: 'okhttp', version: okhttpVersion } findbugs = { project.dependencies.compile group: 'com.google.code.findbugs', name: 'jsr305', version: findbugsVersion } + json = { project.dependencies.compile group: 'org.json', name: 'json', version: jsonVersion } include = { String name -> project.dependencies.compile project.project(':' + name) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9c942e6d..568c50bf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,20 +1,5 @@ -# -# Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip diff --git a/settings.gradle b/settings.gradle index d135a579..428a7fb8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,4 +15,4 @@ */ rootProject.name = 'JDA-Utilities' -include 'commons', 'menu', 'command', 'doc', 'examples' +include 'commons', 'menu', 'command', 'doc', 'examples', 'statuspage' diff --git a/statuspage/README.md b/statuspage/README.md new file mode 100644 index 00000000..9ec7dc71 --- /dev/null +++ b/statuspage/README.md @@ -0,0 +1,3 @@ +# Statuspage Package + +This API can be used to retrieve data from [https://status.discordapp.com](https://status.discordapp.com). diff --git a/statuspage/build.gradle b/statuspage/build.gradle new file mode 100644 index 00000000..a922f997 --- /dev/null +++ b/statuspage/build.gradle @@ -0,0 +1,20 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +dependencies { + okhttp() + json() + findbugs() +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java new file mode 100644 index 00000000..95ff9e5c --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java @@ -0,0 +1,468 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage; + +import com.jagrosh.jdautilities.statuspage.data.*; +import com.jagrosh.jdautilities.statuspage.endpoints.*; +import okhttp3.*; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; +import java.io.Reader; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Consumer; + +@Immutable +public class Statuspage +{ + @Nonnull + protected static final String URL_API_BASE = "https://status.discordapp.com/api/v2/"; + @Nonnull + protected static final String URL_SUMMARY = URL_API_BASE + "summary.json"; + @Nonnull + protected static final String URL_SERVICE_STATUS = URL_API_BASE + "status.json"; + @Nonnull + protected static final String URL_COMPONENTS = URL_API_BASE + "components.json"; + @Nonnull + protected static final String URL_INCIDENTS_ALL = URL_API_BASE + "incidents.json"; + @Nonnull + protected static final String URL_INCIDENTS_UNRESOLVED = URL_API_BASE + "incidents/unresolved.json"; + @Nonnull + protected static final String URL_SCHEDULED_MAINTENANCES_ALL = URL_API_BASE + "scheduled-maintenances.json"; + @Nonnull + protected static final String URL_SCHEDULED_MAINTENANCES_ACTIVE = URL_API_BASE + "scheduled-maintenances/active.json"; + @Nonnull + protected static final String URL_SCHEDULED_MAINTENANCES_UPCOMING = URL_API_BASE + "scheduled-maintenances/upcoming.json"; + + @Nonnull + protected final OkHttpClient client; + @Nonnull + protected final ExecutorService pool; + + public Statuspage() + { + this(null, null); + } + + public Statuspage(@Nullable OkHttpClient client) + { + this(client, null); + } + + public Statuspage(@Nullable ExecutorService pool) + { + this(null, pool); + } + + public Statuspage(@Nullable OkHttpClient client, @Nullable ExecutorService pool) + { + this.client = client == null ? new OkHttpClient.Builder().build() : client; + this.pool = pool == null ? Executors.newSingleThreadExecutor() : pool; + } + + /** + * Get a summary of the status page, including a status indicator, component statuses, unresolved incidents, and any upcoming or + * in-progress scheduled maintenances. + */ + @Nonnull + public CompletableFuture getSummary() + { + return createFuture(f -> f.complete(createSummary(get(URL_SUMMARY)))); + } + + /** + * Get a list of the 50 most recent incidents. This includes all unresolved incidents as described above, + * as well as those in the Resolved and Postmortem state. + */ + @Nonnull + public CompletableFuture getIncidentsAll() + { + return createFuture(f -> f.complete(createIncidents(get(URL_INCIDENTS_ALL)))); + } + + /** + * Get a list of any unresolved incidents. This endpoint will only return incidents in the Investigating, Identified, or Monitoring state. + */ + @Nonnull + public CompletableFuture getIncidentsUnresolved() + { + return createFuture(f -> f.complete(createIncidents(get(URL_INCIDENTS_UNRESOLVED)))); + } + + /** + * Get the components for the page. Each component is listed along with its status - one of operational, + * degraded_performance, partial_outage, or major_outage. + */ + @Nonnull + public CompletableFuture getComponents() + { + return createFuture(f -> f.complete(createComponents(get(URL_COMPONENTS)))); + } + + /** + * Get a list of the 50 most recent scheduled maintenances. This includes scheduled maintenances as described in the above two endpoints, as well as those in the Completed state. + */ + @Nonnull + public CompletableFuture getScheduledMaintenancesAll() + { + return createFuture(f -> f.complete(createScheduledMaintenances(get(URL_SCHEDULED_MAINTENANCES_ALL)))); + } + + /** + * Get a list of any active maintenances. This endpoint will only return scheduled maintenances in the In Progress or Verifying state. + */ + @Nonnull + public CompletableFuture getScheduledMaintenancesActive() + { + return createFuture(f -> f.complete(createScheduledMaintenances(get(URL_SCHEDULED_MAINTENANCES_ACTIVE)))); + } + + /** + * Get a list of any upcoming maintenances. This endpoint will only return scheduled maintenances still in the Scheduled state. + */ + @Nonnull + public CompletableFuture getScheduledMaintenancesUpcoming() + { + return createFuture(f -> f.complete(createScheduledMaintenances(get(URL_SCHEDULED_MAINTENANCES_UPCOMING)))); + } + + /** + * Get the status rollup for the whole page. This endpoint includes an indicator - one of none, minor, major, or critical, + * as well as a human description of the blended component status. Examples of the blended status include + * "All Systems Operational", "Partial System Outage", and "Major Service Outage". + */ + @Nonnull + public CompletableFuture getServiceStatus() + { + return createFuture(f -> f.complete(createServiceStatus(get(URL_SERVICE_STATUS)))); + } + + @Nonnull + protected Summary createSummary(@Nonnull JSONObject object) + { + @Nonnull + final JSONArray componentsArray = object.getJSONArray("components"); + @Nonnull + final List components = new ArrayList<>(componentsArray.length()); + for (int i = 0; i < componentsArray.length(); i++) + components.add(createComponent(componentsArray.getJSONObject(i))); + @Nonnull + final JSONArray incidentsArray = object.getJSONArray("incidents"); + @Nonnull + final List incidents = new ArrayList<>(incidentsArray.length()); + for (int i = 0; i < incidentsArray.length(); i++) + incidents.add(createIncident(incidentsArray.getJSONObject(i))); + @Nonnull + final JSONArray scheduledMaintenancesArray = object.getJSONArray("scheduled_maintenances"); + @Nonnull + final List scheduledMaintenances = new ArrayList<>(scheduledMaintenancesArray.length()); + for (int i = 0; i < scheduledMaintenancesArray.length(); i++) + scheduledMaintenances.add(createScheduledMaintenance(scheduledMaintenancesArray.getJSONObject(i))); + @Nonnull + final JSONObject pageObject = object.getJSONObject("page"); + @Nonnull + final Page page = createPage(pageObject); + @Nonnull + final JSONObject statusObject = object.getJSONObject("status"); + @Nonnull + final Status status = createStatus(statusObject); + + return new Summary(components, incidents, page, scheduledMaintenances, status); + } + + @Nonnull + protected Components createComponents(@Nonnull JSONObject object) + { + @Nonnull + final JSONObject pageObject = object.getJSONObject("page"); + @Nonnull + final Page page = createPage(pageObject); + @Nonnull + final JSONArray componentsArray = object.getJSONArray("components"); + @Nonnull + final List components = new ArrayList<>(componentsArray.length()); + for (int i = 0; i < componentsArray.length(); i++) + components.add(createComponent(componentsArray.getJSONObject(i))); + + return new Components(page, components); + } + + @Nonnull + protected ServiceStatus createServiceStatus(@Nonnull JSONObject object) + { + @Nonnull + final JSONObject pageObject = object.getJSONObject("page"); + @Nonnull + final Page page = createPage(pageObject); + @Nonnull + final JSONObject statusObject = object.getJSONObject("status"); + @Nonnull + final Status status = createStatus(statusObject); + + return new ServiceStatus(page, status); + } + + @Nonnull + protected ScheduledMaintenances createScheduledMaintenances(@Nonnull JSONObject object) + { + @Nonnull + final JSONObject pageObject = object.getJSONObject("page"); + @Nonnull + final Page page = createPage(pageObject); + @Nonnull + final JSONArray scheduledMaintenancesArray = object.getJSONArray("scheduled_maintenances"); + @Nonnull + final List scheduledMaintenances = new ArrayList<>(scheduledMaintenancesArray.length()); + for (int i = 0; i < scheduledMaintenancesArray.length(); i++) + scheduledMaintenances.add(createScheduledMaintenance(scheduledMaintenancesArray.getJSONObject(i))); + + return new ScheduledMaintenances(page, scheduledMaintenances); + } + + @Nonnull + protected CompletableFuture createFuture(@Nonnull Consumer> action) + { + CompletableFuture future = new CompletableFuture<>(); + + pool.submit(() -> { + try + { + action.accept(future); + } + catch (Exception e) + { + future.completeExceptionally(e); + } + }); + + return future; + } + + @Nonnull + protected JSONObject get(@Nonnull String url) + { + try + { + // @formatter:off + Request request = new Request.Builder() + .get() + .url(url) + .header("Content-Type", "application/json") + .build(); + // @formatter:on + + Call call = client.newCall(request); + + try (Response response = call.execute()) + { + ResponseBody body = response.body(); + + if (body == null) + throw new IllegalStateException("response has no body"); + + Reader reader = body.charStream(); + + return new JSONObject(new JSONTokener(reader)); + } + } + catch (RuntimeException e) + { + throw e; + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + @Nonnull + protected Incident createIncident(@Nonnull JSONObject object) + { + @Nullable + final String monitoringAt = object.optString("monitoring_at"); + @Nonnull + final String pageId = object.getString("page_id"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + @Nullable + final String resolvedAt = object.optString("resolved_at"); + @Nonnull + final String impact = object.getString("impact"); + @Nonnull + final String name = object.getString("name"); + @Nonnull + final String createdAt = object.getString("created_at"); + @Nonnull + final JSONArray updatesArray = object.getJSONArray("incident_updates"); + @Nonnull + final List updates = new ArrayList<>(updatesArray.length()); + for (int i = 0; i < updatesArray.length(); i++) + updates.add(createIncidentUpdate(updatesArray.getJSONObject(i))); + @Nonnull + final String id = object.getString("id"); + @Nonnull + final String shortlink = object.getString("shortlink"); + @Nonnull + final String status = object.getString("status"); + + return new Incident(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status)); + } + + @Nonnull + protected Incidents createIncidents(@Nonnull JSONObject object) + { + @Nonnull + final JSONArray incidentsArray = object.getJSONArray("incidents"); + @Nonnull + final List incidents = new ArrayList<>(incidentsArray.length()); + for (int i = 0; i < incidentsArray.length(); i++) + incidents.add(createIncident(incidentsArray.getJSONObject(i))); + @Nonnull + final JSONObject pageObject = object.getJSONObject("page"); + @Nonnull + final Page page = createPage(pageObject); + + return new Incidents(page, incidents); + } + + @Nonnull + protected Incident.Update createIncidentUpdate(@Nonnull JSONObject object) + { + @Nonnull + final String incidentId = object.getString("incident_id"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + @Nonnull + final String createdAt = object.getString("created_at"); + @Nonnull + final String id = object.getString("id"); + @Nonnull + final String body = object.getString("body"); + @Nonnull + final String displayAt = object.getString("display_at"); + @Nonnull + final String status = object.getString("status"); + + // There are 3 more fields but they aren't part of the public API + // and I'm unsure what they are used for: + // 'affected_components', 'custom_tweet' and 'deliver_notifications' + + return new Incident.Update(incidentId, toOffsetDateTime(updatedAt), toOffsetDateTime(createdAt), id, body, toOffsetDateTime(displayAt), Incident.Status.from(status)); + } + + @Nonnull + protected Page createPage(@Nonnull JSONObject object) + { + @Nonnull + final String name = object.getString("name"); + @Nonnull + final String id = object.getString("id"); + @Nonnull + final String url = object.getString("url"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + + return new Page(name, id, url, toOffsetDateTime(updatedAt)); + } + + @Nonnull + protected Status createStatus(@Nonnull JSONObject object) + { + @Nonnull + final String indicator = object.getString("indicator"); + @Nonnull + final String description = object.getString("description"); + + return new Status(Status.Indicator.from(indicator), description); + } + + @Nonnull + protected Component createComponent(@Nonnull JSONObject object) + { + @Nonnull + final String pageId = object.getString("page_id"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + @Nonnull + final String name = object.getString("name"); + @Nonnull + final String createdAt = object.getString("created_at"); + @Nullable + final String description = object.optString("description"); + @Nonnull + final String id = object.getString("id"); + final int position = object.getInt("position"); + @Nonnull + final String status = object.getString("status"); + final boolean showcase = object.getBoolean("showcase"); + @Nullable + final String groupId = object.optString("group_id"); + final boolean group = object.getBoolean("group"); + final boolean showOnlyIfDegraded = object.getBoolean("only_show_if_degraded"); + + return new Component(pageId, toOffsetDateTime(updatedAt), name, toOffsetDateTime(createdAt), description, id, position, Component.Status.from(status), showcase, groupId, group, showOnlyIfDegraded); + } + + @Nonnull + protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject object) + { + @Nullable + final String monitoringAt = object.optString("monitoring_at"); + @Nonnull + final String pageId = object.getString("page_id"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + @Nullable + final String resolvedAt = object.optString("resolved_at"); + @Nonnull + final String impact = object.getString("impact"); + @Nonnull + final String name = object.getString("name"); + @Nonnull + final String createdAt = object.getString("created_at"); + final JSONArray updatesArray = object.getJSONArray("incident_updates"); + @Nonnull + final List updates = new ArrayList<>(updatesArray.length()); + for (int i = 0; i < updatesArray.length(); i++) + updates.add(createIncidentUpdate(updatesArray.getJSONObject(i))); + @Nonnull + final String id = object.getString("id"); + @Nonnull + final String shortlink = object.getString("shortlink"); + @Nonnull + final String status = object.getString("status"); + @Nonnull + final String scheduledFor = object.getString("updated_at"); + @Nonnull + final String scheduledUntil = object.getString("updated_at"); + + return new ScheduledMaintenance(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status), toOffsetDateTime(scheduledFor), toOffsetDateTime(scheduledUntil)); + } + + protected OffsetDateTime toOffsetDateTime(String time) + { + return time == null ? null : OffsetDateTime.parse(time); + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java new file mode 100644 index 00000000..f410cb68 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java @@ -0,0 +1,158 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.data; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; +import java.time.OffsetDateTime; + +@Immutable +public class Component +{ + @Nonnull + protected final String pageId; + @Nonnull + protected final OffsetDateTime updatedAt; + @Nonnull + protected final String name; + @Nonnull + protected final OffsetDateTime createdAt; + @Nullable + protected final String description; + @Nonnull + protected final String id; + protected final int position; + @Nonnull + protected final Status status; + protected final boolean showcase; + @Nullable + protected final String groupId; + protected final boolean group; + protected final boolean showOnlyIfDegraded; + + public Component(@Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nullable String description, @Nonnull String id, int position, @Nonnull Status status, boolean showcase, @Nullable String groupId, boolean group, boolean showOnlyIfDegraded) + { + this.pageId = pageId; + this.updatedAt = updatedAt; + this.name = name; + this.createdAt = createdAt; + this.description = description; + this.id = id; + this.position = position; + this.status = status; + this.showcase = showcase; + this.groupId = groupId; + this.group = group; + this.showOnlyIfDegraded = showOnlyIfDegraded; + } + + @Nonnull + public String getPageId() + { + return pageId; + } + + @Nonnull + public OffsetDateTime getUpdatedAt() + { + return updatedAt; + } + + @Nonnull + public String getName() + { + return name; + } + + @Nonnull + public OffsetDateTime getCreatedAt() + { + return createdAt; + } + + @Nullable + public String getDescription() + { + return description; + } + + @Nonnull + public String getId() + { + return id; + } + + public int getPosition() + { + return position; + } + + @Nonnull + public Status getStatus() + { + return status; + } + + public boolean isShowcase() + { + return showcase; + } + + @Nullable + public String getGroupId() + { + return groupId; + } + + public boolean isGroup() + { + return group; + } + + public boolean isShowOnlyIfDegraded() + { + return showOnlyIfDegraded; + } + + public enum Status + { + OPERATIONAL, + DEGRADED_PERFORMANCE, + PARTIAL_OUTAGE, + MAJOR_OUTAGE, + + UNKNOWN; + + @Nonnull + public static Status from(String name) + { + switch (name.toLowerCase()) + { + case "operational": + return OPERATIONAL; + case "degraded_performance": + return DEGRADED_PERFORMANCE; + case "partial_outage": + return PARTIAL_OUTAGE; + case "major_outage": + return MAJOR_OUTAGE; + default: + return UNKNOWN; + } + } + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java new file mode 100644 index 00000000..331aac0a --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java @@ -0,0 +1,260 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.data; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; +import java.time.OffsetDateTime; +import java.util.List; + +@Immutable +public class Incident +{ + @Nullable + protected final OffsetDateTime monitoringAt; + @Nonnull + protected final String pageId; + @Nonnull + protected final OffsetDateTime updatedAt; + @Nullable + protected final OffsetDateTime resolvedAt; + @Nonnull + protected final String impact; + @Nonnull + protected final String name; + @Nonnull + protected final OffsetDateTime createdAt; + @Nonnull + protected final List updates; + @Nonnull + protected final String id; + @Nonnull + protected final String shortlink; + @Nonnull + protected final Status status; + + public Incident(@Nullable OffsetDateTime monitoringAt, @Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, @Nullable OffsetDateTime resolvedAt, @Nonnull String impact, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nonnull List updates, @Nonnull String id, @Nonnull String shortlink, @Nonnull Status status) + { + this.monitoringAt = monitoringAt; + this.pageId = pageId; + this.updatedAt = updatedAt; + this.resolvedAt = resolvedAt; + this.impact = impact; + this.name = name; + this.createdAt = createdAt; + this.updates = updates; + this.id = id; + this.shortlink = shortlink; + this.status = status; + } + + @Nullable + public OffsetDateTime getMonitoringAt() + { + return monitoringAt; + } + + @Nonnull + public String getPageId() + { + return pageId; + } + + @Nonnull + public OffsetDateTime getUpdatedAt() + { + return updatedAt; + } + + @Nullable + public OffsetDateTime getResolvedAt() + { + return resolvedAt; + } + + @Nonnull + public String getImpact() + { + return impact; + } + + @Nonnull + public String getName() + { + return name; + } + + @Nonnull + public OffsetDateTime getCreatedAt() + { + return createdAt; + } + + @Nonnull + public List getUpdates() + { + return updates; + } + + @Nonnull + public String getId() + { + return id; + } + + @Nonnull + public String getShortlink() + { + return shortlink; + } + + @Nonnull + public Status getStatus() + { + return status; + } + + public enum Status + { + INVESTIGATING, + IDENTIFIED, + MONITORING, + RESOLVED, + POSTMORTEM, + + UNKNOWN; + + @Nonnull + public static Status from(String name) + { + switch (name) + { + case "investigating": + return INVESTIGATING; + case "identified": + return IDENTIFIED; + case "monitoring": + return MONITORING; + case "resolved": + return RESOLVED; + case "postmortem": + return POSTMORTEM; + default: + return UNKNOWN; + } + } + } + + public enum Impact + { + NONE, + MINOR, + MAJOR, + CRITICAL, + + UNKNOWN; + + @Nonnull + public static Impact from(String name) + { + switch (name) + { + case "none": + return NONE; + case "minor": + return MINOR; + case "major": + return MAJOR; + case "critical": + return CRITICAL; + default: + return UNKNOWN; + } + } + } + + public static class Update + { + @Nonnull + protected final String incidentId; + @Nonnull + protected final OffsetDateTime updatedAt; + @Nonnull + protected final OffsetDateTime createdAt; + @Nonnull + protected final String id; + @Nonnull + protected final String body; + @Nonnull + protected final OffsetDateTime displayAt; + @Nonnull + protected final Status status; + + public Update(@Nonnull String incidentId, @Nonnull OffsetDateTime updatedAt, @Nonnull OffsetDateTime createdAt, @Nonnull String id, @Nonnull String body, @Nonnull OffsetDateTime displayAt, @Nonnull Status status) + { + this.incidentId = incidentId; + this.updatedAt = updatedAt; + this.createdAt = createdAt; + this.id = id; + this.body = body; + this.displayAt = displayAt; + this.status = status; + } + + @Nonnull + public String getIncidentId() + { + return incidentId; + } + + @Nonnull + public OffsetDateTime getUpdatedAt() + { + return updatedAt; + } + + @Nonnull + public OffsetDateTime getCreatedAt() + { + return createdAt; + } + + @Nonnull + public String getId() + { + return id; + } + + @Nonnull + public String getBody() + { + return body; + } + + @Nonnull + public OffsetDateTime getDisplayAt() + { + return displayAt; + } + + @Nonnull + public Status getStatus() + { + return status; + } + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Page.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Page.java new file mode 100644 index 00000000..15832efa --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Page.java @@ -0,0 +1,65 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.data; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import java.time.OffsetDateTime; + +@Immutable +public class Page +{ + @Nonnull + protected final String name; + @Nonnull + protected final String id; + @Nonnull + protected final String url; + @Nonnull + protected final OffsetDateTime updatedAt; + + public Page(@Nonnull String name, @Nonnull String id, @Nonnull String url, @Nonnull OffsetDateTime updatedAt) + { + this.name = name; + this.id = id; + this.url = url; + this.updatedAt = updatedAt; + } + + @Nonnull + public String getName() + { + return name; + } + + @Nonnull + public String getId() + { + return id; + } + + @Nonnull + public String getUrl() + { + return url; + } + + @Nonnull + public OffsetDateTime getUpdatedAt() + { + return updatedAt; + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java new file mode 100644 index 00000000..80858e13 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java @@ -0,0 +1,50 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.data; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import java.time.OffsetDateTime; +import java.util.List; + +@Immutable +public class ScheduledMaintenance extends Incident +{ + @Nonnull + protected final OffsetDateTime scheduledFor; + @Nonnull + protected final OffsetDateTime scheduledUntil; + + public ScheduledMaintenance(OffsetDateTime monitoringAt, @Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, OffsetDateTime resolvedAt, @Nonnull String impact, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nonnull List updates, @Nonnull String id, @Nonnull String shortlink, @Nonnull Status status, @Nonnull OffsetDateTime scheduledFor, @Nonnull OffsetDateTime scheduledUntil) + { + super(monitoringAt, pageId, updatedAt, resolvedAt, impact, name, createdAt, updates, id, shortlink, status); + + this.scheduledFor = scheduledFor; + this.scheduledUntil = scheduledUntil; + } + + @Nonnull + public OffsetDateTime getScheduledFor() + { + return scheduledFor; + } + + @Nonnull + public OffsetDateTime getScheduledUntil() + { + return scheduledUntil; + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java new file mode 100644 index 00000000..26eefc86 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java @@ -0,0 +1,74 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.data; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +@Immutable +public class Status +{ + @Nonnull + protected final Indicator indicator; + @Nonnull + protected final String description; + + public Status(@Nonnull Indicator indicator, @Nonnull String description) + { + this.indicator = indicator; + this.description = description; + } + + @Nonnull + public Indicator getIndicator() + { + return indicator; + } + + @Nonnull + public String getDescription() + { + return description; + } + + public enum Indicator + { + NONE, + MINOR, + MAJOR, + CRITICAL, + + UNKNOWN; + + @Nonnull + public static Indicator from(String severity) + { + switch (severity.toLowerCase()) + { + case "none": + return NONE; + case "minor": + return MINOR; + case "major": + return MAJOR; + case "critical": + return CRITICAL; + default: + return UNKNOWN; + } + } + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java new file mode 100644 index 00000000..e7548d13 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java @@ -0,0 +1,132 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.endpoints; + +import com.jagrosh.jdautilities.statuspage.data.Component; +import com.jagrosh.jdautilities.statuspage.data.Page; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +@Immutable +public class Components implements List +{ + @Nonnull + protected final Page page; + @Nonnull + protected final List components; + + public Components(@Nonnull Page page, @Nonnull List components) + { + this.page = page; + this.components = components; + } + + @Nonnull + public Page getPage() + { + return page; + } + + @Nonnull + public List getComponents() + { + return components; + } + + @Override + public int size() {return components.size();} + + @Override + public boolean isEmpty() {return components.isEmpty();} + + @Override + public boolean contains(Object o) {return components.contains(o);} + + @Override + @Nonnull + public Iterator iterator() {return components.iterator();} + + @Override + @Nonnull + public Object[] toArray() {return components.toArray();} + + @Override + @Nonnull + @SuppressWarnings("SuspiciousToArrayCall") + public T[] toArray(@Nonnull T[] a) {return components.toArray(a);} + + @Override + public boolean add(Component component) {return components.add(component);} + + @Override + public boolean remove(Object o) {return components.remove(o);} + + @Override + public boolean containsAll(@Nonnull Collection c) {return components.containsAll(c);} + + @Override + public boolean addAll(@Nonnull Collection c) {return components.addAll(c);} + + @Override + public boolean addAll(int index, @Nonnull Collection c) {return components.addAll(index, c);} + + @Override + public boolean removeAll(@Nonnull Collection c) {return components.removeAll(c);} + + @Override + public boolean retainAll(@Nonnull Collection c) {return components.retainAll(c);} + + @Override + public void clear() {components.clear();} + + @Override + public int hashCode() {return components.hashCode();} + + @Override + public Component get(int index) {return components.get(index);} + + @Override + public Component set(int index, Component element) {return components.set(index, element);} + + @Override + public void add(int index, Component element) {components.add(index, element);} + + @Override + public Component remove(int index) {return components.remove(index);} + + @Override + public int indexOf(Object o) {return components.indexOf(o);} + + @Override + public int lastIndexOf(Object o) {return components.lastIndexOf(o);} + + @Override + @Nonnull + public ListIterator listIterator() {return components.listIterator();} + + @Override + @Nonnull + public ListIterator listIterator(int index) {return components.listIterator(index);} + + @Override + @Nonnull + public List subList(int fromIndex, int toIndex) {return components.subList(fromIndex, toIndex);} +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java new file mode 100644 index 00000000..3dc7caeb --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java @@ -0,0 +1,132 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.endpoints; + +import com.jagrosh.jdautilities.statuspage.data.Incident; +import com.jagrosh.jdautilities.statuspage.data.Page; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +@Immutable +public class Incidents implements List +{ + @Nonnull + protected final Page page; + @Nonnull + protected final List incidents; + + public Incidents(@Nonnull Page page, @Nonnull List incidents) + { + this.page = page; + this.incidents = incidents; + } + + @Nonnull + public Page getPage() + { + return page; + } + + @Nonnull + public List getIncidents() + { + return incidents; + } + + @Override + public int size() {return incidents.size();} + + @Override + public boolean isEmpty() {return incidents.isEmpty();} + + @Override + public boolean contains(Object o) {return incidents.contains(o);} + + @Override + @Nonnull + public Iterator iterator() {return incidents.iterator();} + + @Override + @Nonnull + public Object[] toArray() {return incidents.toArray();} + + @Override + @Nonnull + @SuppressWarnings("SuspiciousToArrayCall") + public T[] toArray(@Nonnull T[] a) {return incidents.toArray(a);} + + @Override + public boolean add(Incident incident) {return incidents.add(incident);} + + @Override + public boolean remove(Object o) {return incidents.remove(o);} + + @Override + public boolean containsAll(@Nonnull Collection c) {return incidents.containsAll(c);} + + @Override + public boolean addAll(@Nonnull Collection c) {return incidents.addAll(c);} + + @Override + public boolean addAll(int index, @Nonnull Collection c) {return incidents.addAll(index, c);} + + @Override + public boolean removeAll(@Nonnull Collection c) {return incidents.removeAll(c);} + + @Override + public boolean retainAll(@Nonnull Collection c) {return incidents.retainAll(c);} + + @Override + public void clear() {incidents.clear();} + + @Override + public int hashCode() {return incidents.hashCode();} + + @Override + public Incident get(int index) {return incidents.get(index);} + + @Override + public Incident set(int index, Incident element) {return incidents.set(index, element);} + + @Override + public void add(int index, Incident element) {incidents.add(index, element);} + + @Override + public Incident remove(int index) {return incidents.remove(index);} + + @Override + public int indexOf(Object o) {return incidents.indexOf(o);} + + @Override + public int lastIndexOf(Object o) {return incidents.lastIndexOf(o);} + + @Override + @Nonnull + public ListIterator listIterator() {return incidents.listIterator();} + + @Override + @Nonnull + public ListIterator listIterator(int index) {return incidents.listIterator(index);} + + @Override + @Nonnull + public List subList(int fromIndex, int toIndex) {return incidents.subList(fromIndex, toIndex);} +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java new file mode 100644 index 00000000..670f476c --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java @@ -0,0 +1,132 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.endpoints; + +import com.jagrosh.jdautilities.statuspage.data.Page; +import com.jagrosh.jdautilities.statuspage.data.ScheduledMaintenance; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +@Immutable +public class ScheduledMaintenances implements List +{ + @Nonnull + protected final Page page; + @Nonnull + protected final List ScheduledMaintenances; + + public ScheduledMaintenances(@Nonnull Page page, @Nonnull List ScheduledMaintenances) + { + this.page = page; + this.ScheduledMaintenances = ScheduledMaintenances; + } + + @Nonnull + public Page getPage() + { + return page; + } + + @Nonnull + public List getScheduledMaintenances() + { + return ScheduledMaintenances; + } + + @Override + public int size() {return ScheduledMaintenances.size();} + + @Override + public boolean isEmpty() {return ScheduledMaintenances.isEmpty();} + + @Override + public boolean contains(Object o) {return ScheduledMaintenances.contains(o);} + + @Override + @Nonnull + public Iterator iterator() {return ScheduledMaintenances.iterator();} + + @Override + @Nonnull + public Object[] toArray() {return ScheduledMaintenances.toArray();} + + @Override + @Nonnull + @SuppressWarnings("SuspiciousToArrayCall") + public T[] toArray(@Nonnull T[] a) {return ScheduledMaintenances.toArray(a);} + + @Override + public boolean add(ScheduledMaintenance ScheduledMaintenance) {return ScheduledMaintenances.add(ScheduledMaintenance);} + + @Override + public boolean remove(Object o) {return ScheduledMaintenances.remove(o);} + + @Override + public boolean containsAll(@Nonnull Collection c) {return ScheduledMaintenances.containsAll(c);} + + @Override + public boolean addAll(@Nonnull Collection c) {return ScheduledMaintenances.addAll(c);} + + @Override + public boolean addAll(int index, @Nonnull Collection c) {return ScheduledMaintenances.addAll(index, c);} + + @Override + public boolean removeAll(@Nonnull Collection c) {return ScheduledMaintenances.removeAll(c);} + + @Override + public boolean retainAll(@Nonnull Collection c) {return ScheduledMaintenances.retainAll(c);} + + @Override + public void clear() {ScheduledMaintenances.clear();} + + @Override + public int hashCode() {return ScheduledMaintenances.hashCode();} + + @Override + public ScheduledMaintenance get(int index) {return ScheduledMaintenances.get(index);} + + @Override + public ScheduledMaintenance set(int index, ScheduledMaintenance element) {return ScheduledMaintenances.set(index, element);} + + @Override + public void add(int index, ScheduledMaintenance element) {ScheduledMaintenances.add(index, element);} + + @Override + public ScheduledMaintenance remove(int index) {return ScheduledMaintenances.remove(index);} + + @Override + public int indexOf(Object o) {return ScheduledMaintenances.indexOf(o);} + + @Override + public int lastIndexOf(Object o) {return ScheduledMaintenances.lastIndexOf(o);} + + @Override + @Nonnull + public ListIterator listIterator() {return ScheduledMaintenances.listIterator();} + + @Override + @Nonnull + public ListIterator listIterator(int index) {return ScheduledMaintenances.listIterator(index);} + + @Override + @Nonnull + public List subList(int fromIndex, int toIndex) {return ScheduledMaintenances.subList(fromIndex, toIndex);} +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ServiceStatus.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ServiceStatus.java new file mode 100644 index 00000000..6bd15176 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ServiceStatus.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.endpoints; + +import com.jagrosh.jdautilities.statuspage.data.Page; +import com.jagrosh.jdautilities.statuspage.data.Status; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +@Immutable +public class ServiceStatus +{ + @Nonnull + protected final Page page; + @Nonnull + protected final Status status; + + public ServiceStatus(@Nonnull Page page, @Nonnull Status status) + { + this.page = page; + this.status = status; + } + + @Nonnull + public Page getPage() + { + return page; + } + + @Nonnull + public Status getStatus() + { + return status; + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java new file mode 100644 index 00000000..b83df024 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.jdautilities.statuspage.endpoints; + +import com.jagrosh.jdautilities.statuspage.data.*; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; +import java.util.List; + +@Immutable +public class Summary +{ + @Nonnull + protected final List components; + @Nonnull + protected final List incidents; + @Nonnull + protected final Page page; + @Nonnull + protected final List scheduledMaintenances; + @Nonnull + protected final Status status; + + public Summary(@Nonnull List components, @Nonnull List incidents, @Nonnull Page page, @Nonnull List scheduledMaintenances, @Nonnull Status status) + { + this.components = components; + this.incidents = incidents; + this.page = page; + this.scheduledMaintenances = scheduledMaintenances; + this.status = status; + } + + @Nonnull + public List getComponents() + { + return components; + } + + @Nonnull + public List getIncidents() + { + return incidents; + } + + @Nonnull + public Page getPage() + { + return page; + } + + @Nonnull + public List getScheduledMaintenances() + { + return scheduledMaintenances; + } + + @Nonnull + public Status getStatus() + { + return status; + } +} diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java new file mode 100644 index 00000000..964b8036 --- /dev/null +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright 2016-2018 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Statuspage package.
+ */ +package com.jagrosh.jdautilities.statuspage; From e31257c148695133c6eb3797fffbb952483b239e Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Tue, 13 Feb 2018 17:07:29 +0100 Subject: [PATCH 02/12] Added tests, removed the need of a ThreadPool and fixed parsing of OffsetDateTimes --- build.gradle | 2 + statuspage/build.gradle | 1 + .../jdautilities/statuspage/Statuspage.java | 96 +++++++------------ .../statuspage/tests/StatuspageTest.java | 57 +++++++++++ 4 files changed, 97 insertions(+), 59 deletions(-) create mode 100644 statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java diff --git a/build.gradle b/build.gradle index d79c42eb..eac5014b 100644 --- a/build.gradle +++ b/build.gradle @@ -39,12 +39,14 @@ allprojects { okhttpVersion = '3.9.1' findbugsVersion = '3.0.2' jsonVersion = '20180130' + junitVersion = '4.12' jda = { project.dependencies.compileOnly group: 'net.dv8tion', name: 'JDA', version: jdaVersion } slf4j = { project.dependencies.compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion } okhttp = { project.dependencies.compile group: 'com.squareup.okhttp3', name: 'okhttp', version: okhttpVersion } findbugs = { project.dependencies.compile group: 'com.google.code.findbugs', name: 'jsr305', version: findbugsVersion } json = { project.dependencies.compile group: 'org.json', name: 'json', version: jsonVersion } + junit = { project.dependencies.testCompile group: 'junit', name: 'junit', version: junitVersion } include = { String name -> project.dependencies.compile project.project(':' + name) } diff --git a/statuspage/build.gradle b/statuspage/build.gradle index a922f997..829b82bd 100644 --- a/statuspage/build.gradle +++ b/statuspage/build.gradle @@ -17,4 +17,5 @@ dependencies { okhttp() json() findbugs() + junit() } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java index 95ff9e5c..7d9c6dfc 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java @@ -25,14 +25,14 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import java.io.IOException; import java.io.Reader; import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; +import java.util.function.Function; @Immutable public class Statuspage @@ -57,29 +57,19 @@ public class Statuspage protected static final String URL_SCHEDULED_MAINTENANCES_UPCOMING = URL_API_BASE + "scheduled-maintenances/upcoming.json"; @Nonnull - protected final OkHttpClient client; + protected static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + @Nonnull - protected final ExecutorService pool; + protected final OkHttpClient client; public Statuspage() { - this(null, null); + this(null); } public Statuspage(@Nullable OkHttpClient client) - { - this(client, null); - } - - public Statuspage(@Nullable ExecutorService pool) - { - this(null, pool); - } - - public Statuspage(@Nullable OkHttpClient client, @Nullable ExecutorService pool) { this.client = client == null ? new OkHttpClient.Builder().build() : client; - this.pool = pool == null ? Executors.newSingleThreadExecutor() : pool; } /** @@ -89,7 +79,7 @@ public Statuspage(@Nullable OkHttpClient client, @Nullable ExecutorService pool) @Nonnull public CompletableFuture getSummary() { - return createFuture(f -> f.complete(createSummary(get(URL_SUMMARY)))); + return get(URL_SUMMARY, this::createSummary); } /** @@ -99,7 +89,7 @@ public CompletableFuture getSummary() @Nonnull public CompletableFuture getIncidentsAll() { - return createFuture(f -> f.complete(createIncidents(get(URL_INCIDENTS_ALL)))); + return get(URL_INCIDENTS_ALL, this::createIncidents); } /** @@ -108,7 +98,7 @@ public CompletableFuture getIncidentsAll() @Nonnull public CompletableFuture getIncidentsUnresolved() { - return createFuture(f -> f.complete(createIncidents(get(URL_INCIDENTS_UNRESOLVED)))); + return get(URL_INCIDENTS_UNRESOLVED, this::createIncidents); } /** @@ -118,7 +108,7 @@ public CompletableFuture getIncidentsUnresolved() @Nonnull public CompletableFuture getComponents() { - return createFuture(f -> f.complete(createComponents(get(URL_COMPONENTS)))); + return get(URL_COMPONENTS, this::createComponents); } /** @@ -127,7 +117,7 @@ public CompletableFuture getComponents() @Nonnull public CompletableFuture getScheduledMaintenancesAll() { - return createFuture(f -> f.complete(createScheduledMaintenances(get(URL_SCHEDULED_MAINTENANCES_ALL)))); + return get(URL_SCHEDULED_MAINTENANCES_ALL, this::createScheduledMaintenances); } /** @@ -136,7 +126,7 @@ public CompletableFuture getScheduledMaintenancesAll() @Nonnull public CompletableFuture getScheduledMaintenancesActive() { - return createFuture(f -> f.complete(createScheduledMaintenances(get(URL_SCHEDULED_MAINTENANCES_ACTIVE)))); + return get(URL_SCHEDULED_MAINTENANCES_ACTIVE, this::createScheduledMaintenances); } /** @@ -145,7 +135,7 @@ public CompletableFuture getScheduledMaintenancesActive() @Nonnull public CompletableFuture getScheduledMaintenancesUpcoming() { - return createFuture(f -> f.complete(createScheduledMaintenances(get(URL_SCHEDULED_MAINTENANCES_UPCOMING)))); + return get(URL_SCHEDULED_MAINTENANCES_UPCOMING, this::createScheduledMaintenances); } /** @@ -156,7 +146,7 @@ public CompletableFuture getScheduledMaintenancesUpcoming @Nonnull public CompletableFuture getServiceStatus() { - return createFuture(f -> f.complete(createServiceStatus(get(URL_SERVICE_STATUS)))); + return get(URL_SERVICE_STATUS, this::createServiceStatus); } @Nonnull @@ -242,30 +232,11 @@ protected ScheduledMaintenances createScheduledMaintenances(@Nonnull JSONObject } @Nonnull - protected CompletableFuture createFuture(@Nonnull Consumer> action) + protected CompletableFuture get(@Nonnull String url, @Nonnull Function funtion) { CompletableFuture future = new CompletableFuture<>(); - pool.submit(() -> { - try - { - action.accept(future); - } - catch (Exception e) - { - future.completeExceptionally(e); - } - }); - - return future; - } - - @Nonnull - protected JSONObject get(@Nonnull String url) - { - try - { - // @formatter:off + // @formatter:off Request request = new Request.Builder() .get() .url(url) @@ -273,9 +244,12 @@ protected JSONObject get(@Nonnull String url) .build(); // @formatter:on - Call call = client.newCall(request); + Call call = this.client.newCall(request); - try (Response response = call.execute()) + call.enqueue(new Callback() + { + @Override + public void onResponse(@Nonnull Call call, @Nonnull Response response) { ResponseBody body = response.body(); @@ -284,17 +258,21 @@ protected JSONObject get(@Nonnull String url) Reader reader = body.charStream(); - return new JSONObject(new JSONTokener(reader)); + JSONObject object = new JSONObject(new JSONTokener(reader)); + + T t = funtion.apply(object); + + future.complete(t); } - } - catch (RuntimeException e) - { - throw e; - } - catch (Exception e) - { - throw new RuntimeException(e); - } + + @Override + public void onFailure(@Nonnull Call call, @Nonnull IOException e) + { + future.completeExceptionally(e); + } + }); + + return future; } @Nonnull @@ -463,6 +441,6 @@ protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject ob protected OffsetDateTime toOffsetDateTime(String time) { - return time == null ? null : OffsetDateTime.parse(time); + return time == null || time.isEmpty() ? null : OffsetDateTime.parse(time, DATE_TIME_FORMATTER); } } diff --git a/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java b/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java new file mode 100644 index 00000000..9efabff4 --- /dev/null +++ b/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java @@ -0,0 +1,57 @@ +package com.jagrosh.jdautilities.statuspage.tests; + +import com.jagrosh.jdautilities.statuspage.Statuspage; +import org.junit.Test; + +public class StatuspageTest +{ + public final Statuspage statuspage = new Statuspage(); + + @Test + public void testComponents() throws Exception + { + statuspage.getComponents().get(); + } + + @Test + public void testIncidentsAll() throws Exception + { + statuspage.getIncidentsAll().get(); + } + + @Test + public void testIncidentsUnresolved() throws Exception + { + statuspage.getIncidentsUnresolved().get(); + } + + @Test + public void testScheduledMaintenancesActive() throws Exception + { + statuspage.getScheduledMaintenancesActive().get(); + } + + @Test + public void testScheduledMaintenancesAll() throws Exception + { + statuspage.getScheduledMaintenancesAll().get(); + } + + @Test + public void testScheduledMaintenancesUpcoming() throws Exception + { + statuspage.getScheduledMaintenancesUpcoming().get(); + } + + @Test + public void testServiceStatus() throws Exception + { + statuspage.getServiceStatus().get(); + } + + @Test + public void testSummary() throws Exception + { + statuspage.getSummary().get(); + } +} From cd2c50dc094988415ea4132cf2aed7811d0b82c6 Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Tue, 13 Feb 2018 17:21:55 +0100 Subject: [PATCH 03/12] Hid the CompletableFuture class behing an interface to deny access to internal methods. --- build.gradle | 5 +++- .../commons/async/AsyncFuture.java | 6 +++++ .../jdautilities/commons/async/AsyncTask.java | 12 ++++++++++ statuspage/build.gradle | 3 +++ .../jdautilities/statuspage/Statuspage.java | 23 ++++++++++--------- 5 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncFuture.java create mode 100644 commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncTask.java diff --git a/build.gradle b/build.gradle index eac5014b..3c9da92a 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,10 @@ allprojects { jsonVersion = '20180130' junitVersion = '4.12' - jda = { project.dependencies.compileOnly group: 'net.dv8tion', name: 'JDA', version: jdaVersion } + jda = { + project.dependencies.compileOnly group: 'net.dv8tion', name: 'JDA', version: jdaVersion + project.dependencies.testCompile group: 'net.dv8tion', name: 'JDA', version: jdaVersion + } slf4j = { project.dependencies.compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion } okhttp = { project.dependencies.compile group: 'com.squareup.okhttp3', name: 'okhttp', version: okhttpVersion } findbugs = { project.dependencies.compile group: 'com.google.code.findbugs', name: 'jsr305', version: findbugsVersion } diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncFuture.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncFuture.java new file mode 100644 index 00000000..1c39a7a2 --- /dev/null +++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncFuture.java @@ -0,0 +1,6 @@ +package com.jagrosh.jdautilities.commons.async; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Future; + +public interface AsyncFuture extends Future, CompletionStage {} diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncTask.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncTask.java new file mode 100644 index 00000000..a040817a --- /dev/null +++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/async/AsyncTask.java @@ -0,0 +1,12 @@ +package com.jagrosh.jdautilities.commons.async; + +import java.util.concurrent.CompletableFuture; + +public class AsyncTask extends CompletableFuture implements AsyncFuture +{ + @Override + public CompletableFuture toCompletableFuture() + { + throw new UnsupportedOperationException("Access to the CompletableFuture is not supported."); + } +} diff --git a/statuspage/build.gradle b/statuspage/build.gradle index 829b82bd..be0cb95c 100644 --- a/statuspage/build.gradle +++ b/statuspage/build.gradle @@ -14,8 +14,11 @@ * limitations under the License. */ dependencies { + include('commons') + okhttp() json() findbugs() + junit() } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java index 7d9c6dfc..dd378eee 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java @@ -15,6 +15,8 @@ */ package com.jagrosh.jdautilities.statuspage; +import com.jagrosh.jdautilities.commons.async.AsyncFuture; +import com.jagrosh.jdautilities.commons.async.AsyncTask; import com.jagrosh.jdautilities.statuspage.data.*; import com.jagrosh.jdautilities.statuspage.endpoints.*; import okhttp3.*; @@ -31,7 +33,6 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.function.Function; @Immutable @@ -77,7 +78,7 @@ public Statuspage(@Nullable OkHttpClient client) * in-progress scheduled maintenances. */ @Nonnull - public CompletableFuture getSummary() + public AsyncFuture getSummary() { return get(URL_SUMMARY, this::createSummary); } @@ -87,7 +88,7 @@ public CompletableFuture getSummary() * as well as those in the Resolved and Postmortem state. */ @Nonnull - public CompletableFuture getIncidentsAll() + public AsyncFuture getIncidentsAll() { return get(URL_INCIDENTS_ALL, this::createIncidents); } @@ -96,7 +97,7 @@ public CompletableFuture getIncidentsAll() * Get a list of any unresolved incidents. This endpoint will only return incidents in the Investigating, Identified, or Monitoring state. */ @Nonnull - public CompletableFuture getIncidentsUnresolved() + public AsyncFuture getIncidentsUnresolved() { return get(URL_INCIDENTS_UNRESOLVED, this::createIncidents); } @@ -106,7 +107,7 @@ public CompletableFuture getIncidentsUnresolved() * degraded_performance, partial_outage, or major_outage. */ @Nonnull - public CompletableFuture getComponents() + public AsyncFuture getComponents() { return get(URL_COMPONENTS, this::createComponents); } @@ -115,7 +116,7 @@ public CompletableFuture getComponents() * Get a list of the 50 most recent scheduled maintenances. This includes scheduled maintenances as described in the above two endpoints, as well as those in the Completed state. */ @Nonnull - public CompletableFuture getScheduledMaintenancesAll() + public AsyncFuture getScheduledMaintenancesAll() { return get(URL_SCHEDULED_MAINTENANCES_ALL, this::createScheduledMaintenances); } @@ -124,7 +125,7 @@ public CompletableFuture getScheduledMaintenancesAll() * Get a list of any active maintenances. This endpoint will only return scheduled maintenances in the In Progress or Verifying state. */ @Nonnull - public CompletableFuture getScheduledMaintenancesActive() + public AsyncFuture getScheduledMaintenancesActive() { return get(URL_SCHEDULED_MAINTENANCES_ACTIVE, this::createScheduledMaintenances); } @@ -133,7 +134,7 @@ public CompletableFuture getScheduledMaintenancesActive() * Get a list of any upcoming maintenances. This endpoint will only return scheduled maintenances still in the Scheduled state. */ @Nonnull - public CompletableFuture getScheduledMaintenancesUpcoming() + public AsyncFuture getScheduledMaintenancesUpcoming() { return get(URL_SCHEDULED_MAINTENANCES_UPCOMING, this::createScheduledMaintenances); } @@ -144,7 +145,7 @@ public CompletableFuture getScheduledMaintenancesUpcoming * "All Systems Operational", "Partial System Outage", and "Major Service Outage". */ @Nonnull - public CompletableFuture getServiceStatus() + public AsyncFuture getServiceStatus() { return get(URL_SERVICE_STATUS, this::createServiceStatus); } @@ -232,9 +233,9 @@ protected ScheduledMaintenances createScheduledMaintenances(@Nonnull JSONObject } @Nonnull - protected CompletableFuture get(@Nonnull String url, @Nonnull Function funtion) + protected AsyncFuture get(@Nonnull String url, @Nonnull Function funtion) { - CompletableFuture future = new CompletableFuture<>(); + AsyncTask future = new AsyncTask<>(); // @formatter:off Request request = new Request.Builder() From 7c559751663586cda13264da3635cd191e53b2ee Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Tue, 13 Feb 2018 17:42:35 +0100 Subject: [PATCH 04/12] Made a little gradle thing more beautiful --- build.gradle | 6 ++++-- command/build.gradle | 2 +- doc/build.gradle | 2 +- examples/build.gradle | 8 ++++---- menu/build.gradle | 2 +- statuspage/build.gradle | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 3c9da92a..8bed9dcd 100644 --- a/build.gradle +++ b/build.gradle @@ -51,14 +51,16 @@ allprojects { json = { project.dependencies.compile group: 'org.json', name: 'json', version: jsonVersion } junit = { project.dependencies.testCompile group: 'junit', name: 'junit', version: junitVersion } - include = { String name -> project.dependencies.compile project.project(':' + name) } - artifactId = (rootProject == project ? rootProject.name : (rootProject.name + '-' + project.name)).toLowerCase() moduleName = rootProject == project ? "com.jagrosh.jdautilities" : "com.jagrosh.jdautilities.${project.name.toLowerCase()}" } + rootProject.subprojects.each { subproject -> + project.ext."$subproject.name" = { project.dependencies.compile project.project(":$subproject.name") } + } + repositories { jcenter() } diff --git a/command/build.gradle b/command/build.gradle index 4aac21ad..39778a60 100644 --- a/command/build.gradle +++ b/command/build.gradle @@ -14,7 +14,7 @@ * limitations under the License. */ dependencies { - include('commons') + commons() jda() slf4j() diff --git a/doc/build.gradle b/doc/build.gradle index 9fd6679c..c136723e 100644 --- a/doc/build.gradle +++ b/doc/build.gradle @@ -14,7 +14,7 @@ * limitations under the License. */ dependencies { - include('commons') + commons() jda() } diff --git a/examples/build.gradle b/examples/build.gradle index eb266f75..048d30f9 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -14,10 +14,10 @@ * limitations under the License. */ dependencies { - include('commons') - include('command') - include('menu') - include('doc') + commons() + command() + menu() + doc() jda() slf4j() diff --git a/menu/build.gradle b/menu/build.gradle index 62769c46..d79bb53a 100644 --- a/menu/build.gradle +++ b/menu/build.gradle @@ -14,7 +14,7 @@ * limitations under the License. */ dependencies { - include('commons') + commons() jda() findbugs() diff --git a/statuspage/build.gradle b/statuspage/build.gradle index be0cb95c..606225bb 100644 --- a/statuspage/build.gradle +++ b/statuspage/build.gradle @@ -14,7 +14,7 @@ * limitations under the License. */ dependencies { - include('commons') + commons() okhttp() json() From f86ce388660146ccf2ab32ddffa38cfeee4033c0 Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Tue, 13 Feb 2018 18:58:22 +0100 Subject: [PATCH 05/12] Changed enum implementation --- .../statuspage/data/Component.java | 49 +++++---- .../statuspage/data/Incident.java | 100 +++++++++++------- .../jdautilities/statuspage/data/Status.java | 49 +++++---- 3 files changed, 119 insertions(+), 79 deletions(-) diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java index f410cb68..51104e18 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java @@ -19,6 +19,8 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; @Immutable public class Component @@ -130,29 +132,38 @@ public boolean isShowOnlyIfDegraded() public enum Status { - OPERATIONAL, - DEGRADED_PERFORMANCE, - PARTIAL_OUTAGE, - MAJOR_OUTAGE, + OPERATIONAL("operational"), + DEGRADED_PERFORMANCE("degraded_performance"), + PARTIAL_OUTAGE("partial_outage"), + MAJOR_OUTAGE("major_outage"), - UNKNOWN; + UNKNOWN(""); + + private static final Map MAP = new HashMap<>(); + + static + { + for (Status status : Status.values()) + if (MAP.put(status.getKey(), status) != null) + throw new IllegalStateException("Duplicate key: " + status.getKey()); + } + + private final String key; + + Status(String key) + { + this.key = key; + } @Nonnull - public static Status from(String name) + public static Status from(String key) + { + return MAP.getOrDefault(key, UNKNOWN); + } + + public String getKey() { - switch (name.toLowerCase()) - { - case "operational": - return OPERATIONAL; - case "degraded_performance": - return DEGRADED_PERFORMANCE; - case "partial_outage": - return PARTIAL_OUTAGE; - case "major_outage": - return MAJOR_OUTAGE; - default: - return UNKNOWN; - } + return key; } } } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java index 331aac0a..168928ab 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java @@ -19,7 +19,9 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import java.time.OffsetDateTime; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Immutable public class Incident @@ -130,60 +132,76 @@ public Status getStatus() public enum Status { - INVESTIGATING, - IDENTIFIED, - MONITORING, - RESOLVED, - POSTMORTEM, + INVESTIGATING("investigating"), + IDENTIFIED("identified"), + MONITORING("monitoring"), + RESOLVED("resolved"), + POSTMORTEM("postmortem"), - UNKNOWN; + UNKNOWN(""); + + private static final Map MAP = new HashMap<>(); + + static + { + for (Status status : Status.values()) + if (MAP.put(status.getKey(), status) != null) + throw new IllegalStateException("Duplicate key: " + status.getKey()); + } + + private final String key; + + Status(String key) + { + this.key = key; + } @Nonnull - public static Status from(String name) + public static Status from(String key) + { + return MAP.getOrDefault(key, UNKNOWN); + } + + public String getKey() { - switch (name) - { - case "investigating": - return INVESTIGATING; - case "identified": - return IDENTIFIED; - case "monitoring": - return MONITORING; - case "resolved": - return RESOLVED; - case "postmortem": - return POSTMORTEM; - default: - return UNKNOWN; - } + return key; } } public enum Impact { - NONE, - MINOR, - MAJOR, - CRITICAL, + NONE("none"), + MINOR("minor"), + MAJOR("major"), + CRITICAL("critical"), - UNKNOWN; + UNKNOWN(""); + + private static final Map MAP = new HashMap<>(); + + static + { + for (Impact impact : Impact.values()) + if (MAP.put(impact.getKey(), impact) != null) + throw new IllegalStateException("Duplicate key: " + impact.getKey()); + } + + private final String key; + + Impact(String key) + { + this.key = key; + } @Nonnull - public static Impact from(String name) + public static Impact from(String key) + { + return MAP.getOrDefault(key, UNKNOWN); + } + + public String getKey() { - switch (name) - { - case "none": - return NONE; - case "minor": - return MINOR; - case "major": - return MAJOR; - case "critical": - return CRITICAL; - default: - return UNKNOWN; - } + return key; } } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java index 26eefc86..439d9be5 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java @@ -17,6 +17,8 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; +import java.util.HashMap; +import java.util.Map; @Immutable public class Status @@ -46,29 +48,38 @@ public String getDescription() public enum Indicator { - NONE, - MINOR, - MAJOR, - CRITICAL, + NONE("none"), + MINOR("minor"), + MAJOR("major"), + CRITICAL("critical"), - UNKNOWN; + UNKNOWN(""); + + private static final Map MAP = new HashMap<>(); + + static + { + for (Indicator indicator : Indicator.values()) + if (MAP.put(indicator.getKey(), indicator) != null) + throw new IllegalStateException("Duplicate key: " + indicator.getKey()); + } + + private final String key; + + Indicator(String key) + { + this.key = key; + } @Nonnull - public static Indicator from(String severity) + public static Indicator from(String key) + { + return MAP.getOrDefault(key, UNKNOWN); + } + + public String getKey() { - switch (severity.toLowerCase()) - { - case "none": - return NONE; - case "minor": - return MINOR; - case "major": - return MAJOR; - case "critical": - return CRITICAL; - default: - return UNKNOWN; - } + return key; } } } From 3c4b5a9dfa870b010c8b050c17e56c2ee23a902c Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Wed, 14 Feb 2018 13:15:01 +0100 Subject: [PATCH 06/12] Reordered methods --- .../jdautilities/statuspage/Statuspage.java | 246 +++++++++--------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java index dd378eee..ec271544 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java @@ -83,6 +83,16 @@ public AsyncFuture getSummary() return get(URL_SUMMARY, this::createSummary); } + /** + * Get the components for the page. Each component is listed along with its status - one of operational, + * degraded_performance, partial_outage, or major_outage. + */ + @Nonnull + public AsyncFuture getComponents() + { + return get(URL_COMPONENTS, this::createComponents); + } + /** * Get a list of the 50 most recent incidents. This includes all unresolved incidents as described above, * as well as those in the Resolved and Postmortem state. @@ -102,16 +112,6 @@ public AsyncFuture getIncidentsUnresolved() return get(URL_INCIDENTS_UNRESOLVED, this::createIncidents); } - /** - * Get the components for the page. Each component is listed along with its status - one of operational, - * degraded_performance, partial_outage, or major_outage. - */ - @Nonnull - public AsyncFuture getComponents() - { - return get(URL_COMPONENTS, this::createComponents); - } - /** * Get a list of the 50 most recent scheduled maintenances. This includes scheduled maintenances as described in the above two endpoints, as well as those in the Completed state. */ @@ -150,6 +150,50 @@ public AsyncFuture getServiceStatus() return get(URL_SERVICE_STATUS, this::createServiceStatus); } + @Nonnull + protected AsyncFuture get(@Nonnull String url, @Nonnull Function funtion) + { + AsyncTask future = new AsyncTask<>(); + + // @formatter:off + Request request = new Request.Builder() + .get() + .url(url) + .header("Content-Type", "application/json") + .build(); + // @formatter:on + + Call call = this.client.newCall(request); + + call.enqueue(new Callback() + { + @Override + public void onResponse(@Nonnull Call call, @Nonnull Response response) + { + ResponseBody body = response.body(); + + if (body == null) + throw new IllegalStateException("response has no body"); + + Reader reader = body.charStream(); + + JSONObject object = new JSONObject(new JSONTokener(reader)); + + T t = funtion.apply(object); + + future.complete(t); + } + + @Override + public void onFailure(@Nonnull Call call, @Nonnull IOException e) + { + future.completeExceptionally(e); + } + }); + + return future; + } + @Nonnull protected Summary createSummary(@Nonnull JSONObject object) { @@ -201,18 +245,20 @@ protected Components createComponents(@Nonnull JSONObject object) } @Nonnull - protected ServiceStatus createServiceStatus(@Nonnull JSONObject object) + protected Incidents createIncidents(@Nonnull JSONObject object) { @Nonnull - final JSONObject pageObject = object.getJSONObject("page"); + final JSONArray incidentsArray = object.getJSONArray("incidents"); @Nonnull - final Page page = createPage(pageObject); + final List incidents = new ArrayList<>(incidentsArray.length()); + for (int i = 0; i < incidentsArray.length(); i++) + incidents.add(createIncident(incidentsArray.getJSONObject(i))); @Nonnull - final JSONObject statusObject = object.getJSONObject("status"); + final JSONObject pageObject = object.getJSONObject("page"); @Nonnull - final Status status = createStatus(statusObject); + final Page page = createPage(pageObject); - return new ServiceStatus(page, status); + return new Incidents(page, incidents); } @Nonnull @@ -233,47 +279,45 @@ protected ScheduledMaintenances createScheduledMaintenances(@Nonnull JSONObject } @Nonnull - protected AsyncFuture get(@Nonnull String url, @Nonnull Function funtion) + protected ServiceStatus createServiceStatus(@Nonnull JSONObject object) { - AsyncTask future = new AsyncTask<>(); - - // @formatter:off - Request request = new Request.Builder() - .get() - .url(url) - .header("Content-Type", "application/json") - .build(); - // @formatter:on - - Call call = this.client.newCall(request); - - call.enqueue(new Callback() - { - @Override - public void onResponse(@Nonnull Call call, @Nonnull Response response) - { - ResponseBody body = response.body(); - - if (body == null) - throw new IllegalStateException("response has no body"); - - Reader reader = body.charStream(); - - JSONObject object = new JSONObject(new JSONTokener(reader)); - - T t = funtion.apply(object); + @Nonnull + final JSONObject pageObject = object.getJSONObject("page"); + @Nonnull + final Page page = createPage(pageObject); + @Nonnull + final JSONObject statusObject = object.getJSONObject("status"); + @Nonnull + final Status status = createStatus(statusObject); - future.complete(t); - } + return new ServiceStatus(page, status); + } - @Override - public void onFailure(@Nonnull Call call, @Nonnull IOException e) - { - future.completeExceptionally(e); - } - }); + @Nonnull + protected Component createComponent(@Nonnull JSONObject object) + { + @Nonnull + final String pageId = object.getString("page_id"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + @Nonnull + final String name = object.getString("name"); + @Nonnull + final String createdAt = object.getString("created_at"); + @Nullable + final String description = object.optString("description"); + @Nonnull + final String id = object.getString("id"); + final int position = object.getInt("position"); + @Nonnull + final String status = object.getString("status"); + final boolean showcase = object.getBoolean("showcase"); + @Nullable + final String groupId = object.optString("group_id"); + final boolean group = object.getBoolean("group"); + final boolean showOnlyIfDegraded = object.getBoolean("only_show_if_degraded"); - return future; + return new Component(pageId, toOffsetDateTime(updatedAt), name, toOffsetDateTime(createdAt), description, id, position, Component.Status.from(status), showcase, groupId, group, showOnlyIfDegraded); } @Nonnull @@ -309,23 +353,6 @@ protected Incident createIncident(@Nonnull JSONObject object) return new Incident(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status)); } - @Nonnull - protected Incidents createIncidents(@Nonnull JSONObject object) - { - @Nonnull - final JSONArray incidentsArray = object.getJSONArray("incidents"); - @Nonnull - final List incidents = new ArrayList<>(incidentsArray.length()); - for (int i = 0; i < incidentsArray.length(); i++) - incidents.add(createIncident(incidentsArray.getJSONObject(i))); - @Nonnull - final JSONObject pageObject = object.getJSONObject("page"); - @Nonnull - final Page page = createPage(pageObject); - - return new Incidents(page, incidents); - } - @Nonnull protected Incident.Update createIncidentUpdate(@Nonnull JSONObject object) { @@ -351,59 +378,6 @@ protected Incident.Update createIncidentUpdate(@Nonnull JSONObject object) return new Incident.Update(incidentId, toOffsetDateTime(updatedAt), toOffsetDateTime(createdAt), id, body, toOffsetDateTime(displayAt), Incident.Status.from(status)); } - @Nonnull - protected Page createPage(@Nonnull JSONObject object) - { - @Nonnull - final String name = object.getString("name"); - @Nonnull - final String id = object.getString("id"); - @Nonnull - final String url = object.getString("url"); - @Nonnull - final String updatedAt = object.getString("updated_at"); - - return new Page(name, id, url, toOffsetDateTime(updatedAt)); - } - - @Nonnull - protected Status createStatus(@Nonnull JSONObject object) - { - @Nonnull - final String indicator = object.getString("indicator"); - @Nonnull - final String description = object.getString("description"); - - return new Status(Status.Indicator.from(indicator), description); - } - - @Nonnull - protected Component createComponent(@Nonnull JSONObject object) - { - @Nonnull - final String pageId = object.getString("page_id"); - @Nonnull - final String updatedAt = object.getString("updated_at"); - @Nonnull - final String name = object.getString("name"); - @Nonnull - final String createdAt = object.getString("created_at"); - @Nullable - final String description = object.optString("description"); - @Nonnull - final String id = object.getString("id"); - final int position = object.getInt("position"); - @Nonnull - final String status = object.getString("status"); - final boolean showcase = object.getBoolean("showcase"); - @Nullable - final String groupId = object.optString("group_id"); - final boolean group = object.getBoolean("group"); - final boolean showOnlyIfDegraded = object.getBoolean("only_show_if_degraded"); - - return new Component(pageId, toOffsetDateTime(updatedAt), name, toOffsetDateTime(createdAt), description, id, position, Component.Status.from(status), showcase, groupId, group, showOnlyIfDegraded); - } - @Nonnull protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject object) { @@ -440,6 +414,32 @@ protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject ob return new ScheduledMaintenance(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status), toOffsetDateTime(scheduledFor), toOffsetDateTime(scheduledUntil)); } + @Nonnull + protected Status createStatus(@Nonnull JSONObject object) + { + @Nonnull + final String indicator = object.getString("indicator"); + @Nonnull + final String description = object.getString("description"); + + return new Status(Status.Indicator.from(indicator), description); + } + + @Nonnull + protected Page createPage(@Nonnull JSONObject object) + { + @Nonnull + final String name = object.getString("name"); + @Nonnull + final String id = object.getString("id"); + @Nonnull + final String url = object.getString("url"); + @Nonnull + final String updatedAt = object.getString("updated_at"); + + return new Page(name, id, url, toOffsetDateTime(updatedAt)); + } + protected OffsetDateTime toOffsetDateTime(String time) { return time == null || time.isEmpty() ? null : OffsetDateTime.parse(time, DATE_TIME_FORMATTER); From 7d52a82d2c0ce3c0ec6817734e249f8423fe9e22 Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Wed, 21 Feb 2018 19:28:09 +0100 Subject: [PATCH 07/12] Allowing submodules to not be included in parent and implemented this for the statuspage module. --- build.gradle | 28 +++++++++++++++++++++------- statuspage/build.gradle | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 8bed9dcd..efc39c81 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ allprojects { version = '2.1' project.ext { - jdaVersion = '3.5.0_335' + jdaVersion = '3.5.1_339' slf4jVersion = '1.7.25' okhttpVersion = '3.9.1' findbugsVersion = '3.0.2' @@ -53,8 +53,7 @@ allprojects { artifactId = (rootProject == project ? rootProject.name : (rootProject.name + '-' + project.name)).toLowerCase() - moduleName = rootProject == project ? "com.jagrosh.jdautilities" : - "com.jagrosh.jdautilities.${project.name.toLowerCase()}" + moduleName = rootProject == project ? "com.jagrosh.jdautilities" : "com.jagrosh.jdautilities.${project.name.toLowerCase()}" } rootProject.subprojects.each { subproject -> @@ -109,6 +108,10 @@ allprojects { subprojects { apply plugin: 'java' + ext { + includeInParent = true + } + compileJava { options.encoding = 'UTF-8' } @@ -165,6 +168,12 @@ subprojects { } } } + + afterEvaluate { + if (project.includeInParent) + rootProject.dependencies.compile project + } + } configurations { @@ -174,10 +183,6 @@ configurations { } } -dependencies { - compile subprojects -} - tasks.create('jar', ShadowJar) { group = 'build' @@ -292,3 +297,12 @@ publishing { } } } + +dependencyUpdates.resolutionStrategy = { + componentSelection { rules -> + rules.all { selection -> + if ( ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier -> selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/ } ) + selection.reject('only a release candidate') + } + } +} diff --git a/statuspage/build.gradle b/statuspage/build.gradle index 606225bb..703eff17 100644 --- a/statuspage/build.gradle +++ b/statuspage/build.gradle @@ -22,3 +22,5 @@ dependencies { junit() } + +includeInParent = false From 8c1a572046053a5197184734fac152926d5d537e Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Wed, 21 Feb 2018 20:03:53 +0100 Subject: [PATCH 08/12] Cleanup - Fixed immutable classes - Removed nullability annotation abuse - Removed List interface from classes as yo ucan get the list via a method --- .../jdautilities/statuspage/Statuspage.java | 94 +++---------------- .../statuspage/data/Component.java | 7 +- .../statuspage/data/Incident.java | 17 +++- .../jdautilities/statuspage/data/Status.java | 7 +- .../statuspage/endpoints/Components.java | 87 +---------------- .../statuspage/endpoints/Incidents.java | 87 +---------------- .../endpoints/ScheduledMaintenances.java | 92 +----------------- .../statuspage/endpoints/Summary.java | 7 +- 8 files changed, 50 insertions(+), 348 deletions(-) diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java index ec271544..a909cf85 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java @@ -39,23 +39,27 @@ public class Statuspage { @Nonnull - protected static final String URL_API_BASE = "https://status.discordapp.com/api/v2/"; + protected static final String URL_API_BASE = "https://status.discordapp.com/api/v2"; @Nonnull - protected static final String URL_SUMMARY = URL_API_BASE + "summary.json"; + protected static final String URL_SUMMARY = URL_API_BASE + "/summary.json"; @Nonnull - protected static final String URL_SERVICE_STATUS = URL_API_BASE + "status.json"; + protected static final String URL_SERVICE_STATUS = URL_API_BASE + "/status.json"; @Nonnull - protected static final String URL_COMPONENTS = URL_API_BASE + "components.json"; + protected static final String URL_COMPONENTS = URL_API_BASE + "/components.json"; @Nonnull - protected static final String URL_INCIDENTS_ALL = URL_API_BASE + "incidents.json"; + protected static final String URL_SCHEDULED_INCIDENTS_BASE = URL_API_BASE + "/incidents"; @Nonnull - protected static final String URL_INCIDENTS_UNRESOLVED = URL_API_BASE + "incidents/unresolved.json"; + protected static final String URL_INCIDENTS_ALL = URL_SCHEDULED_INCIDENTS_BASE + ".json"; @Nonnull - protected static final String URL_SCHEDULED_MAINTENANCES_ALL = URL_API_BASE + "scheduled-maintenances.json"; + protected static final String URL_INCIDENTS_UNRESOLVED = URL_SCHEDULED_INCIDENTS_BASE + "/unresolved.json"; @Nonnull - protected static final String URL_SCHEDULED_MAINTENANCES_ACTIVE = URL_API_BASE + "scheduled-maintenances/active.json"; + protected static final String URL_SCHEDULED_MAINTENANCES_BASE = URL_API_BASE + "/scheduled-maintenances"; @Nonnull - protected static final String URL_SCHEDULED_MAINTENANCES_UPCOMING = URL_API_BASE + "scheduled-maintenances/upcoming.json"; + protected static final String URL_SCHEDULED_MAINTENANCES_ALL = URL_SCHEDULED_MAINTENANCES_BASE + ".json"; + @Nonnull + protected static final String URL_SCHEDULED_MAINTENANCES_ACTIVE = URL_SCHEDULED_MAINTENANCES_BASE + "/active.json"; + @Nonnull + protected static final String URL_SCHEDULED_MAINTENANCES_UPCOMING = URL_SCHEDULED_MAINTENANCES_BASE + "/upcoming.json"; @Nonnull protected static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); @@ -197,31 +201,21 @@ public void onFailure(@Nonnull Call call, @Nonnull IOException e) @Nonnull protected Summary createSummary(@Nonnull JSONObject object) { - @Nonnull final JSONArray componentsArray = object.getJSONArray("components"); - @Nonnull final List components = new ArrayList<>(componentsArray.length()); for (int i = 0; i < componentsArray.length(); i++) components.add(createComponent(componentsArray.getJSONObject(i))); - @Nonnull final JSONArray incidentsArray = object.getJSONArray("incidents"); - @Nonnull final List incidents = new ArrayList<>(incidentsArray.length()); for (int i = 0; i < incidentsArray.length(); i++) incidents.add(createIncident(incidentsArray.getJSONObject(i))); - @Nonnull final JSONArray scheduledMaintenancesArray = object.getJSONArray("scheduled_maintenances"); - @Nonnull final List scheduledMaintenances = new ArrayList<>(scheduledMaintenancesArray.length()); for (int i = 0; i < scheduledMaintenancesArray.length(); i++) scheduledMaintenances.add(createScheduledMaintenance(scheduledMaintenancesArray.getJSONObject(i))); - @Nonnull final JSONObject pageObject = object.getJSONObject("page"); - @Nonnull final Page page = createPage(pageObject); - @Nonnull final JSONObject statusObject = object.getJSONObject("status"); - @Nonnull final Status status = createStatus(statusObject); return new Summary(components, incidents, page, scheduledMaintenances, status); @@ -230,13 +224,9 @@ protected Summary createSummary(@Nonnull JSONObject object) @Nonnull protected Components createComponents(@Nonnull JSONObject object) { - @Nonnull final JSONObject pageObject = object.getJSONObject("page"); - @Nonnull final Page page = createPage(pageObject); - @Nonnull final JSONArray componentsArray = object.getJSONArray("components"); - @Nonnull final List components = new ArrayList<>(componentsArray.length()); for (int i = 0; i < componentsArray.length(); i++) components.add(createComponent(componentsArray.getJSONObject(i))); @@ -247,15 +237,11 @@ protected Components createComponents(@Nonnull JSONObject object) @Nonnull protected Incidents createIncidents(@Nonnull JSONObject object) { - @Nonnull final JSONArray incidentsArray = object.getJSONArray("incidents"); - @Nonnull final List incidents = new ArrayList<>(incidentsArray.length()); for (int i = 0; i < incidentsArray.length(); i++) incidents.add(createIncident(incidentsArray.getJSONObject(i))); - @Nonnull final JSONObject pageObject = object.getJSONObject("page"); - @Nonnull final Page page = createPage(pageObject); return new Incidents(page, incidents); @@ -264,13 +250,9 @@ protected Incidents createIncidents(@Nonnull JSONObject object) @Nonnull protected ScheduledMaintenances createScheduledMaintenances(@Nonnull JSONObject object) { - @Nonnull final JSONObject pageObject = object.getJSONObject("page"); - @Nonnull final Page page = createPage(pageObject); - @Nonnull final JSONArray scheduledMaintenancesArray = object.getJSONArray("scheduled_maintenances"); - @Nonnull final List scheduledMaintenances = new ArrayList<>(scheduledMaintenancesArray.length()); for (int i = 0; i < scheduledMaintenancesArray.length(); i++) scheduledMaintenances.add(createScheduledMaintenance(scheduledMaintenancesArray.getJSONObject(i))); @@ -281,13 +263,9 @@ protected ScheduledMaintenances createScheduledMaintenances(@Nonnull JSONObject @Nonnull protected ServiceStatus createServiceStatus(@Nonnull JSONObject object) { - @Nonnull final JSONObject pageObject = object.getJSONObject("page"); - @Nonnull final Page page = createPage(pageObject); - @Nonnull final JSONObject statusObject = object.getJSONObject("status"); - @Nonnull final Status status = createStatus(statusObject); return new ServiceStatus(page, status); @@ -296,23 +274,15 @@ protected ServiceStatus createServiceStatus(@Nonnull JSONObject object) @Nonnull protected Component createComponent(@Nonnull JSONObject object) { - @Nonnull final String pageId = object.getString("page_id"); - @Nonnull final String updatedAt = object.getString("updated_at"); - @Nonnull final String name = object.getString("name"); - @Nonnull final String createdAt = object.getString("created_at"); - @Nullable final String description = object.optString("description"); - @Nonnull final String id = object.getString("id"); final int position = object.getInt("position"); - @Nonnull final String status = object.getString("status"); final boolean showcase = object.getBoolean("showcase"); - @Nullable final String groupId = object.optString("group_id"); final boolean group = object.getBoolean("group"); final boolean showOnlyIfDegraded = object.getBoolean("only_show_if_degraded"); @@ -323,31 +293,19 @@ protected Component createComponent(@Nonnull JSONObject object) @Nonnull protected Incident createIncident(@Nonnull JSONObject object) { - @Nullable final String monitoringAt = object.optString("monitoring_at"); - @Nonnull final String pageId = object.getString("page_id"); - @Nonnull final String updatedAt = object.getString("updated_at"); - @Nullable final String resolvedAt = object.optString("resolved_at"); - @Nonnull final String impact = object.getString("impact"); - @Nonnull final String name = object.getString("name"); - @Nonnull final String createdAt = object.getString("created_at"); - @Nonnull final JSONArray updatesArray = object.getJSONArray("incident_updates"); - @Nonnull final List updates = new ArrayList<>(updatesArray.length()); for (int i = 0; i < updatesArray.length(); i++) updates.add(createIncidentUpdate(updatesArray.getJSONObject(i))); - @Nonnull final String id = object.getString("id"); - @Nonnull final String shortlink = object.getString("shortlink"); - @Nonnull final String status = object.getString("status"); return new Incident(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status)); @@ -356,19 +314,12 @@ protected Incident createIncident(@Nonnull JSONObject object) @Nonnull protected Incident.Update createIncidentUpdate(@Nonnull JSONObject object) { - @Nonnull final String incidentId = object.getString("incident_id"); - @Nonnull final String updatedAt = object.getString("updated_at"); - @Nonnull final String createdAt = object.getString("created_at"); - @Nonnull final String id = object.getString("id"); - @Nonnull final String body = object.getString("body"); - @Nonnull final String displayAt = object.getString("display_at"); - @Nonnull final String status = object.getString("status"); // There are 3 more fields but they aren't part of the public API @@ -381,34 +332,21 @@ protected Incident.Update createIncidentUpdate(@Nonnull JSONObject object) @Nonnull protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject object) { - @Nullable final String monitoringAt = object.optString("monitoring_at"); - @Nonnull final String pageId = object.getString("page_id"); - @Nonnull final String updatedAt = object.getString("updated_at"); - @Nullable final String resolvedAt = object.optString("resolved_at"); - @Nonnull final String impact = object.getString("impact"); - @Nonnull final String name = object.getString("name"); - @Nonnull final String createdAt = object.getString("created_at"); final JSONArray updatesArray = object.getJSONArray("incident_updates"); - @Nonnull final List updates = new ArrayList<>(updatesArray.length()); for (int i = 0; i < updatesArray.length(); i++) updates.add(createIncidentUpdate(updatesArray.getJSONObject(i))); - @Nonnull final String id = object.getString("id"); - @Nonnull final String shortlink = object.getString("shortlink"); - @Nonnull final String status = object.getString("status"); - @Nonnull final String scheduledFor = object.getString("updated_at"); - @Nonnull final String scheduledUntil = object.getString("updated_at"); return new ScheduledMaintenance(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status), toOffsetDateTime(scheduledFor), toOffsetDateTime(scheduledUntil)); @@ -417,9 +355,7 @@ protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject ob @Nonnull protected Status createStatus(@Nonnull JSONObject object) { - @Nonnull final String indicator = object.getString("indicator"); - @Nonnull final String description = object.getString("description"); return new Status(Status.Indicator.from(indicator), description); @@ -428,13 +364,9 @@ protected Status createStatus(@Nonnull JSONObject object) @Nonnull protected Page createPage(@Nonnull JSONObject object) { - @Nonnull final String name = object.getString("name"); - @Nonnull final String id = object.getString("id"); - @Nonnull final String url = object.getString("url"); - @Nonnull final String updatedAt = object.getString("updated_at"); return new Page(name, id, url, toOffsetDateTime(updatedAt)); diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java index 51104e18..cca58c06 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Component.java @@ -139,6 +139,7 @@ public enum Status UNKNOWN(""); + @Nonnull private static final Map MAP = new HashMap<>(); static @@ -148,19 +149,21 @@ public enum Status throw new IllegalStateException("Duplicate key: " + status.getKey()); } + @Nonnull private final String key; - Status(String key) + Status(@Nonnull String key) { this.key = key; } @Nonnull - public static Status from(String key) + public static Status from(@Nullable String key) { return MAP.getOrDefault(key, UNKNOWN); } + @Nonnull public String getKey() { return key; diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java index 168928ab..c0f7d320 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java @@ -19,6 +19,7 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import java.time.OffsetDateTime; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +59,7 @@ public Incident(@Nullable OffsetDateTime monitoringAt, @Nonnull String pageId, @ this.impact = impact; this.name = name; this.createdAt = createdAt; - this.updates = updates; + this.updates = Collections.unmodifiableList(updates); this.id = id; this.shortlink = shortlink; this.status = status; @@ -140,6 +141,7 @@ public enum Status UNKNOWN(""); + @Nonnull private static final Map MAP = new HashMap<>(); static @@ -149,19 +151,21 @@ public enum Status throw new IllegalStateException("Duplicate key: " + status.getKey()); } + @Nonnull private final String key; - Status(String key) + Status(@Nonnull String key) { this.key = key; } @Nonnull - public static Status from(String key) + public static Status from(@Nullable String key) { return MAP.getOrDefault(key, UNKNOWN); } + @Nonnull public String getKey() { return key; @@ -177,6 +181,7 @@ public enum Impact UNKNOWN(""); + @Nonnull private static final Map MAP = new HashMap<>(); static @@ -186,19 +191,21 @@ public enum Impact throw new IllegalStateException("Duplicate key: " + impact.getKey()); } + @Nonnull private final String key; - Impact(String key) + Impact(@Nonnull String key) { this.key = key; } @Nonnull - public static Impact from(String key) + public static Impact from(@Nullable String key) { return MAP.getOrDefault(key, UNKNOWN); } + @Nonnull public String getKey() { return key; diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java index 439d9be5..ed887b57 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Status.java @@ -16,6 +16,7 @@ package com.jagrosh.jdautilities.statuspage.data; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import java.util.HashMap; import java.util.Map; @@ -64,19 +65,21 @@ public enum Indicator throw new IllegalStateException("Duplicate key: " + indicator.getKey()); } + @Nonnull private final String key; - Indicator(String key) + Indicator(@Nonnull String key) { this.key = key; } @Nonnull - public static Indicator from(String key) + public static Indicator from(@Nullable String key) { return MAP.getOrDefault(key, UNKNOWN); } + @Nonnull public String getKey() { return key; diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java index e7548d13..b9a601e5 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Components.java @@ -20,13 +20,11 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; -import java.util.Collection; -import java.util.Iterator; +import java.util.Collections; import java.util.List; -import java.util.ListIterator; @Immutable -public class Components implements List +public class Components { @Nonnull protected final Page page; @@ -36,7 +34,7 @@ public class Components implements List public Components(@Nonnull Page page, @Nonnull List components) { this.page = page; - this.components = components; + this.components = Collections.unmodifiableList(components); } @Nonnull @@ -50,83 +48,4 @@ public List getComponents() { return components; } - - @Override - public int size() {return components.size();} - - @Override - public boolean isEmpty() {return components.isEmpty();} - - @Override - public boolean contains(Object o) {return components.contains(o);} - - @Override - @Nonnull - public Iterator iterator() {return components.iterator();} - - @Override - @Nonnull - public Object[] toArray() {return components.toArray();} - - @Override - @Nonnull - @SuppressWarnings("SuspiciousToArrayCall") - public T[] toArray(@Nonnull T[] a) {return components.toArray(a);} - - @Override - public boolean add(Component component) {return components.add(component);} - - @Override - public boolean remove(Object o) {return components.remove(o);} - - @Override - public boolean containsAll(@Nonnull Collection c) {return components.containsAll(c);} - - @Override - public boolean addAll(@Nonnull Collection c) {return components.addAll(c);} - - @Override - public boolean addAll(int index, @Nonnull Collection c) {return components.addAll(index, c);} - - @Override - public boolean removeAll(@Nonnull Collection c) {return components.removeAll(c);} - - @Override - public boolean retainAll(@Nonnull Collection c) {return components.retainAll(c);} - - @Override - public void clear() {components.clear();} - - @Override - public int hashCode() {return components.hashCode();} - - @Override - public Component get(int index) {return components.get(index);} - - @Override - public Component set(int index, Component element) {return components.set(index, element);} - - @Override - public void add(int index, Component element) {components.add(index, element);} - - @Override - public Component remove(int index) {return components.remove(index);} - - @Override - public int indexOf(Object o) {return components.indexOf(o);} - - @Override - public int lastIndexOf(Object o) {return components.lastIndexOf(o);} - - @Override - @Nonnull - public ListIterator listIterator() {return components.listIterator();} - - @Override - @Nonnull - public ListIterator listIterator(int index) {return components.listIterator(index);} - - @Override - @Nonnull - public List subList(int fromIndex, int toIndex) {return components.subList(fromIndex, toIndex);} } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java index 3dc7caeb..344a9a70 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Incidents.java @@ -20,13 +20,11 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; -import java.util.Collection; -import java.util.Iterator; +import java.util.Collections; import java.util.List; -import java.util.ListIterator; @Immutable -public class Incidents implements List +public class Incidents { @Nonnull protected final Page page; @@ -36,7 +34,7 @@ public class Incidents implements List public Incidents(@Nonnull Page page, @Nonnull List incidents) { this.page = page; - this.incidents = incidents; + this.incidents = Collections.unmodifiableList(incidents); } @Nonnull @@ -50,83 +48,4 @@ public List getIncidents() { return incidents; } - - @Override - public int size() {return incidents.size();} - - @Override - public boolean isEmpty() {return incidents.isEmpty();} - - @Override - public boolean contains(Object o) {return incidents.contains(o);} - - @Override - @Nonnull - public Iterator iterator() {return incidents.iterator();} - - @Override - @Nonnull - public Object[] toArray() {return incidents.toArray();} - - @Override - @Nonnull - @SuppressWarnings("SuspiciousToArrayCall") - public T[] toArray(@Nonnull T[] a) {return incidents.toArray(a);} - - @Override - public boolean add(Incident incident) {return incidents.add(incident);} - - @Override - public boolean remove(Object o) {return incidents.remove(o);} - - @Override - public boolean containsAll(@Nonnull Collection c) {return incidents.containsAll(c);} - - @Override - public boolean addAll(@Nonnull Collection c) {return incidents.addAll(c);} - - @Override - public boolean addAll(int index, @Nonnull Collection c) {return incidents.addAll(index, c);} - - @Override - public boolean removeAll(@Nonnull Collection c) {return incidents.removeAll(c);} - - @Override - public boolean retainAll(@Nonnull Collection c) {return incidents.retainAll(c);} - - @Override - public void clear() {incidents.clear();} - - @Override - public int hashCode() {return incidents.hashCode();} - - @Override - public Incident get(int index) {return incidents.get(index);} - - @Override - public Incident set(int index, Incident element) {return incidents.set(index, element);} - - @Override - public void add(int index, Incident element) {incidents.add(index, element);} - - @Override - public Incident remove(int index) {return incidents.remove(index);} - - @Override - public int indexOf(Object o) {return incidents.indexOf(o);} - - @Override - public int lastIndexOf(Object o) {return incidents.lastIndexOf(o);} - - @Override - @Nonnull - public ListIterator listIterator() {return incidents.listIterator();} - - @Override - @Nonnull - public ListIterator listIterator(int index) {return incidents.listIterator(index);} - - @Override - @Nonnull - public List subList(int fromIndex, int toIndex) {return incidents.subList(fromIndex, toIndex);} } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java index 670f476c..f09a8942 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/ScheduledMaintenances.java @@ -20,23 +20,20 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; -import java.util.Collection; -import java.util.Iterator; import java.util.List; -import java.util.ListIterator; @Immutable -public class ScheduledMaintenances implements List +public class ScheduledMaintenances { @Nonnull protected final Page page; @Nonnull - protected final List ScheduledMaintenances; + protected final List scheduledMaintenances; - public ScheduledMaintenances(@Nonnull Page page, @Nonnull List ScheduledMaintenances) + public ScheduledMaintenances(@Nonnull Page page, @Nonnull List scheduledMaintenances) { this.page = page; - this.ScheduledMaintenances = ScheduledMaintenances; + this.scheduledMaintenances = scheduledMaintenances; } @Nonnull @@ -48,85 +45,6 @@ public Page getPage() @Nonnull public List getScheduledMaintenances() { - return ScheduledMaintenances; + return scheduledMaintenances; } - - @Override - public int size() {return ScheduledMaintenances.size();} - - @Override - public boolean isEmpty() {return ScheduledMaintenances.isEmpty();} - - @Override - public boolean contains(Object o) {return ScheduledMaintenances.contains(o);} - - @Override - @Nonnull - public Iterator iterator() {return ScheduledMaintenances.iterator();} - - @Override - @Nonnull - public Object[] toArray() {return ScheduledMaintenances.toArray();} - - @Override - @Nonnull - @SuppressWarnings("SuspiciousToArrayCall") - public T[] toArray(@Nonnull T[] a) {return ScheduledMaintenances.toArray(a);} - - @Override - public boolean add(ScheduledMaintenance ScheduledMaintenance) {return ScheduledMaintenances.add(ScheduledMaintenance);} - - @Override - public boolean remove(Object o) {return ScheduledMaintenances.remove(o);} - - @Override - public boolean containsAll(@Nonnull Collection c) {return ScheduledMaintenances.containsAll(c);} - - @Override - public boolean addAll(@Nonnull Collection c) {return ScheduledMaintenances.addAll(c);} - - @Override - public boolean addAll(int index, @Nonnull Collection c) {return ScheduledMaintenances.addAll(index, c);} - - @Override - public boolean removeAll(@Nonnull Collection c) {return ScheduledMaintenances.removeAll(c);} - - @Override - public boolean retainAll(@Nonnull Collection c) {return ScheduledMaintenances.retainAll(c);} - - @Override - public void clear() {ScheduledMaintenances.clear();} - - @Override - public int hashCode() {return ScheduledMaintenances.hashCode();} - - @Override - public ScheduledMaintenance get(int index) {return ScheduledMaintenances.get(index);} - - @Override - public ScheduledMaintenance set(int index, ScheduledMaintenance element) {return ScheduledMaintenances.set(index, element);} - - @Override - public void add(int index, ScheduledMaintenance element) {ScheduledMaintenances.add(index, element);} - - @Override - public ScheduledMaintenance remove(int index) {return ScheduledMaintenances.remove(index);} - - @Override - public int indexOf(Object o) {return ScheduledMaintenances.indexOf(o);} - - @Override - public int lastIndexOf(Object o) {return ScheduledMaintenances.lastIndexOf(o);} - - @Override - @Nonnull - public ListIterator listIterator() {return ScheduledMaintenances.listIterator();} - - @Override - @Nonnull - public ListIterator listIterator(int index) {return ScheduledMaintenances.listIterator(index);} - - @Override - @Nonnull - public List subList(int fromIndex, int toIndex) {return ScheduledMaintenances.subList(fromIndex, toIndex);} } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java index b83df024..d045f386 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/endpoints/Summary.java @@ -19,6 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; +import java.util.Collections; import java.util.List; @Immutable @@ -37,10 +38,10 @@ public class Summary public Summary(@Nonnull List components, @Nonnull List incidents, @Nonnull Page page, @Nonnull List scheduledMaintenances, @Nonnull Status status) { - this.components = components; - this.incidents = incidents; + this.components = Collections.unmodifiableList(components); + this.incidents = Collections.unmodifiableList(incidents); this.page = page; - this.scheduledMaintenances = scheduledMaintenances; + this.scheduledMaintenances = Collections.unmodifiableList(scheduledMaintenances); this.status = status; } From 4aff9abaa74e71ac3f1e6abea1a330688e25508d Mon Sep 17 00:00:00 2001 From: Almighty Alpaca Date: Wed, 21 Feb 2018 20:12:14 +0100 Subject: [PATCH 09/12] Fixed field type --- .../jdautilities/statuspage/Statuspage.java | 16 +++++++++++----- .../jdautilities/statuspage/data/Incident.java | 6 +++--- .../statuspage/data/ScheduledMaintenance.java | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java index a909cf85..474804da 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java @@ -117,7 +117,8 @@ public AsyncFuture getIncidentsUnresolved() } /** - * Get a list of the 50 most recent scheduled maintenances. This includes scheduled maintenances as described in the above two endpoints, as well as those in the Completed state. + * Get a list of the 50 most recent scheduled maintenances. This includes scheduled maintenances as described in the above two endpoints, + * as well as those in the Completed state. */ @Nonnull public AsyncFuture getScheduledMaintenancesAll() @@ -287,7 +288,8 @@ protected Component createComponent(@Nonnull JSONObject object) final boolean group = object.getBoolean("group"); final boolean showOnlyIfDegraded = object.getBoolean("only_show_if_degraded"); - return new Component(pageId, toOffsetDateTime(updatedAt), name, toOffsetDateTime(createdAt), description, id, position, Component.Status.from(status), showcase, groupId, group, showOnlyIfDegraded); + return new Component(pageId, toOffsetDateTime(updatedAt), name, toOffsetDateTime(createdAt), description, id, position, + Component.Status.from(status), showcase, groupId, group, showOnlyIfDegraded); } @Nonnull @@ -308,7 +310,8 @@ protected Incident createIncident(@Nonnull JSONObject object) final String shortlink = object.getString("shortlink"); final String status = object.getString("status"); - return new Incident(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status)); + return new Incident(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), + Incident.Impact.from(impact), name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status)); } @Nonnull @@ -326,7 +329,8 @@ protected Incident.Update createIncidentUpdate(@Nonnull JSONObject object) // and I'm unsure what they are used for: // 'affected_components', 'custom_tweet' and 'deliver_notifications' - return new Incident.Update(incidentId, toOffsetDateTime(updatedAt), toOffsetDateTime(createdAt), id, body, toOffsetDateTime(displayAt), Incident.Status.from(status)); + return new Incident.Update(incidentId, toOffsetDateTime(updatedAt), toOffsetDateTime(createdAt), id, body, + toOffsetDateTime(displayAt), Incident.Status.from(status)); } @Nonnull @@ -349,7 +353,9 @@ protected ScheduledMaintenance createScheduledMaintenance(@Nonnull JSONObject ob final String scheduledFor = object.getString("updated_at"); final String scheduledUntil = object.getString("updated_at"); - return new ScheduledMaintenance(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), impact, name, toOffsetDateTime(createdAt), updates, id, shortlink, Incident.Status.from(status), toOffsetDateTime(scheduledFor), toOffsetDateTime(scheduledUntil)); + return new ScheduledMaintenance(toOffsetDateTime(monitoringAt), pageId, toOffsetDateTime(updatedAt), toOffsetDateTime(resolvedAt), + Incident.Impact.from(impact), name, toOffsetDateTime(createdAt), updates, id, shortlink, + Incident.Status.from(status), toOffsetDateTime(scheduledFor), toOffsetDateTime(scheduledUntil)); } @Nonnull diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java index c0f7d320..2e98337e 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/Incident.java @@ -36,7 +36,7 @@ public class Incident @Nullable protected final OffsetDateTime resolvedAt; @Nonnull - protected final String impact; + protected final Impact impact; @Nonnull protected final String name; @Nonnull @@ -50,7 +50,7 @@ public class Incident @Nonnull protected final Status status; - public Incident(@Nullable OffsetDateTime monitoringAt, @Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, @Nullable OffsetDateTime resolvedAt, @Nonnull String impact, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nonnull List updates, @Nonnull String id, @Nonnull String shortlink, @Nonnull Status status) + public Incident(@Nullable OffsetDateTime monitoringAt, @Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, @Nullable OffsetDateTime resolvedAt, @Nonnull Impact impact, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nonnull List updates, @Nonnull String id, @Nonnull String shortlink, @Nonnull Status status) { this.monitoringAt = monitoringAt; this.pageId = pageId; @@ -90,7 +90,7 @@ public OffsetDateTime getResolvedAt() } @Nonnull - public String getImpact() + public Impact getImpact() { return impact; } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java index 80858e13..47747fe2 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/data/ScheduledMaintenance.java @@ -28,7 +28,7 @@ public class ScheduledMaintenance extends Incident @Nonnull protected final OffsetDateTime scheduledUntil; - public ScheduledMaintenance(OffsetDateTime monitoringAt, @Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, OffsetDateTime resolvedAt, @Nonnull String impact, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nonnull List updates, @Nonnull String id, @Nonnull String shortlink, @Nonnull Status status, @Nonnull OffsetDateTime scheduledFor, @Nonnull OffsetDateTime scheduledUntil) + public ScheduledMaintenance(OffsetDateTime monitoringAt, @Nonnull String pageId, @Nonnull OffsetDateTime updatedAt, OffsetDateTime resolvedAt, @Nonnull Impact impact, @Nonnull String name, @Nonnull OffsetDateTime createdAt, @Nonnull List updates, @Nonnull String id, @Nonnull String shortlink, @Nonnull Status status, @Nonnull OffsetDateTime scheduledFor, @Nonnull OffsetDateTime scheduledUntil) { super(monitoringAt, pageId, updatedAt, resolvedAt, impact, name, createdAt, updates, id, shortlink, status); From 4e8cca7915bd6af68bcbbb225f5f9f7fdedb493b Mon Sep 17 00:00:00 2001 From: TheMonitorLizard Date: Thu, 31 May 2018 15:21:40 -0500 Subject: [PATCH 10/12] fixed statuspage build --- statuspage/build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/statuspage/build.gradle b/statuspage/build.gradle index 703eff17..ed3552f3 100644 --- a/statuspage/build.gradle +++ b/statuspage/build.gradle @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +includeInParent = false + dependencies { - commons() + compile okhttp() + compile json() + compile findbugs() - okhttp() - json() - findbugs() + compile commons() - junit() + testCompile "junit:junit:4.12" // temporary fix while I add junit as an extension on master (brb) } - -includeInParent = false From 61dbd2edae2b6e807674a0c42ce0c3efc94dff62 Mon Sep 17 00:00:00 2001 From: TheMonitorLizard Date: Thu, 31 May 2018 15:24:26 -0500 Subject: [PATCH 11/12] done with that! --- statuspage/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statuspage/build.gradle b/statuspage/build.gradle index ed3552f3..8de5838b 100644 --- a/statuspage/build.gradle +++ b/statuspage/build.gradle @@ -22,5 +22,5 @@ dependencies { compile commons() - testCompile "junit:junit:4.12" // temporary fix while I add junit as an extension on master (brb) + testCompile junit() } From e932eac6130ac3cf15fd3f9aaf76db40c9bafbb3 Mon Sep 17 00:00:00 2001 From: TheMonitorLizard Date: Thu, 31 May 2018 15:28:11 -0500 Subject: [PATCH 12/12] Renamed Statuspage to StatusPage --- .../{Statuspage.java => StatusPage.java} | 7 +++--- .../jdautilities/statuspage/package-info.java | 2 +- ...tatuspageTest.java => StatusPageTest.java} | 22 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) rename statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/{Statuspage.java => StatusPage.java} (99%) rename statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/{StatuspageTest.java => StatusPageTest.java} (57%) diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/StatusPage.java similarity index 99% rename from statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java rename to statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/StatusPage.java index 474804da..cc83d5de 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/Statuspage.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/StatusPage.java @@ -36,7 +36,7 @@ import java.util.function.Function; @Immutable -public class Statuspage +public class StatusPage { @Nonnull protected static final String URL_API_BASE = "https://status.discordapp.com/api/v2"; @@ -60,19 +60,18 @@ public class Statuspage protected static final String URL_SCHEDULED_MAINTENANCES_ACTIVE = URL_SCHEDULED_MAINTENANCES_BASE + "/active.json"; @Nonnull protected static final String URL_SCHEDULED_MAINTENANCES_UPCOMING = URL_SCHEDULED_MAINTENANCES_BASE + "/upcoming.json"; - @Nonnull protected static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); @Nonnull protected final OkHttpClient client; - public Statuspage() + public StatusPage() { this(null); } - public Statuspage(@Nullable OkHttpClient client) + public StatusPage(@Nullable OkHttpClient client) { this.client = client == null ? new OkHttpClient.Builder().build() : client; } diff --git a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java index 964b8036..07f80493 100644 --- a/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java +++ b/statuspage/src/main/java/com/jagrosh/jdautilities/statuspage/package-info.java @@ -14,6 +14,6 @@ * limitations under the License. */ /** - * Statuspage package.
+ * StatusPage package.
*/ package com.jagrosh.jdautilities.statuspage; diff --git a/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java b/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatusPageTest.java similarity index 57% rename from statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java rename to statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatusPageTest.java index 9efabff4..ee893970 100644 --- a/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatuspageTest.java +++ b/statuspage/src/test/java/com/jagrosh/jdautilities/statuspage/tests/StatusPageTest.java @@ -1,57 +1,57 @@ package com.jagrosh.jdautilities.statuspage.tests; -import com.jagrosh.jdautilities.statuspage.Statuspage; +import com.jagrosh.jdautilities.statuspage.StatusPage; import org.junit.Test; -public class StatuspageTest +public class StatusPageTest { - public final Statuspage statuspage = new Statuspage(); + public final StatusPage statusPage = new StatusPage(); @Test public void testComponents() throws Exception { - statuspage.getComponents().get(); + statusPage.getComponents().get(); } @Test public void testIncidentsAll() throws Exception { - statuspage.getIncidentsAll().get(); + statusPage.getIncidentsAll().get(); } @Test public void testIncidentsUnresolved() throws Exception { - statuspage.getIncidentsUnresolved().get(); + statusPage.getIncidentsUnresolved().get(); } @Test public void testScheduledMaintenancesActive() throws Exception { - statuspage.getScheduledMaintenancesActive().get(); + statusPage.getScheduledMaintenancesActive().get(); } @Test public void testScheduledMaintenancesAll() throws Exception { - statuspage.getScheduledMaintenancesAll().get(); + statusPage.getScheduledMaintenancesAll().get(); } @Test public void testScheduledMaintenancesUpcoming() throws Exception { - statuspage.getScheduledMaintenancesUpcoming().get(); + statusPage.getScheduledMaintenancesUpcoming().get(); } @Test public void testServiceStatus() throws Exception { - statuspage.getServiceStatus().get(); + statusPage.getServiceStatus().get(); } @Test public void testSummary() throws Exception { - statuspage.getSummary().get(); + statusPage.getSummary().get(); } }