From 7207a3ec1782f8b4bd87b686b01e47fa50e1c4a7 Mon Sep 17 00:00:00 2001 From: bivashy Date: Tue, 3 Feb 2026 23:58:56 +0500 Subject: [PATCH] Basic implementation of shikimori graphql api to retrieve anime by id --- .dockerignore | 5 + .gitignore | 46 +++ .mvn/wrapper/maven-wrapper.properties | 3 + README.md | 62 ++++ mvnw | 295 +++++++++++++++++ mvnw.cmd | 189 +++++++++++ pom.xml | 13 +- src/main/docker/Dockerfile.jvm | 100 ++++++ src/main/docker/Dockerfile.legacy-jar | 96 ++++++ src/main/docker/Dockerfile.native | 29 ++ src/main/docker/Dockerfile.native-micro | 32 ++ .../metadata/shikimori/api/ShikimoriAPI.java | 22 ++ .../metadata/shikimori/api/model/Anime.java | 300 ++++++++++++++++++ .../shikimori/api/model/AnimeKindEnum.java | 13 + .../shikimori/api/model/AnimeOriginEnum.java | 21 ++ .../shikimori/api/model/AnimeRatingEnum.java | 11 + .../shikimori/api/model/AnimeStatusEnum.java | 7 + .../metadata/shikimori/api/model/Genre.java | 4 + .../api/model/GenreEntryTypeEnum.java | 6 + .../shikimori/api/model/GenreKindEnum.java | 7 + .../shikimori/api/model/IncompleteDate.java | 51 +++ .../shikimori/api/model/OrderEnum.java | 20 ++ .../metadata/shikimori/api/model/Poster.java | 5 + .../metadata/shikimori/api/model/Related.java | 5 + .../shikimori/api/model/RelatedAnime.java | 4 + .../shikimori/api/model/RelatedManga.java | 4 + .../shikimori/model/AnimeMetadata.java | 13 - .../metadata/shikimori/model/Character.java | 8 - .../shikimori/model/RelatedAnime.java | 7 - .../metadata/shikimori/model/VoiceActor.java | 7 - .../shikimori/resource/ShikimoriResource.java | 28 ++ .../shikimori/service/MetadataResource.java | 22 -- .../shikimori/service/ShikimoriService.java | 17 - .../shikimori/service/GreetingResourceIT.java | 8 + .../service/GreetingResourceTest.java | 20 ++ 35 files changed, 1401 insertions(+), 79 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 README.md create mode 100755 mvnw create mode 100644 mvnw.cmd create mode 100644 src/main/docker/Dockerfile.jvm create mode 100644 src/main/docker/Dockerfile.legacy-jar create mode 100644 src/main/docker/Dockerfile.native create mode 100644 src/main/docker/Dockerfile.native-micro create mode 100644 src/main/java/com/backend/metadata/shikimori/api/ShikimoriAPI.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/Anime.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/AnimeKindEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/AnimeOriginEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/AnimeRatingEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/AnimeStatusEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/Genre.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/GenreEntryTypeEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/GenreKindEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/IncompleteDate.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/OrderEnum.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/Poster.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/Related.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/RelatedAnime.java create mode 100644 src/main/java/com/backend/metadata/shikimori/api/model/RelatedManga.java delete mode 100644 src/main/java/com/backend/metadata/shikimori/model/AnimeMetadata.java delete mode 100644 src/main/java/com/backend/metadata/shikimori/model/Character.java delete mode 100644 src/main/java/com/backend/metadata/shikimori/model/RelatedAnime.java delete mode 100644 src/main/java/com/backend/metadata/shikimori/model/VoiceActor.java create mode 100644 src/main/java/com/backend/metadata/shikimori/resource/ShikimoriResource.java delete mode 100644 src/main/java/com/backend/metadata/shikimori/service/MetadataResource.java delete mode 100644 src/main/java/com/backend/metadata/shikimori/service/ShikimoriService.java create mode 100644 src/test/java/com/backend/metadata/shikimori/service/GreetingResourceIT.java create mode 100644 src/test/java/com/backend/metadata/shikimori/service/GreetingResourceTest.java diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..94810d0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* +!target/quarkus-app/* \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae6e07d --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +#Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +release.properties +.flattened-pom.xml + +# Eclipse +.project +.classpath +.settings/ +bin/ + +# IntelliJ +.idea +*.ipr +*.iml +*.iws + +# NetBeans +nb-configuration.xml + +# Visual Studio Code +.vscode +.factorypath + +# OSX +.DS_Store + +# Vim +*.swp +*.swo + +# patch +*.orig +*.rej + +# Local environment +.env + +# Plugin directory +/.quarkus/cli/plugins/ +# TLS Certificates +.certs/ +.aider* diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..8dea6c2 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4273cc --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# anyame-shikimori-metadata-backend + +This project uses Quarkus, the Supersonic Subatomic Java Framework. + +If you want to learn more about Quarkus, please visit its website: . + +## Running the application in dev mode + +You can run your application in dev mode that enables live coding using: + +```shell script +./mvnw quarkus:dev +``` + +> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at . + +## Packaging and running the application + +The application can be packaged using: + +```shell script +./mvnw package +``` + +It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. +Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. + +The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. + +If you want to build an _über-jar_, execute the following command: + +```shell script +./mvnw package -Dquarkus.package.jar.type=uber-jar +``` + +The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. + +## Creating a native executable + +You can create a native executable using: + +```shell script +./mvnw package -Dnative +``` + +Or, if you don't have GraalVM installed, you can run the native executable build in a container using: + +```shell script +./mvnw package -Dnative -Dquarkus.native.container-build=true +``` + +You can then execute your native executable with: `./target/anyame-shikimori-metadata-backend-0.0.1-SNAPSHOT-runner` + +If you want to learn more about building native executables, please consult . + +## Provided Code + +### REST + +Easily start your REST Web Services + +[Related guide section...](https://quarkus.io/guides/getting-started-reactive#reactive-jax-rs-resources) diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml index 9727c63..6dbe33b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 com.backend.metadata.shikimori.service anyame-shikimori-metadata-backend @@ -40,12 +42,12 @@ quarkus-rest - org.eclipse.microprofile.rest.client - microprofile-rest-client-api + io.quarkus + quarkus-smallrye-graphql-client io.quarkus - quarkus-rest-client + quarkus-rest-jackson io.quarkus @@ -99,7 +101,8 @@ @{argLine} - ${project.build.directory}/${project.build.finalName}-runner + + ${project.build.directory}/${project.build.finalName}-runner org.jboss.logmanager.LogManager ${maven.home} diff --git a/src/main/docker/Dockerfile.jvm b/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..b491681 --- /dev/null +++ b/src/main/docker/Dockerfile.jvm @@ -0,0 +1,100 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/anyame-shikimori-metadata-backend-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/anyame-shikimori-metadata-backend-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/anyame-shikimori-metadata-backend-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +# You can find more information about the UBI base runtime images and their configuration here: +# https://rh-openjdk.github.io/redhat-openjdk-containers/ +### +FROM registry.access.redhat.com/ubi9/openjdk-25:1.23 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/src/main/docker/Dockerfile.legacy-jar b/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 0000000..31d7d4b --- /dev/null +++ b/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,96 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/anyame-shikimori-metadata-backend-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/anyame-shikimori-metadata-backend-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/anyame-shikimori-metadata-backend-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +# You can find more information about the UBI base runtime images and their configuration here: +# https://rh-openjdk.github.io/redhat-openjdk-containers/ +### +FROM registry.access.redhat.com/ubi9/openjdk-25:1.23 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/src/main/docker/Dockerfile.native b/src/main/docker/Dockerfile.native new file mode 100644 index 0000000..b7b7625 --- /dev/null +++ b/src/main/docker/Dockerfile.native @@ -0,0 +1,29 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/anyame-shikimori-metadata-backend . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/anyame-shikimori-metadata-backend +# +# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.7` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. +### +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.7 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/src/main/docker/Dockerfile.native-micro b/src/main/docker/Dockerfile.native-micro new file mode 100644 index 0000000..7cc8158 --- /dev/null +++ b/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,32 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/anyame-shikimori-metadata-backend . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/anyame-shikimori-metadata-backend +# +# The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. +### +FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/src/main/java/com/backend/metadata/shikimori/api/ShikimoriAPI.java b/src/main/java/com/backend/metadata/shikimori/api/ShikimoriAPI.java new file mode 100644 index 0000000..db11231 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/ShikimoriAPI.java @@ -0,0 +1,22 @@ +package com.backend.metadata.shikimori.api; + +import java.util.List; + +import org.eclipse.microprofile.graphql.DefaultValue; +import org.eclipse.microprofile.graphql.Name; +import org.eclipse.microprofile.graphql.Query; + +import com.backend.metadata.shikimori.api.model.Anime; + +import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi; + +@GraphQLClientApi(endpoint = "https://shikimori.one/api/graphql") +public interface ShikimoriAPI { + @Query("animes") + List animes( + @Name("page") @DefaultValue("1") Integer page, + @Name("limit") @DefaultValue("2") Integer limit, + @Name("ids") String ids, + @Name("excludeIds") String excludeIds, + @Name("search") String search); +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/Anime.java b/src/main/java/com/backend/metadata/shikimori/api/model/Anime.java new file mode 100644 index 0000000..472136b --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/Anime.java @@ -0,0 +1,300 @@ +package com.backend.metadata.shikimori.api.model; + +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.util.List; + +import io.smallrye.graphql.api.Nullable; + +public class Anime { + private String id; + private String name; + private String russian; + + @Nullable + private IncompleteDate airedOn; + + @Nullable + private IncompleteDate releasedOn; + + @Nullable + private String kind; + + @Nullable + private AnimeStatusEnum status; + + @Nullable + private AnimeRatingEnum rating; + + @Nullable + private AnimeOriginEnum origin; + + private Integer episodes; + private Integer episodesAired; + + @Nullable + private Integer duration; + + @Nullable + private Float score; + + private String description; + + @Nullable + private String descriptionHtml; + + @Nullable + private String descriptionSource; + + @Nullable + private String franchise; + + private Boolean isCensored; + + @Nullable + private String english; + + @Nullable + private String japanese; + + private List synonyms; + private List genres; + private List related; + + @Nullable + private Poster poster; + + @Nullable + private String url; + + @Nullable + private OffsetDateTime nextEpisodeAt; + + private OffsetDateTime createdAt; + private OffsetDateTime updatedAt; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRussian() { + return russian; + } + + public void setRussian(String russian) { + this.russian = russian; + } + + public IncompleteDate getAiredOn() { + return airedOn; + } + + public void setAiredOn(IncompleteDate airedOn) { + this.airedOn = airedOn; + } + + public IncompleteDate getReleasedOn() { + return releasedOn; + } + + public void setReleasedOn(IncompleteDate releasedOn) { + this.releasedOn = releasedOn; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public AnimeStatusEnum getStatus() { + return status; + } + + public void setStatus(AnimeStatusEnum status) { + this.status = status; + } + + public AnimeRatingEnum getRating() { + return rating; + } + + public void setRating(AnimeRatingEnum rating) { + this.rating = rating; + } + + public AnimeOriginEnum getOrigin() { + return origin; + } + + public void setOrigin(AnimeOriginEnum origin) { + this.origin = origin; + } + + public Integer getEpisodes() { + return episodes; + } + + public void setEpisodes(Integer episodes) { + this.episodes = episodes; + } + + public Integer getEpisodesAired() { + return episodesAired; + } + + public void setEpisodesAired(Integer episodesAired) { + this.episodesAired = episodesAired; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public Float getScore() { + return score; + } + + public void setScore(Float score) { + this.score = score; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescriptionHtml() { + return descriptionHtml; + } + + public void setDescriptionHtml(String descriptionHtml) { + this.descriptionHtml = descriptionHtml; + } + + public String getDescriptionSource() { + return descriptionSource; + } + + public void setDescriptionSource(String descriptionSource) { + this.descriptionSource = descriptionSource; + } + + public String getFranchise() { + return franchise; + } + + public void setFranchise(String franchise) { + this.franchise = franchise; + } + + public Boolean getIsCensored() { + return isCensored; + } + + public void setIsCensored(Boolean isCensored) { + this.isCensored = isCensored; + } + + public String getEnglish() { + return english; + } + + public void setEnglish(String english) { + this.english = english; + } + + public String getJapanese() { + return japanese; + } + + public void setJapanese(String japanese) { + this.japanese = japanese; + } + + public List getSynonyms() { + return synonyms; + } + + public void setSynonyms(List synonyms) { + this.synonyms = synonyms; + } + + public List getGenres() { + return genres; + } + + public void setGenres(List genres) { + this.genres = genres; + } + + public Poster getPoster() { + return poster; + } + + public void setPoster(Poster poster) { + this.poster = poster; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public OffsetDateTime getNextEpisodeAt() { + return nextEpisodeAt; + } + + public void setNextEpisodeAt(OffsetDateTime nextEpisodeAt) { + this.nextEpisodeAt = nextEpisodeAt; + } + + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(OffsetDateTime createdAt) { + this.createdAt = createdAt; + } + + public OffsetDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(OffsetDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + public List getRelated() { + return related; + } + + public void setRelated(List related) { + this.related = related; + } + +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/AnimeKindEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeKindEnum.java new file mode 100644 index 0000000..19d5f04 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeKindEnum.java @@ -0,0 +1,13 @@ +package com.backend.metadata.shikimori.api.model; + +public enum AnimeKindEnum { + tv, + movie, + ova, + ona, + special, + tv_special, + music, + pv, + cm +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/AnimeOriginEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeOriginEnum.java new file mode 100644 index 0000000..59a9cf2 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeOriginEnum.java @@ -0,0 +1,21 @@ +package com.backend.metadata.shikimori.api.model; + +public enum AnimeOriginEnum { + original, + manga, + web_manga, + four_koma_manga, + novel, + web_novel, + visual_novel, + light_novel, + game, + card_game, + music, + radio, + book, + picture_book, + mixed_media, + other, + unknown +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/AnimeRatingEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeRatingEnum.java new file mode 100644 index 0000000..f180606 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeRatingEnum.java @@ -0,0 +1,11 @@ +package com.backend.metadata.shikimori.api.model; + +public enum AnimeRatingEnum { + none, + g, + pg, + pg_13, + r, + r_plus, + rx +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/AnimeStatusEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeStatusEnum.java new file mode 100644 index 0000000..5cb9edd --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/AnimeStatusEnum.java @@ -0,0 +1,7 @@ +package com.backend.metadata.shikimori.api.model; + +public enum AnimeStatusEnum { + anons, + ongoing, + released +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/Genre.java b/src/main/java/com/backend/metadata/shikimori/api/model/Genre.java new file mode 100644 index 0000000..8c0406b --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/Genre.java @@ -0,0 +1,4 @@ +package com.backend.metadata.shikimori.api.model; + +public record Genre(String id, String name, String russian, GenreEntryTypeEnum entryType, GenreKindEnum kind) { +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/GenreEntryTypeEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/GenreEntryTypeEnum.java new file mode 100644 index 0000000..0cd8d40 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/GenreEntryTypeEnum.java @@ -0,0 +1,6 @@ +package com.backend.metadata.shikimori.api.model; + +public enum GenreEntryTypeEnum { + Anime, + Manga +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/GenreKindEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/GenreKindEnum.java new file mode 100644 index 0000000..6289e02 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/GenreKindEnum.java @@ -0,0 +1,7 @@ +package com.backend.metadata.shikimori.api.model; + +public enum GenreKindEnum { + demographic, + genre, + theme +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/IncompleteDate.java b/src/main/java/com/backend/metadata/shikimori/api/model/IncompleteDate.java new file mode 100644 index 0000000..730b470 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/IncompleteDate.java @@ -0,0 +1,51 @@ +package com.backend.metadata.shikimori.api.model; + +import java.time.LocalDate; + +import io.smallrye.graphql.api.Nullable; + +public class IncompleteDate { + @Nullable + private LocalDate date; + + @Nullable + private Integer day; + + @Nullable + private Integer month; + + @Nullable + private Integer year; + + public LocalDate getDate() { + return date; + } + + public void setDate(LocalDate date) { + this.date = date; + } + + public Integer getDay() { + return day; + } + + public void setDay(Integer day) { + this.day = day; + } + + public Integer getMonth() { + return month; + } + + public void setMonth(Integer month) { + this.month = month; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/OrderEnum.java b/src/main/java/com/backend/metadata/shikimori/api/model/OrderEnum.java new file mode 100644 index 0000000..19c1d82 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/OrderEnum.java @@ -0,0 +1,20 @@ +package com.backend.metadata.shikimori.api.model; + +public enum OrderEnum { + id, + id_desc, + ranked, + kind, + popularity, + name, + aired_on, + episodes, + status, + random, + ranked_random, + ranked_shiki, + created_at, + created_at_desc, + updated_at, + updated_at_desc +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/Poster.java b/src/main/java/com/backend/metadata/shikimori/api/model/Poster.java new file mode 100644 index 0000000..142f901 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/Poster.java @@ -0,0 +1,5 @@ +package com.backend.metadata.shikimori.api.model; + +public record Poster(String id, String originalUrl, String mainUrl, String main2xUrl, String previewUrl, + String preview2xUrl, String miniUrl, String mini2xUrl) { +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/Related.java b/src/main/java/com/backend/metadata/shikimori/api/model/Related.java new file mode 100644 index 0000000..dda0123 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/Related.java @@ -0,0 +1,5 @@ +package com.backend.metadata.shikimori.api.model; + +public record Related(String id, RelatedAnime anime, RelatedManga manga, String relationKind, String relationText) { + +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/RelatedAnime.java b/src/main/java/com/backend/metadata/shikimori/api/model/RelatedAnime.java new file mode 100644 index 0000000..a735a92 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/RelatedAnime.java @@ -0,0 +1,4 @@ +package com.backend.metadata.shikimori.api.model; + +public record RelatedAnime(String id, String name) { +} diff --git a/src/main/java/com/backend/metadata/shikimori/api/model/RelatedManga.java b/src/main/java/com/backend/metadata/shikimori/api/model/RelatedManga.java new file mode 100644 index 0000000..2300e5a --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/api/model/RelatedManga.java @@ -0,0 +1,4 @@ +package com.backend.metadata.shikimori.api.model; + +public record RelatedManga(String id, String name) { +} diff --git a/src/main/java/com/backend/metadata/shikimori/model/AnimeMetadata.java b/src/main/java/com/backend/metadata/shikimori/model/AnimeMetadata.java deleted file mode 100644 index ba31561..0000000 --- a/src/main/java/com/backend/metadata/shikimori/model/AnimeMetadata.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.backend.metadata.shikimori.model; - -import java.util.List; - -public class AnimeMetadata { - public int shikimori_id; - public String title; - public String poster; - public String description; - public List characters; - public List related; - public List voice_actors; -} diff --git a/src/main/java/com/backend/metadata/shikimori/model/Character.java b/src/main/java/com/backend/metadata/shikimori/model/Character.java deleted file mode 100644 index 1ac9b9b..0000000 --- a/src/main/java/com/backend/metadata/shikimori/model/Character.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.backend.metadata.shikimori.model; - -public class Character { - public String name; - public String role; - public String poster; - public String seiyuu; -} diff --git a/src/main/java/com/backend/metadata/shikimori/model/RelatedAnime.java b/src/main/java/com/backend/metadata/shikimori/model/RelatedAnime.java deleted file mode 100644 index b28e41d..0000000 --- a/src/main/java/com/backend/metadata/shikimori/model/RelatedAnime.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.backend.metadata.shikimori.model; - -public class RelatedAnime { - public int shikimori_id; - public String relation; - public String title; -} diff --git a/src/main/java/com/backend/metadata/shikimori/model/VoiceActor.java b/src/main/java/com/backend/metadata/shikimori/model/VoiceActor.java deleted file mode 100644 index 223ce18..0000000 --- a/src/main/java/com/backend/metadata/shikimori/model/VoiceActor.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.backend.metadata.shikimori.model; - -public class VoiceActor { - public String name; - public String language; - public String character; -} diff --git a/src/main/java/com/backend/metadata/shikimori/resource/ShikimoriResource.java b/src/main/java/com/backend/metadata/shikimori/resource/ShikimoriResource.java new file mode 100644 index 0000000..bd9c984 --- /dev/null +++ b/src/main/java/com/backend/metadata/shikimori/resource/ShikimoriResource.java @@ -0,0 +1,28 @@ +package com.backend.metadata.shikimori.resource; + +import java.util.List; + +import com.backend.metadata.shikimori.api.ShikimoriAPI; +import com.backend.metadata.shikimori.api.model.Anime; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.NotFoundException; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +@Path("/shikimori") +public class ShikimoriResource { + private final ShikimoriAPI shikimoriAPI; + + public ShikimoriResource(ShikimoriAPI shikimoriAPI) { + this.shikimoriAPI = shikimoriAPI; + } + + @GET + public Anime findById(@QueryParam("id") String id) { + List result = shikimoriAPI.animes(1, 1, id, null, null); + if (result.isEmpty()) + throw new NotFoundException("cannot find anime by id"); + return result.get(0); + } +} diff --git a/src/main/java/com/backend/metadata/shikimori/service/MetadataResource.java b/src/main/java/com/backend/metadata/shikimori/service/MetadataResource.java deleted file mode 100644 index eae76de..0000000 --- a/src/main/java/com/backend/metadata/shikimori/service/MetadataResource.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.backend.metadata.shikimori.service; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import org.eclipse.microprofile.rest.client.inject.RestClient; - -@Path("/metadata") -public class MetadataResource { - - @RestClient - ShikimoriService shikimoriService; - - @GET - @Path("/{shikimori_id}") - @Produces(MediaType.APPLICATION_JSON) - public AnimeMetadata getMetadata(@PathParam("shikimori_id") int shikimoriId) { - return shikimoriService.getMetadata(shikimoriId); - } -} diff --git a/src/main/java/com/backend/metadata/shikimori/service/ShikimoriService.java b/src/main/java/com/backend/metadata/shikimori/service/ShikimoriService.java deleted file mode 100644 index beb20f8..0000000 --- a/src/main/java/com/backend/metadata/shikimori/service/ShikimoriService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.backend.metadata.shikimori.service; - -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; - -@RegisterRestClient(configKey = "shikimori-api") -public interface ShikimoriService { - - @GET - @Path("/api/graphql") - @Produces(MediaType.APPLICATION_JSON) - AnimeMetadata getMetadata(@PathParam("id") int shikimoriId); -} diff --git a/src/test/java/com/backend/metadata/shikimori/service/GreetingResourceIT.java b/src/test/java/com/backend/metadata/shikimori/service/GreetingResourceIT.java new file mode 100644 index 0000000..0adde8d --- /dev/null +++ b/src/test/java/com/backend/metadata/shikimori/service/GreetingResourceIT.java @@ -0,0 +1,8 @@ +package com.backend.metadata.shikimori.service; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class GreetingResourceIT extends GreetingResourceTest { + // Execute the same tests but in packaged mode. +} diff --git a/src/test/java/com/backend/metadata/shikimori/service/GreetingResourceTest.java b/src/test/java/com/backend/metadata/shikimori/service/GreetingResourceTest.java new file mode 100644 index 0000000..e1e2d04 --- /dev/null +++ b/src/test/java/com/backend/metadata/shikimori/service/GreetingResourceTest.java @@ -0,0 +1,20 @@ +package com.backend.metadata.shikimori.service; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +@QuarkusTest +class GreetingResourceTest { + @Test + void testHelloEndpoint() { + given() + .when().get("/hello") + .then() + .statusCode(200) + .body(is("Hello from Quarkus REST")); + } + +} \ No newline at end of file