Skip to content
Merged

Dev #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,29 @@ docker\.env
bin/

geek.log

# Environment & Secrets (AIOS)
.env
.env.local
.env.*.local
*.key
*.pem

# Dependencies (AIOS)
node_modules/
node_modules

# Build & Logs (AIOS)
*.log
logs/

# IDE & OS (AIOS)
.DS_Store
Thumbs.db
.idea/
*.swp

# AIOS Local (AIOS)
.aios-core/local/
.claude/settings.local.json
.aios/install-log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ResponseEntity<String> runJob(@PathVariable Long executionId) {
}

@GetMapping("/stop/{executionId}")
@PreAuthorize("hasRole('aadmin')")
@PreAuthorize("hasRole('admin')")
public ResponseEntity<String> stopJob(@PathVariable Long executionId) {
try {
boolean result = jobOperator.stop(executionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public MediaPage getMovie(@Argument(name = "id") Integer id, @Argument(name = "name") String name, DataFetchingEnvironment dataFetchingEnvironment) {
name = name == null ? null : name.trim();

if (name == null & id == null || name == "" & id == null) {
if (name == null && id == null || name == "" && id == null) {

Check warning on line 46 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'

Check warning on line 46 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'
return new MediaPage();
Comment on lines +46 to 47
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check uses name == "", which compares references rather than string content; empty (or whitespace-only) names may not be detected and will fall through to the service call unexpectedly. After trimming, prefer name.isEmpty()/name.isBlank() (and simplify to something like if (id == null && (name == null || name.isBlank()))).

Copilot uses AI. Check for mistakes.
}

Expand All @@ -62,7 +62,7 @@
public MediaPage getSerie(@Argument(name = "id") Integer id, @Argument(name = "name") String name, DataFetchingEnvironment dataFetchingEnvironment) {
name = name == null ? null : name.trim();

if (name == null & id == null || name == "" & id == null) {
if (name == null && id == null || name == "" && id == null) {

Check warning on line 65 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'

Check warning on line 65 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'
return new MediaPage();
Comment on lines +65 to 66
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check uses name == "", which compares references rather than string content; empty (or whitespace-only) names may not be detected and will fall through to the service call unexpectedly. After trimming, prefer name.isEmpty()/name.isBlank() (and simplify to something like if (id == null && (name == null || name.isBlank()))).

Copilot uses AI. Check for mistakes.
}

Expand All @@ -81,7 +81,7 @@
public MediaPage getGame(@Argument(name = "id") Integer id, @Argument(name = "name") String name, DataFetchingEnvironment dataFetchingEnvironment) {
name = name == null ? null : name.trim();

if (name == null & id == null || name == "" & id == null) {
if (name == null && id == null || name == "" && id == null) {

Check warning on line 84 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'

Check warning on line 84 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'
return new MediaPage();
Comment on lines +84 to 85
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check uses name == "", which compares references rather than string content; empty (or whitespace-only) names may not be detected and will fall through to the service call unexpectedly. After trimming, prefer name.isEmpty()/name.isBlank() (and simplify to something like if (id == null && (name == null || name.isBlank()))).

Copilot uses AI. Check for mistakes.
}

Expand All @@ -101,7 +101,7 @@
MediaPage response = new MediaPage();
name = name == null ? null : name.trim();

if (name == null & id == null || name == "" & id == null) {
if (name == null && id == null || name == "" && id == null) {

Check warning on line 104 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'

Check warning on line 104 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'
return response;
Comment on lines +104 to 105
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check uses name == "", which compares references rather than string content; empty (or whitespace-only) names may not be detected and will fall through to the service call unexpectedly. After trimming, prefer name.isEmpty()/name.isBlank() (and simplify to something like if (id == null && (name == null || name.isBlank()))).

Copilot uses AI. Check for mistakes.
}

Expand All @@ -119,7 +119,7 @@
public MediaPage getAnime(@Argument(name = "id") Integer id, @Argument(name = "name") String name, DataFetchingEnvironment dataFetchingEnvironment) {
name = name == null ? null : name.trim();

if (name == null & id == null || name == "" & id == null) {
if (name == null && id == null || name == "" && id == null) {

Check warning on line 122 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'

Check warning on line 122 in src/main/java/com/espacogeek/geek/controllers/MediaController.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

String comparison using '==', instead of 'equals()'

String values are compared using `==`, not 'equals()'
return new MediaPage();
Comment on lines +122 to 123
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check uses name == "", which compares references rather than string content; empty (or whitespace-only) names may not be detected and will fall through to the service call unexpectedly. After trimming, prefer name.isEmpty()/name.isBlank() (and simplify to something like if (id == null && (name == null || name.isBlank()))).

Copilot uses AI. Check for mistakes.
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/espacogeek/geek/data/api/MediaApi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.espacogeek.geek.data.api;

import java.util.List;
import java.io.InputStream;

import lombok.Getter;
import org.json.simple.JSONArray;
Expand Down Expand Up @@ -45,6 +46,10 @@ default JSONArray updateTitles() {
throw new UnsupportedOperationException();
}

default InputStream updateTitlesStream() {
throw new UnsupportedOperationException();
}

default MediaModel getDetails(Integer id) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.io.InputStream;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -64,13 +65,19 @@
return DataJumpUtils.getDataJumpTMDBArray(DataJumpTypeTMDB.MOVIE);
}

@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public InputStream updateTitlesStream() {
return DataJumpUtils.getDataJumpTMDBStream(DataJumpTypeTMDB.MOVIE);
}

/**
* @see MediaApi#updateTitles(
*/
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
@Override
public MediaModel getDetails(Integer id) {
MovieDb movieDb = new MovieDb();

Check warning on line 80 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `movieDb` initializer `new MovieDb()` is redundant

Check warning on line 80 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `movieDb` initializer `new MovieDb()` is redundant
try {
movieDb = api.getDetails(id, "en-US", MovieAppendToResponse.EXTERNAL_IDS, MovieAppendToResponse.ALTERNATIVE_TITLES, MovieAppendToResponse.IMAGES, MovieAppendToResponse.VIDEOS);
} catch (TmdbException e) {
Expand Down Expand Up @@ -104,7 +111,7 @@
}

public ExternalReferenceModel getTrailer(MovieDb movieDb) {
ExternalReferenceModel trailers = null;

Check warning on line 114 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `trailers` initializer `null` is redundant

Check warning on line 114 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `trailers` initializer `null` is redundant

trailers = movieDb.getVideos().getResults().stream().filter(video -> video.getType().equals("Trailer"))
.findFirst().map(video -> new ExternalReferenceModel(null, video.getKey(), null, typeReferenceService.findById(MediaDataController.ExternalReferenceType.YT.getId()).get()))
Expand All @@ -118,7 +125,7 @@
*/
@Override
public MediaModel getArtwork(Integer id) {
Images rawArtwork = new Images();

Check warning on line 128 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawArtwork` initializer `new Images()` is redundant

Check warning on line 128 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawArtwork` initializer `new Images()` is redundant
try {
rawArtwork = api.getImages(id, "en");
} catch (TmdbException e) {
Expand Down Expand Up @@ -153,7 +160,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public List<AlternativeTitleModel> getAlternativeTitles(Integer id) {
List<AlternativeTitle> rawAlternativeTitles = new ArrayList<>();

Check warning on line 163 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawAlternativeTitles` initializer `new ArrayList<>()` is redundant

Check warning on line 163 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawAlternativeTitles` initializer `new ArrayList<>()` is redundant
try {
rawAlternativeTitles = api.getAlternativeTitles(id, "us").getTitles();
} catch (TmdbException e) {
Expand All @@ -179,7 +186,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public List<ExternalReferenceModel> getExternalReference(Integer id) {
ExternalIds rawExternalReferences = new ExternalIds();

Check warning on line 189 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawExternalReferences` initializer `new ExternalIds()` is redundant

Check warning on line 189 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawExternalReferences` initializer `new ExternalIds()` is redundant
try {
rawExternalReferences = api.getExternalIds(id);
} catch (TmdbException e) {
Expand Down Expand Up @@ -207,7 +214,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public List<GenreModel> getGenre(Integer id) {
MovieDb movieDb = new MovieDb();

Check warning on line 217 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `movieDb` initializer `new MovieDb()` is redundant

Check warning on line 217 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `movieDb` initializer `new MovieDb()` is redundant
try {
movieDb = api.getDetails(id, "en-US");
} catch (TmdbException e) {
Expand All @@ -222,7 +229,7 @@
}

private List<GenreModel> formatGenre(List<Genre> rawGenres) {
List<GenreModel> genres = new ArrayList<GenreModel>();

Check warning on line 232 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `genres` initializer `new ArrayList<GenreModel>()` is redundant

Check warning on line 232 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `genres` initializer `new ArrayList<GenreModel>()` is redundant
List<String> rawStringGenres = rawGenres.stream().map((rawGenre) -> rawGenre.getName()).toList();
List<String> newRawGenres = new ArrayList<String>();

Expand All @@ -230,7 +237,7 @@
var genre = rawStringGenres.get(i);
if (genre.contains("&")) {
for (String genreDivided : genre.split("&")) {
genreDivided.replace("&", "");

Check warning on line 240 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Result of method call ignored

Result of `String.replace()` is ignored

Check warning on line 240 in src/main/java/com/espacogeek/geek/data/api/impl/MovieAPIImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Result of method call ignored

Result of `String.replace()` is ignored
genreDivided = genreDivided.strip();
newRawGenres.add(genreDivided);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.io.InputStream;

import info.movito.themoviedbapi.model.core.NamedIdElement;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -69,13 +70,19 @@
return DataJumpUtils.getDataJumpTMDBArray(DataJumpTypeTMDB.SERIES);
}

@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public InputStream updateTitlesStream() {
return DataJumpUtils.getDataJumpTMDBStream(DataJumpTypeTMDB.SERIES);
}

/**
* @see MediaApi#updateTitles()
*/
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
@Override
public MediaModel getDetails(Integer id) {
TvSeriesDb rawSerieDetails = new TvSeriesDb();

Check warning on line 85 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawSerieDetails` initializer `new TvSeriesDb()` is redundant

Check warning on line 85 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawSerieDetails` initializer `new TvSeriesDb()` is redundant
try {
rawSerieDetails = api.getDetails(id, "en-US", TvSeriesAppendToResponse.EXTERNAL_IDS, TvSeriesAppendToResponse.ALTERNATIVE_TITLES, TvSeriesAppendToResponse.IMAGES, TvSeriesAppendToResponse.VIDEOS);
} catch (TmdbException e) {
Expand Down Expand Up @@ -110,7 +117,7 @@
}

public ExternalReferenceModel getTrailer(TvSeriesDb rawSerieDetails) {
ExternalReferenceModel trailers = null;

Check warning on line 120 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `trailers` initializer `null` is redundant

Check warning on line 120 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `trailers` initializer `null` is redundant

trailers = rawSerieDetails.getVideos().getResults().stream().filter(video -> video.getType().equals("Trailer"))
.findFirst().map(video -> new ExternalReferenceModel(null, video.getKey(), null,
Expand All @@ -126,7 +133,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public MediaModel getArtwork(Integer id) {
Images rawArtwork = new Images();

Check warning on line 136 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawArtwork` initializer `new Images()` is redundant

Check warning on line 136 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawArtwork` initializer `new Images()` is redundant
try {
rawArtwork = api.getImages(id, "");
} catch (TmdbException e) {
Expand Down Expand Up @@ -160,7 +167,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public List<AlternativeTitleModel> getAlternativeTitles(Integer id) {
List<AlternativeTitle> rawAlternativeTitles = new ArrayList<>();

Check warning on line 170 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawAlternativeTitles` initializer `new ArrayList<>()` is redundant

Check warning on line 170 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawAlternativeTitles` initializer `new ArrayList<>()` is redundant
try {
rawAlternativeTitles = api.getAlternativeTitles(id).getResults();
} catch (TmdbException e) {
Expand All @@ -185,7 +192,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public List<ExternalReferenceModel> getExternalReference(Integer id) {
ExternalIds rawExternalReferences = new ExternalIds();

Check warning on line 195 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawExternalReferences` initializer `new ExternalIds()` is redundant

Check warning on line 195 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawExternalReferences` initializer `new ExternalIds()` is redundant
try {
rawExternalReferences = api.getExternalIds(id);
} catch (TmdbException e) {
Expand Down Expand Up @@ -218,7 +225,7 @@
@Override
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public List<GenreModel> getGenre(Integer id) {
TvSeriesDb rawSerieDetails = new TvSeriesDb();

Check warning on line 228 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawSerieDetails` initializer `new TvSeriesDb()` is redundant

Check warning on line 228 in src/main/java/com/espacogeek/geek/data/api/impl/TvSeriesApiImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

Variable `rawSerieDetails` initializer `new TvSeriesDb()` is redundant
try {
rawSerieDetails = api.getDetails(id, "en-US");
} catch (TmdbException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@
public MediaPage findSerieByIdOrName(Integer id, String name, Pageable pageable) {
Page<MediaModel> results;
if (id != null) {
results = (Page<MediaModel>) this.mediaRepository.findById(id).orElseGet(null);
var medias = new ArrayList<MediaModel>();
this.mediaRepository.findById(id).ifPresent(medias::add);
Pageable safePageable = pageable != null ? pageable : Pageable.unpaged();
results = new PageImpl<>(medias, safePageable, medias.size());
} else {
results = this.mediaRepository.findMediaByNameOrAlternativeTitleAndMediaCategory(name, name, mediaCategoryService.findById(MediaDataController.MediaType.SERIE.getId()).get().getId(), pageable);
}
Expand Down Expand Up @@ -139,19 +142,26 @@
public MediaPage findGameByIdOrName(Integer id, String name, Pageable pageable) {
Page<MediaModel> results;
if (id != null) {
results = (Page<MediaModel>) this.mediaRepository.findById(id).orElseGet(null);
var medias = new ArrayList<MediaModel>();
this.mediaRepository.findById(id).ifPresent(medias::add);
Pageable safePageable = pageable != null ? pageable : Pageable.unpaged();
results = new PageImpl<>(medias, safePageable, medias.size());
} else {
results = this.mediaRepository.findMediaByNameOrAlternativeTitleAndMediaCategory(name, name, mediaCategoryService.findById(MediaDataController.MediaType.GAME.getId()).get().getId(), pageable);
}
return mountMediaPage(results);
}

@Override
@SuppressWarnings("unchecked")
public MediaPage findVisualNovelByIdOrName(Integer id, String name, Pageable pageable) {
Page<MediaModel> results;

if(id != null) {
results = (Page<MediaModel>) this.mediaRepository.findById(id).orElseGet(null);
var medias = new ArrayList<MediaModel>();
this.mediaRepository.findById(id).ifPresent(medias::add);
Pageable safePageable = pageable != null ? pageable : Pageable.unpaged();
results = new PageImpl<>(medias, safePageable, medias.size());
} else {
results = this.mediaRepository.findMediaByNameOrAlternativeTitleAndMediaCategory(name, name, mediaCategoryService.findById(MediaDataController.MediaType.VN.getId()).get().getId(), pageable);
}
Expand All @@ -178,7 +188,7 @@
var fieldList = new ArrayList<Field>();
MediaModel media = (MediaModel) mediaRepository.findById(id).orElseGet(null);

if (media == null)

Check warning on line 191 in src/main/java/com/espacogeek/geek/services/impl/MediaServiceImpl.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Constant values

Condition `media == null` is always `false`
return Optional.empty();

for (Field field : media.getClass().getDeclaredFields()) {
Expand Down Expand Up @@ -278,15 +288,15 @@
return mountMediaPage(results);
}

/**
* @see MediaService#findAnimeByIdOrName(Integer, String, Pageable)
*/
@Override
@SuppressWarnings("unchecked")
public MediaPage findAnimeByIdOrName(Integer id, String name, Pageable pageable) {
Page<MediaModel> results;
if (id != null) {
results = (Page<MediaModel>) this.mediaRepository.findById(id).orElseGet(null);
var medias = new ArrayList<MediaModel>();
this.mediaRepository.findById(id).ifPresent(medias::add);
Pageable safePageable = pageable != null ? pageable : Pageable.unpaged();
results = new PageImpl<>(medias, safePageable, medias.size());
} else {
results = (Page<MediaModel>) this.mediaRepository.findMediaByNameOrAlternativeTitleAndMediaCategory(name, name, mediaCategoryService.findById(MediaDataController.MediaType.ANIME_SERIE.getId()).get().getId(), pageable);
}
Expand All @@ -301,7 +311,10 @@
public MediaPage findMovieByIdOrName(Integer id, String name, Pageable pageable) {
Page<MediaModel> results;
if (id != null) {
results = (Page<MediaModel>) this.mediaRepository.findById(id).orElseGet(null);
var medias = new ArrayList<MediaModel>();
this.mediaRepository.findById(id).ifPresent(medias::add);
Pageable safePageable = pageable != null ? pageable : Pageable.unpaged();
results = new PageImpl<>(medias, safePageable, medias.size());
} else {
results = (Page<MediaModel>) this.mediaRepository.findMediaByNameOrAlternativeTitleAndMediaCategory(name, name, mediaCategoryService.findById(MediaDataController.MediaType.MOVIE.getId()).get().getId(), pageable);
}
Expand Down Expand Up @@ -330,16 +343,21 @@

var mediasList = medias.getContent();
for (MediaModel mediaModel : mediasList) {
switch (mediaModel.getMediaCategory().getId()) {
case 5:
case 1:
serieController.updateArtworks(mediaModel, null);
case 7:
case 4:
genericMediaDataController.updateArtworks(mediaModel, null, typeReferenceService.findById(MediaDataController.ExternalReferenceType.TMDB.getId()).get(), movieAPI);
case 2:
case 3:
genericMediaDataController.updateArtworks(mediaModel, null, typeReferenceService.findById(MediaDataController.ExternalReferenceType.IGDB.getId()).get(), gamesAndVNsAPI);
if (MediaUtils.updateMediaWhenLastTimeUpdateMoreThanOneDay(mediaModel)) {
switch (mediaModel.getMediaCategory().getId()) {
case 5:
case 1:
serieController.updateArtworks(mediaModel, null);
break;
case 7:
case 4:
genericMediaDataController.updateArtworks(mediaModel, null, typeReferenceService.findById(MediaDataController.ExternalReferenceType.TMDB.getId()).get(), movieAPI);
break;
case 2:
case 3:
genericMediaDataController.updateArtworks(mediaModel, null, typeReferenceService.findById(MediaDataController.ExternalReferenceType.IGDB.getId()).get(), gamesAndVNsAPI);
break;
}
}
}

Expand Down
69 changes: 40 additions & 29 deletions src/main/java/com/espacogeek/geek/utils/DataJumpUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.espacogeek.geek.utils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.zip.GZIPInputStream;

import lombok.Getter;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org.json.simple.JSONObject is imported but no longer used in this file. In Java, unused imports fail compilation; remove the unused import (or reintroduce the usage if it was intended).

Suggested change
import org.json.simple.JSONObject;

Copilot uses AI. Check for mistakes.
import org.json.simple.parser.JSONParser;
Expand All @@ -21,7 +24,8 @@
public final class DataJumpUtils {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DataJumpUtils.class);

public static enum DataJumpTypeTMDB {
@Getter
public enum DataJumpTypeTMDB {
MOVIE("movie"), SERIES("tv_series"), PERSON("person");

private final String value;
Expand All @@ -30,22 +34,15 @@ public static enum DataJumpTypeTMDB {
this.value = value;
}

public String getValue() {
return value;
}
}

/**
*
* This function get the daily datajump available by tmdb
* This function get the daily datajump available by tmdb as a stream
*
* @return a JSON Array with all serie titles
* @throws IOException
* @throws ParseException
* @return an uncompressed GZIP InputStream with all titles
*/
@SuppressWarnings({ "unchecked", "null" })
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public static JSONArray getDataJumpTMDBArray(final @NotNull DataJumpTypeTMDB type) {
public static InputStream getDataJumpTMDBStream(final @NotNull DataJumpTypeTMDB type) {
var now = LocalDateTime.now();

// formatting the date to do request as tmdb pattern
Expand All @@ -54,7 +51,7 @@ public static JSONArray getDataJumpTMDBArray(final @NotNull DataJumpTypeTMDB typ
var year = String.valueOf(now.getYear()).replace(".", "");

var client = new OkHttpClient().newBuilder().build();
Request request = null;
Request request;
try {
request = new Request.Builder()
.url(MessageFormat.format("http://files.tmdb.org/p/exports/{3}_ids_{0}_{1}_{2}.json.gz", month, day, year, type.getValue()))
Expand All @@ -68,29 +65,43 @@ public static JSONArray getDataJumpTMDBArray(final @NotNull DataJumpTypeTMDB typ
Response response = null;
try {
response = client.newCall(request).execute();
if (!response.isSuccessful()) {
log.error("Failed to fetch TMDB daily export: {}", response.message());
response.close();
throw new com.espacogeek.geek.exception.RequestException();
}
assert response.body() != null;
return new GZIPInputStream(response.body().byteStream());
} catch (IOException e) {
Comment on lines 65 to 75
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDataJumpTMDBStream returns a stream backed by an OkHttp Response, but the Response is never closed on the success path. This will leak connections/sockets unless the response is reliably closed when the returned stream is closed; consider wrapping the returned InputStream so close() also closes the OkHttp Response (and replace the assert response.body() != null with an explicit null check that throws a RequestException).

Copilot uses AI. Check for mistakes.
log.error(e.getMessage(), e);
if (response != null) response.close();
throw new com.espacogeek.geek.exception.RequestException();
}
}

GZIPInputStream inputStream = null;
String[] json = null;
try {
inputStream = new GZIPInputStream(new ByteArrayInputStream(response.body().bytes()));
json = new String(inputStream.readAllBytes()).split("\n");
} catch (IOException e) {
log.error(e.getMessage(), e);
}

/**
*
* This function get the daily datajump available by tmdb
*
* @return a JSON Array with all serie titles
*/
@SuppressWarnings({ "unchecked" })
@Retryable(maxAttempts = 2, backoff = @Backoff(delay = 2000), retryFor = com.espacogeek.geek.exception.RequestException.class)
public static JSONArray getDataJumpTMDBArray(final @NotNull DataJumpTypeTMDB type) {
JSONArray jsonArray = new JSONArray();
for (var item : json) {
try (InputStream is = getDataJumpTMDBStream(type);
BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
String line;
Comment on lines +92 to +94
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new InputStreamReader(is) uses the platform default charset; JSON from TMDB exports is UTF-8. Specify StandardCharsets.UTF_8 to avoid parsing issues on non-UTF-8 default platforms.

Copilot uses AI. Check for mistakes.
JSONParser parser = new JSONParser();
JSONObject jsonObject = null;
try {
jsonObject = (JSONObject) parser.parse(item);
} catch (ParseException e) {
log.error(e.getMessage(), e);
while ((line = reader.readLine()) != null) {
try {
jsonArray.add(parser.parse(line));
} catch (ParseException e) {
log.error("Error parsing TMDB JSON line: {}", e.getMessage());
}
}
jsonArray.add(jsonObject);
} catch (Exception e) {
log.error("Error reading TMDB array: {}", e.getMessage());
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDataJumpTMDBArray is annotated with @Retryable(...RequestException.class) but the outer catch (Exception e) swallows failures and returns a partial/empty array, which prevents retries and hides errors from callers. Re-throw a RequestException (or let it propagate) after logging so retry semantics work as intended.

Suggested change
log.error("Error reading TMDB array: {}", e.getMessage());
log.error("Error reading TMDB array", e);
throw new com.espacogeek.geek.exception.RequestException();

Copilot uses AI. Check for mistakes.
}
return jsonArray;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/espacogeek/geek/utils/MediaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
* update was more than one day ago
* or if the update date is null), <code>false</code> otherwise
*/
private static Boolean updateMediaWhenLastTimeUpdateMoreThanOneDay(MediaModel media) {
public static Boolean updateMediaWhenLastTimeUpdateMoreThanOneDay(MediaModel media) {
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is now public and used as a boolean predicate, but it returns the boxed Boolean type. Prefer returning primitive boolean to avoid unnecessary boxing and the possibility of null-related issues as this becomes part of a wider API surface.

Suggested change
public static Boolean updateMediaWhenLastTimeUpdateMoreThanOneDay(MediaModel media) {
public static boolean updateMediaWhenLastTimeUpdateMoreThanOneDay(MediaModel media) {

Copilot uses AI. Check for mistakes.
if (media == null)
return false;

LocalDate mediaUpdateAt = media.getUpdateAt() == null ? null : LocalDate.ofInstant(media.getUpdateAt().toInstant(), ZoneId.systemDefault());

if (mediaUpdateAt == null || ChronoUnit.DAYS.between(mediaUpdateAt, LocalDate.now()) > 1l) {

Check warning on line 43 in src/main/java/com/espacogeek/geek/utils/MediaUtils.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

'long' literal ending with 'l' instead of 'L'

'long' literal `1l` ends with lowercase 'l'

Check warning on line 43 in src/main/java/com/espacogeek/geek/utils/MediaUtils.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

'long' literal ending with 'l' instead of 'L'

'long' literal `1l` ends with lowercase 'l'
return true;
}

Expand All @@ -61,7 +61,7 @@
*/
public static List<MediaModel> updateGenericMedia(List<MediaModel> medias, MediaDataController mediaDataController,
TypeReferenceModel typeReference, MediaApi mediaApi) {
List<MediaModel> updatedMedias = new ArrayList<>();

Check warning on line 64 in src/main/java/com/espacogeek/geek/utils/MediaUtils.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatched query and update of collection

Contents of collection `updatedMedias` are updated, but never queried

Check warning on line 64 in src/main/java/com/espacogeek/geek/utils/MediaUtils.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatched query and update of collection

Contents of collection `updatedMedias` are updated, but never queried

for (MediaModel media : medias) {
updatedMedias.add(updateMediaWhenLastTimeUpdateMoreThanOneDay(media)
Expand All @@ -81,7 +81,7 @@
* @return the list of updated medias
*/
public static List<MediaModel> updateMedia(List<MediaModel> medias, MediaDataController mediaDataController) {
List<MediaModel> updatedMedias = new ArrayList<>();

Check warning on line 84 in src/main/java/com/espacogeek/geek/utils/MediaUtils.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatched query and update of collection

Contents of collection `updatedMedias` are updated, but never queried

Check warning on line 84 in src/main/java/com/espacogeek/geek/utils/MediaUtils.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Mismatched query and update of collection

Contents of collection `updatedMedias` are updated, but never queried

for (MediaModel media : medias) {
updatedMedias.add(updateMediaWhenLastTimeUpdateMoreThanOneDay(media)
Expand Down
Loading