diff --git a/src/main/java/com/botdarr/api/AddStrategy.java b/src/main/java/com/botdarr/api/AddStrategy.java index 2fcf4be..2ac5ce0 100644 --- a/src/main/java/com/botdarr/api/AddStrategy.java +++ b/src/main/java/com/botdarr/api/AddStrategy.java @@ -22,7 +22,6 @@ public AddStrategy(ChatClientResponseBuilder chatC public abstract String getItemId(T item); public abstract ChatClientResponse addContent(T content); public abstract ChatClientResponse getResponse(T item); - protected abstract void cacheContent(T addContent); public ChatClientResponse addWithSearchId(String searchText, String id) { try { @@ -41,7 +40,6 @@ public ChatClientResponse addWithSearchId(String searchText, String id) { return chatClientResponseBuilder.createErrorMessage(this.contentDisplayName + " already exists"); } ChatClientResponse chatClientResponse = addContent(item); - cacheContent(item); return chatClientResponse; } } diff --git a/src/main/java/com/botdarr/api/lidarr/LidarrApi.java b/src/main/java/com/botdarr/api/lidarr/LidarrApi.java index a0a1230..cd51252 100644 --- a/src/main/java/com/botdarr/api/lidarr/LidarrApi.java +++ b/src/main/java/com/botdarr/api/lidarr/LidarrApi.java @@ -199,11 +199,6 @@ public ChatClientResponse addContent(LidarrArtist content) { public ChatClientResponse getResponse(LidarrArtist item) { return chatClientResponseBuilder.getArtistResponse(item); } - - @Override - protected void cacheContent(LidarrArtist addContent) { - LIDARR_CACHE.addArtist(addContent); - } }; } @@ -293,6 +288,8 @@ private ChatClientResponse addArtist(LidarrArtist lidarrArtist) { if (statusCode != 200 && statusCode != 201) { return chatClientResponseBuilder.createErrorMessage("Could not add artist, status-code=" + statusCode + ", reason=" + response.getStatusLine().getReasonPhrase()); } + //cache artist after successful response + LIDARR_CACHE.addArtist(lidarrArtist); LogManager.getLogger("AuditLog").info("User " + username + " added " + lidarrArtist.getArtistName()); apiRequests.auditRequest(apiRequestType, username, lidarrArtist.getArtistName()); return chatClientResponseBuilder.createSuccessMessage("Artist " + lidarrArtist.getArtistName() + " added, lidarr-detail=" + response.getStatusLine().getReasonPhrase()); diff --git a/src/main/java/com/botdarr/api/radarr/RadarrApi.java b/src/main/java/com/botdarr/api/radarr/RadarrApi.java index 171e83f..68df357 100644 --- a/src/main/java/com/botdarr/api/radarr/RadarrApi.java +++ b/src/main/java/com/botdarr/api/radarr/RadarrApi.java @@ -277,11 +277,6 @@ public ChatClientResponse addContent(RadarrMovie content) { public ChatClientResponse getResponse(RadarrMovie item) { return chatClientResponseBuilder.getMovieResponse(item); } - - @Override - protected void cacheContent(RadarrMovie addContent) { - RADARR_CACHE.add(addContent); - } }; } @@ -327,6 +322,8 @@ private ChatClientResponse addMovie(RadarrMovie radarrMovie) { if (statusCode != 200 && statusCode != 201) { return chatClientResponseBuilder.createErrorMessage("Could not add movie, status-code=" + statusCode + ", reason=" + response.getStatusLine().getReasonPhrase()); } + //cache data after a successful request + RADARR_CACHE.add(radarrMovie); LogManager.getLogger("AuditLog").info("User " + username + " added " + radarrMovie.getTitle()); apiRequests.auditRequest(apiRequestType, username, radarrMovie.getTitle()); return chatClientResponseBuilder.createSuccessMessage("Movie " + radarrMovie.getTitle() + " added, radarr-detail=" + response.getStatusLine().getReasonPhrase()); diff --git a/src/main/java/com/botdarr/api/radarr/RadarrCache.java b/src/main/java/com/botdarr/api/radarr/RadarrCache.java index 7fd5969..1e231c7 100644 --- a/src/main/java/com/botdarr/api/radarr/RadarrCache.java +++ b/src/main/java/com/botdarr/api/radarr/RadarrCache.java @@ -42,7 +42,7 @@ public void removeDeletedMovies(List addUpdatedMovies) { for (Long tmdbId : addUpdatedMovies) { RadarrMovie radarrMovie = existingTmdbIdsToMovies.get(tmdbId); if (radarrMovie != null) { - existingMovieTitles.add(radarrMovie.getTitle()); + existingMovieTitles.add(radarrMovie.getTitle().toLowerCase()); } } existingTmdbIdsToMovies.keySet().retainAll(addUpdatedMovies); diff --git a/src/main/java/com/botdarr/api/sonarr/SonarrApi.java b/src/main/java/com/botdarr/api/sonarr/SonarrApi.java index e48c531..25daec6 100644 --- a/src/main/java/com/botdarr/api/sonarr/SonarrApi.java +++ b/src/main/java/com/botdarr/api/sonarr/SonarrApi.java @@ -188,11 +188,6 @@ public ChatClientResponse addContent(SonarrShow content) { public ChatClientResponse getResponse(SonarrShow item) { return chatClientResponseBuilder.getShowResponse(item); } - - @Override - protected void cacheContent(SonarrShow addContent) { - SONARR_CACHE.add(addContent); - } }; } @@ -245,6 +240,8 @@ private ChatClientResponse addShow(SonarrShow sonarrShow) { if (statusCode != 200 && statusCode != 201) { return chatClientResponseBuilder.createErrorMessage("Could not add show, status-code=" + statusCode + ", reason=" + response.getStatusLine().getReasonPhrase()); } + //cache show after successful request + SONARR_CACHE.add(sonarrShow); LogManager.getLogger("AuditLog").info("User " + username + " added " + title); apiRequests.auditRequest(apiRequestType, username, title); return chatClientResponseBuilder.createSuccessMessage("Show " + title + " added, sonarr-detail=" + response.getStatusLine().getReasonPhrase()); diff --git a/src/main/java/com/botdarr/api/sonarr/SonarrCache.java b/src/main/java/com/botdarr/api/sonarr/SonarrCache.java index c77602f..65fa95c 100644 --- a/src/main/java/com/botdarr/api/sonarr/SonarrCache.java +++ b/src/main/java/com/botdarr/api/sonarr/SonarrCache.java @@ -50,12 +50,12 @@ public void removeDeletedShows(List addUpdatedTvdbShowIds) { for (Long tvdbId : addUpdatedTvdbShowIds) { SonarrShow sonarrShow = existingTvdbIdsToMovies.get(tvdbId); if (sonarrShow != null) { - existingShowTitles.add(sonarrShow.getTitle()); + existingShowTitles.add(sonarrShow.getTitle().toLowerCase()); existingTvRageIds.add(sonarrShow.getTvRageId()); existingTvmazeIds.add(sonarrShow.getTvMazeId()); } } - existingShowTitlesToSonarrId.keySet().retainAll(addUpdatedTvdbShowIds); + existingShowTitlesToSonarrId.keySet().retainAll(existingShowTitles); existingTvdbIdsToMovies.keySet().retainAll(addUpdatedTvdbShowIds); existingTvrageIdsToMovies.keySet().retainAll(existingTvRageIds); existingTvmazeIdsToMovies.keySet().retainAll(existingTvmazeIds); diff --git a/src/test/java/com/botdarr/api/AddStrategyTests.java b/src/test/java/com/botdarr/api/AddStrategyTests.java index c76d9eb..61ad906 100644 --- a/src/test/java/com/botdarr/api/AddStrategyTests.java +++ b/src/test/java/com/botdarr/api/AddStrategyTests.java @@ -81,7 +81,6 @@ public void addWithSearchId_moviesFound_addMovieResponseReturned() throws Except mockAddStrategy.getItemId(movie); times = 1; result = searchId; mockAddStrategy.doesItemExist(movie); times = 1; result = false; mockAddStrategy.addContent(movie); times = 1; result = expectedResponse; - mockAddStrategy.cacheContent(movie); times = 1; }}; ChatClientResponse chatClientResponse = mockAddStrategy.addWithSearchId(searchText, searchId); Assert.assertNotNull(chatClientResponse); @@ -287,10 +286,5 @@ public ChatClientResponse addContent(Object content) { public ChatClientResponse getResponse(Object item) { return null; } - - @Override - protected void cacheContent(Object addContent) { - - } } }