-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from Shikkanime/dev
Dev
- Loading branch information
Showing
25 changed files
with
215 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package fr.shikkanime.converters.anime | ||
|
||
import com.google.inject.Inject | ||
import fr.shikkanime.converters.AbstractConverter | ||
import fr.shikkanime.dtos.animes.UpdatedAnimeDto | ||
import fr.shikkanime.dtos.enums.Status | ||
import fr.shikkanime.dtos.simulcasts.SimulcastDto | ||
import fr.shikkanime.entities.Anime | ||
import fr.shikkanime.entities.SortParameter | ||
import fr.shikkanime.services.caches.EpisodeCacheService | ||
import fr.shikkanime.utils.StringUtils | ||
import fr.shikkanime.utils.withUTC | ||
import org.apache.tika.language.detect.LanguageDetector | ||
import org.hibernate.Hibernate | ||
import java.time.format.DateTimeFormatter | ||
|
||
class AnimeToUpdatedAnimeDtoConverter : AbstractConverter<Anime, UpdatedAnimeDto>() { | ||
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels() | ||
|
||
@Inject | ||
private lateinit var episodeCacheService: EpisodeCacheService | ||
|
||
override fun convert(from: Anime): UpdatedAnimeDto { | ||
val lastReleaseDate = episodeCacheService.findAllBy( | ||
from.countryCode!!, | ||
from.uuid, | ||
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)), | ||
1, | ||
1 | ||
)?.data?.firstOrNull()?.releaseDateTime | ||
|
||
val status = if ( | ||
from.image.isNullOrBlank() || | ||
from.banner.isNullOrBlank() || | ||
from.description.isNullOrBlank() || | ||
from.description?.startsWith("(") == true || | ||
languageDetector.detect(from.description).language.lowercase() != from.countryCode.name.lowercase() | ||
) Status.INVALID else Status.VALID | ||
|
||
return UpdatedAnimeDto( | ||
uuid = from.uuid, | ||
releaseDateTime = from.releaseDateTime.withUTC() | ||
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), | ||
image = from.image, | ||
banner = from.banner, | ||
countryCode = from.countryCode, | ||
name = from.name!!, | ||
shortName = StringUtils.getShortName(from.name!!), | ||
description = from.description, | ||
simulcasts = if (Hibernate.isInitialized(from.simulcasts)) convert( | ||
from.simulcasts, | ||
SimulcastDto::class.java | ||
) else null, | ||
status = status, | ||
slug = from.slug, | ||
lastReleaseDateTime = lastReleaseDate | ||
) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/fr/shikkanime/converters/episode/EpisodeToEpisodeDtoConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fr.shikkanime.converters.simulcast | ||
|
||
import com.google.inject.Inject | ||
import fr.shikkanime.converters.AbstractConverter | ||
import fr.shikkanime.dtos.simulcasts.UpdatedSimulcastDto | ||
import fr.shikkanime.entities.Simulcast | ||
import fr.shikkanime.entities.SortParameter | ||
import fr.shikkanime.entities.enums.CountryCode | ||
import fr.shikkanime.services.caches.AnimeCacheService | ||
|
||
class SimulcastToUpdatedSimulcastDtoConverter : AbstractConverter<Simulcast, UpdatedSimulcastDto>() { | ||
@Inject | ||
private lateinit var animeCacheService: AnimeCacheService | ||
|
||
override fun convert(from: Simulcast): UpdatedSimulcastDto { | ||
val lastReleaseDateTime = animeCacheService.findAllBy( | ||
CountryCode.FR, | ||
from.uuid, | ||
listOf(SortParameter("releaseDateTime", SortParameter.Order.DESC)), | ||
1, | ||
1 | ||
)?.data?.firstOrNull()?.releaseDateTime | ||
|
||
return UpdatedSimulcastDto( | ||
uuid = from.uuid, | ||
season = from.season!!, | ||
year = from.year!!, | ||
slug = "${from.season.lowercase()}-${from.year}", | ||
label = when (from.season) { | ||
"WINTER" -> "Hiver" | ||
"SPRING" -> "Printemps" | ||
"SUMMER" -> "Été" | ||
"AUTUMN" -> "Automne" | ||
else -> "Inconnu" | ||
} + " ${from.year}", | ||
lastReleaseDateTime = lastReleaseDateTime | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/fr/shikkanime/dtos/animes/UpdatedAnimeDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.shikkanime.dtos.animes | ||
|
||
import fr.shikkanime.dtos.enums.Status | ||
import fr.shikkanime.dtos.simulcasts.SimulcastDto | ||
import fr.shikkanime.entities.enums.CountryCode | ||
import java.io.Serializable | ||
import java.util.* | ||
|
||
data class UpdatedAnimeDto( | ||
val uuid: UUID?, | ||
val countryCode: CountryCode, | ||
var name: String, | ||
var shortName: String, | ||
var releaseDateTime: String, | ||
val image: String? = null, | ||
val banner: String? = null, | ||
val description: String?, | ||
val simulcasts: List<SimulcastDto>?, | ||
val status: Status? = null, | ||
val slug: String? = null, | ||
val lastReleaseDateTime: String? = null | ||
) : Serializable |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/fr/shikkanime/dtos/simulcasts/SimulcastDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package fr.shikkanime.dtos.simulcasts | ||
|
||
import java.io.Serializable | ||
import java.util.* | ||
|
||
data class SimulcastDto( | ||
val uuid: UUID?, | ||
val season: String, | ||
val year: Int, | ||
val slug: String, | ||
val label: String, | ||
) : Serializable |
4 changes: 2 additions & 2 deletions
4
...kotlin/fr/shikkanime/dtos/SimulcastDto.kt → ...me/dtos/simulcasts/UpdatedSimulcastDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.