mirror of
https://github.com/JasonHHouse/gaps.git
synced 2026-01-09 20:49:39 -06:00
Removing code smells
This commit is contained in:
@@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.jasonhhouse.gaps.json.ScheduleDeserializer;
|
||||
import com.jasonhhouse.gaps.json.ScheduleSerializer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -61,13 +61,7 @@ public enum Schedule {
|
||||
}
|
||||
|
||||
public static List<Schedule> getAllSchedules() {
|
||||
return new ArrayList<>() {{
|
||||
add(HOURLY);
|
||||
add(DAILY_4AM);
|
||||
add(EVERY_MONDAY);
|
||||
add(EVERY_TWO_WEEKS);
|
||||
add(EVERY_MONTH);
|
||||
}};
|
||||
return Arrays.asList(HOURLY, DAILY_4AM, EVERY_MONDAY, EVERY_TWO_WEEKS, EVERY_MONTH);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
13
Core/src/main/java/com/jasonhhouse/gaps/SearchStatus.java
Normal file
13
Core/src/main/java/com/jasonhhouse/gaps/SearchStatus.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.jasonhhouse.gaps;
|
||||
|
||||
public final class SearchStatus {
|
||||
private final Boolean isSearching;
|
||||
|
||||
public SearchStatus(Boolean isSearching) {
|
||||
this.isSearching = isSearching;
|
||||
}
|
||||
|
||||
public Boolean getIsSearching() {
|
||||
return isSearching;
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,8 @@ import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.jasonhhouse.gaps.Movie;
|
||||
import com.jasonhhouse.gaps.MovieFromCollection;
|
||||
import com.jasonhhouse.gaps.Schedule;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScheduleDeserializer extends StdDeserializer<Schedule> {
|
||||
public ScheduleDeserializer() {
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class PushBulletProperties extends AbstractNotificationProperties {
|
||||
@NotNull
|
||||
private final String channel_tag;
|
||||
private final String channelTag;
|
||||
|
||||
@NotNull
|
||||
private final String accessToken;
|
||||
@@ -26,16 +26,16 @@ 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<NotificationType> notificationTypes,
|
||||
@JsonProperty(value = "channel_tag", required = true) @NotNull String channel_tag,
|
||||
@JsonProperty(value = "channel_tag", required = true) @NotNull String channelTag,
|
||||
@JsonProperty(value = "accessToken", required = true) @NotNull String accessToken) {
|
||||
super(enabled, notificationTypes);
|
||||
this.channel_tag = channel_tag;
|
||||
this.channelTag = channelTag;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getChannel_tag() {
|
||||
return channel_tag;
|
||||
public String getChannelTag() {
|
||||
return channelTag;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -46,7 +46,7 @@ public final class PushBulletProperties extends AbstractNotificationProperties {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PushBulletProperties{" +
|
||||
"channel_tag='" + channel_tag + '\'' +
|
||||
"channel_tag='" + channelTag + '\'' +
|
||||
", accessToken='" + accessToken + '\'' +
|
||||
", enabled=" + enabled +
|
||||
", notificationTypes=" + notificationTypes +
|
||||
|
||||
@@ -17,7 +17,10 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
@@ -64,6 +67,12 @@ public class GapsApplication {
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier("Gaps")
|
||||
public TaskScheduler taskScheduler() {
|
||||
return new ThreadPoolTaskScheduler();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class MyConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
@@ -71,10 +80,4 @@ public class GapsApplication {
|
||||
registry.addFormatter(new PlexPropertiesFormatter());
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier("Gaps")
|
||||
public TaskScheduler taskScheduler() {
|
||||
return new ThreadPoolTaskScheduler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ package com.jasonhhouse.gaps;
|
||||
|
||||
import com.jasonhhouse.gaps.notifications.EmailNotificationAgent;
|
||||
import com.jasonhhouse.gaps.notifications.GotifyNotificationAgent;
|
||||
import com.jasonhhouse.gaps.notifications.NotificationAgent;
|
||||
import com.jasonhhouse.gaps.notifications.PushBulletNotificationAgent;
|
||||
import com.jasonhhouse.gaps.notifications.SlackNotificationAgent;
|
||||
import com.jasonhhouse.gaps.notifications.TelegramNotificationAgent;
|
||||
@@ -30,27 +29,27 @@ public class NotificationConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotificationAgent getTelegramElement() {
|
||||
public TelegramNotificationAgent getTelegramElement() {
|
||||
return new TelegramNotificationAgent(ioService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotificationAgent getPushBulletElement() {
|
||||
public PushBulletNotificationAgent getPushBulletElement() {
|
||||
return new PushBulletNotificationAgent(ioService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotificationAgent getSlackElement() {
|
||||
public SlackNotificationAgent getSlackElement() {
|
||||
return new SlackNotificationAgent(ioService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotificationAgent getEmailElement() {
|
||||
public EmailNotificationAgent getEmailElement() {
|
||||
return new EmailNotificationAgent(ioService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotificationAgent getGotifyElement() {
|
||||
public GotifyNotificationAgent getGotifyElement() {
|
||||
return new GotifyNotificationAgent(ioService);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
LOGGER.info("Name: {}", myConfig.getName());
|
||||
LOGGER.info("Name: {}", myConfig.getName());
|
||||
LOGGER.info("Description: {}", myConfig.getDescription());
|
||||
LOGGER.info("Version: {}" , myConfig.getVersion());
|
||||
LOGGER.info("Version: {}", myConfig.getVersion());
|
||||
LOGGER.info("LoginEnabled: {}", myConfig.getLoginEnabled());
|
||||
|
||||
if (myConfig.getLoginEnabled() && myConfig.getSslEnabled()) {
|
||||
|
||||
@@ -13,8 +13,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.jasonhhouse.gaps.GapsService;
|
||||
import com.jasonhhouse.gaps.Payload;
|
||||
import com.jasonhhouse.gaps.properties.PlexProperties;
|
||||
import com.jasonhhouse.gaps.PlexServer;
|
||||
import com.jasonhhouse.gaps.properties.PlexProperties;
|
||||
import com.jasonhhouse.gaps.service.IoService;
|
||||
import com.jasonhhouse.gaps.service.PlexQueryImpl;
|
||||
import com.jasonhhouse.gaps.service.SchedulerService;
|
||||
|
||||
@@ -13,8 +13,8 @@ import com.jasonhhouse.gaps.GapsService;
|
||||
import com.jasonhhouse.gaps.Movie;
|
||||
import com.jasonhhouse.gaps.Payload;
|
||||
import com.jasonhhouse.gaps.PlexLibrary;
|
||||
import com.jasonhhouse.gaps.properties.PlexProperties;
|
||||
import com.jasonhhouse.gaps.PlexServer;
|
||||
import com.jasonhhouse.gaps.properties.PlexProperties;
|
||||
import com.jasonhhouse.gaps.service.IoService;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,6 +44,7 @@ public class NotificationController {
|
||||
this.notificationService = notificationService;
|
||||
this.ioService = ioService;
|
||||
}
|
||||
|
||||
@PutMapping(produces = MediaType.APPLICATION_JSON_VALUE,
|
||||
consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||
value = "/email")
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SchedulerController {
|
||||
|
||||
@GetMapping(value = "/all",
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<?> getAllSchedules() {
|
||||
public ResponseEntity<List<Schedule>> getAllSchedules() {
|
||||
LOGGER.info("getAllSchedules()");
|
||||
return ResponseEntity.ok().body(schedulerService.getAllSchedules());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package com.jasonhhouse.gaps.controller;
|
||||
|
||||
import com.jasonhhouse.gaps.GapsSearch;
|
||||
import com.jasonhhouse.gaps.SearchStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -55,24 +56,13 @@ public class SearchController {
|
||||
throw new IllegalStateException("Need to pass in machineIdentifier and plex key");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/isSearching",
|
||||
@GetMapping(value = "/searchStatus",
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<IsSearching> getIsSearching() {
|
||||
LOGGER.info("getIsSearching()");
|
||||
public ResponseEntity<SearchStatus> getIsSearching() {
|
||||
LOGGER.info("getSearchStatus()");
|
||||
|
||||
IsSearching isSearching = new IsSearching(gapsSearch.isSearching());
|
||||
return ResponseEntity.ok().body(isSearching);
|
||||
SearchStatus searchStatus = new SearchStatus(gapsSearch.isSearching());
|
||||
return ResponseEntity.ok().body(searchStatus);
|
||||
}
|
||||
|
||||
public static class IsSearching {
|
||||
private final Boolean isSearching;
|
||||
|
||||
public IsSearching(Boolean isSearching) {
|
||||
this.isSearching = isSearching;
|
||||
}
|
||||
|
||||
public Boolean getIsSearching() {
|
||||
return isSearching;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import com.jasonhhouse.gaps.service.IoService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.AGENT_NOT_ENABLED_FOR_NOTIFICATION_TYPE;
|
||||
|
||||
public abstract class AbstractNotificationAgent<T extends NotificationProperties> implements NotificationAgent<T> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractNotificationAgent.class);
|
||||
|
||||
@@ -22,6 +22,9 @@ import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_READ_PROPERTIES;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.SEND_MESSAGE;
|
||||
|
||||
public class EmailNotificationAgent extends AbstractNotificationAgent<EmailProperties> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EmailNotificationAgent.class);
|
||||
@@ -44,7 +47,7 @@ public class EmailNotificationAgent extends AbstractNotificationAgent<EmailPrope
|
||||
public boolean sendMessage(NotificationType notificationType, String level, String title, String message) {
|
||||
LOGGER.info(SEND_MESSAGE, level, title, message);
|
||||
|
||||
if(sendPrepMessage(notificationType)) {
|
||||
if (sendPrepMessage(notificationType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_PARSE_JSON;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_READ_PROPERTIES;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.SEND_MESSAGE;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.TIMEOUT;
|
||||
|
||||
public class GotifyNotificationAgent extends AbstractNotificationAgent<GotifyProperties> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GotifyNotificationAgent.class);
|
||||
@@ -87,7 +92,7 @@ public class GotifyNotificationAgent extends AbstractNotificationAgent<GotifyPro
|
||||
LOGGER.info("Gotify message sent via {}", url);
|
||||
return true;
|
||||
} else {
|
||||
LOGGER.error("Error with Gotify Url: {} Body returned {}", url, response.body().toString());
|
||||
LOGGER.error("Error with Gotify Url: {} Body returned {}", url, response.body());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface NotificationAgent<T extends NotificationProperties> {
|
||||
|
||||
String FAILED_TO_READ_PROPERTIES = "Failed to read %s from Properties file.";
|
||||
|
||||
String AGENT_NOT_ENABLED_FOR_NOTIFICATION_TYPE = "{} not enabled for notification type {}";
|
||||
|
||||
String FAILED_TO_PARSE_JSON = "Failed to turn %s message into JSON";
|
||||
|
||||
String SEND_MESSAGE = "sendMessage( {}, {}, {} )";
|
||||
|
||||
long TIMEOUT = 2500;
|
||||
|
||||
int getId();
|
||||
|
||||
String getName();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.jasonhhouse.gaps.notifications;
|
||||
|
||||
public final class NotificationStatus {
|
||||
|
||||
public static final String FAILED_TO_READ_PROPERTIES = "Failed to read %s from Properties file.";
|
||||
|
||||
public static final String AGENT_NOT_ENABLED_FOR_NOTIFICATION_TYPE = "{} not enabled for notification type {}";
|
||||
|
||||
public static final String FAILED_TO_PARSE_JSON = "Failed to turn %s message into JSON";
|
||||
|
||||
public static final String SEND_MESSAGE = "sendMessage( {}, {}, {} )";
|
||||
|
||||
public static final long TIMEOUT = 2500;
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package com.jasonhhouse.gaps.notifications;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jasonhhouse.gaps.NotificationType;
|
||||
@@ -27,6 +28,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_PARSE_JSON;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_READ_PROPERTIES;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.SEND_MESSAGE;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.TIMEOUT;
|
||||
|
||||
public class PushBulletNotificationAgent extends AbstractNotificationAgent<PushBulletProperties> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PushBulletNotificationAgent.class);
|
||||
@@ -58,7 +64,7 @@ public class PushBulletNotificationAgent extends AbstractNotificationAgent<PushB
|
||||
public boolean sendMessage(NotificationType notificationType, String level, String title, String message) {
|
||||
LOGGER.info(SEND_MESSAGE, level, title, message);
|
||||
|
||||
if(sendPrepMessage(notificationType)) {
|
||||
if (sendPrepMessage(notificationType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,10 +80,7 @@ public class PushBulletNotificationAgent extends AbstractNotificationAgent<PushB
|
||||
.add("Access-Token", t.getAccessToken())
|
||||
.build();
|
||||
|
||||
PushBullet pushBullet = new PushBullet();
|
||||
pushBullet.setBody(message);
|
||||
pushBullet.setTitle(title);
|
||||
pushBullet.setChannel_tag(t.getChannel_tag());
|
||||
PushBullet pushBullet = new PushBullet(t.getChannelTag(), title, message);
|
||||
|
||||
String pushBulletMessage = "";
|
||||
try {
|
||||
@@ -101,7 +104,7 @@ public class PushBulletNotificationAgent extends AbstractNotificationAgent<PushB
|
||||
LOGGER.info("PushBullet message sent via {}", url);
|
||||
return true;
|
||||
} else {
|
||||
LOGGER.error("Error with PushBullet Url: {} Body returned {}", url, response.body().toString());
|
||||
LOGGER.error("Error with PushBullet Url: {} Body returned {}", url, response.body());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -124,20 +127,20 @@ public class PushBulletNotificationAgent extends AbstractNotificationAgent<PushB
|
||||
|
||||
public static final class PushBullet {
|
||||
private final String type;
|
||||
private String channel_tag;
|
||||
private String title;
|
||||
private String body;
|
||||
private final String channelTag;
|
||||
private final String title;
|
||||
private final String body;
|
||||
|
||||
public PushBullet() {
|
||||
public PushBullet(String channelTag, String title, String body) {
|
||||
this.channelTag = channelTag;
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
type = "note";
|
||||
}
|
||||
|
||||
public String getChannel_tag() {
|
||||
return channel_tag;
|
||||
}
|
||||
|
||||
public void setChannel_tag(String channel_tag) {
|
||||
this.channel_tag = channel_tag;
|
||||
@JsonProperty("channel_tag")
|
||||
public String getChannelTag() {
|
||||
return channelTag;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
@@ -148,16 +151,8 @@ public class PushBulletNotificationAgent extends AbstractNotificationAgent<PushB
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
package com.jasonhhouse.gaps.notifications;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jasonhhouse.gaps.NotificationType;
|
||||
@@ -28,6 +29,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_READ_PROPERTIES;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.TIMEOUT;
|
||||
|
||||
public class SlackNotificationAgent extends AbstractNotificationAgent<SlackProperties> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SlackNotificationAgent.class);
|
||||
@@ -68,7 +72,7 @@ public class SlackNotificationAgent extends AbstractNotificationAgent<SlackPrope
|
||||
.add("Content-Type", org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
|
||||
.build();
|
||||
|
||||
Slack slack = new Slack(String.format("*%s*\n%s", title, message));
|
||||
Slack slack = new Slack(String.format("*%s*%n%s", title, message));
|
||||
|
||||
String slackMessage = "";
|
||||
try {
|
||||
@@ -92,7 +96,7 @@ public class SlackNotificationAgent extends AbstractNotificationAgent<SlackPrope
|
||||
LOGGER.info("Slack message sent via {}", url);
|
||||
return true;
|
||||
} else {
|
||||
LOGGER.error("Error with Slack Url: {} Body returned {}", url, response.body().toString());
|
||||
LOGGER.error("Error with Slack Url: {} Body returned {}", url, response.body());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -146,19 +150,20 @@ public class SlackNotificationAgent extends AbstractNotificationAgent<SlackPrope
|
||||
|
||||
private static final class Text {
|
||||
private final String type;
|
||||
private final String text;
|
||||
private final String value;
|
||||
|
||||
private Text(String text) {
|
||||
private Text(String value) {
|
||||
this.type = "mrkdwn";
|
||||
this.text = text;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
@JsonProperty("text")
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package com.jasonhhouse.gaps.notifications;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jasonhhouse.gaps.NotificationType;
|
||||
@@ -25,6 +26,11 @@ import okhttp3.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_PARSE_JSON;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.FAILED_TO_READ_PROPERTIES;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.SEND_MESSAGE;
|
||||
import static com.jasonhhouse.gaps.notifications.NotificationStatus.TIMEOUT;
|
||||
|
||||
public class TelegramNotificationAgent extends AbstractNotificationAgent<TelegramProperties> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TelegramNotificationAgent.class);
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
@@ -55,7 +61,7 @@ public class TelegramNotificationAgent extends AbstractNotificationAgent<Telegra
|
||||
public boolean sendMessage(NotificationType notificationType, String level, String title, String message) {
|
||||
LOGGER.info(SEND_MESSAGE, level, title, message);
|
||||
|
||||
if(sendPrepMessage(notificationType)) {
|
||||
if (sendPrepMessage(notificationType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,7 +72,7 @@ public class TelegramNotificationAgent extends AbstractNotificationAgent<Telegra
|
||||
.addPathSegment("sendMessage")
|
||||
.build();
|
||||
|
||||
Telegram telegram = new Telegram(t.getChatId(), String.format("<strong>%s</strong>\n%s", title, message), "HTML");
|
||||
Telegram telegram = new Telegram(t.getChatId(), String.format("<strong>%s</strong>%n%s", title, message), "HTML");
|
||||
|
||||
String telegramMessage = "";
|
||||
try {
|
||||
@@ -89,7 +95,7 @@ public class TelegramNotificationAgent extends AbstractNotificationAgent<Telegra
|
||||
LOGGER.info("Telegram message sent via {}", url);
|
||||
return true;
|
||||
} else {
|
||||
LOGGER.error("Error with Telegram Url: {} Body returned {}", url, response.body().toString());
|
||||
LOGGER.error("Error with Telegram Url: {} Body returned {}", url, response.body());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -110,26 +116,28 @@ public class TelegramNotificationAgent extends AbstractNotificationAgent<Telegra
|
||||
}
|
||||
|
||||
public static final class Telegram {
|
||||
private final String chat_id;
|
||||
private final String chatId;
|
||||
private final String text;
|
||||
private final String parse_mode;
|
||||
private final String parseMode;
|
||||
|
||||
public Telegram(String chat_id, String text, String parse_mode) {
|
||||
this.chat_id = chat_id;
|
||||
public Telegram(String chatId, String text, String parseMode) {
|
||||
this.chatId = chatId;
|
||||
this.text = text;
|
||||
this.parse_mode = parse_mode;
|
||||
this.parseMode = parseMode;
|
||||
}
|
||||
|
||||
public String getChat_id() {
|
||||
return chat_id;
|
||||
@JsonProperty("chat_id")
|
||||
public String getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getParse_mode() {
|
||||
return parse_mode;
|
||||
@JsonProperty("parse_mode")
|
||||
public String getParseMode() {
|
||||
return parseMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -112,8 +113,25 @@ public class GapsSearchService implements GapsSearch {
|
||||
public void run(String machineIdentifier, Integer key) {
|
||||
LOGGER.info("run( {}, {} )", machineIdentifier, key);
|
||||
|
||||
PlexServer plexServer = gapsService.getPlexProperties().getPlexServers().stream().filter(tempPlexServer -> tempPlexServer.getMachineIdentifier().equals(machineIdentifier)).findFirst().get();
|
||||
PlexLibrary plexLibrary = plexServer.getPlexLibraries().stream().filter(tempPlexLibrary -> tempPlexLibrary.getKey().equals(key)).findAny().get();
|
||||
Optional<PlexServer> optionalPlexServer = gapsService.getPlexProperties().getPlexServers().stream().filter(tempPlexServer -> tempPlexServer.getMachineIdentifier().equals(machineIdentifier)).findFirst();
|
||||
PlexServer plexServer;
|
||||
if (optionalPlexServer.isPresent()) {
|
||||
plexServer = optionalPlexServer.get();
|
||||
} else {
|
||||
LOGGER.error("Plex server not found with machineIdentifier {} and key {}", machineIdentifier, key);
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<PlexLibrary> optionalPlexLibrary = plexServer.getPlexLibraries().stream().filter(tempPlexLibrary -> tempPlexLibrary.getKey().equals(key)).findAny();
|
||||
|
||||
PlexLibrary plexLibrary;
|
||||
if (optionalPlexLibrary.isPresent()) {
|
||||
plexLibrary = optionalPlexLibrary.get();
|
||||
} else {
|
||||
LOGGER.error("Plex library not found with machineIdentifier {} and key {}", machineIdentifier, key);
|
||||
return;
|
||||
}
|
||||
|
||||
notificationService.recommendedMoviesSearchStarted(plexServer, plexLibrary);
|
||||
|
||||
if (StringUtils.isEmpty(gapsService.getPlexProperties().getMovieDbApiKey())) {
|
||||
|
||||
@@ -54,11 +54,8 @@ public class IoService {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private final String storageFolder;
|
||||
|
||||
private final YamlConfig yamlConfig;
|
||||
|
||||
@Autowired
|
||||
public IoService(YamlConfig yamlConfig) {
|
||||
this.yamlConfig = yamlConfig;
|
||||
//Look for properties file for file locations
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.contains("Windows")) {
|
||||
@@ -357,9 +354,10 @@ public class IoService {
|
||||
final String properties = storageFolder + PROPERTIES;
|
||||
File propertiesFile = new File(properties);
|
||||
if (propertiesFile.exists()) {
|
||||
boolean deleted = propertiesFile.delete();
|
||||
if (!deleted) {
|
||||
LOGGER.error("Can't delete existing file {}", propertiesFile.getName());
|
||||
try {
|
||||
Files.delete(propertiesFile.toPath());
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(String.format("Can't delete existing file %s", propertiesFile.getName()), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.jasonhhouse.gaps.NotificationType;
|
||||
import com.jasonhhouse.gaps.PlexLibrary;
|
||||
import com.jasonhhouse.gaps.PlexServer;
|
||||
import com.jasonhhouse.gaps.notifications.NotificationAgent;
|
||||
import com.jasonhhouse.gaps.notifications.TelegramNotificationAgent;
|
||||
import com.jasonhhouse.gaps.properties.NotificationProperties;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -22,17 +22,17 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class NotificationService implements Notification {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TelegramNotificationAgent.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NotificationService.class);
|
||||
|
||||
private final List<NotificationAgent> notificationAgents;
|
||||
private final List<NotificationAgent<? extends NotificationProperties>> notificationAgents;
|
||||
|
||||
public NotificationService(List<NotificationAgent> notificationAgents) {
|
||||
public NotificationService(List<NotificationAgent<? extends NotificationProperties>> notificationAgents) {
|
||||
this.notificationAgents = notificationAgents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void plexServerConnectFailed(PlexServer plexServer, String error) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.TEST_PLEX_SERVER, "ERROR", "Gaps Search", String.format("Connection to Plex Server %s Failed. %s", plexServer.getFriendlyName(), error));
|
||||
@@ -45,7 +45,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void plexServerConnectSuccessful(PlexServer plexServer) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.TEST_PLEX_SERVER, "INFO", "Gaps Search", String.format("Connection to Plex Server %s Successful", plexServer.getFriendlyName()));
|
||||
@@ -58,7 +58,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void plexLibraryScanFailed(PlexServer plexServer, PlexLibrary plexLibrary, String error) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.SCAN_PLEX_SERVER, "INFO", "Gaps Search", String.format("Scanning Plex Server %s in %s Library Failed. %s", plexServer.getFriendlyName(), plexLibrary.getTitle(), error));
|
||||
@@ -71,7 +71,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void plexLibraryScanSuccessful(PlexServer plexServer, PlexLibrary plexLibrary) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.SCAN_PLEX_SERVER, "INFO", "Gaps Search", String.format("Scanning Plex Server %s in %s Library Successful", plexServer.getFriendlyName(), plexLibrary.getTitle()));
|
||||
@@ -84,7 +84,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void tmdbConnectionFailed(String error) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.TEST_TMDB, "INFO", "Gaps Search", String.format("TMDB Connection Failed. %s", error));
|
||||
@@ -97,7 +97,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void tmdbConnectionSuccessful() {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.TEST_TMDB, "INFO", "Gaps Search", "TMDB Connection Successful");
|
||||
@@ -110,7 +110,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void recommendedMoviesSearchStarted(PlexServer plexServer, PlexLibrary plexLibrary) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Started", plexServer.getFriendlyName(), plexLibrary.getTitle()));
|
||||
@@ -123,7 +123,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void recommendedMoviesSearchFailed(PlexServer plexServer, PlexLibrary plexLibrary, String error) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Failed %s", plexServer.getFriendlyName(), plexLibrary.getTitle(), error));
|
||||
@@ -136,7 +136,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public void recommendedMoviesSearchFinished(PlexServer plexServer, PlexLibrary plexLibrary) {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.isEnabled()) {
|
||||
try {
|
||||
notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Successfully Finished", plexServer.getFriendlyName(), plexLibrary.getTitle()));
|
||||
@@ -151,7 +151,7 @@ public class NotificationService implements Notification {
|
||||
public boolean test() {
|
||||
boolean passedTest = true;
|
||||
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
try {
|
||||
boolean result = notificationAgent.sendMessage(NotificationType.TEST, "DEBUG", "Gaps Test", "Test Successful");
|
||||
if (!result) {
|
||||
@@ -168,7 +168,7 @@ public class NotificationService implements Notification {
|
||||
|
||||
@Override
|
||||
public boolean test(int id) throws IllegalArgumentException {
|
||||
for (NotificationAgent notificationAgent : notificationAgents) {
|
||||
for (NotificationAgent<? extends NotificationProperties> notificationAgent : notificationAgents) {
|
||||
if (notificationAgent.getId() == id) {
|
||||
try {
|
||||
return notificationAgent.sendMessage(NotificationType.TEST, "DEBUG", "Gaps Test", "Test Successful");
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.jasonhhouse.gaps.sql;
|
||||
|
||||
import java.sql.Types;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.type.StringType;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
public class SQLDialect extends Dialect {
|
||||
|
||||
public SQLDialect() {
|
||||
@@ -58,6 +57,7 @@ public class SQLDialect extends Dialect {
|
||||
return "select last_insert_rowid()";
|
||||
}
|
||||
|
||||
|
||||
public boolean supportsTemporaryTables() {
|
||||
return true;
|
||||
}
|
||||
@@ -70,59 +70,73 @@ public class SQLDialect extends Dialect {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCurrentTimestampSelection() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentTimestampSelectStringCallable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentTimestampSelectString() {
|
||||
return "select current_timestamp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUnionAll() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlterTable() {
|
||||
return false; // As specify in NHibernate dialect
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dropConstraints() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddColumnString() {
|
||||
return "add column";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForUpdateString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsOuterJoinForUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDropForeignKeyString() {
|
||||
throw new UnsupportedOperationException("No drop foreign key syntax supported by SQLiteDialect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable,
|
||||
String[] primaryKey, boolean referencesPrimaryKey) {
|
||||
throw new UnsupportedOperationException("No add foreign key syntax supported by SQLiteDialect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddPrimaryKeyConstraintString(String constraintName) {
|
||||
throw new UnsupportedOperationException("No add primary key syntax supported by SQLiteDialect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIfExistsBeforeTableName() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCascadeDelete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ function searchBestMovieLibrary(cy) {
|
||||
}
|
||||
|
||||
function waitUtilSearchingIsDone() {
|
||||
cy.request('/isSearching')
|
||||
cy.request('/searchStatus')
|
||||
.then((resp) => {
|
||||
|
||||
if (resp.status === 200 && resp.body.isSearching === false) {
|
||||
|
||||
Reference in New Issue
Block a user