Merge branch 'master' into bugfix/improved_unit_testing

This commit is contained in:
Jason House
2020-09-02 10:03:42 +09:00
12 changed files with 103 additions and 39 deletions

View File

@@ -9,7 +9,7 @@
*
*/
package com.jasonhhouse.gaps;
package com.jasonhhouse.gaps.service;
/**
* Handles the process of searching, movies, counts, and canceling

View File

@@ -0,0 +1,67 @@
/*
* 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.service;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.properties.PlexProperties;
import java.io.File;
import java.util.List;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
public interface IO {
@NotNull List<Movie> readRecommendedMovies(@NotNull String machineIdentifier, @NotNull Integer key);
@NotNull Boolean doesRssFileExist(@NotNull String machineIdentifier, @NotNull Integer key);
@NotNull String getRssFile(String machineIdentifier, @NotNull Integer key);
/**
* Write the recommended movie list to the RSS file for endpoint to display.
*
* @param recommended The recommended movies. (IMDB ID is required.)
*/
void writeRssFile(@NotNull String machineIdentifier, @NotNull Integer key, @NotNull Set<Movie> recommended);
/**
* Prints out all recommended movies to recommendedMovies.json
*/
void writeRecommendedToFile(@NotNull Set<Movie> recommended, @NotNull String machineIdentifier, @NotNull Integer key);
/**
* Prints out all owned movies to ownedMovies.json
*/
void writeOwnedMoviesToFile(@NotNull List<Movie> ownedMovies, @NotNull String machineIdentifier, @NotNull Integer key);
@NotNull List<Movie> readOwnedMovies(@NotNull String machineIdentifier, @NotNull Integer key);
/**
* Prints out all movies to a text file movieIds.json
*/
void writeMovieIdsToFile(@NotNull Set<Movie> everyMovie);
void writeMovieIdsToFile(@NotNull Set<Movie> everyMovie, @NotNull File file);
/**
* Prints out all recommended files to a text file called gaps_recommended_movies.txt
*/
@NotNull Set<Movie> readMovieIdsFromFile();
void writeProperties(@NotNull PlexProperties plexProperties);
@NotNull PlexProperties readProperties();
@NotNull Payload nuke();
}

View File

@@ -9,7 +9,7 @@
*
*/
package com.jasonhhouse.gaps;
package com.jasonhhouse.gaps.service;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Pair;

View File

@@ -11,8 +11,10 @@
package com.jasonhhouse.gaps;
import com.jasonhhouse.gaps.properties.PlexProperties;
import com.jasonhhouse.gaps.service.GapsSearch;
import com.jasonhhouse.gaps.service.IoService;
import com.jasonhhouse.gaps.service.NotificationService;
import com.jasonhhouse.gaps.service.PlexQuery;
import com.jasonhhouse.gaps.service.TmdbService;
import com.jasonhhouse.plex.libs.PlexLibrary;
import java.util.HashMap;

View File

@@ -10,7 +10,7 @@
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.Mislabeled;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.service.PlexQuery;
import com.jasonhhouse.gaps.properties.PlexProperties;
import com.jasonhhouse.gaps.service.IoService;
import com.jasonhhouse.gaps.service.MediaContainerService;

View File

@@ -13,7 +13,7 @@ package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.GapsUrlGenerator;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Pair;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.service.PlexQuery;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.properties.PlexProperties;
import com.jasonhhouse.gaps.service.IoService;

View File

@@ -9,7 +9,7 @@
*/
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.GapsSearch;
import com.jasonhhouse.gaps.service.GapsSearch;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.PlexServer;

View File

@@ -9,7 +9,7 @@
*/
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.GapsSearch;
import com.jasonhhouse.gaps.service.GapsSearch;
import com.jasonhhouse.gaps.SearchStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.jasonhhouse.gaps.GapsSearch;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.MovieFromCollection;
import com.jasonhhouse.gaps.Payload;

View File

@@ -40,7 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class IoService {
public class IoService implements IO {
public static final String RSS_FEED_JSON_FILE = "rssFeed.json";
public static final String PLEX_CONFIGURATION = "plexConfiguration.json";
@@ -53,7 +53,7 @@ public class IoService {
private final String storageFolder;
@Autowired
public IoService(YamlConfig yamlConfig) {
public IoService() {
//Look for properties file for file locations
String os = System.getProperty("os.name");
if (os.contains("Windows")) {
@@ -68,7 +68,8 @@ public class IoService {
}
}
public @NotNull List<Movie> readRecommendedMovies(String machineIdentifier, int key) {
@Override
public @NotNull List<Movie> readRecommendedMovies(@NotNull String machineIdentifier, @NotNull Integer key) {
LOGGER.info("readRecommendedMovies({}, {} )", machineIdentifier, key);
final File ownedMovieFile = new File(storageFolder + machineIdentifier + File.separator + key + File.separator + RECOMMENDED_MOVIES);
@@ -96,11 +97,13 @@ public class IoService {
return Collections.emptyList();
}
public boolean doesRssFileExist(String machineIdentifier, int key) {
@Override
public @NotNull Boolean doesRssFileExist(@NotNull String machineIdentifier, @NotNull Integer key) {
return new File(storageFolder + machineIdentifier + File.separator + key + File.separator + RSS_FEED_JSON_FILE).exists();
}
public @NotNull String getRssFile(String machineIdentifier, int key) {
@Override
public @NotNull String getRssFile(String machineIdentifier, @NotNull Integer key) {
try {
Path path = new File(storageFolder + machineIdentifier + File.separator + key + File.separator + RSS_FEED_JSON_FILE).toPath();
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
@@ -110,12 +113,8 @@ public class IoService {
}
}
/**
* Write the recommended movie list to the RSS file for endpoint to display.
*
* @param recommended The recommended movies. (IMDB ID is required.)
*/
public void writeRssFile(String machineIdentifier, int key, Set<Movie> recommended) {
@Override
public void writeRssFile(@NotNull String machineIdentifier, @NotNull Integer key, @NotNull Set<Movie> recommended) {
File file = new File(storageFolder + machineIdentifier + File.separator + key + File.separator + RSS_FEED_JSON_FILE);
if (file.exists()) {
@@ -149,10 +148,8 @@ public class IoService {
}
}
/**
* Prints out all recommended movies to recommendedMovies.json
*/
public void writeRecommendedToFile(Set<Movie> recommended, String machineIdentifier, Integer key) {
@Override
public void writeRecommendedToFile(@NotNull Set<Movie> recommended,@NotNull String machineIdentifier, @NotNull Integer key) {
LOGGER.info("writeRecommendedToFile()");
final String fileName = storageFolder + machineIdentifier + File.separator + key + File.separator + RECOMMENDED_MOVIES;
@@ -162,10 +159,8 @@ public class IoService {
writeMovieIdsToFile(recommended, file);
}
/**
* Prints out all recommended movies to recommendedMovies.json
*/
public void writeOwnedMoviesToFile(List<Movie> ownedMovies, String machineIdentifier, int key) {
@Override
public void writeOwnedMoviesToFile(@NotNull List<Movie> ownedMovies, @NotNull String machineIdentifier, @NotNull Integer key) {
LOGGER.info("writeOwnedMoviesToFile()");
final String fileName = storageFolder + machineIdentifier + File.separator + key + File.separator + OWNED_MOVIES;
@@ -175,7 +170,7 @@ public class IoService {
writeMovieIdsToFile(new HashSet<>(ownedMovies), file);
}
private void makeFolder(String machineIdentifier, int key) {
private void makeFolder(@NotNull String machineIdentifier, @NotNull Integer key) {
File folder = new File(storageFolder + machineIdentifier + File.separator + key);
if (!folder.exists()) {
boolean isCreated = folder.mkdirs();
@@ -188,7 +183,9 @@ public class IoService {
}
public List<Movie> readOwnedMovies(String machineIdentifier, Integer key) {
@Override
@NotNull
public List<Movie> readOwnedMovies(@NotNull String machineIdentifier,@NotNull Integer key) {
LOGGER.info("readOwnedMovies( {}, {} )", machineIdentifier, key);
final File ownedMovieFile = new File(storageFolder + machineIdentifier + File.separator + key + File.separator + OWNED_MOVIES);
@@ -216,17 +213,16 @@ public class IoService {
return Collections.emptyList();
}
/**
* Prints out all movies to a text file movieIds.json
*/
public void writeMovieIdsToFile(Set<Movie> everyMovie) {
@Override
public void writeMovieIdsToFile(@NotNull Set<Movie> everyMovie) {
LOGGER.info("writeMovieIdsToFile()");
final String fileName = storageFolder + STORAGE;
File file = new File(fileName);
writeMovieIdsToFile(everyMovie, file);
}
public void writeMovieIdsToFile(Set<Movie> everyMovie, File file) {
@Override
public void writeMovieIdsToFile(@NotNull Set<Movie> everyMovie,@NotNull File file) {
if (file.exists()) {
boolean deleted = file.delete();
if (!deleted) {
@@ -256,9 +252,8 @@ public class IoService {
}
}
/**
* Prints out all recommended files to a text file called gaps_recommended_movies.txt
*/
@Override
@NotNull
public Set<Movie> readMovieIdsFromFile() {
Set<Movie> everyMovie = Collections.emptySet();
final String fileName = storageFolder + STORAGE;
@@ -286,6 +281,7 @@ public class IoService {
return everyMovie;
}
@Override
public void writeProperties(@NotNull PlexProperties plexProperties) {
LOGGER.info("writeProperties( {} )", plexProperties);
@@ -321,6 +317,7 @@ public class IoService {
}
}
@Override
@NotNull
public PlexProperties readProperties() {
LOGGER.info("readProperties()");
@@ -347,6 +344,8 @@ public class IoService {
}
}
@Override
@NotNull
public Payload nuke() {
LOGGER.info("nuke()");
File folder = new File(storageFolder);

View File

@@ -13,7 +13,6 @@ package com.jasonhhouse.gaps.service;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Pair;
import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.UrlGenerator;
import com.jasonhhouse.gaps.properties.PlexProperties;

View File

@@ -11,9 +11,7 @@
package com.jasonhhouse.gaps.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jasonhhouse.gaps.GapsSearch;
import com.jasonhhouse.gaps.GapsUrlGenerator;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.Schedule;
import com.jasonhhouse.gaps.SchedulePayload;
import com.jasonhhouse.gaps.SearchGapsTask;