From 0e0c7f81c6bf2e56b8c3c2fe08e6dad52a048e29 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 9 Jan 2021 21:44:59 -0500 Subject: [PATCH 01/13] Cleaning up code, removing bugs --- .../java/com/jasonhhouse/gaps/Schedule.java | 6 +- .../gaps/json/ScheduleDeserializer.java | 4 +- .../gaps/json/ScheduleSerializer.java | 7 +- .../AbstractNotificationProperties.java | 2 +- .../gaps/properties/PlexProperties.java | 2 - .../gaps/properties/PushBulletProperties.java | 13 +-- .../java/com/jasonhhouse/gaps/service/IO.java | 3 +- .../jasonhhouse/gaps/service/PlexQuery.java | 4 +- .../properties/DiscordPropertiesTest.java | 2 +- .../gaps/properties/EmailPropertiesTest.java | 2 +- .../gaps/properties/GotifyPropertiesTest.java | 2 +- .../properties/PushBulletPropertiesTest.java | 8 +- .../properties/PushOverPropertiesTest.java | 2 +- .../gaps/properties/SlackPropertiesTest.java | 2 +- .../properties/TelegramPropertiesTest.java | 2 +- .../com/jasonhhouse/gaps/GapsApplication.java | 2 - .../jasonhhouse/gaps/WebSecurityConfig.java | 3 +- .../controller/ConfigurationController.java | 1 - .../gaps/controller/GapsController.java | 2 +- .../gaps/controller/SchedulerController.java | 15 ++-- .../gaps/controller/SearchController.java | 15 ---- .../AbstractNotificationAgent.java | 1 - .../DiscordNotificationAgent.java | 3 - .../notifications/EmailNotificationAgent.java | 2 - .../GotifyNotificationAgent.java | 1 - .../notifications/NotificationStatus.java | 10 +++ .../PushBulletNotificationAgent.java | 3 +- .../PushOverNotificationAgent.java | 1 - .../TelegramNotificationAgent.java | 1 + .../gaps/service/FileIoService.java | 86 ++++++++++--------- .../gaps/service/PlexQueryImpl.java | 17 ++-- .../templates/fragments/notifications.html | 54 ++++++++---- .../main/resources/templates/libraries.html | 14 +-- .../main/resources/templates/mislabeled.html | 10 +-- .../main/resources/templates/recommended.html | 12 +-- .../gaps/service/FakeIoService.java | 3 +- 36 files changed, 171 insertions(+), 146 deletions(-) diff --git a/Core/src/main/java/com/jasonhhouse/gaps/Schedule.java b/Core/src/main/java/com/jasonhhouse/gaps/Schedule.java index aef1f138..a7a27988 100644 --- a/Core/src/main/java/com/jasonhhouse/gaps/Schedule.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/Schedule.java @@ -28,9 +28,9 @@ public enum Schedule { EVERY_TWO_WEEKS("Bi-weekly", "0 0 4 1,15 * ?", 3), EVERY_MONTH("Monthly", "0 0 4 1 * ?", 4); - public static final String ID = "id"; - public static final String MESSAGE = "message"; - public static final String ENABLED = "enabled"; + public static final String ID_LABEL = "id"; + public static final String MESSAGE_LABEL = "message"; + public static final String ENABLED_LABEL = "enabled"; @NotNull private final String message; diff --git a/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleDeserializer.java b/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleDeserializer.java index 2307ceaf..bd6d64e0 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleDeserializer.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleDeserializer.java @@ -29,8 +29,8 @@ protected ScheduleDeserializer(Class vc) { @Override public Schedule deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); - int id = node.get(Schedule.ID).numberValue().intValue(); - Boolean enabled = node.get(Schedule.ENABLED).booleanValue(); + int id = node.get(Schedule.ID_LABEL).numberValue().intValue(); + Boolean enabled = node.get(Schedule.ENABLED_LABEL).booleanValue(); return Schedule.getSchedule(id).setEnabled(enabled); } } diff --git a/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleSerializer.java b/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleSerializer.java index f3761d47..81b3da12 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleSerializer.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/json/ScheduleSerializer.java @@ -17,6 +17,7 @@ import java.io.IOException; public class ScheduleSerializer extends StdSerializer { + public ScheduleSerializer() { this(null); } @@ -28,9 +29,9 @@ protected ScheduleSerializer(Class t) { @Override public void serialize(Schedule value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException { jsonGenerator.writeStartObject(); - jsonGenerator.writeNumberField(Schedule.ID, value.getId()); - jsonGenerator.writeStringField(Schedule.MESSAGE, value.getMessage()); - jsonGenerator.writeBooleanField("enabled", value.getEnabled()); + jsonGenerator.writeNumberField(Schedule.ID_LABEL, value.getId()); + jsonGenerator.writeStringField(Schedule.MESSAGE_LABEL, value.getMessage()); + jsonGenerator.writeBooleanField(Schedule.ENABLED_LABEL, value.getEnabled()); jsonGenerator.writeEndObject(); } } diff --git a/Core/src/main/java/com/jasonhhouse/gaps/properties/AbstractNotificationProperties.java b/Core/src/main/java/com/jasonhhouse/gaps/properties/AbstractNotificationProperties.java index d82e52b0..e5252bbc 100644 --- a/Core/src/main/java/com/jasonhhouse/gaps/properties/AbstractNotificationProperties.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/properties/AbstractNotificationProperties.java @@ -27,7 +27,7 @@ abstract class AbstractNotificationProperties implements NotificationProperties @NotNull protected final List notificationTypes; - public AbstractNotificationProperties(@NotNull Boolean enabled, @NotNull List notificationTypes) { + protected AbstractNotificationProperties(@NotNull Boolean enabled, @NotNull List notificationTypes) { this.enabled = enabled; this.notificationTypes = notificationTypes; } diff --git a/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java b/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java index c7f25b69..b63006ae 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java @@ -17,9 +17,7 @@ import com.jasonhhouse.gaps.PlexServer; import com.jasonhhouse.gaps.Schedule; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/Core/src/main/java/com/jasonhhouse/gaps/properties/PushBulletProperties.java b/Core/src/main/java/com/jasonhhouse/gaps/properties/PushBulletProperties.java index f9b7b0cc..77a0eea5 100644 --- a/Core/src/main/java/com/jasonhhouse/gaps/properties/PushBulletProperties.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/properties/PushBulletProperties.java @@ -26,8 +26,9 @@ public final class PushBulletProperties extends AbstractNotificationProperties { @NotNull + @JsonProperty("channel_tag") @Schema(required = true, description = "The channel tag to receive messages") - private final String channel_tag; + private final String channelTag; @NotNull @Schema(required = true, description = "The API token connect to PushBullet") @@ -36,10 +37,10 @@ public final class PushBulletProperties extends AbstractNotificationProperties { @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public PushBulletProperties(@JsonProperty(value = "enabled", required = true) @NotNull Boolean enabled, @JsonProperty(value = "notificationTypes", required = true) @NotNull List notificationTypes, - @JsonProperty(value = "channel_tag") @Nullable String channel_tag, + @JsonProperty(value = "channel_tag") @Nullable String channelTag, @JsonProperty(value = "accessToken") @Nullable String accessToken) { super(enabled, notificationTypes); - this.channel_tag = channel_tag == null ? "" : channel_tag; + this.channelTag = channelTag == null ? "" : channelTag; this.accessToken = accessToken == null ? "" : accessToken; } @@ -48,8 +49,8 @@ static PushBulletProperties getDefault() { } @NotNull - public String getChannel_tag() { - return channel_tag; + public String getChannelTag() { + return channelTag; } @NotNull @@ -60,7 +61,7 @@ public String getAccessToken() { @Override public String toString() { return "PushBulletProperties{" + - "channel_tag='" + channel_tag + '\'' + + "channelTag='" + channelTag + '\'' + ", accessToken='" + accessToken + '\'' + ", enabled=" + enabled + ", notificationTypes=" + notificationTypes + diff --git a/Core/src/main/java/com/jasonhhouse/gaps/service/IO.java b/Core/src/main/java/com/jasonhhouse/gaps/service/IO.java index 87635097..ec6b8452 100644 --- a/Core/src/main/java/com/jasonhhouse/gaps/service/IO.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/service/IO.java @@ -15,6 +15,7 @@ import com.jasonhhouse.gaps.Payload; import com.jasonhhouse.gaps.properties.PlexProperties; import java.io.File; +import java.nio.file.Path; import java.util.List; import java.util.Set; import org.jetbrains.annotations.NotNull; @@ -51,7 +52,7 @@ public interface IO { */ void writeMovieIdsToFile(@NotNull Set everyBasicMovie); - void writeMovieIdsToFile(@NotNull Set everyBasicMovie, @NotNull File file); + void writeMovieIdsToFile(@NotNull Set everyBasicMovie, @NotNull Path path); /** * Prints out all recommended files to a text file called gaps_recommended_movies.txt diff --git a/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java b/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java index ec25042e..3bb1caed 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java @@ -50,7 +50,7 @@ public interface PlexQuery { void findAllMovieIds(@NotNull List basicMovies, @NotNull PlexServer plexServer, @NotNull PlexLibrary plexLibrary); - @NotNull PlexServer getPlexServerFromMachineIdentifier(@NotNull PlexProperties plexProperties,@NotNull String machineIdentifier) throws IllegalArgumentException; + @NotNull PlexServer getPlexServerFromMachineIdentifier(@NotNull PlexProperties plexProperties,@NotNull String machineIdentifier); - @NotNull PlexLibrary getPlexLibraryFromKey(@NotNull PlexServer plexServer,@NotNull Integer key) throws IllegalArgumentException; + @NotNull PlexLibrary getPlexLibraryFromKey(@NotNull PlexServer plexServer,@NotNull Integer key); } diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/DiscordPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/DiscordPropertiesTest.java index 0ef6b99a..97f564a5 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/DiscordPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/DiscordPropertiesTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class DiscordPropertiesTest { +class DiscordPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/EmailPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/EmailPropertiesTest.java index cca922b7..f5fc86a2 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/EmailPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/EmailPropertiesTest.java @@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class EmailPropertiesTest { +class EmailPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/GotifyPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/GotifyPropertiesTest.java index 8d11ba55..1447029e 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/GotifyPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/GotifyPropertiesTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class GotifyPropertiesTest { +class GotifyPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/PushBulletPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/PushBulletPropertiesTest.java index 2635e9b9..ee45da16 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/PushBulletPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/PushBulletPropertiesTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class PushBulletPropertiesTest { +class PushBulletPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -36,7 +36,7 @@ void addingEnabledAndNotificationTypes() throws JsonProcessingException { PushBulletProperties pushBulletProperties = objectMapper.readValue("{\"enabled\":true,\"notificationTypes\":[]}", PushBulletProperties.class); assertTrue(CollectionUtils.isEmpty(pushBulletProperties.getNotificationTypes())); assertTrue(pushBulletProperties.getEnabled()); - assertTrue(StringUtils.isEmpty(pushBulletProperties.getChannel_tag())); + assertTrue(StringUtils.isEmpty(pushBulletProperties.getChannelTag())); assertTrue(StringUtils.isEmpty(pushBulletProperties.getAccessToken())); } @@ -45,7 +45,7 @@ void missingOneValue() throws JsonProcessingException { PushBulletProperties pushBulletProperties = objectMapper.readValue("{\"enabled\":true,\"notificationTypes\":[],\"channel_tag\":\"123\"}", PushBulletProperties.class); assertTrue(CollectionUtils.isEmpty(pushBulletProperties.getNotificationTypes())); assertTrue(pushBulletProperties.getEnabled()); - assertEquals("123", pushBulletProperties.getChannel_tag()); + assertEquals("123", pushBulletProperties.getChannelTag()); assertTrue(StringUtils.isEmpty(pushBulletProperties.getAccessToken())); } @@ -54,7 +54,7 @@ void allValues() throws JsonProcessingException { PushBulletProperties pushBulletProperties = objectMapper.readValue("{\"enabled\":true,\"notificationTypes\":[\"TEST\"],\"channel_tag\":\"123\",\"accessToken\":\"abc\"}", PushBulletProperties.class); assertTrue(CollectionUtils.isNotEmpty(pushBulletProperties.getNotificationTypes())); assertTrue(pushBulletProperties.getEnabled()); - assertEquals("123", pushBulletProperties.getChannel_tag()); + assertEquals("123", pushBulletProperties.getChannelTag()); assertEquals("abc", pushBulletProperties.getAccessToken()); } } diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/PushOverPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/PushOverPropertiesTest.java index 82270f7d..595f413f 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/PushOverPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/PushOverPropertiesTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class PushOverPropertiesTest { +class PushOverPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/SlackPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/SlackPropertiesTest.java index 8d4bb541..8ad80cce 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/SlackPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/SlackPropertiesTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class SlackPropertiesTest { +class SlackPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/Core/src/test/java/com/jasonhhouse/gaps/properties/TelegramPropertiesTest.java b/Core/src/test/java/com/jasonhhouse/gaps/properties/TelegramPropertiesTest.java index 91a4cb5b..3454c081 100644 --- a/Core/src/test/java/com/jasonhhouse/gaps/properties/TelegramPropertiesTest.java +++ b/Core/src/test/java/com/jasonhhouse/gaps/properties/TelegramPropertiesTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class TelegramPropertiesTest { +class TelegramPropertiesTest { private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java index b29c867a..01655c39 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java @@ -12,13 +12,11 @@ import java.util.concurrent.Executor; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/WebSecurityConfig.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/WebSecurityConfig.java index 7bf7bd52..fd983d0b 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/WebSecurityConfig.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/WebSecurityConfig.java @@ -60,6 +60,7 @@ protected void configure(HttpSecurity http) throws Exception { "/js/jquery-3.4.1.min.js", "/js/bootstrap.bundle.min.js", "/js/index.min.js", + "/images/final-2.svg", "/images/final-gaps.svg").permitAll() .anyRequest().fullyAuthenticated() @@ -70,7 +71,7 @@ protected void configure(HttpSecurity http) throws Exception { .and() .logout() .permitAll(); - } else if (Boolean.TRUE.equals(gapsConfiguration.getLoginEnabled()) && !gapsConfiguration.getSslEnabled()) { + } else if (Boolean.TRUE.equals(gapsConfiguration.getLoginEnabled()) && Boolean.FALSE.equals(gapsConfiguration.getSslEnabled())) { LOGGER.info("Login Enabled. Configuring site security without ssl."); http.cors().and().csrf().disable() diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java index de10adcd..d1ffa45b 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java @@ -47,7 +47,6 @@ public class ConfigurationController { private static final ObjectMapper objectMapper = new ObjectMapper(); private static final String TMDB_KEY = "tmdbKey:"; private static final String SUCCESS = "success"; - private static final String FAILED_TO_READ_PLEX_PROPERTIES = "Failed to read PlexProperties"; private static final String CONFIGURATION_PLEX = "/configuration/plex"; private static final String CONFIGURATION_PLEX_COMPLETE = CONFIGURATION_PLEX + "/complete"; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/GapsController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/GapsController.java index 0f85da47..d77af817 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/GapsController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/GapsController.java @@ -114,7 +114,7 @@ public Object getSounds() { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(resource.getInputStream(), Object.class); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("Failed to read sounds.json", e); } return null; } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SchedulerController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SchedulerController.java index c0ee025b..aa37a58e 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SchedulerController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SchedulerController.java @@ -72,6 +72,7 @@ public ResponseEntity getSchedule() { produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getAllSchedules() { LOGGER.info("getAllSchedules()"); + return ResponseEntity.ok().body(schedulerService.getAllSchedules()); } @@ -79,12 +80,14 @@ public ResponseEntity> getAllSchedules() { produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getTestSchedule() { LOGGER.info("getTestSchedule()"); - new Runnable() { - @Override - public void run() { - schedulerService.test(); - } - }; + new MyRunnable(); return ResponseEntity.ok().body("{\"message\":\"Test schedule started\"}"); } + + private class MyRunnable implements Runnable { + @Override + public void run() { + schedulerService.test(); + } + } } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SearchController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SearchController.java index fc872fb0..1e8df315 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SearchController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/SearchController.java @@ -41,21 +41,6 @@ public void cancelSearching() { gapsSearch.cancelSearch(); } - /** - * Main REST call to start Gaps searching for missing movies - * - * @deprecated No long used to do search - */ - @PostMapping(value = "startSearching") - @ResponseStatus(value = HttpStatus.OK) - @Deprecated(forRemoval = true) - public void postStartSearching() { - LOGGER.info("postStartSearching()"); - LOGGER.warn("Deprecated Method"); - - throw new IllegalStateException("Need to pass in machineIdentifier and plex key"); - } - @GetMapping(value = "/searchStatus", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getIsSearching() { diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/AbstractNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/AbstractNotificationAgent.java index fbb83b68..b8cfc18a 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/AbstractNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/AbstractNotificationAgent.java @@ -12,7 +12,6 @@ import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.properties.NotificationProperties; -import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.IO; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/DiscordNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/DiscordNotificationAgent.java index a458f8cd..bd777bb1 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/DiscordNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/DiscordNotificationAgent.java @@ -14,10 +14,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.properties.DiscordProperties; -import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.IO; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -29,7 +27,6 @@ import okhttp3.RequestBody; import okhttp3.Response; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/EmailNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/EmailNotificationAgent.java index 0d4b7cc0..efe31a87 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/EmailNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/EmailNotificationAgent.java @@ -12,11 +12,9 @@ import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.properties.EmailProperties; -import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.IO; import java.util.Properties; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.mail.MailException; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/GotifyNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/GotifyNotificationAgent.java index 99a9368d..4ace1b59 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/GotifyNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/GotifyNotificationAgent.java @@ -14,7 +14,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.properties.GotifyProperties; -import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.IO; import java.io.IOException; import java.util.concurrent.TimeUnit; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/NotificationStatus.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/NotificationStatus.java index f0f8793f..2648a112 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/NotificationStatus.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/NotificationStatus.java @@ -1,3 +1,13 @@ +/* + * Copyright 2019 Jason H House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + package com.jasonhhouse.gaps.notifications; import org.jetbrains.annotations.NotNull; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushBulletNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushBulletNotificationAgent.java index a92e6404..4551ee65 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushBulletNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushBulletNotificationAgent.java @@ -14,7 +14,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.properties.PushBulletProperties; -import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.IO; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -84,7 +83,7 @@ public PushBulletNotificationAgent(@NotNull IO ioService) { .add("Access-Token", t.getAccessToken()) .build(); - PushBullet pushBullet = new PushBullet(t.getChannel_tag(), title, message); + PushBullet pushBullet = new PushBullet(t.getChannelTag(), title, message); String pushBulletMessage = ""; try { diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushOverNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushOverNotificationAgent.java index 95e20d37..4f89303c 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushOverNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/PushOverNotificationAgent.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.properties.PushOverProperties; -import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.IO; import java.io.IOException; import java.util.concurrent.TimeUnit; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/TelegramNotificationAgent.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/TelegramNotificationAgent.java index 32ba0944..5b09358c 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/TelegramNotificationAgent.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/notifications/TelegramNotificationAgent.java @@ -7,6 +7,7 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + package com.jasonhhouse.gaps.notifications; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/FileIoService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/FileIoService.java index 98771a27..c56a9259 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/FileIoService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/FileIoService.java @@ -13,9 +13,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.jasonhhouse.gaps.BasicMovie; +import com.jasonhhouse.gaps.GapsConfiguration; import com.jasonhhouse.gaps.Payload; import com.jasonhhouse.gaps.Rss; -import com.jasonhhouse.gaps.GapsConfiguration; import com.jasonhhouse.gaps.properties.PlexProperties; import java.io.BufferedReader; import java.io.File; @@ -98,29 +98,28 @@ public FileIoService(GapsConfiguration gapsConfiguration) { @Override public void writeRssFile(@NotNull String machineIdentifier, @NotNull Integer key, @NotNull Set recommended) { - File file = Paths.get(gapsConfiguration.getStorageFolder(), machineIdentifier, key.toString(), gapsConfiguration.getProperties().getRssFeed()).toFile(); + Path path = Paths.get(gapsConfiguration.getStorageFolder(), machineIdentifier, key.toString(), gapsConfiguration.getProperties().getRssFeed()); - if (file.exists()) { - boolean deleted = file.delete(); - if (!deleted) { - LOGGER.error("Can't delete existing file {}", file.getPath()); - return; - } + try { + Files.delete(path); + } catch (IOException e) { + LOGGER.error("Can't delete existing file", e); + return; } try { - boolean created = file.createNewFile(); + boolean created = path.toFile().createNewFile(); if (!created) { - LOGGER.error("Can't create file {}", file.getPath()); + LOGGER.error("Can't create file {}", path.toFile().getPath()); return; } } catch (IOException e) { - LOGGER.error(String.format("Can't create file %s", file.getPath()), e); + LOGGER.error(String.format("Can't create file %s", path.toFile().getPath()), e); return; } // Create writer that java will close for us. - try (FileOutputStream outputStream = new FileOutputStream(file)) { + try (FileOutputStream outputStream = new FileOutputStream(path.toFile())) { List rssList = recommended.stream().map(movie -> new Rss(movie.getImdbId(), movie.getYear(), movie.getTmdbId(), movie.getName(), movie.getPosterUrl())).collect(Collectors.toList()); byte[] output = objectMapper.writeValueAsBytes(rssList); outputStream.write(output); @@ -134,17 +133,17 @@ public void writeRssFile(@NotNull String machineIdentifier, @NotNull Integer key @Override public void writeRecommendedToFile(@NotNull Set recommended, @NotNull String machineIdentifier, @NotNull Integer key) { LOGGER.info("writeRecommendedToFile()"); - final File file = Paths.get(gapsConfiguration.getStorageFolder(), machineIdentifier, key.toString(), gapsConfiguration.getProperties().getRecommendedMovies()).toFile(); + final Path path = Paths.get(gapsConfiguration.getStorageFolder(), machineIdentifier, key.toString(), gapsConfiguration.getProperties().getRecommendedMovies()); makeFolder(machineIdentifier, key); - writeMovieIdsToFile(recommended, file); + writeMovieIdsToFile(recommended, path); } @Override public void writeOwnedMoviesToFile(@NotNull List ownedBasicMovies, @NotNull String machineIdentifier, @NotNull Integer key) { LOGGER.info("writeOwnedMoviesToFile()"); - final File file = Paths.get(gapsConfiguration.getStorageFolder(), machineIdentifier, key.toString(), gapsConfiguration.getProperties().getOwnedMovies()).toFile(); + final Path path = Paths.get(gapsConfiguration.getStorageFolder(), machineIdentifier, key.toString(), gapsConfiguration.getProperties().getOwnedMovies()); makeFolder(machineIdentifier, key); - writeMovieIdsToFile(new HashSet<>(ownedBasicMovies), file); + writeMovieIdsToFile(new HashSet<>(ownedBasicMovies), path); } private void makeFolder(@NotNull String machineIdentifier, @NotNull Integer key) { @@ -192,38 +191,37 @@ public List readOwnedMovies(@NotNull String machineIdentifier, @NotN @Override public void writeMovieIdsToFile(@NotNull Set everyBasicMovie) { LOGGER.info("writeMovieIdsToFile()"); - File file = Paths.get(gapsConfiguration.getStorageFolder(), gapsConfiguration.getProperties().getMovieIds()).toFile(); - writeMovieIdsToFile(everyBasicMovie, file); + Path path = Paths.get(gapsConfiguration.getStorageFolder(), gapsConfiguration.getProperties().getMovieIds()); + writeMovieIdsToFile(everyBasicMovie, path); } @Override - public void writeMovieIdsToFile(@NotNull Set everyBasicMovie, @NotNull File file) { - if (file.exists()) { - boolean deleted = file.delete(); - if (!deleted) { - LOGGER.error("Can't delete existing file {}", file.getName()); - return; - } + public void writeMovieIdsToFile(@NotNull Set everyBasicMovie, @NotNull Path path) { + try { + Files.delete(path); + } catch (IOException e) { + LOGGER.error("Can't delete existing file", e); + return; } try { - boolean created = file.createNewFile(); + boolean created = path.toFile().createNewFile(); if (!created) { - LOGGER.error("Can't create file {}", file.getAbsolutePath()); + LOGGER.error("Can't create file {}", path.toFile().getAbsolutePath()); return; } } catch (IOException e) { - LOGGER.error(String.format("Can't create file %s", file.getAbsolutePath()), e); + LOGGER.error(String.format("Can't create file %s", path.toFile().getAbsolutePath()), e); return; } - try (FileOutputStream outputStream = new FileOutputStream(file)) { + try (FileOutputStream outputStream = new FileOutputStream(path.toFile())) { byte[] output = objectMapper.writeValueAsBytes(everyBasicMovie); outputStream.write(output); } catch (FileNotFoundException e) { - LOGGER.error(String.format("Can't find file %s", file.getAbsolutePath()), e); + LOGGER.error(String.format("Can't find file %s", path.toFile().getAbsolutePath()), e); } catch (IOException e) { - LOGGER.error(String.format("Can't write to file %s", file.getAbsolutePath()), e); + LOGGER.error(String.format("Can't write to file %s", path.toFile().getAbsolutePath()), e); } } @@ -321,7 +319,7 @@ public PlexProperties readProperties() { @NotNull public Payload nuke() { LOGGER.info("nuke()"); - File folder = new File(gapsConfiguration.getStorageFolder()); + Path folder = new File(gapsConfiguration.getStorageFolder()).toPath(); try { nuke(folder); return Payload.NUKE_SUCCESSFUL; @@ -331,22 +329,30 @@ public Payload nuke() { } } - private void nuke(File file) { - LOGGER.info("nuke( {} )", file); - if (!file.isFile()) { - File[] files = file.listFiles(); + private void nuke(Path path) { + LOGGER.info("nuke( {} )", path); + if (!path.toFile().isFile()) { + File[] files = path.toFile().listFiles(); if (files == null) { return; } for (File children : files) { - nuke(children); + nuke(children.toPath()); } } else { - boolean isDeleted = file.delete(); + try { + Files.delete(path); + LOGGER.info("File deleted: {}", path.toFile().getPath()); + } catch (IOException e) { + LOGGER.error("Can't delete existing file", e); + return; + } + + boolean isDeleted = path.toFile().delete(); if (isDeleted) { - LOGGER.info("File deleted: {}", file); + } else { - LOGGER.warn("File not deleted: {}", file); + LOGGER.warn("File not deleted: {}", path.toFile().getPath()); } } } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java index 7d44cbeb..5337d016 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; @@ -300,8 +301,7 @@ public void findAllMovieIds(@NotNull List basicMovies, @NotNull Plex } InputStream fileIS = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); + DocumentBuilder builder = getDocumentBuilder(); Document xmlDocument = builder.parse(fileIS); XPath xPath = XPathFactory.newInstance().newXPath(); String expression = "/MediaContainer/Video/Guid"; @@ -398,8 +398,7 @@ public void findAllMovieIds(@NotNull List basicMovies, @NotNull Plex } InputStream fileIS = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); + DocumentBuilder builder = getDocumentBuilder(); Document xmlDocument = builder.parse(fileIS); XPath xPath = XPathFactory.newInstance().newXPath(); String expression = "/MediaContainer/Video"; @@ -527,11 +526,17 @@ private T parseXml(@NotNull Response response, @NotNull HttpUrl url, @NotNul } InputStream fileIS = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); + DocumentBuilder builder = getDocumentBuilder(); Document xmlDocument = builder.parse(fileIS); XPath xPath = XPathFactory.newInstance().newXPath(); return (T) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); } + private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + builderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + builderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); + return builderFactory.newDocumentBuilder(); + } + } diff --git a/GapsWeb/src/main/resources/templates/fragments/notifications.html b/GapsWeb/src/main/resources/templates/fragments/notifications.html index e2f6a66d..07ec58ee 100644 --- a/GapsWeb/src/main/resources/templates/fragments/notifications.html +++ b/GapsWeb/src/main/resources/templates/fragments/notifications.html @@ -10,11 +10,15 @@ + + Notifications +

Telegram Notifications

-
@@ -23,7 +27,8 @@

Telegram Notifications

- BotFather is the one bot to rule them all. + BotFather is the one + bot to rule them all. 1. Make a bot using BotFather 2. Paste the bot token in this field @@ -132,7 +137,7 @@

Success!

Slack Notifications

-
@@ -237,7 +242,8 @@

Success!

PushBullet Notifications

-
@@ -255,7 +261,7 @@

PushBullet Notifications

aria-describedby="pushBulletAccessTokenHelp" th:value="${plexProperties?.pushBulletProperties?.accessToken}"> The Access Token can be found here. + target="_blank" rel="noopener noreferrer">here.
@@ -462,7 +468,7 @@

Success!

Email Notifications

-
@@ -621,7 +627,8 @@

Success!

PushOver Notifications

-
@@ -642,11 +649,26 @@

PushOver Notifications

@@ -759,7 +781,8 @@

Success!

Discord Notifications

-
@@ -768,8 +791,9 @@

Discord Notifications

- Get your WebHook as explained here. + Get your WebHook as explained here.
diff --git a/GapsWeb/src/main/resources/templates/libraries.html b/GapsWeb/src/main/resources/templates/libraries.html index 5a13fc90..47b0d4c3 100755 --- a/GapsWeb/src/main/resources/templates/libraries.html +++ b/GapsWeb/src/main/resources/templates/libraries.html @@ -128,14 +128,14 @@
Your movies are really missing