Skip to content

Commit

Permalink
Merge pull request #288 from JasonHHouse/improvement/Gaps_currently_r…
Browse files Browse the repository at this point in the history
…eports_future_releases_as_missing#257

Initial work to implement and remove unreleased movies or show all
  • Loading branch information
JasonHHouse authored Jan 26, 2022
2 parents 7b9ad45 + 60570bb commit 86f7796
Show file tree
Hide file tree
Showing 34 changed files with 396 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>Gaps</artifactId>
<groupId>com.jasonhhouse</groupId>
<version>0.9.13</version>
<version>0.10.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
58 changes: 58 additions & 0 deletions Core/src/main/java/com/jasonhhouse/gaps/MovieStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.jasonhhouse.gaps;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.jasonhhouse.gaps.json.MovieStatusDeserializer;
import com.jasonhhouse.gaps.json.MovieStatusSerializer;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.NotNull;

@JsonSerialize(using = MovieStatusSerializer.class)
@JsonDeserialize(using = MovieStatusDeserializer.class)
public enum MovieStatus {
ALL("All", 0),
RELEASED("Released", 1);

public static final String ID_LABEL = "id";
public static final String MESSAGE_LABEL = "message";

@NotNull
private final String message;

@NotNull
private final Integer id;

MovieStatus(@NotNull String message, @NotNull Integer id) {
this.message = message;
this.id = id;
}

public static MovieStatus getMovieStatus(@NotNull Integer id) {
if (RELEASED.getId().equals(id)) {
return RELEASED;
} else {
return ALL;
}
}

public static @NotNull List<MovieStatus> getAllMovieStatuses() {
return Arrays.asList(ALL, RELEASED);
}

public @NotNull String getMessage() {
return message;
}

public @NotNull Integer getId() {
return id;
}

@Override
public @NotNull String toString() {
return "MovieStatus{" +
"message='" + message + '\'' +
", id=" + id +
'}';
}
}
24 changes: 24 additions & 0 deletions Core/src/main/java/com/jasonhhouse/gaps/MovieStatusPayload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jasonhhouse.gaps;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public final class MovieStatusPayload {
private final Integer status;

@JsonCreator
public MovieStatusPayload(@JsonProperty("status") Integer status) {
this.status = status;
}

public Integer getStatus() {
return status;
}

@Override
public String toString() {
return "MovieStatusPayload{" +
"status=" + status +
'}';
}
}
6 changes: 5 additions & 1 deletion Core/src/main/java/com/jasonhhouse/gaps/Payload.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public enum Payload {
DISCORD_NOTIFICATION_UPDATE_SUCCEEDED(140, "Discord Notification Update Succeeded."),
DISCORD_NOTIFICATION_UPDATE_FAILED(141, "Discord Notification Update Failed."),
DISCORD_NOTIFICATION_FOUND(142, "Discord Notification Found."),
DISCORD_NOTIFICATION_NOT_FOUND(143, "Discord Notification Not Found.");
DISCORD_NOTIFICATION_NOT_FOUND(143, "Discord Notification Not Found."),
MOVIE_STATUS_FOUND(150, "Movie status found."),
MOVIE_STATUS_NOT_FOUND(151, "Movie status not found."),
MOVIE_STATUS_UPDATED(152, "Movie status updated successfully."),
MOVIE_STATUS_NOT_UPDATED(153, "Movie status update failed.");

private final int code;
private final String reason;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/main/java/com/jasonhhouse/gaps/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Schedule getSchedule(@NotNull Integer id) {
}
}

public static List<Schedule> getAllSchedules() {
public static @NotNull List<Schedule> getAllSchedules() {
return Arrays.asList(HOURLY, DAILY_4AM, EVERY_MONDAY, EVERY_TWO_WEEKS, EVERY_MONTH);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jasonhhouse.gaps.json;

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.jasonhhouse.gaps.MovieStatus;
import java.io.IOException;

public class MovieStatusDeserializer extends StdDeserializer<MovieStatus> {
public MovieStatusDeserializer() {
this(null);
}

protected MovieStatusDeserializer(Class<?> vc) {
super(vc);
}

@Override
public MovieStatus deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
int id = node.get(MovieStatus.ID_LABEL).numberValue().intValue();
return MovieStatus.getMovieStatus(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2020 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.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.jasonhhouse.gaps.MovieStatus;
import java.io.IOException;

public class MovieStatusSerializer extends StdSerializer<MovieStatus> {

public MovieStatusSerializer() {
this(null);
}

protected MovieStatusSerializer(Class<MovieStatus> t) {
super(t);
}

@Override
public void serialize(MovieStatus value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeNumberField(MovieStatus.ID_LABEL, value.getId());
jsonGenerator.writeStringField(MovieStatus.MESSAGE_LABEL, value.getMessage());
jsonGenerator.writeEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jasonhhouse.gaps.MovieStatus;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.Schedule;
import java.util.ArrayList;
Expand Down Expand Up @@ -47,6 +48,8 @@ public final class PlexProperties {
private DiscordProperties discordProperties;
@NotNull
private Schedule schedule;
@NotNull
private MovieStatus movieStatus;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlexProperties(@JsonProperty(value = "plexServers") @Nullable List<PlexServer> plexServers,
Expand All @@ -59,7 +62,8 @@ public PlexProperties(@JsonProperty(value = "plexServers") @Nullable List<PlexSe
@JsonProperty(value = "discordProperties") @Nullable DiscordProperties discordProperties,
@JsonProperty(value = "movieDbApiKey") @Nullable String movieDbApiKey,
@JsonProperty(value = "password") @Nullable String password,
@JsonProperty(value = "schedule") @Nullable Schedule schedule) {
@JsonProperty(value = "schedule") @Nullable Schedule schedule,
@JsonProperty(value = "movieStatus") @Nullable MovieStatus movieStatus) {
this.plexServers = plexServers == null ? new ArrayList<>() : plexServers;
this.telegramProperties = telegramProperties == null ? TelegramProperties.getDefault() : telegramProperties;
this.pushBulletProperties = pushBulletProperties == null ? PushBulletProperties.getDefault() : pushBulletProperties;
Expand All @@ -71,6 +75,7 @@ public PlexProperties(@JsonProperty(value = "plexServers") @Nullable List<PlexSe
this.movieDbApiKey = movieDbApiKey == null ? "" : movieDbApiKey;
this.password = password == null ? "" : password;
this.schedule = schedule == null ? Schedule.EVERY_MONDAY : schedule;
this.movieStatus = movieStatus == null ? MovieStatus.ALL : movieStatus;
}

public PlexProperties() {
Expand All @@ -85,6 +90,7 @@ public PlexProperties() {
this.movieDbApiKey = "";
this.password = "";
this.schedule = Schedule.EVERY_MONDAY;
this.movieStatus = MovieStatus.ALL;
}

@NotNull
Expand Down Expand Up @@ -185,6 +191,14 @@ public void setDiscordProperties(@NotNull DiscordProperties discordProperties) {
this.discordProperties = discordProperties;
}

public @NotNull MovieStatus getMovieStatus() {
return movieStatus;
}

public void setMovieStatus(@NotNull MovieStatus movieStatus) {
this.movieStatus = movieStatus;
}

@Override
public String toString() {
return "PlexProperties{" +
Expand All @@ -199,6 +213,7 @@ public String toString() {
", pushOverProperties=" + pushOverProperties +
", discordProperties=" + discordProperties +
", schedule=" + schedule +
", movieStatus=" + movieStatus +
'}';
}
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/app

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.13.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.10.0.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.riscv64
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/app

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.13.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.10.0.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion GapsAsJar/gaps.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ RMDIR /r $INSTDIR
SectionEnd

# name the installer
OutFile "gaps-0.9.13-installer.exe"
OutFile "gaps-0.10.0-installer.exe"
2 changes: 1 addition & 1 deletion GapsWeb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>Gaps</artifactId>
<groupId>com.jasonhhouse</groupId>
<version>0.9.13</version>
<version>0.10.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.properties.PlexProperties;
import com.jasonhhouse.gaps.service.FileIoService;
import com.jasonhhouse.gaps.service.MovieStatusService;
import com.jasonhhouse.gaps.service.PlexQueryImpl;
import com.jasonhhouse.gaps.service.SchedulerService;
import com.jasonhhouse.gaps.service.TmdbService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -50,18 +52,31 @@ public class ConfigurationController {
private static final String CONFIGURATION_PLEX = "/configuration/plex";
private static final String CONFIGURATION_PLEX_COMPLETE = CONFIGURATION_PLEX + "/complete";

@NotNull
private final TmdbService tmdbService;
@NotNull
private final SimpMessagingTemplate template;
@NotNull
private final PlexQueryImpl plexQuery;
@NotNull
private final FileIoService fileIoService;
@NotNull
private final SchedulerService schedulerService;

public ConfigurationController(TmdbService tmdbService, SimpMessagingTemplate template, PlexQueryImpl plexQuery, FileIoService fileIoService, SchedulerService schedulerService) {
@NotNull
private final MovieStatusService movieStatusService;

public ConfigurationController(@NotNull TmdbService tmdbService,
@NotNull SimpMessagingTemplate template,
@NotNull PlexQueryImpl plexQuery,
@NotNull FileIoService fileIoService,
@NotNull SchedulerService schedulerService,
@NotNull MovieStatusService movieStatusService) {
this.tmdbService = tmdbService;
this.template = template;
this.plexQuery = plexQuery;
this.fileIoService = fileIoService;
this.schedulerService = schedulerService;
this.movieStatusService = movieStatusService;
}

@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
Expand All @@ -72,6 +87,7 @@ public ModelAndView getConfiguration() {
ModelAndView modelAndView = new ModelAndView("configuration");
modelAndView.addObject("plexProperties", plexProperties);
modelAndView.addObject("schedules", schedulerService.getAllSchedules());
modelAndView.addObject("movieStatuses", movieStatusService.getAllMovieStatuses());
modelAndView.addObject("configurationPage", true);
return modelAndView;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.jasonhhouse.gaps.controller;

import com.jasonhhouse.gaps.MovieStatusPayload;
import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.service.MovieStatusService;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/movieStatus")
public class MovieStatusController {

private static final Logger LOGGER = LoggerFactory.getLogger(MovieStatusController.class);

private final MovieStatusService movieStatusService;

@Autowired
public MovieStatusController(MovieStatusService movieStatusService) {
this.movieStatusService = movieStatusService;
}

@PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<Payload> putMovieStatus(@RequestBody final MovieStatusPayload movieStatusPayload) {
LOGGER.info("putMovieStatus( {} )", movieStatusPayload);

try {
movieStatusService.setMovieStatus(movieStatusPayload);
} catch (Exception e) {
LOGGER.error("Failed to update Movie Status", e);
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(Payload.MOVIE_STATUS_NOT_UPDATED);
}

return ResponseEntity.ok().body(Payload.MOVIE_STATUS_UPDATED);
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getSchedule() {
LOGGER.info("getSchedule()");
try {
return ResponseEntity.ok().body(movieStatusService.getJsonMovieStatus());
} catch (IOException e) {
LOGGER.error("Failed to parse schedule into JSON", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to parse schedule into JSON");
}
}
}
Loading

0 comments on commit 86f7796

Please sign in to comment.