-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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 | ||
Check warning on line 29 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt Codecov / codecov/patchsrc/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L25-L29
|
||
)?.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, | ||
Check warning on line 49 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt Codecov / codecov/patchsrc/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L40-L49
|
||
simulcasts = if (Hibernate.isInitialized(from.simulcasts)) convert( | ||
from.simulcasts, | ||
SimulcastDto::class.java | ||
) else null, | ||
status = status, | ||
slug = from.slug, | ||
lastReleaseDateTime = lastReleaseDate | ||
Check warning on line 56 in src/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt Codecov / codecov/patchsrc/main/kotlin/fr/shikkanime/converters/anime/AnimeToUpdatedAnimeDtoConverter.kt#L53-L56
|
||
) | ||
} | ||
} |
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 | ||
Check warning on line 21 in src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt Codecov / codecov/patchsrc/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt#L17-L21
|
||
)?.data?.firstOrNull()?.releaseDateTime | ||
|
||
return UpdatedSimulcastDto( | ||
uuid = from.uuid, | ||
season = from.season!!, | ||
year = from.year!!, | ||
slug = "${from.season.lowercase()}-${from.year}", | ||
Check warning on line 28 in src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt Codecov / codecov/patchsrc/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt#L24-L28
|
||
label = when (from.season) { | ||
"WINTER" -> "Hiver" | ||
"SPRING" -> "Printemps" | ||
"SUMMER" -> "Été" | ||
"AUTUMN" -> "Automne" | ||
else -> "Inconnu" | ||
} + " ${from.year}", | ||
lastReleaseDateTime = lastReleaseDateTime | ||
Check warning on line 36 in src/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt Codecov / codecov/patchsrc/main/kotlin/fr/shikkanime/converters/simulcast/SimulcastToUpdatedSimulcastDtoConverter.kt#L30-L36
|
||
) | ||
} | ||
} |
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 | ||
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 |