Compare commits
141 Commits
ca22c0c461
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| fa2e249e94 | |||
| 132f0f3646 | |||
| 3cbcec5f53 | |||
|
|
8835175fb3 | ||
| 28c3abdb4a | |||
| b30bfc9293 | |||
| d70423fcc0 | |||
| 1b7c0c48e7 | |||
|
|
cb86137730 | ||
| c8913af660 | |||
| 9611049e01 | |||
| bad5947fb5 | |||
| d27558a3ee | |||
| 81f6f78c49 | |||
| bf593445bd | |||
| aa032c0140 | |||
|
|
95e60692c0 | ||
| fda2cdbecb | |||
| a1cc9f18c4 | |||
| 084d35d605 | |||
|
|
02aac24a09 | ||
| 51c2bf6985 | |||
| 4e99d12be1 | |||
| 8b5d8f92e0 | |||
| d3c9dd6eb9 | |||
| 254ff36c50 | |||
| b317196217 | |||
| cc343ee27c | |||
| 74d1b16b7c | |||
| adf6889712 | |||
| 653082868a | |||
| 997e770256 | |||
| fb1a6456e6 | |||
| 43cd80600e | |||
|
|
23e1abdbbb | ||
| e575021f53 | |||
| 7e8c89ce45 | |||
| a40a8df894 | |||
|
|
41f36ed18a | ||
| e04189bbfe | |||
| 20988e425a | |||
| df63937406 | |||
| 4ba408859d | |||
| 996e95f93c | |||
|
|
c4bd0b5a67 | ||
| 5c43873ede | |||
| 249645619e | |||
| be9f303b37 | |||
| 6da8b3b6e4 | |||
| a3cd451575 | |||
|
|
6f700c923a | ||
| 46fd59ed71 | |||
| ba49463ee7 | |||
| 576380e9a0 | |||
| cac534ccbb | |||
| 2e68105da4 | |||
| ed7ed6636d | |||
| e190359041 | |||
|
|
bed94790d4 | ||
| d8ad61ec54 | |||
| 7e9a1482d6 | |||
| aa0adbf993 | |||
| 00af9a9701 | |||
| fcdede2dd6 | |||
| 5d17b23c3a | |||
| 1ec8a43a50 | |||
| 96cfa91c67 | |||
| 669ace82c0 | |||
| 93163ae6e8 | |||
| af2d506da1 | |||
| 637541994a | |||
|
|
63cd4c4f5e | ||
| fd4104da39 | |||
| 5bb23fbcfa | |||
| 6a22c54e9f | |||
| 3ac3262e77 | |||
| 18ecc07240 | |||
| cb468492b3 | |||
| 379a2161ca | |||
| c47a7e28c7 | |||
|
|
502126c915 | ||
| 2ace632022 | |||
| feee2b0bff | |||
| b7dfc53bc0 | |||
| d77c3c7a5c | |||
|
|
faaa59ae01 | ||
| 1bde2690b6 | |||
| 92fddd9e4a | |||
| f9414b2db7 | |||
| d1e7e7eaca | |||
| 75929a15f8 | |||
| c0585d7107 | |||
| aeeed1c138 | |||
| 10f05fabc9 | |||
| 78b719d3c2 | |||
|
|
052ade3e91 | ||
| 035851133e | |||
| 1ff8883d25 | |||
| 30ada043ef | |||
| e0aaa7c92e | |||
| edae13541f | |||
| d150c19f9f | |||
| 71890e4cc2 | |||
| 95494efcae | |||
| 8893a80c12 | |||
| a4facf74d7 | |||
| ed8fd89217 | |||
| 58869be9f7 | |||
| fda0174a77 | |||
|
|
52c6239f6d | ||
| c007cee093 | |||
| d011268d20 | |||
| 126d3ef4c4 | |||
| 3f228ef6e2 | |||
| 8733184dc5 | |||
| 5f815d8a54 | |||
| 6d491eb694 | |||
|
|
42e0e75d70 | ||
| c24e27a9db | |||
| 3d12ae4da4 | |||
|
|
b9e6916dfe | ||
| 7cd9ef53b5 | |||
| e747a9820e | |||
| ba6940e64b | |||
|
|
4342e9b1b1 | ||
| a212a1d8cc | |||
| cd0c13203f | |||
| 77d7bdb265 | |||
| fb5e753769 | |||
| c953232f3c | |||
| cd2666d8e2 | |||
| 2f34c52b6f | |||
|
|
2606b22185 | ||
| 038e1634eb | |||
| f03f111d5e | |||
| aaa58346d3 | |||
| 506762c538 | |||
|
|
492d474c82 | ||
| 225995c892 | |||
| dfe109ac8d | |||
| 3ab518a9b6 |
@@ -125,6 +125,18 @@ jobs:
|
|||||||
docker build -t "$FRONTEND_IMAGE" ./frontend
|
docker build -t "$FRONTEND_IMAGE" ./frontend
|
||||||
docker push "$FRONTEND_IMAGE"
|
docker push "$FRONTEND_IMAGE"
|
||||||
|
|
||||||
|
- name: Cleanup Docker on runner (prevent vdisk growth)
|
||||||
|
if: always()
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set +e
|
||||||
|
|
||||||
|
# Keep recent artifacts, drop old local residue from CI builds.
|
||||||
|
docker container prune -f --filter "until=168h" || true
|
||||||
|
docker image prune -a -f --filter "until=168h" || true
|
||||||
|
docker builder prune -a -f --filter "until=168h" || true
|
||||||
|
docker network prune -f --filter "until=168h" || true
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: build-and-push
|
needs: build-and-push
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -205,9 +217,12 @@ jobs:
|
|||||||
ADMIN_TTL="${ADMIN_TTL:-480}"
|
ADMIN_TTL="${ADMIN_TTL:-480}"
|
||||||
printf 'ADMIN_PASSWORD="%s"\nADMIN_SESSION_SECRET="%s"\nADMIN_SESSION_TTL_MINUTES="%s"\n' \
|
printf 'ADMIN_PASSWORD="%s"\nADMIN_SESSION_SECRET="%s"\nADMIN_SESSION_TTL_MINUTES="%s"\n' \
|
||||||
"${{ secrets.ADMIN_PASSWORD }}" "${{ secrets.ADMIN_SESSION_SECRET }}" "$ADMIN_TTL" >> /tmp/full_env.env
|
"${{ secrets.ADMIN_PASSWORD }}" "${{ secrets.ADMIN_SESSION_SECRET }}" "$ADMIN_TTL" >> /tmp/full_env.env
|
||||||
|
if [[ -n "${{ secrets.OPENAI_API_KEY }}" ]]; then
|
||||||
|
printf 'OPENAI_API_KEY="%s"\n' "${{ secrets.OPENAI_API_KEY }}" >> /tmp/full_env.env
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Preparing to send env file with variables:"
|
echo "Preparing to send env file with variables:"
|
||||||
grep -Ev "PASSWORD|SECRET" /tmp/full_env.env || true
|
grep -Ev "PASSWORD|SECRET|KEY|TOKEN" /tmp/full_env.env || true
|
||||||
|
|
||||||
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes "${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}" \
|
ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes "${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}" \
|
||||||
"setenv ${{ env.ENV }}" < /tmp/full_env.env
|
"setenv ${{ env.ENV }}" < /tmp/full_env.env
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -46,10 +46,12 @@ build/
|
|||||||
./storage_quotes
|
./storage_quotes
|
||||||
./storage_requests
|
./storage_requests
|
||||||
./storage_media
|
./storage_media
|
||||||
|
./storage_shop
|
||||||
storage_orders
|
storage_orders
|
||||||
storage_quotes
|
storage_quotes
|
||||||
storage_requests
|
storage_requests
|
||||||
storage_media
|
storage_media
|
||||||
|
storage_shop
|
||||||
|
|
||||||
# Qodana local reports/artifacts
|
# Qodana local reports/artifacts
|
||||||
backend/.qodana/
|
backend/.qodana/
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -32,8 +32,8 @@ Crea un database PostgreSQL chiamato `printcalc`. Lo schema viene gestito dal pr
|
|||||||
Configura il percorso di OrcaSlicer in `backend/src/main/resources/application.properties` o tramite la variabile d'ambiente `SLICER_PATH`. Per il media service pubblico puoi configurare anche:
|
Configura il percorso di OrcaSlicer in `backend/src/main/resources/application.properties` o tramite la variabile d'ambiente `SLICER_PATH`. Per il media service pubblico puoi configurare anche:
|
||||||
|
|
||||||
- `MEDIA_STORAGE_ROOT` per la root `storage_media` usata dal backend (`original/`, `public/`, `private/`)
|
- `MEDIA_STORAGE_ROOT` per la root `storage_media` usata dal backend (`original/`, `public/`, `private/`)
|
||||||
- `MEDIA_PUBLIC_BASE_URL` per gli URL assoluti restituiti dalle API admin, ad esempio `https://example.com/media`
|
- `SHOP_STORAGE_ROOT` per la root `storage_shop` usata dal backend per i modelli dei prodotti shop
|
||||||
- `MEDIA_FFMPEG_PATH` per il binario `ffmpeg`
|
- `MEDIA_FFMPEG_PATH` per il binario `ffmpeg` (nel deploy Docker default: `/usr/local/bin/ffmpeg-media`)
|
||||||
- `MEDIA_UPLOAD_MAX_FILE_SIZE_BYTES` per il limite per asset immagine
|
- `MEDIA_UPLOAD_MAX_FILE_SIZE_BYTES` per il limite per asset immagine
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -64,12 +64,13 @@ I prezzi non sono più gestiti tramite variabili d'ambiente fisse ma tramite tab
|
|||||||
* `/frontend`: Applicazione Angular.
|
* `/frontend`: Applicazione Angular.
|
||||||
* `/backend/profiles`: Contiene i file di configurazione per OrcaSlicer.
|
* `/backend/profiles`: Contiene i file di configurazione per OrcaSlicer.
|
||||||
* `/storage_media`: Originali e varianti media pubbliche/private su filesystem.
|
* `/storage_media`: Originali e varianti media pubbliche/private su filesystem.
|
||||||
|
* `/storage_shop`: Modelli e file prodotti dello shop.
|
||||||
|
|
||||||
## Media pubblici
|
## Media pubblici
|
||||||
|
|
||||||
Il backend salva sempre l'originale in `storage_media/original/` e precomputa le varianti pubbliche in `storage_media/public/`. La cartella `storage_media/private/` è predisposta per asset non pubblici.
|
Il backend salva sempre l'originale in `storage_media/original/` e precomputa le varianti pubbliche in `storage_media/public/`. La cartella `storage_media/private/` è predisposta per asset non pubblici.
|
||||||
|
|
||||||
Nel deploy Docker il volume media atteso è `/mnt/cache/appdata/print-calculator/${ENV}/storage_media:/app/storage_media`.
|
Nel deploy Docker i volumi attesi sono `/mnt/cache/appdata/print-calculator/${ENV}/storage_media:/app/storage_media` e `/mnt/cache/appdata/print-calculator/${ENV}/storage_shop:/app/storage_shop`.
|
||||||
|
|
||||||
Nginx non deve passare dal backend per i file pubblici. Configurazione attesa:
|
Nginx non deve passare dal backend per i file pubblici. Configurazione attesa:
|
||||||
|
|
||||||
@@ -106,7 +107,10 @@ Operativamente:
|
|||||||
Assicurati che `slicer.path` punti al binario corretto. Su macOS è solitamente `/Applications/OrcaSlicer.app/Contents/MacOS/OrcaSlicer`. Su Linux è il percorso all'AppImage (estratta o meno).
|
Assicurati che `slicer.path` punti al binario corretto. Su macOS è solitamente `/Applications/OrcaSlicer.app/Contents/MacOS/OrcaSlicer`. Su Linux è il percorso all'AppImage (estratta o meno).
|
||||||
|
|
||||||
### FFmpeg e media pubblici
|
### FFmpeg e media pubblici
|
||||||
Verifica che `MEDIA_FFMPEG_PATH` punti a un `ffmpeg` con supporto JPEG, WebP e AVIF. Se gli URL media restituiti dalle API admin non sono raggiungibili, controlla che `MEDIA_PUBLIC_BASE_URL` corrisponda al `location /media/` esposto da Nginx e che il volume `storage_media` sia montato correttamente.
|
Verifica che `MEDIA_FFMPEG_PATH` punti a un `ffmpeg` con supporto JPEG, WebP e AVIF (encoder + muxer AVIF). Nel container backend il default è `/usr/local/bin/ffmpeg-media`: usa `/usr/bin/ffmpeg` se già compatibile, altrimenti installa un fallback statico con supporto AVIF. Se gli URL media restituiti dalle API admin non sono raggiungibili, controlla che `APP_FRONTEND_BASE_URL` punti al dominio corretto, che `location /media/` sia esposto da Nginx e che il volume `storage_media` sia montato correttamente.
|
||||||
|
|
||||||
### Database connection
|
### Database connection
|
||||||
Verifica le credenziali in `application.properties`. Se usi Docker, puoi passare `DB_URL`, `DB_USERNAME` e `DB_PASSWORD` come variabili d'ambiente.
|
Verifica le credenziali in `application.properties`. Se usi Docker, puoi passare `DB_URL`, `DB_USERNAME` e `DB_PASSWORD` come variabili d'ambiente.
|
||||||
|
|
||||||
|
### Deploy e traduzioni OpenAI
|
||||||
|
Nel deploy Gitea la chiave OpenAI deve stare nel secret `OPENAI_API_KEY`. La pipeline la aggiunge al file `.env` dell'ambiente durante il deploy e il container backend la riceve come variabile runtime. I file `deploy/envs/*.env` restano per i valori specifici di `dev/int/prod`.
|
||||||
|
|||||||
@@ -12,25 +12,48 @@ RUN ./gradlew bootJar -x test --no-daemon
|
|||||||
FROM eclipse-temurin:21-jre-jammy
|
FROM eclipse-temurin:21-jre-jammy
|
||||||
ARG ORCA_VERSION=2.3.1
|
ARG ORCA_VERSION=2.3.1
|
||||||
ARG ORCA_DOWNLOAD_URL
|
ARG ORCA_DOWNLOAD_URL
|
||||||
|
ARG FFMPEG_STATIC_URL=https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
|
||||||
|
|
||||||
# Install system dependencies for OrcaSlicer and media processing.
|
# Install system dependencies for OrcaSlicer and media processing.
|
||||||
# The build fails fast if the packaged ffmpeg lacks JPEG/WebP/AVIF encoders.
|
# Prefer system ffmpeg; if AVIF support is incomplete, install a static ffmpeg fallback.
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apt-get update; \
|
apt-get update; \
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
ffmpeg \
|
ffmpeg \
|
||||||
wget \
|
wget \
|
||||||
|
xz-utils \
|
||||||
|
ca-certificates \
|
||||||
assimp-utils \
|
assimp-utils \
|
||||||
libgl1 \
|
libgl1 \
|
||||||
libglib2.0-0 \
|
libglib2.0-0 \
|
||||||
libgtk-3-0 \
|
libgtk-3-0 \
|
||||||
libdbus-1-3 \
|
libdbus-1-3 \
|
||||||
libwebkit2gtk-4.0-37; \
|
libwebkit2gtk-4.0-37; \
|
||||||
ffmpeg -hide_banner -encoders > /tmp/ffmpeg-encoders.txt; \
|
check_ffmpeg_support() { \
|
||||||
grep -Eq '[[:space:]]mjpeg[[:space:]]' /tmp/ffmpeg-encoders.txt; \
|
ffmpeg_bin="$1"; \
|
||||||
grep -Eq '[[:space:]](libwebp|webp)[[:space:]]' /tmp/ffmpeg-encoders.txt; \
|
"$ffmpeg_bin" -hide_banner -encoders > /tmp/ffmpeg-encoders.txt 2>&1 || return 1; \
|
||||||
grep -Eq '[[:space:]](libaom-av1|librav1e|libsvtav1)[[:space:]]' /tmp/ffmpeg-encoders.txt; \
|
"$ffmpeg_bin" -hide_banner -muxers > /tmp/ffmpeg-muxers.txt 2>&1 || return 1; \
|
||||||
|
grep -Eq '[[:space:]]mjpeg[[:space:]]' /tmp/ffmpeg-encoders.txt || return 1; \
|
||||||
|
grep -Eq '[[:space:]](libwebp|webp)[[:space:]]' /tmp/ffmpeg-encoders.txt || return 1; \
|
||||||
|
grep -Eq '[[:space:]](libaom-av1|librav1e|libsvtav1)[[:space:]]' /tmp/ffmpeg-encoders.txt || return 1; \
|
||||||
|
grep -Eq '[[:space:]]avif([[:space:]]|,|$)' /tmp/ffmpeg-muxers.txt || return 1; \
|
||||||
|
return 0; \
|
||||||
|
}; \
|
||||||
|
if check_ffmpeg_support /usr/bin/ffmpeg; then \
|
||||||
|
ln -sf /usr/bin/ffmpeg /usr/local/bin/ffmpeg-media; \
|
||||||
|
else \
|
||||||
|
echo "System ffmpeg lacks AVIF support, installing static fallback from ${FFMPEG_STATIC_URL}"; \
|
||||||
|
wget -q "${FFMPEG_STATIC_URL}" -O /tmp/ffmpeg-static.tar.xz; \
|
||||||
|
tar -xJf /tmp/ffmpeg-static.tar.xz -C /tmp; \
|
||||||
|
FFMPEG_STATIC_BIN="$(find /tmp -maxdepth 2 -type f -name ffmpeg | head -n 1)"; \
|
||||||
|
test -n "${FFMPEG_STATIC_BIN}"; \
|
||||||
|
install -m 0755 "${FFMPEG_STATIC_BIN}" /usr/local/bin/ffmpeg-media; \
|
||||||
|
check_ffmpeg_support /usr/local/bin/ffmpeg-media; \
|
||||||
|
fi; \
|
||||||
|
rm -f /tmp/ffmpeg-muxers.txt; \
|
||||||
rm -f /tmp/ffmpeg-encoders.txt; \
|
rm -f /tmp/ffmpeg-encoders.txt; \
|
||||||
|
rm -f /tmp/ffmpeg-static.tar.xz; \
|
||||||
|
rm -rf /tmp/ffmpeg-*-amd64-static; \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install OrcaSlicer
|
# Install OrcaSlicer
|
||||||
@@ -71,6 +94,8 @@ ENV PATH="/opt/orcaslicer/usr/bin:${PATH}"
|
|||||||
# Set Slicer Path env variable for Java app
|
# Set Slicer Path env variable for Java app
|
||||||
ENV SLICER_PATH="/opt/orcaslicer/AppRun"
|
ENV SLICER_PATH="/opt/orcaslicer/AppRun"
|
||||||
ENV ASSIMP_PATH="assimp"
|
ENV ASSIMP_PATH="assimp"
|
||||||
|
# Use ffmpeg selected at image build time (system or static fallback) for media generation.
|
||||||
|
ENV MEDIA_FFMPEG_PATH="/usr/local/bin/ffmpeg-media"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Copy JAR from build stage
|
# Copy JAR from build stage
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
implementation 'net.codecrete.qrbill:qrbill-generator:3.4.0'
|
implementation 'net.codecrete.qrbill:qrbill-generator:3.4.0'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
||||||
|
implementation 'org.jsoup:jsoup:1.18.3'
|
||||||
implementation platform('org.lwjgl:lwjgl-bom:3.3.4')
|
implementation platform('org.lwjgl:lwjgl-bom:3.3.4')
|
||||||
implementation 'org.lwjgl:lwjgl'
|
implementation 'org.lwjgl:lwjgl'
|
||||||
implementation 'org.lwjgl:lwjgl-assimp'
|
implementation 'org.lwjgl:lwjgl-assimp'
|
||||||
|
|||||||
@@ -1,10 +1,61 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# In container default to the ffmpeg selected during image build.
|
||||||
|
if [ -z "${MEDIA_FFMPEG_PATH:-}" ]; then
|
||||||
|
MEDIA_FFMPEG_PATH="/usr/local/bin/ffmpeg-media"
|
||||||
|
fi
|
||||||
|
export MEDIA_FFMPEG_PATH
|
||||||
|
|
||||||
|
validate_ffmpeg_support() {
|
||||||
|
ffmpeg_bin="$1"
|
||||||
|
if ! command -v "$ffmpeg_bin" >/dev/null 2>&1; then
|
||||||
|
echo "ERROR: FFmpeg executable not found: ${ffmpeg_bin}" >&2
|
||||||
|
exit 11
|
||||||
|
fi
|
||||||
|
|
||||||
|
encoders="$(mktemp)"
|
||||||
|
muxers="$(mktemp)"
|
||||||
|
trap 'rm -f "$encoders" "$muxers"' EXIT
|
||||||
|
|
||||||
|
"$ffmpeg_bin" -hide_banner -encoders > "$encoders" 2>&1 || {
|
||||||
|
echo "ERROR: Unable to inspect FFmpeg encoders from ${ffmpeg_bin}" >&2
|
||||||
|
cat "$encoders" >&2
|
||||||
|
exit 12
|
||||||
|
}
|
||||||
|
"$ffmpeg_bin" -hide_banner -muxers > "$muxers" 2>&1 || {
|
||||||
|
echo "ERROR: Unable to inspect FFmpeg muxers from ${ffmpeg_bin}" >&2
|
||||||
|
cat "$muxers" >&2
|
||||||
|
exit 13
|
||||||
|
}
|
||||||
|
|
||||||
|
grep -Eq '[[:space:]]mjpeg[[:space:]]' "$encoders" || {
|
||||||
|
echo "ERROR: FFmpeg '${ffmpeg_bin}' missing JPEG encoder (mjpeg)." >&2
|
||||||
|
exit 14
|
||||||
|
}
|
||||||
|
grep -Eq '[[:space:]](libwebp|webp)[[:space:]]' "$encoders" || {
|
||||||
|
echo "ERROR: FFmpeg '${ffmpeg_bin}' missing WebP encoder." >&2
|
||||||
|
exit 15
|
||||||
|
}
|
||||||
|
grep -Eq '[[:space:]](libaom-av1|librav1e|libsvtav1)[[:space:]]' "$encoders" || {
|
||||||
|
echo "ERROR: FFmpeg '${ffmpeg_bin}' missing AVIF-capable encoder." >&2
|
||||||
|
exit 16
|
||||||
|
}
|
||||||
|
grep -Eq '[[:space:]]avif([[:space:]]|,|$)' "$muxers" || {
|
||||||
|
echo "ERROR: FFmpeg '${ffmpeg_bin}' missing AVIF muxer." >&2
|
||||||
|
exit 17
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validate_ffmpeg_support "$MEDIA_FFMPEG_PATH"
|
||||||
|
|
||||||
echo "----------------------------------------------------------------"
|
echo "----------------------------------------------------------------"
|
||||||
echo "Starting Backend Application"
|
echo "Starting Backend Application"
|
||||||
echo "DB_URL: $DB_URL"
|
echo "DB_URL: $DB_URL"
|
||||||
echo "DB_USERNAME: $DB_USERNAME"
|
echo "DB_USERNAME: $DB_USERNAME"
|
||||||
echo "SPRING_DATASOURCE_URL: $SPRING_DATASOURCE_URL"
|
echo "SPRING_DATASOURCE_URL: $SPRING_DATASOURCE_URL"
|
||||||
echo "SLICER_PATH: $SLICER_PATH"
|
echo "SLICER_PATH: $SLICER_PATH"
|
||||||
|
echo "MEDIA_FFMPEG_PATH: $MEDIA_FFMPEG_PATH"
|
||||||
echo "----------------------------------------------------------------"
|
echo "----------------------------------------------------------------"
|
||||||
|
|
||||||
# Determine which environment variables to use for database connection
|
# Determine which environment variables to use for database connection
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.printcalculator.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AllowedOriginService {
|
||||||
|
|
||||||
|
private final List<String> allowedOrigins;
|
||||||
|
|
||||||
|
public AllowedOriginService(
|
||||||
|
@Value("${app.frontend.base-url:http://localhost:4200}") String frontendBaseUrl,
|
||||||
|
@Value("${app.cors.additional-allowed-origins:}") String additionalAllowedOrigins
|
||||||
|
) {
|
||||||
|
LinkedHashSet<String> configuredOrigins = new LinkedHashSet<>();
|
||||||
|
addConfiguredOrigin(configuredOrigins, frontendBaseUrl, "app.frontend.base-url");
|
||||||
|
|
||||||
|
for (String rawOrigin : additionalAllowedOrigins.split(",")) {
|
||||||
|
addConfiguredOrigin(configuredOrigins, rawOrigin, "app.cors.additional-allowed-origins");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configuredOrigins.isEmpty()) {
|
||||||
|
throw new IllegalStateException("At least one allowed origin must be configured.");
|
||||||
|
}
|
||||||
|
this.allowedOrigins = List.copyOf(configuredOrigins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAllowedOrigins() {
|
||||||
|
return allowedOrigins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllowed(String rawOriginOrUrl) {
|
||||||
|
String normalizedOrigin = normalizeRequestOrigin(rawOriginOrUrl);
|
||||||
|
return normalizedOrigin != null && allowedOrigins.contains(normalizedOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConfiguredOrigin(Set<String> configuredOrigins, String rawOriginOrUrl, String propertyName) {
|
||||||
|
if (rawOriginOrUrl == null || rawOriginOrUrl.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedOrigin = normalizeRequestOrigin(rawOriginOrUrl);
|
||||||
|
if (normalizedOrigin == null) {
|
||||||
|
throw new IllegalStateException(propertyName + " must contain absolute http(s) URLs.");
|
||||||
|
}
|
||||||
|
configuredOrigins.add(normalizedOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeRequestOrigin(String rawOriginOrUrl) {
|
||||||
|
if (rawOriginOrUrl == null || rawOriginOrUrl.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
URI uri = URI.create(rawOriginOrUrl.trim());
|
||||||
|
String scheme = uri.getScheme();
|
||||||
|
String host = uri.getHost();
|
||||||
|
if (scheme == null || host == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedScheme = scheme.toLowerCase(Locale.ROOT);
|
||||||
|
if (!"http".equals(normalizedScheme) && !"https".equals(normalizedScheme)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalizedHost = host.toLowerCase(Locale.ROOT);
|
||||||
|
int port = uri.getPort();
|
||||||
|
if (isDefaultPort(normalizedScheme, port) || port < 0) {
|
||||||
|
return normalizedScheme + "://" + normalizedHost;
|
||||||
|
}
|
||||||
|
return normalizedScheme + "://" + normalizedHost + ":" + port;
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDefaultPort(String scheme, int port) {
|
||||||
|
return ("http".equals(scheme) && port == 80)
|
||||||
|
|| ("https".equals(scheme) && port == 443);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
package com.printcalculator.config;
|
package com.printcalculator.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.cors.CorsConfigurationSource;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class CorsConfig implements WebMvcConfigurer {
|
public class CorsConfig {
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
public CorsConfigurationSource corsConfigurationSource(AllowedOriginService allowedOriginService) {
|
||||||
registry.addMapping("/**")
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
.allowedOrigins(
|
configuration.setAllowedOrigins(allowedOriginService.getAllowedOrigins());
|
||||||
"http://localhost",
|
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
|
||||||
"http://localhost:4200",
|
configuration.setAllowedHeaders(List.of("*"));
|
||||||
"http://localhost:80",
|
configuration.setAllowCredentials(true);
|
||||||
"http://127.0.0.1",
|
configuration.setMaxAge(3600L);
|
||||||
"https://dev.3d-fab.ch",
|
|
||||||
"https://int.3d-fab.ch",
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
"https://3d-fab.ch"
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
)
|
return source;
|
||||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")
|
|
||||||
.allowedHeaders("*")
|
|
||||||
.allowCredentials(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.printcalculator.config;
|
package com.printcalculator.config;
|
||||||
|
|
||||||
|
import com.printcalculator.security.AdminCsrfProtectionFilter;
|
||||||
import com.printcalculator.security.AdminSessionAuthenticationFilter;
|
import com.printcalculator.security.AdminSessionAuthenticationFilter;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -18,6 +19,7 @@ public class SecurityConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(
|
public SecurityFilterChain securityFilterChain(
|
||||||
HttpSecurity http,
|
HttpSecurity http,
|
||||||
|
AdminCsrfProtectionFilter adminCsrfProtectionFilter,
|
||||||
AdminSessionAuthenticationFilter adminSessionAuthenticationFilter
|
AdminSessionAuthenticationFilter adminSessionAuthenticationFilter
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
http
|
http
|
||||||
@@ -40,7 +42,8 @@ public class SecurityConfig {
|
|||||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
response.getWriter().write("{\"error\":\"UNAUTHORIZED\"}");
|
response.getWriter().write("{\"error\":\"UNAUTHORIZED\"}");
|
||||||
}))
|
}))
|
||||||
.addFilterBefore(adminSessionAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
|
.addFilterBefore(adminCsrfProtectionFilter, UsernamePasswordAuthenticationFilter.class)
|
||||||
|
.addFilterAfter(adminSessionAuthenticationFilter, AdminCsrfProtectionFilter.class);
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ public class OptionsController {
|
|||||||
v.getId(),
|
v.getId(),
|
||||||
v.getVariantDisplayName(),
|
v.getVariantDisplayName(),
|
||||||
v.getColorName(),
|
v.getColorName(),
|
||||||
|
v.getColorLabelIt(),
|
||||||
|
v.getColorLabelEn(),
|
||||||
|
v.getColorLabelDe(),
|
||||||
|
v.getColorLabelFr(),
|
||||||
resolveHexColor(v),
|
resolveHexColor(v),
|
||||||
v.getFinishType() != null ? v.getFinishType() : "GLOSSY",
|
v.getFinishType() != null ? v.getFinishType() : "GLOSSY",
|
||||||
v.getStockSpools() != null ? v.getStockSpools().doubleValue() : 0d,
|
v.getStockSpools() != null ? v.getStockSpools().doubleValue() : 0d,
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.ShopCategoryDetailDto;
|
||||||
|
import com.printcalculator.dto.ShopCategoryTreeDto;
|
||||||
|
import com.printcalculator.dto.ShopProductCatalogResponseDto;
|
||||||
|
import com.printcalculator.dto.ShopProductDetailDto;
|
||||||
|
import com.printcalculator.service.shop.PublicShopCatalogService;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/shop")
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class PublicShopController {
|
||||||
|
private final PublicShopCatalogService publicShopCatalogService;
|
||||||
|
|
||||||
|
public PublicShopController(PublicShopCatalogService publicShopCatalogService) {
|
||||||
|
this.publicShopCatalogService = publicShopCatalogService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/categories")
|
||||||
|
public ResponseEntity<List<ShopCategoryTreeDto>> getCategories(@RequestParam(required = false) String lang) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getCategories(lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/categories/{slug}")
|
||||||
|
public ResponseEntity<ShopCategoryDetailDto> getCategory(@PathVariable String slug,
|
||||||
|
@RequestParam(required = false) String lang) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getCategory(slug, lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/products")
|
||||||
|
public ResponseEntity<ShopProductCatalogResponseDto> getProducts(
|
||||||
|
@RequestParam(required = false) String categorySlug,
|
||||||
|
@RequestParam(required = false) Boolean featured,
|
||||||
|
@RequestParam(required = false) String lang
|
||||||
|
) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getProductCatalog(categorySlug, featured, lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/products/{slug}")
|
||||||
|
public ResponseEntity<ShopProductDetailDto> getProduct(@PathVariable String slug,
|
||||||
|
@RequestParam(required = false) String lang) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getProduct(slug, lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/products/by-path/{publicPath}")
|
||||||
|
public ResponseEntity<ShopProductDetailDto> getProductByPublicPath(@PathVariable String publicPath,
|
||||||
|
@RequestParam(required = false) String lang) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getProductByPublicPath(publicPath, lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/products/by-id-prefix/{idPrefix}")
|
||||||
|
public ResponseEntity<ShopProductDetailDto> getProductByIdPrefix(@PathVariable String idPrefix,
|
||||||
|
@RequestParam(required = false) String lang) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getProductByIdPrefix(idPrefix, lang));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/products/{slug}/model")
|
||||||
|
public ResponseEntity<Resource> getProductModel(@PathVariable String slug) throws IOException {
|
||||||
|
PublicShopCatalogService.ProductModelDownload model = publicShopCatalogService.getProductModelDownload(slug);
|
||||||
|
Resource resource = new UrlResource(model.path().toUri());
|
||||||
|
MediaType contentType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
|
if (model.mimeType() != null && !model.mimeType().isBlank()) {
|
||||||
|
try {
|
||||||
|
contentType = MediaType.parseMediaType(model.mimeType());
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
contentType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(contentType)
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + model.filename() + "\"")
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import java.math.BigDecimal;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
@@ -124,6 +125,9 @@ public class QuoteController {
|
|||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.badRequest().build();
|
||||||
}
|
}
|
||||||
|
if (!isSupportedInputFile(file)) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Unsupported file type. Allowed: stl, 3mf");
|
||||||
|
}
|
||||||
|
|
||||||
// Scan for virus
|
// Scan for virus
|
||||||
clamAVService.scan(file.getInputStream());
|
clamAVService.scan(file.getInputStream());
|
||||||
@@ -153,4 +157,14 @@ public class QuoteController {
|
|||||||
Files.deleteIfExists(tempInput);
|
Files.deleteIfExists(tempInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSupportedInputFile(MultipartFile file) {
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
if (originalFilename == null || originalFilename.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalized = originalFilename.toLowerCase(Locale.ROOT);
|
||||||
|
return normalized.endsWith(".stl") || normalized.endsWith(".3mf");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public class QuoteSessionController {
|
|||||||
public ResponseEntity<QuoteSession> createSession() {
|
public ResponseEntity<QuoteSession> createSession() {
|
||||||
QuoteSession session = new QuoteSession();
|
QuoteSession session = new QuoteSession();
|
||||||
session.setStatus("ACTIVE");
|
session.setStatus("ACTIVE");
|
||||||
|
session.setSessionType("PRINT_QUOTE");
|
||||||
session.setPricingVersion("v1");
|
session.setPricingVersion("v1");
|
||||||
session.setMaterialCode("PLA");
|
session.setMaterialCode("PLA");
|
||||||
session.setSupportsEnabled(false);
|
session.setSupportsEnabled(false);
|
||||||
@@ -129,6 +130,7 @@ public class QuoteSessionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public ResponseEntity<Map<String, Object>> getQuoteSession(@PathVariable UUID id) {
|
public ResponseEntity<Map<String, Object>> getQuoteSession(@PathVariable UUID id) {
|
||||||
QuoteSession session = sessionRepo.findById(id)
|
QuoteSession session = sessionRepo.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Session not found"));
|
.orElseThrow(() -> new RuntimeException("Session not found"));
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.ShopCartAddItemRequest;
|
||||||
|
import com.printcalculator.dto.ShopCartUpdateItemRequest;
|
||||||
|
import com.printcalculator.service.shop.ShopCartCookieService;
|
||||||
|
import com.printcalculator.service.shop.ShopCartService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/shop/cart")
|
||||||
|
public class ShopCartController {
|
||||||
|
private final ShopCartService shopCartService;
|
||||||
|
private final ShopCartCookieService shopCartCookieService;
|
||||||
|
|
||||||
|
public ShopCartController(ShopCartService shopCartService, ShopCartCookieService shopCartCookieService) {
|
||||||
|
this.shopCartService = shopCartService;
|
||||||
|
this.shopCartCookieService = shopCartCookieService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<?> getCart(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
ShopCartService.CartResult result = shopCartService.loadCart(request);
|
||||||
|
applyCookie(response, result);
|
||||||
|
return ResponseEntity.ok(result.response());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/items")
|
||||||
|
public ResponseEntity<?> addItem(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
@Valid @RequestBody ShopCartAddItemRequest payload) {
|
||||||
|
ShopCartService.CartResult result = shopCartService.addItem(request, payload);
|
||||||
|
applyCookie(response, result);
|
||||||
|
return ResponseEntity.ok(result.response());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/items/{lineItemId}")
|
||||||
|
public ResponseEntity<?> updateItem(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
@PathVariable UUID lineItemId,
|
||||||
|
@Valid @RequestBody ShopCartUpdateItemRequest payload) {
|
||||||
|
ShopCartService.CartResult result = shopCartService.updateItem(request, lineItemId, payload);
|
||||||
|
applyCookie(response, result);
|
||||||
|
return ResponseEntity.ok(result.response());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/items/{lineItemId}")
|
||||||
|
public ResponseEntity<?> removeItem(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
@PathVariable UUID lineItemId) {
|
||||||
|
ShopCartService.CartResult result = shopCartService.removeItem(request, lineItemId);
|
||||||
|
applyCookie(response, result);
|
||||||
|
return ResponseEntity.ok(result.response());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping
|
||||||
|
public ResponseEntity<?> clearCart(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
ShopCartService.CartResult result = shopCartService.clearCart(request);
|
||||||
|
applyCookie(response, result);
|
||||||
|
return ResponseEntity.ok(result.response());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCookie(HttpServletResponse response, ShopCartService.CartResult result) {
|
||||||
|
if (result.clearCookie()) {
|
||||||
|
response.addHeader(HttpHeaders.SET_COOKIE, shopCartCookieService.buildClearCookie().toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result.sessionId() != null) {
|
||||||
|
response.addHeader(HttpHeaders.SET_COOKIE, shopCartCookieService.buildSessionCookie(result.sessionId()).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.service.shop.ShopSitemapService;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.CacheControl;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class SitemapController {
|
||||||
|
private final ShopSitemapService shopSitemapService;
|
||||||
|
private final long cacheSeconds;
|
||||||
|
|
||||||
|
public SitemapController(
|
||||||
|
ShopSitemapService shopSitemapService,
|
||||||
|
@Value("${app.sitemap.shop.cache-seconds:3600}") long cacheSeconds
|
||||||
|
) {
|
||||||
|
this.shopSitemapService = shopSitemapService;
|
||||||
|
this.cacheSeconds = Math.max(cacheSeconds, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/api/sitemap-shop.xml", produces = MediaType.APPLICATION_XML_VALUE)
|
||||||
|
public ResponseEntity<String> getShopSitemap() {
|
||||||
|
CacheControl cacheControl = cacheSeconds > 0
|
||||||
|
? CacheControl.maxAge(Duration.ofSeconds(cacheSeconds)).cachePublic()
|
||||||
|
: CacheControl.noCache();
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(MediaType.parseMediaType("application/xml;charset=UTF-8"))
|
||||||
|
.cacheControl(cacheControl)
|
||||||
|
.body(shopSitemapService.getShopSitemapXml());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,13 @@ public class AdminMediaController {
|
|||||||
return ResponseEntity.ok(adminMediaControllerService.getAsset(mediaAssetId));
|
return ResponseEntity.ok(adminMediaControllerService.getAsset(mediaAssetId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/usages")
|
||||||
|
public ResponseEntity<List<AdminMediaUsageDto>> getUsages(@RequestParam String usageType,
|
||||||
|
@RequestParam String usageKey,
|
||||||
|
@RequestParam(required = false) UUID ownerId) {
|
||||||
|
return ResponseEntity.ok(adminMediaControllerService.getUsages(usageType, usageKey, ownerId));
|
||||||
|
}
|
||||||
|
|
||||||
@PatchMapping("/assets/{mediaAssetId}")
|
@PatchMapping("/assets/{mediaAssetId}")
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<AdminMediaAssetDto> updateAsset(@PathVariable UUID mediaAssetId,
|
public ResponseEntity<AdminMediaAssetDto> updateAsset(@PathVariable UUID mediaAssetId,
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.printcalculator.controller.admin;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.AdminShopCategoryDto;
|
||||||
|
import com.printcalculator.dto.AdminUpsertShopCategoryRequest;
|
||||||
|
import com.printcalculator.service.admin.AdminShopCategoryControllerService;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/shop/categories")
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AdminShopCategoryController {
|
||||||
|
private final AdminShopCategoryControllerService adminShopCategoryControllerService;
|
||||||
|
|
||||||
|
public AdminShopCategoryController(AdminShopCategoryControllerService adminShopCategoryControllerService) {
|
||||||
|
this.adminShopCategoryControllerService = adminShopCategoryControllerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<AdminShopCategoryDto>> getCategories() {
|
||||||
|
return ResponseEntity.ok(adminShopCategoryControllerService.getCategories());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tree")
|
||||||
|
public ResponseEntity<List<AdminShopCategoryDto>> getCategoryTree() {
|
||||||
|
return ResponseEntity.ok(adminShopCategoryControllerService.getCategoryTree());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{categoryId}")
|
||||||
|
public ResponseEntity<AdminShopCategoryDto> getCategory(@PathVariable UUID categoryId) {
|
||||||
|
return ResponseEntity.ok(adminShopCategoryControllerService.getCategory(categoryId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<AdminShopCategoryDto> createCategory(@RequestBody AdminUpsertShopCategoryRequest payload) {
|
||||||
|
return ResponseEntity.ok(adminShopCategoryControllerService.createCategory(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{categoryId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<AdminShopCategoryDto> updateCategory(@PathVariable UUID categoryId,
|
||||||
|
@RequestBody AdminUpsertShopCategoryRequest payload) {
|
||||||
|
return ResponseEntity.ok(adminShopCategoryControllerService.updateCategory(categoryId, payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{categoryId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<Void> deleteCategory(@PathVariable UUID categoryId) {
|
||||||
|
adminShopCategoryControllerService.deleteCategory(categoryId);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.printcalculator.controller.admin;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.AdminShopProductDto;
|
||||||
|
import com.printcalculator.dto.AdminTranslateShopProductRequest;
|
||||||
|
import com.printcalculator.dto.AdminTranslateShopProductResponse;
|
||||||
|
import com.printcalculator.dto.AdminUpsertShopProductRequest;
|
||||||
|
import com.printcalculator.service.admin.AdminShopProductControllerService;
|
||||||
|
import com.printcalculator.service.admin.AdminShopProductTranslationService;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/shop/products")
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AdminShopProductController {
|
||||||
|
private final AdminShopProductControllerService adminShopProductControllerService;
|
||||||
|
private final AdminShopProductTranslationService adminShopProductTranslationService;
|
||||||
|
|
||||||
|
public AdminShopProductController(AdminShopProductControllerService adminShopProductControllerService,
|
||||||
|
AdminShopProductTranslationService adminShopProductTranslationService) {
|
||||||
|
this.adminShopProductControllerService = adminShopProductControllerService;
|
||||||
|
this.adminShopProductTranslationService = adminShopProductTranslationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<AdminShopProductDto>> getProducts() {
|
||||||
|
return ResponseEntity.ok(adminShopProductControllerService.getProducts());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{productId}")
|
||||||
|
public ResponseEntity<AdminShopProductDto> getProduct(@PathVariable UUID productId) {
|
||||||
|
return ResponseEntity.ok(adminShopProductControllerService.getProduct(productId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<AdminShopProductDto> createProduct(@RequestBody AdminUpsertShopProductRequest payload) {
|
||||||
|
return ResponseEntity.ok(adminShopProductControllerService.createProduct(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/translate")
|
||||||
|
public ResponseEntity<AdminTranslateShopProductResponse> translateProduct(@RequestBody AdminTranslateShopProductRequest payload) {
|
||||||
|
return ResponseEntity.ok(adminShopProductTranslationService.translateProduct(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{productId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<AdminShopProductDto> updateProduct(@PathVariable UUID productId,
|
||||||
|
@RequestBody AdminUpsertShopProductRequest payload) {
|
||||||
|
return ResponseEntity.ok(adminShopProductControllerService.updateProduct(productId, payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{productId}")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<Void> deleteProduct(@PathVariable UUID productId) {
|
||||||
|
adminShopProductControllerService.deleteProduct(productId);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{productId}/model")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<AdminShopProductDto> uploadProductModel(@PathVariable UUID productId,
|
||||||
|
@RequestParam("file") MultipartFile file) throws IOException {
|
||||||
|
return ResponseEntity.ok(adminShopProductControllerService.uploadProductModel(productId, file));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{productId}/model")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<Void> deleteProductModel(@PathVariable UUID productId) {
|
||||||
|
adminShopProductControllerService.deleteProductModel(productId);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{productId}/model")
|
||||||
|
public ResponseEntity<Resource> getProductModel(@PathVariable UUID productId) throws IOException {
|
||||||
|
AdminShopProductControllerService.ProductModelDownload model = adminShopProductControllerService.getProductModel(productId);
|
||||||
|
Resource resource = new UrlResource(model.path().toUri());
|
||||||
|
MediaType contentType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
|
if (model.mimeType() != null && !model.mimeType().isBlank()) {
|
||||||
|
try {
|
||||||
|
contentType = MediaType.parseMediaType(model.mimeType());
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
contentType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(contentType)
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + model.filename() + "\"")
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,10 @@ public class AdminFilamentVariantDto {
|
|||||||
private String materialTechnicalTypeLabel;
|
private String materialTechnicalTypeLabel;
|
||||||
private String variantDisplayName;
|
private String variantDisplayName;
|
||||||
private String colorName;
|
private String colorName;
|
||||||
|
private String colorLabelIt;
|
||||||
|
private String colorLabelEn;
|
||||||
|
private String colorLabelDe;
|
||||||
|
private String colorLabelFr;
|
||||||
private String colorHex;
|
private String colorHex;
|
||||||
private String finishType;
|
private String finishType;
|
||||||
private String brand;
|
private String brand;
|
||||||
@@ -89,6 +93,38 @@ public class AdminFilamentVariantDto {
|
|||||||
this.colorName = colorName;
|
this.colorName = colorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColorLabelIt() {
|
||||||
|
return colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelIt(String colorLabelIt) {
|
||||||
|
this.colorLabelIt = colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelEn() {
|
||||||
|
return colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelEn(String colorLabelEn) {
|
||||||
|
this.colorLabelEn = colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelDe() {
|
||||||
|
return colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelDe(String colorLabelDe) {
|
||||||
|
this.colorLabelDe = colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelFr() {
|
||||||
|
return colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelFr(String colorLabelFr) {
|
||||||
|
this.colorLabelFr = colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
public String getColorHex() {
|
public String getColorHex() {
|
||||||
return colorHex;
|
return colorHex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.UUID;
|
|||||||
public class AdminQuoteSessionDto {
|
public class AdminQuoteSessionDto {
|
||||||
private UUID id;
|
private UUID id;
|
||||||
private String status;
|
private String status;
|
||||||
|
private String sessionType;
|
||||||
private String materialCode;
|
private String materialCode;
|
||||||
private OffsetDateTime createdAt;
|
private OffsetDateTime createdAt;
|
||||||
private OffsetDateTime expiresAt;
|
private OffsetDateTime expiresAt;
|
||||||
@@ -32,6 +33,14 @@ public class AdminQuoteSessionDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSessionType() {
|
||||||
|
return sessionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionType(String sessionType) {
|
||||||
|
this.sessionType = sessionType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMaterialCode() {
|
public String getMaterialCode() {
|
||||||
return materialCode;
|
return materialCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,359 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminShopCategoryDto {
|
||||||
|
private UUID id;
|
||||||
|
private UUID parentCategoryId;
|
||||||
|
private String parentCategoryName;
|
||||||
|
private String slug;
|
||||||
|
private String name;
|
||||||
|
private String nameIt;
|
||||||
|
private String nameEn;
|
||||||
|
private String nameDe;
|
||||||
|
private String nameFr;
|
||||||
|
private String description;
|
||||||
|
private String descriptionIt;
|
||||||
|
private String descriptionEn;
|
||||||
|
private String descriptionDe;
|
||||||
|
private String descriptionFr;
|
||||||
|
private String seoTitle;
|
||||||
|
private String seoTitleIt;
|
||||||
|
private String seoTitleEn;
|
||||||
|
private String seoTitleDe;
|
||||||
|
private String seoTitleFr;
|
||||||
|
private String seoDescription;
|
||||||
|
private String seoDescriptionIt;
|
||||||
|
private String seoDescriptionEn;
|
||||||
|
private String seoDescriptionDe;
|
||||||
|
private String seoDescriptionFr;
|
||||||
|
private String ogTitle;
|
||||||
|
private String ogDescription;
|
||||||
|
private Boolean indexable;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Integer sortOrder;
|
||||||
|
private Integer depth;
|
||||||
|
private Integer childCount;
|
||||||
|
private Integer directProductCount;
|
||||||
|
private Integer descendantProductCount;
|
||||||
|
private String mediaUsageType;
|
||||||
|
private String mediaUsageKey;
|
||||||
|
private List<AdminShopCategoryRefDto> breadcrumbs;
|
||||||
|
private List<AdminShopCategoryDto> children;
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getParentCategoryId() {
|
||||||
|
return parentCategoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentCategoryId(UUID parentCategoryId) {
|
||||||
|
this.parentCategoryId = parentCategoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParentCategoryName() {
|
||||||
|
return parentCategoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentCategoryName(String parentCategoryName) {
|
||||||
|
this.parentCategoryName = parentCategoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameIt() {
|
||||||
|
return nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameIt(String nameIt) {
|
||||||
|
this.nameIt = nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEn() {
|
||||||
|
return nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameEn(String nameEn) {
|
||||||
|
this.nameEn = nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameDe() {
|
||||||
|
return nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameDe(String nameDe) {
|
||||||
|
this.nameDe = nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFr() {
|
||||||
|
return nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameFr(String nameFr) {
|
||||||
|
this.nameFr = nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionIt() {
|
||||||
|
return descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionIt(String descriptionIt) {
|
||||||
|
this.descriptionIt = descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionEn() {
|
||||||
|
return descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionEn(String descriptionEn) {
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionDe() {
|
||||||
|
return descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionDe(String descriptionDe) {
|
||||||
|
this.descriptionDe = descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionFr() {
|
||||||
|
return descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionFr(String descriptionFr) {
|
||||||
|
this.descriptionFr = descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleIt() {
|
||||||
|
return seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleIt(String seoTitleIt) {
|
||||||
|
this.seoTitleIt = seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleEn() {
|
||||||
|
return seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleEn(String seoTitleEn) {
|
||||||
|
this.seoTitleEn = seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleDe() {
|
||||||
|
return seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleDe(String seoTitleDe) {
|
||||||
|
this.seoTitleDe = seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleFr() {
|
||||||
|
return seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleFr(String seoTitleFr) {
|
||||||
|
this.seoTitleFr = seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionIt() {
|
||||||
|
return seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionIt(String seoDescriptionIt) {
|
||||||
|
this.seoDescriptionIt = seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionEn() {
|
||||||
|
return seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionEn(String seoDescriptionEn) {
|
||||||
|
this.seoDescriptionEn = seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionDe() {
|
||||||
|
return seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionDe(String seoDescriptionDe) {
|
||||||
|
this.seoDescriptionDe = seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionFr() {
|
||||||
|
return seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionFr(String seoDescriptionFr) {
|
||||||
|
this.seoDescriptionFr = seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgTitle() {
|
||||||
|
return ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgTitle(String ogTitle) {
|
||||||
|
this.ogTitle = ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgDescription() {
|
||||||
|
return ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgDescription(String ogDescription) {
|
||||||
|
this.ogDescription = ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIndexable() {
|
||||||
|
return indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexable(Boolean indexable) {
|
||||||
|
this.indexable = indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDepth() {
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDepth(Integer depth) {
|
||||||
|
this.depth = depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getChildCount() {
|
||||||
|
return childCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildCount(Integer childCount) {
|
||||||
|
this.childCount = childCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDirectProductCount() {
|
||||||
|
return directProductCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDirectProductCount(Integer directProductCount) {
|
||||||
|
this.directProductCount = directProductCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDescendantProductCount() {
|
||||||
|
return descendantProductCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescendantProductCount(Integer descendantProductCount) {
|
||||||
|
this.descendantProductCount = descendantProductCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMediaUsageType() {
|
||||||
|
return mediaUsageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMediaUsageType(String mediaUsageType) {
|
||||||
|
this.mediaUsageType = mediaUsageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMediaUsageKey() {
|
||||||
|
return mediaUsageKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMediaUsageKey(String mediaUsageKey) {
|
||||||
|
this.mediaUsageKey = mediaUsageKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminShopCategoryRefDto> getBreadcrumbs() {
|
||||||
|
return breadcrumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBreadcrumbs(List<AdminShopCategoryRefDto> breadcrumbs) {
|
||||||
|
this.breadcrumbs = breadcrumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminShopCategoryDto> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(List<AdminShopCategoryDto> children) {
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminShopCategoryRefDto {
|
||||||
|
private UUID id;
|
||||||
|
private String slug;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,441 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminShopProductDto {
|
||||||
|
private UUID id;
|
||||||
|
private UUID categoryId;
|
||||||
|
private String categoryName;
|
||||||
|
private String categorySlug;
|
||||||
|
private String slug;
|
||||||
|
private String name;
|
||||||
|
private String nameIt;
|
||||||
|
private String nameEn;
|
||||||
|
private String nameDe;
|
||||||
|
private String nameFr;
|
||||||
|
private String excerpt;
|
||||||
|
private String excerptIt;
|
||||||
|
private String excerptEn;
|
||||||
|
private String excerptDe;
|
||||||
|
private String excerptFr;
|
||||||
|
private String description;
|
||||||
|
private String descriptionIt;
|
||||||
|
private String descriptionEn;
|
||||||
|
private String descriptionDe;
|
||||||
|
private String descriptionFr;
|
||||||
|
private String seoTitle;
|
||||||
|
private String seoTitleIt;
|
||||||
|
private String seoTitleEn;
|
||||||
|
private String seoTitleDe;
|
||||||
|
private String seoTitleFr;
|
||||||
|
private String seoDescription;
|
||||||
|
private String seoDescriptionIt;
|
||||||
|
private String seoDescriptionEn;
|
||||||
|
private String seoDescriptionDe;
|
||||||
|
private String seoDescriptionFr;
|
||||||
|
private String ogTitle;
|
||||||
|
private String ogDescription;
|
||||||
|
private Boolean indexable;
|
||||||
|
private Boolean isFeatured;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Integer sortOrder;
|
||||||
|
private Integer variantCount;
|
||||||
|
private Integer activeVariantCount;
|
||||||
|
private BigDecimal priceFromChf;
|
||||||
|
private BigDecimal priceToChf;
|
||||||
|
private String mediaUsageType;
|
||||||
|
private String mediaUsageKey;
|
||||||
|
private List<AdminMediaUsageDto> mediaUsages;
|
||||||
|
private List<PublicMediaUsageDto> images;
|
||||||
|
private ShopProductModelDto model3d;
|
||||||
|
private List<AdminShopProductVariantDto> variants;
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getCategoryId() {
|
||||||
|
return categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryId(UUID categoryId) {
|
||||||
|
this.categoryId = categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategoryName() {
|
||||||
|
return categoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryName(String categoryName) {
|
||||||
|
this.categoryName = categoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategorySlug() {
|
||||||
|
return categorySlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategorySlug(String categorySlug) {
|
||||||
|
this.categorySlug = categorySlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameIt() {
|
||||||
|
return nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameIt(String nameIt) {
|
||||||
|
this.nameIt = nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEn() {
|
||||||
|
return nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameEn(String nameEn) {
|
||||||
|
this.nameEn = nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameDe() {
|
||||||
|
return nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameDe(String nameDe) {
|
||||||
|
this.nameDe = nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFr() {
|
||||||
|
return nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameFr(String nameFr) {
|
||||||
|
this.nameFr = nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerpt() {
|
||||||
|
return excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerpt(String excerpt) {
|
||||||
|
this.excerpt = excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptIt() {
|
||||||
|
return excerptIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptIt(String excerptIt) {
|
||||||
|
this.excerptIt = excerptIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptEn() {
|
||||||
|
return excerptEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptEn(String excerptEn) {
|
||||||
|
this.excerptEn = excerptEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptDe() {
|
||||||
|
return excerptDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptDe(String excerptDe) {
|
||||||
|
this.excerptDe = excerptDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptFr() {
|
||||||
|
return excerptFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptFr(String excerptFr) {
|
||||||
|
this.excerptFr = excerptFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionIt() {
|
||||||
|
return descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionIt(String descriptionIt) {
|
||||||
|
this.descriptionIt = descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionEn() {
|
||||||
|
return descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionEn(String descriptionEn) {
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionDe() {
|
||||||
|
return descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionDe(String descriptionDe) {
|
||||||
|
this.descriptionDe = descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionFr() {
|
||||||
|
return descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionFr(String descriptionFr) {
|
||||||
|
this.descriptionFr = descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleIt() {
|
||||||
|
return seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleIt(String seoTitleIt) {
|
||||||
|
this.seoTitleIt = seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleEn() {
|
||||||
|
return seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleEn(String seoTitleEn) {
|
||||||
|
this.seoTitleEn = seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleDe() {
|
||||||
|
return seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleDe(String seoTitleDe) {
|
||||||
|
this.seoTitleDe = seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleFr() {
|
||||||
|
return seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleFr(String seoTitleFr) {
|
||||||
|
this.seoTitleFr = seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionIt() {
|
||||||
|
return seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionIt(String seoDescriptionIt) {
|
||||||
|
this.seoDescriptionIt = seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionEn() {
|
||||||
|
return seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionEn(String seoDescriptionEn) {
|
||||||
|
this.seoDescriptionEn = seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionDe() {
|
||||||
|
return seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionDe(String seoDescriptionDe) {
|
||||||
|
this.seoDescriptionDe = seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionFr() {
|
||||||
|
return seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionFr(String seoDescriptionFr) {
|
||||||
|
this.seoDescriptionFr = seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgTitle() {
|
||||||
|
return ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgTitle(String ogTitle) {
|
||||||
|
this.ogTitle = ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgDescription() {
|
||||||
|
return ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgDescription(String ogDescription) {
|
||||||
|
this.ogDescription = ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIndexable() {
|
||||||
|
return indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexable(Boolean indexable) {
|
||||||
|
this.indexable = indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsFeatured() {
|
||||||
|
return isFeatured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsFeatured(Boolean featured) {
|
||||||
|
isFeatured = featured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getVariantCount() {
|
||||||
|
return variantCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariantCount(Integer variantCount) {
|
||||||
|
this.variantCount = variantCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getActiveVariantCount() {
|
||||||
|
return activeVariantCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActiveVariantCount(Integer activeVariantCount) {
|
||||||
|
this.activeVariantCount = activeVariantCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPriceFromChf() {
|
||||||
|
return priceFromChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriceFromChf(BigDecimal priceFromChf) {
|
||||||
|
this.priceFromChf = priceFromChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPriceToChf() {
|
||||||
|
return priceToChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriceToChf(BigDecimal priceToChf) {
|
||||||
|
this.priceToChf = priceToChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMediaUsageType() {
|
||||||
|
return mediaUsageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMediaUsageType(String mediaUsageType) {
|
||||||
|
this.mediaUsageType = mediaUsageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMediaUsageKey() {
|
||||||
|
return mediaUsageKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMediaUsageKey(String mediaUsageKey) {
|
||||||
|
this.mediaUsageKey = mediaUsageKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminMediaUsageDto> getMediaUsages() {
|
||||||
|
return mediaUsages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMediaUsages(List<AdminMediaUsageDto> mediaUsages) {
|
||||||
|
this.mediaUsages = mediaUsages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PublicMediaUsageDto> getImages() {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImages(List<PublicMediaUsageDto> images) {
|
||||||
|
this.images = images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductModelDto getModel3d() {
|
||||||
|
return model3d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel3d(ShopProductModelDto model3d) {
|
||||||
|
this.model3d = model3d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminShopProductVariantDto> getVariants() {
|
||||||
|
return variants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariants(List<AdminShopProductVariantDto> variants) {
|
||||||
|
this.variants = variants;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminShopProductVariantDto {
|
||||||
|
private UUID id;
|
||||||
|
private String sku;
|
||||||
|
private String variantLabel;
|
||||||
|
private String colorName;
|
||||||
|
private String colorLabelIt;
|
||||||
|
private String colorLabelEn;
|
||||||
|
private String colorLabelDe;
|
||||||
|
private String colorLabelFr;
|
||||||
|
private String colorHex;
|
||||||
|
private String internalMaterialCode;
|
||||||
|
private BigDecimal priceChf;
|
||||||
|
private Boolean isDefault;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Integer sortOrder;
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSku() {
|
||||||
|
return sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSku(String sku) {
|
||||||
|
this.sku = sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVariantLabel() {
|
||||||
|
return variantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariantLabel(String variantLabel) {
|
||||||
|
this.variantLabel = variantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorName() {
|
||||||
|
return colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorName(String colorName) {
|
||||||
|
this.colorName = colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelIt() {
|
||||||
|
return colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelIt(String colorLabelIt) {
|
||||||
|
this.colorLabelIt = colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelEn() {
|
||||||
|
return colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelEn(String colorLabelEn) {
|
||||||
|
this.colorLabelEn = colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelDe() {
|
||||||
|
return colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelDe(String colorLabelDe) {
|
||||||
|
this.colorLabelDe = colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelFr() {
|
||||||
|
return colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelFr(String colorLabelFr) {
|
||||||
|
this.colorLabelFr = colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorHex() {
|
||||||
|
return colorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorHex(String colorHex) {
|
||||||
|
this.colorHex = colorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInternalMaterialCode() {
|
||||||
|
return internalMaterialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInternalMaterialCode(String internalMaterialCode) {
|
||||||
|
this.internalMaterialCode = internalMaterialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPriceChf() {
|
||||||
|
return priceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriceChf(BigDecimal priceChf) {
|
||||||
|
this.priceChf = priceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsDefault() {
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDefault(Boolean aDefault) {
|
||||||
|
isDefault = aDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminTranslateShopProductRequest {
|
||||||
|
private UUID categoryId;
|
||||||
|
private String sourceLanguage;
|
||||||
|
private Boolean overwriteExisting;
|
||||||
|
private List<String> materialCodes;
|
||||||
|
private Map<String, String> names;
|
||||||
|
private Map<String, String> excerpts;
|
||||||
|
private Map<String, String> descriptions;
|
||||||
|
private Map<String, String> seoTitles;
|
||||||
|
private Map<String, String> seoDescriptions;
|
||||||
|
|
||||||
|
public UUID getCategoryId() {
|
||||||
|
return categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryId(UUID categoryId) {
|
||||||
|
this.categoryId = categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSourceLanguage() {
|
||||||
|
return sourceLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceLanguage(String sourceLanguage) {
|
||||||
|
this.sourceLanguage = sourceLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getOverwriteExisting() {
|
||||||
|
return overwriteExisting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOverwriteExisting(Boolean overwriteExisting) {
|
||||||
|
this.overwriteExisting = overwriteExisting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getMaterialCodes() {
|
||||||
|
return materialCodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialCodes(List<String> materialCodes) {
|
||||||
|
this.materialCodes = materialCodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getNames() {
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNames(Map<String, String> names) {
|
||||||
|
this.names = names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getExcerpts() {
|
||||||
|
return excerpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerpts(Map<String, String> excerpts) {
|
||||||
|
this.excerpts = excerpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getDescriptions() {
|
||||||
|
return descriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptions(Map<String, String> descriptions) {
|
||||||
|
this.descriptions = descriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getSeoTitles() {
|
||||||
|
return seoTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitles(Map<String, String> seoTitles) {
|
||||||
|
this.seoTitles = seoTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getSeoDescriptions() {
|
||||||
|
return seoDescriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptions(Map<String, String> seoDescriptions) {
|
||||||
|
this.seoDescriptions = seoDescriptions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class AdminTranslateShopProductResponse {
|
||||||
|
private String sourceLanguage;
|
||||||
|
private List<String> targetLanguages;
|
||||||
|
private Map<String, String> names;
|
||||||
|
private Map<String, String> excerpts;
|
||||||
|
private Map<String, String> descriptions;
|
||||||
|
private Map<String, String> seoTitles;
|
||||||
|
private Map<String, String> seoDescriptions;
|
||||||
|
|
||||||
|
public String getSourceLanguage() {
|
||||||
|
return sourceLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceLanguage(String sourceLanguage) {
|
||||||
|
this.sourceLanguage = sourceLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTargetLanguages() {
|
||||||
|
return targetLanguages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetLanguages(List<String> targetLanguages) {
|
||||||
|
this.targetLanguages = targetLanguages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getNames() {
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNames(Map<String, String> names) {
|
||||||
|
this.names = names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getExcerpts() {
|
||||||
|
return excerpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerpts(Map<String, String> excerpts) {
|
||||||
|
this.excerpts = excerpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getDescriptions() {
|
||||||
|
return descriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptions(Map<String, String> descriptions) {
|
||||||
|
this.descriptions = descriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getSeoTitles() {
|
||||||
|
return seoTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitles(Map<String, String> seoTitles) {
|
||||||
|
this.seoTitles = seoTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getSeoDescriptions() {
|
||||||
|
return seoDescriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptions(Map<String, String> seoDescriptions) {
|
||||||
|
this.seoDescriptions = seoDescriptions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,10 @@ public class AdminUpsertFilamentVariantRequest {
|
|||||||
private Long materialTypeId;
|
private Long materialTypeId;
|
||||||
private String variantDisplayName;
|
private String variantDisplayName;
|
||||||
private String colorName;
|
private String colorName;
|
||||||
|
private String colorLabelIt;
|
||||||
|
private String colorLabelEn;
|
||||||
|
private String colorLabelDe;
|
||||||
|
private String colorLabelFr;
|
||||||
private String colorHex;
|
private String colorHex;
|
||||||
private String finishType;
|
private String finishType;
|
||||||
private String brand;
|
private String brand;
|
||||||
@@ -40,6 +44,38 @@ public class AdminUpsertFilamentVariantRequest {
|
|||||||
this.colorName = colorName;
|
this.colorName = colorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColorLabelIt() {
|
||||||
|
return colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelIt(String colorLabelIt) {
|
||||||
|
this.colorLabelIt = colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelEn() {
|
||||||
|
return colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelEn(String colorLabelEn) {
|
||||||
|
this.colorLabelEn = colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelDe() {
|
||||||
|
return colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelDe(String colorLabelDe) {
|
||||||
|
this.colorLabelDe = colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelFr() {
|
||||||
|
return colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelFr(String colorLabelFr) {
|
||||||
|
this.colorLabelFr = colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
public String getColorHex() {
|
public String getColorHex() {
|
||||||
return colorHex;
|
return colorHex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,249 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminUpsertShopCategoryRequest {
|
||||||
|
private UUID parentCategoryId;
|
||||||
|
private String slug;
|
||||||
|
private String name;
|
||||||
|
private String nameIt;
|
||||||
|
private String nameEn;
|
||||||
|
private String nameDe;
|
||||||
|
private String nameFr;
|
||||||
|
private String description;
|
||||||
|
private String descriptionIt;
|
||||||
|
private String descriptionEn;
|
||||||
|
private String descriptionDe;
|
||||||
|
private String descriptionFr;
|
||||||
|
private String seoTitle;
|
||||||
|
private String seoTitleIt;
|
||||||
|
private String seoTitleEn;
|
||||||
|
private String seoTitleDe;
|
||||||
|
private String seoTitleFr;
|
||||||
|
private String seoDescription;
|
||||||
|
private String seoDescriptionIt;
|
||||||
|
private String seoDescriptionEn;
|
||||||
|
private String seoDescriptionDe;
|
||||||
|
private String seoDescriptionFr;
|
||||||
|
private String ogTitle;
|
||||||
|
private String ogDescription;
|
||||||
|
private Boolean indexable;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
public UUID getParentCategoryId() {
|
||||||
|
return parentCategoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentCategoryId(UUID parentCategoryId) {
|
||||||
|
this.parentCategoryId = parentCategoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameIt() {
|
||||||
|
return nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameIt(String nameIt) {
|
||||||
|
this.nameIt = nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEn() {
|
||||||
|
return nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameEn(String nameEn) {
|
||||||
|
this.nameEn = nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameDe() {
|
||||||
|
return nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameDe(String nameDe) {
|
||||||
|
this.nameDe = nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFr() {
|
||||||
|
return nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameFr(String nameFr) {
|
||||||
|
this.nameFr = nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionIt() {
|
||||||
|
return descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionIt(String descriptionIt) {
|
||||||
|
this.descriptionIt = descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionEn() {
|
||||||
|
return descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionEn(String descriptionEn) {
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionDe() {
|
||||||
|
return descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionDe(String descriptionDe) {
|
||||||
|
this.descriptionDe = descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionFr() {
|
||||||
|
return descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionFr(String descriptionFr) {
|
||||||
|
this.descriptionFr = descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleIt() {
|
||||||
|
return seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleIt(String seoTitleIt) {
|
||||||
|
this.seoTitleIt = seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleEn() {
|
||||||
|
return seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleEn(String seoTitleEn) {
|
||||||
|
this.seoTitleEn = seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleDe() {
|
||||||
|
return seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleDe(String seoTitleDe) {
|
||||||
|
this.seoTitleDe = seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleFr() {
|
||||||
|
return seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleFr(String seoTitleFr) {
|
||||||
|
this.seoTitleFr = seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionIt() {
|
||||||
|
return seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionIt(String seoDescriptionIt) {
|
||||||
|
this.seoDescriptionIt = seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionEn() {
|
||||||
|
return seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionEn(String seoDescriptionEn) {
|
||||||
|
this.seoDescriptionEn = seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionDe() {
|
||||||
|
return seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionDe(String seoDescriptionDe) {
|
||||||
|
this.seoDescriptionDe = seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionFr() {
|
||||||
|
return seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionFr(String seoDescriptionFr) {
|
||||||
|
this.seoDescriptionFr = seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgTitle() {
|
||||||
|
return ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgTitle(String ogTitle) {
|
||||||
|
this.ogTitle = ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgDescription() {
|
||||||
|
return ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgDescription(String ogDescription) {
|
||||||
|
this.ogDescription = ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIndexable() {
|
||||||
|
return indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexable(Boolean indexable) {
|
||||||
|
this.indexable = indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminUpsertShopProductRequest {
|
||||||
|
private UUID categoryId;
|
||||||
|
private String slug;
|
||||||
|
private String name;
|
||||||
|
private String nameIt;
|
||||||
|
private String nameEn;
|
||||||
|
private String nameDe;
|
||||||
|
private String nameFr;
|
||||||
|
private String excerpt;
|
||||||
|
private String excerptIt;
|
||||||
|
private String excerptEn;
|
||||||
|
private String excerptDe;
|
||||||
|
private String excerptFr;
|
||||||
|
private String description;
|
||||||
|
private String descriptionIt;
|
||||||
|
private String descriptionEn;
|
||||||
|
private String descriptionDe;
|
||||||
|
private String descriptionFr;
|
||||||
|
private String seoTitle;
|
||||||
|
private String seoTitleIt;
|
||||||
|
private String seoTitleEn;
|
||||||
|
private String seoTitleDe;
|
||||||
|
private String seoTitleFr;
|
||||||
|
private String seoDescription;
|
||||||
|
private String seoDescriptionIt;
|
||||||
|
private String seoDescriptionEn;
|
||||||
|
private String seoDescriptionDe;
|
||||||
|
private String seoDescriptionFr;
|
||||||
|
private String ogTitle;
|
||||||
|
private String ogDescription;
|
||||||
|
private Boolean indexable;
|
||||||
|
private Boolean isFeatured;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Integer sortOrder;
|
||||||
|
private List<AdminUpsertShopProductVariantRequest> variants;
|
||||||
|
|
||||||
|
public UUID getCategoryId() {
|
||||||
|
return categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryId(UUID categoryId) {
|
||||||
|
this.categoryId = categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameIt() {
|
||||||
|
return nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameIt(String nameIt) {
|
||||||
|
this.nameIt = nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEn() {
|
||||||
|
return nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameEn(String nameEn) {
|
||||||
|
this.nameEn = nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameDe() {
|
||||||
|
return nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameDe(String nameDe) {
|
||||||
|
this.nameDe = nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFr() {
|
||||||
|
return nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameFr(String nameFr) {
|
||||||
|
this.nameFr = nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerpt() {
|
||||||
|
return excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerpt(String excerpt) {
|
||||||
|
this.excerpt = excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptIt() {
|
||||||
|
return excerptIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptIt(String excerptIt) {
|
||||||
|
this.excerptIt = excerptIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptEn() {
|
||||||
|
return excerptEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptEn(String excerptEn) {
|
||||||
|
this.excerptEn = excerptEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptDe() {
|
||||||
|
return excerptDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptDe(String excerptDe) {
|
||||||
|
this.excerptDe = excerptDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptFr() {
|
||||||
|
return excerptFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptFr(String excerptFr) {
|
||||||
|
this.excerptFr = excerptFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionIt() {
|
||||||
|
return descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionIt(String descriptionIt) {
|
||||||
|
this.descriptionIt = descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionEn() {
|
||||||
|
return descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionEn(String descriptionEn) {
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionDe() {
|
||||||
|
return descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionDe(String descriptionDe) {
|
||||||
|
this.descriptionDe = descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionFr() {
|
||||||
|
return descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionFr(String descriptionFr) {
|
||||||
|
this.descriptionFr = descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleIt() {
|
||||||
|
return seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleIt(String seoTitleIt) {
|
||||||
|
this.seoTitleIt = seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleEn() {
|
||||||
|
return seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleEn(String seoTitleEn) {
|
||||||
|
this.seoTitleEn = seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleDe() {
|
||||||
|
return seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleDe(String seoTitleDe) {
|
||||||
|
this.seoTitleDe = seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleFr() {
|
||||||
|
return seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleFr(String seoTitleFr) {
|
||||||
|
this.seoTitleFr = seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionIt() {
|
||||||
|
return seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionIt(String seoDescriptionIt) {
|
||||||
|
this.seoDescriptionIt = seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionEn() {
|
||||||
|
return seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionEn(String seoDescriptionEn) {
|
||||||
|
this.seoDescriptionEn = seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionDe() {
|
||||||
|
return seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionDe(String seoDescriptionDe) {
|
||||||
|
this.seoDescriptionDe = seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionFr() {
|
||||||
|
return seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionFr(String seoDescriptionFr) {
|
||||||
|
this.seoDescriptionFr = seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgTitle() {
|
||||||
|
return ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgTitle(String ogTitle) {
|
||||||
|
this.ogTitle = ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgDescription() {
|
||||||
|
return ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgDescription(String ogDescription) {
|
||||||
|
this.ogDescription = ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIndexable() {
|
||||||
|
return indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexable(Boolean indexable) {
|
||||||
|
this.indexable = indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsFeatured() {
|
||||||
|
return isFeatured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsFeatured(Boolean featured) {
|
||||||
|
isFeatured = featured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminUpsertShopProductVariantRequest> getVariants() {
|
||||||
|
return variants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariants(List<AdminUpsertShopProductVariantRequest> variants) {
|
||||||
|
this.variants = variants;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AdminUpsertShopProductVariantRequest {
|
||||||
|
private UUID id;
|
||||||
|
private String sku;
|
||||||
|
private String variantLabel;
|
||||||
|
private String colorName;
|
||||||
|
private String colorLabelIt;
|
||||||
|
private String colorLabelEn;
|
||||||
|
private String colorLabelDe;
|
||||||
|
private String colorLabelFr;
|
||||||
|
private String colorHex;
|
||||||
|
private String internalMaterialCode;
|
||||||
|
private BigDecimal priceChf;
|
||||||
|
private Boolean isDefault;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSku() {
|
||||||
|
return sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSku(String sku) {
|
||||||
|
this.sku = sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVariantLabel() {
|
||||||
|
return variantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariantLabel(String variantLabel) {
|
||||||
|
this.variantLabel = variantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorName() {
|
||||||
|
return colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorName(String colorName) {
|
||||||
|
this.colorName = colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelIt() {
|
||||||
|
return colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelIt(String colorLabelIt) {
|
||||||
|
this.colorLabelIt = colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelEn() {
|
||||||
|
return colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelEn(String colorLabelEn) {
|
||||||
|
this.colorLabelEn = colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelDe() {
|
||||||
|
return colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelDe(String colorLabelDe) {
|
||||||
|
this.colorLabelDe = colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelFr() {
|
||||||
|
return colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelFr(String colorLabelFr) {
|
||||||
|
this.colorLabelFr = colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorHex() {
|
||||||
|
return colorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorHex(String colorHex) {
|
||||||
|
this.colorHex = colorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInternalMaterialCode() {
|
||||||
|
return internalMaterialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInternalMaterialCode(String internalMaterialCode) {
|
||||||
|
this.internalMaterialCode = internalMaterialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPriceChf() {
|
||||||
|
return priceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriceChf(BigDecimal priceChf) {
|
||||||
|
this.priceChf = priceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsDefault() {
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDefault(Boolean aDefault) {
|
||||||
|
isDefault = aDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,10 @@ public record OptionsResponse(
|
|||||||
Long id,
|
Long id,
|
||||||
String name,
|
String name,
|
||||||
String colorName,
|
String colorName,
|
||||||
|
String colorLabelIt,
|
||||||
|
String colorLabelEn,
|
||||||
|
String colorLabelDe,
|
||||||
|
String colorLabelFr,
|
||||||
String hexColor,
|
String hexColor,
|
||||||
String finishType,
|
String finishType,
|
||||||
Double stockSpools,
|
Double stockSpools,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.UUID;
|
|||||||
public class OrderDto {
|
public class OrderDto {
|
||||||
private UUID id;
|
private UUID id;
|
||||||
private String orderNumber;
|
private String orderNumber;
|
||||||
|
private String sourceType;
|
||||||
private String status;
|
private String status;
|
||||||
private String paymentStatus;
|
private String paymentStatus;
|
||||||
private String paymentMethod;
|
private String paymentMethod;
|
||||||
@@ -45,6 +46,9 @@ public class OrderDto {
|
|||||||
public String getOrderNumber() { return orderNumber; }
|
public String getOrderNumber() { return orderNumber; }
|
||||||
public void setOrderNumber(String orderNumber) { this.orderNumber = orderNumber; }
|
public void setOrderNumber(String orderNumber) { this.orderNumber = orderNumber; }
|
||||||
|
|
||||||
|
public String getSourceType() { return sourceType; }
|
||||||
|
public void setSourceType(String sourceType) { this.sourceType = sourceType; }
|
||||||
|
|
||||||
public String getStatus() { return status; }
|
public String getStatus() { return status; }
|
||||||
public void setStatus(String status) { this.status = status; }
|
public void setStatus(String status) { this.status = status; }
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,29 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class OrderItemDto {
|
public class OrderItemDto {
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
private String itemType;
|
||||||
private String originalFilename;
|
private String originalFilename;
|
||||||
|
private String displayName;
|
||||||
private String materialCode;
|
private String materialCode;
|
||||||
private String colorCode;
|
private String colorCode;
|
||||||
private Long filamentVariantId;
|
private Long filamentVariantId;
|
||||||
|
private UUID shopProductId;
|
||||||
|
private UUID shopProductVariantId;
|
||||||
|
private String shopProductSlug;
|
||||||
|
private String shopProductName;
|
||||||
|
private String shopVariantLabel;
|
||||||
|
private String shopVariantColorName;
|
||||||
|
private String shopVariantColorLabelIt;
|
||||||
|
private String shopVariantColorLabelEn;
|
||||||
|
private String shopVariantColorLabelDe;
|
||||||
|
private String shopVariantColorLabelFr;
|
||||||
|
private String shopVariantColorHex;
|
||||||
private String filamentVariantDisplayName;
|
private String filamentVariantDisplayName;
|
||||||
private String filamentColorName;
|
private String filamentColorName;
|
||||||
|
private String filamentColorLabelIt;
|
||||||
|
private String filamentColorLabelEn;
|
||||||
|
private String filamentColorLabelDe;
|
||||||
|
private String filamentColorLabelFr;
|
||||||
private String filamentColorHex;
|
private String filamentColorHex;
|
||||||
private String quality;
|
private String quality;
|
||||||
private BigDecimal nozzleDiameterMm;
|
private BigDecimal nozzleDiameterMm;
|
||||||
@@ -28,9 +45,15 @@ public class OrderItemDto {
|
|||||||
public UUID getId() { return id; }
|
public UUID getId() { return id; }
|
||||||
public void setId(UUID id) { this.id = id; }
|
public void setId(UUID id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getItemType() { return itemType; }
|
||||||
|
public void setItemType(String itemType) { this.itemType = itemType; }
|
||||||
|
|
||||||
public String getOriginalFilename() { return originalFilename; }
|
public String getOriginalFilename() { return originalFilename; }
|
||||||
public void setOriginalFilename(String originalFilename) { this.originalFilename = originalFilename; }
|
public void setOriginalFilename(String originalFilename) { this.originalFilename = originalFilename; }
|
||||||
|
|
||||||
|
public String getDisplayName() { return displayName; }
|
||||||
|
public void setDisplayName(String displayName) { this.displayName = displayName; }
|
||||||
|
|
||||||
public String getMaterialCode() { return materialCode; }
|
public String getMaterialCode() { return materialCode; }
|
||||||
public void setMaterialCode(String materialCode) { this.materialCode = materialCode; }
|
public void setMaterialCode(String materialCode) { this.materialCode = materialCode; }
|
||||||
|
|
||||||
@@ -40,12 +63,57 @@ public class OrderItemDto {
|
|||||||
public Long getFilamentVariantId() { return filamentVariantId; }
|
public Long getFilamentVariantId() { return filamentVariantId; }
|
||||||
public void setFilamentVariantId(Long filamentVariantId) { this.filamentVariantId = filamentVariantId; }
|
public void setFilamentVariantId(Long filamentVariantId) { this.filamentVariantId = filamentVariantId; }
|
||||||
|
|
||||||
|
public UUID getShopProductId() { return shopProductId; }
|
||||||
|
public void setShopProductId(UUID shopProductId) { this.shopProductId = shopProductId; }
|
||||||
|
|
||||||
|
public UUID getShopProductVariantId() { return shopProductVariantId; }
|
||||||
|
public void setShopProductVariantId(UUID shopProductVariantId) { this.shopProductVariantId = shopProductVariantId; }
|
||||||
|
|
||||||
|
public String getShopProductSlug() { return shopProductSlug; }
|
||||||
|
public void setShopProductSlug(String shopProductSlug) { this.shopProductSlug = shopProductSlug; }
|
||||||
|
|
||||||
|
public String getShopProductName() { return shopProductName; }
|
||||||
|
public void setShopProductName(String shopProductName) { this.shopProductName = shopProductName; }
|
||||||
|
|
||||||
|
public String getShopVariantLabel() { return shopVariantLabel; }
|
||||||
|
public void setShopVariantLabel(String shopVariantLabel) { this.shopVariantLabel = shopVariantLabel; }
|
||||||
|
|
||||||
|
public String getShopVariantColorName() { return shopVariantColorName; }
|
||||||
|
public void setShopVariantColorName(String shopVariantColorName) { this.shopVariantColorName = shopVariantColorName; }
|
||||||
|
|
||||||
|
public String getShopVariantColorLabelIt() { return shopVariantColorLabelIt; }
|
||||||
|
public void setShopVariantColorLabelIt(String shopVariantColorLabelIt) { this.shopVariantColorLabelIt = shopVariantColorLabelIt; }
|
||||||
|
|
||||||
|
public String getShopVariantColorLabelEn() { return shopVariantColorLabelEn; }
|
||||||
|
public void setShopVariantColorLabelEn(String shopVariantColorLabelEn) { this.shopVariantColorLabelEn = shopVariantColorLabelEn; }
|
||||||
|
|
||||||
|
public String getShopVariantColorLabelDe() { return shopVariantColorLabelDe; }
|
||||||
|
public void setShopVariantColorLabelDe(String shopVariantColorLabelDe) { this.shopVariantColorLabelDe = shopVariantColorLabelDe; }
|
||||||
|
|
||||||
|
public String getShopVariantColorLabelFr() { return shopVariantColorLabelFr; }
|
||||||
|
public void setShopVariantColorLabelFr(String shopVariantColorLabelFr) { this.shopVariantColorLabelFr = shopVariantColorLabelFr; }
|
||||||
|
|
||||||
|
public String getShopVariantColorHex() { return shopVariantColorHex; }
|
||||||
|
public void setShopVariantColorHex(String shopVariantColorHex) { this.shopVariantColorHex = shopVariantColorHex; }
|
||||||
|
|
||||||
public String getFilamentVariantDisplayName() { return filamentVariantDisplayName; }
|
public String getFilamentVariantDisplayName() { return filamentVariantDisplayName; }
|
||||||
public void setFilamentVariantDisplayName(String filamentVariantDisplayName) { this.filamentVariantDisplayName = filamentVariantDisplayName; }
|
public void setFilamentVariantDisplayName(String filamentVariantDisplayName) { this.filamentVariantDisplayName = filamentVariantDisplayName; }
|
||||||
|
|
||||||
public String getFilamentColorName() { return filamentColorName; }
|
public String getFilamentColorName() { return filamentColorName; }
|
||||||
public void setFilamentColorName(String filamentColorName) { this.filamentColorName = filamentColorName; }
|
public void setFilamentColorName(String filamentColorName) { this.filamentColorName = filamentColorName; }
|
||||||
|
|
||||||
|
public String getFilamentColorLabelIt() { return filamentColorLabelIt; }
|
||||||
|
public void setFilamentColorLabelIt(String filamentColorLabelIt) { this.filamentColorLabelIt = filamentColorLabelIt; }
|
||||||
|
|
||||||
|
public String getFilamentColorLabelEn() { return filamentColorLabelEn; }
|
||||||
|
public void setFilamentColorLabelEn(String filamentColorLabelEn) { this.filamentColorLabelEn = filamentColorLabelEn; }
|
||||||
|
|
||||||
|
public String getFilamentColorLabelDe() { return filamentColorLabelDe; }
|
||||||
|
public void setFilamentColorLabelDe(String filamentColorLabelDe) { this.filamentColorLabelDe = filamentColorLabelDe; }
|
||||||
|
|
||||||
|
public String getFilamentColorLabelFr() { return filamentColorLabelFr; }
|
||||||
|
public void setFilamentColorLabelFr(String filamentColorLabelFr) { this.filamentColorLabelFr = filamentColorLabelFr; }
|
||||||
|
|
||||||
public String getFilamentColorHex() { return filamentColorHex; }
|
public String getFilamentColorHex() { return filamentColorHex; }
|
||||||
public void setFilamentColorHex(String filamentColorHex) { this.filamentColorHex = filamentColorHex; }
|
public void setFilamentColorHex(String filamentColorHex) { this.filamentColorHex = filamentColorHex; }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ShopCartAddItemRequest {
|
||||||
|
@NotNull
|
||||||
|
private UUID shopProductVariantId;
|
||||||
|
|
||||||
|
@Min(1)
|
||||||
|
private Integer quantity = 1;
|
||||||
|
|
||||||
|
public UUID getShopProductVariantId() {
|
||||||
|
return shopProductVariantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductVariantId(UUID shopProductVariantId) {
|
||||||
|
this.shopProductVariantId = shopProductVariantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(Integer quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public class ShopCartUpdateItemRequest {
|
||||||
|
@NotNull
|
||||||
|
@Min(1)
|
||||||
|
private Integer quantity;
|
||||||
|
|
||||||
|
public Integer getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(Integer quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record ShopCategoryDetailDto(
|
||||||
|
UUID id,
|
||||||
|
String slug,
|
||||||
|
String name,
|
||||||
|
String description,
|
||||||
|
String seoTitle,
|
||||||
|
String seoDescription,
|
||||||
|
String ogTitle,
|
||||||
|
String ogDescription,
|
||||||
|
Boolean indexable,
|
||||||
|
Integer sortOrder,
|
||||||
|
Integer productCount,
|
||||||
|
List<ShopCategoryRefDto> breadcrumbs,
|
||||||
|
PublicMediaUsageDto primaryImage,
|
||||||
|
List<PublicMediaUsageDto> images,
|
||||||
|
List<ShopCategoryTreeDto> children
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record ShopCategoryRefDto(
|
||||||
|
UUID id,
|
||||||
|
String slug,
|
||||||
|
String name
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record ShopCategoryTreeDto(
|
||||||
|
UUID id,
|
||||||
|
UUID parentCategoryId,
|
||||||
|
String slug,
|
||||||
|
String name,
|
||||||
|
String description,
|
||||||
|
String seoTitle,
|
||||||
|
String seoDescription,
|
||||||
|
String ogTitle,
|
||||||
|
String ogDescription,
|
||||||
|
Boolean indexable,
|
||||||
|
Integer sortOrder,
|
||||||
|
Integer productCount,
|
||||||
|
PublicMediaUsageDto primaryImage,
|
||||||
|
List<ShopCategoryTreeDto> children
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record ShopProductCatalogResponseDto(
|
||||||
|
String categorySlug,
|
||||||
|
Boolean featuredOnly,
|
||||||
|
ShopCategoryDetailDto category,
|
||||||
|
List<ShopProductSummaryDto> products
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record ShopProductDetailDto(
|
||||||
|
UUID id,
|
||||||
|
String slug,
|
||||||
|
String name,
|
||||||
|
String excerpt,
|
||||||
|
String description,
|
||||||
|
String seoTitle,
|
||||||
|
String seoDescription,
|
||||||
|
String ogTitle,
|
||||||
|
String ogDescription,
|
||||||
|
Boolean indexable,
|
||||||
|
Boolean isFeatured,
|
||||||
|
Integer sortOrder,
|
||||||
|
ShopCategoryRefDto category,
|
||||||
|
List<ShopCategoryRefDto> breadcrumbs,
|
||||||
|
BigDecimal priceFromChf,
|
||||||
|
BigDecimal priceToChf,
|
||||||
|
ShopProductVariantOptionDto defaultVariant,
|
||||||
|
List<ShopProductVariantOptionDto> variants,
|
||||||
|
PublicMediaUsageDto primaryImage,
|
||||||
|
List<PublicMediaUsageDto> images,
|
||||||
|
ShopProductModelDto model3d,
|
||||||
|
String publicPath,
|
||||||
|
Map<String, String> localizedPaths
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public record ShopProductModelDto(
|
||||||
|
String url,
|
||||||
|
String originalFilename,
|
||||||
|
String mimeType,
|
||||||
|
Long fileSizeBytes,
|
||||||
|
BigDecimal boundingBoxXMm,
|
||||||
|
BigDecimal boundingBoxYMm,
|
||||||
|
BigDecimal boundingBoxZMm
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record ShopProductSummaryDto(
|
||||||
|
UUID id,
|
||||||
|
String slug,
|
||||||
|
String name,
|
||||||
|
String excerpt,
|
||||||
|
Boolean isFeatured,
|
||||||
|
Integer sortOrder,
|
||||||
|
ShopCategoryRefDto category,
|
||||||
|
BigDecimal priceFromChf,
|
||||||
|
BigDecimal priceToChf,
|
||||||
|
ShopProductVariantOptionDto defaultVariant,
|
||||||
|
PublicMediaUsageDto primaryImage,
|
||||||
|
ShopProductModelDto model3d,
|
||||||
|
String publicPath,
|
||||||
|
Map<String, String> localizedPaths
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record ShopProductVariantOptionDto(
|
||||||
|
UUID id,
|
||||||
|
String sku,
|
||||||
|
String variantLabel,
|
||||||
|
String colorName,
|
||||||
|
String colorLabel,
|
||||||
|
String colorHex,
|
||||||
|
BigDecimal priceChf,
|
||||||
|
Boolean isDefault
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -24,6 +24,18 @@ public class FilamentVariant {
|
|||||||
@Column(name = "color_name", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "color_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String colorName;
|
private String colorName;
|
||||||
|
|
||||||
|
@Column(name = "color_label_it", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelIt;
|
||||||
|
|
||||||
|
@Column(name = "color_label_en", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelEn;
|
||||||
|
|
||||||
|
@Column(name = "color_label_de", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelDe;
|
||||||
|
|
||||||
|
@Column(name = "color_label_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelFr;
|
||||||
|
|
||||||
@Column(name = "color_hex", length = Integer.MAX_VALUE)
|
@Column(name = "color_hex", length = Integer.MAX_VALUE)
|
||||||
private String colorHex;
|
private String colorHex;
|
||||||
|
|
||||||
@@ -93,6 +105,38 @@ public class FilamentVariant {
|
|||||||
this.colorName = colorName;
|
this.colorName = colorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColorLabelIt() {
|
||||||
|
return colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelIt(String colorLabelIt) {
|
||||||
|
this.colorLabelIt = colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelEn() {
|
||||||
|
return colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelEn(String colorLabelEn) {
|
||||||
|
this.colorLabelEn = colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelDe() {
|
||||||
|
return colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelDe(String colorLabelDe) {
|
||||||
|
this.colorLabelDe = colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelFr() {
|
||||||
|
return colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelFr(String colorLabelFr) {
|
||||||
|
this.colorLabelFr = colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
public String getColorHex() {
|
public String getColorHex() {
|
||||||
return colorHex;
|
return colorHex;
|
||||||
}
|
}
|
||||||
@@ -173,4 +217,60 @@ public class FilamentVariant {
|
|||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColorLabelForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(
|
||||||
|
language,
|
||||||
|
colorName,
|
||||||
|
colorLabelIt,
|
||||||
|
colorLabelEn,
|
||||||
|
colorLabelDe,
|
||||||
|
colorLabelFr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveLocalizedValue(String language,
|
||||||
|
String fallback,
|
||||||
|
String valueIt,
|
||||||
|
String valueEn,
|
||||||
|
String valueDe,
|
||||||
|
String valueFr) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String preferred = switch (normalizedLanguage) {
|
||||||
|
case "it" -> valueIt;
|
||||||
|
case "en" -> valueEn;
|
||||||
|
case "de" -> valueDe;
|
||||||
|
case "fr" -> valueFr;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
String resolved = firstNonBlank(preferred, fallback);
|
||||||
|
if (resolved != null) {
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
return firstNonBlank(valueIt, valueEn, valueDe, valueFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeLanguage(String language) {
|
||||||
|
if (language == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalized = language.trim().toLowerCase();
|
||||||
|
int separatorIndex = normalized.indexOf('-');
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
normalized = normalized.substring(0, separatorIndex);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ public class Order {
|
|||||||
@JoinColumn(name = "source_quote_session_id")
|
@JoinColumn(name = "source_quote_session_id")
|
||||||
private QuoteSession sourceQuoteSession;
|
private QuoteSession sourceQuoteSession;
|
||||||
|
|
||||||
|
@ColumnDefault("'CALCULATOR'")
|
||||||
|
@Column(name = "source_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String sourceType;
|
||||||
|
|
||||||
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
@@ -151,6 +155,34 @@ public class Order {
|
|||||||
@Column(name = "paid_at")
|
@Column(name = "paid_at")
|
||||||
private OffsetDateTime paidAt;
|
private OffsetDateTime paidAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = now;
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = now;
|
||||||
|
}
|
||||||
|
if (shippingSameAsBilling == null) {
|
||||||
|
shippingSameAsBilling = true;
|
||||||
|
}
|
||||||
|
if (sourceType == null || sourceType.isBlank()) {
|
||||||
|
sourceType = "CALCULATOR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
private void onUpdate() {
|
||||||
|
updatedAt = OffsetDateTime.now();
|
||||||
|
if (shippingSameAsBilling == null) {
|
||||||
|
shippingSameAsBilling = true;
|
||||||
|
}
|
||||||
|
if (sourceType == null || sourceType.isBlank()) {
|
||||||
|
sourceType = "CALCULATOR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -177,6 +209,14 @@ public class Order {
|
|||||||
this.sourceQuoteSession = sourceQuoteSession;
|
this.sourceQuoteSession = sourceQuoteSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSourceType() {
|
||||||
|
return sourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceType(String sourceType) {
|
||||||
|
this.sourceType = sourceType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,16 @@ public class OrderItem {
|
|||||||
@JoinColumn(name = "order_id", nullable = false)
|
@JoinColumn(name = "order_id", nullable = false)
|
||||||
private Order order;
|
private Order order;
|
||||||
|
|
||||||
|
@ColumnDefault("'PRINT_FILE'")
|
||||||
|
@Column(name = "item_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String itemType;
|
||||||
|
|
||||||
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String originalFilename;
|
private String originalFilename;
|
||||||
|
|
||||||
|
@Column(name = "display_name", length = Integer.MAX_VALUE)
|
||||||
|
private String displayName;
|
||||||
|
|
||||||
@Column(name = "stored_relative_path", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "stored_relative_path", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String storedRelativePath;
|
private String storedRelativePath;
|
||||||
|
|
||||||
@@ -66,6 +73,29 @@ public class OrderItem {
|
|||||||
@JoinColumn(name = "filament_variant_id")
|
@JoinColumn(name = "filament_variant_id")
|
||||||
private FilamentVariant filamentVariant;
|
private FilamentVariant filamentVariant;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "shop_product_id")
|
||||||
|
private ShopProduct shopProduct;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "shop_product_variant_id")
|
||||||
|
private ShopProductVariant shopProductVariant;
|
||||||
|
|
||||||
|
@Column(name = "shop_product_slug", length = Integer.MAX_VALUE)
|
||||||
|
private String shopProductSlug;
|
||||||
|
|
||||||
|
@Column(name = "shop_product_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shopProductName;
|
||||||
|
|
||||||
|
@Column(name = "shop_variant_label", length = Integer.MAX_VALUE)
|
||||||
|
private String shopVariantLabel;
|
||||||
|
|
||||||
|
@Column(name = "shop_variant_color_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shopVariantColorName;
|
||||||
|
|
||||||
|
@Column(name = "shop_variant_color_hex", length = Integer.MAX_VALUE)
|
||||||
|
private String shopVariantColorHex;
|
||||||
|
|
||||||
@Column(name = "color_code", length = Integer.MAX_VALUE)
|
@Column(name = "color_code", length = Integer.MAX_VALUE)
|
||||||
private String colorCode;
|
private String colorCode;
|
||||||
|
|
||||||
@@ -106,6 +136,14 @@ public class OrderItem {
|
|||||||
if (quantity == null) {
|
if (quantity == null) {
|
||||||
quantity = 1;
|
quantity = 1;
|
||||||
}
|
}
|
||||||
|
if (itemType == null || itemType.isBlank()) {
|
||||||
|
itemType = "PRINT_FILE";
|
||||||
|
}
|
||||||
|
if ((displayName == null || displayName.isBlank()) && originalFilename != null && !originalFilename.isBlank()) {
|
||||||
|
displayName = originalFilename;
|
||||||
|
} else if ((displayName == null || displayName.isBlank()) && shopProductName != null && !shopProductName.isBlank()) {
|
||||||
|
displayName = shopProductName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
@@ -124,6 +162,14 @@ public class OrderItem {
|
|||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getItemType() {
|
||||||
|
return itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemType(String itemType) {
|
||||||
|
this.itemType = itemType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getOriginalFilename() {
|
public String getOriginalFilename() {
|
||||||
return originalFilename;
|
return originalFilename;
|
||||||
}
|
}
|
||||||
@@ -132,6 +178,14 @@ public class OrderItem {
|
|||||||
this.originalFilename = originalFilename;
|
this.originalFilename = originalFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getStoredRelativePath() {
|
public String getStoredRelativePath() {
|
||||||
return storedRelativePath;
|
return storedRelativePath;
|
||||||
}
|
}
|
||||||
@@ -236,6 +290,62 @@ public class OrderItem {
|
|||||||
this.filamentVariant = filamentVariant;
|
this.filamentVariant = filamentVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShopProduct getShopProduct() {
|
||||||
|
return shopProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProduct(ShopProduct shopProduct) {
|
||||||
|
this.shopProduct = shopProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductVariant getShopProductVariant() {
|
||||||
|
return shopProductVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductVariant(ShopProductVariant shopProductVariant) {
|
||||||
|
this.shopProductVariant = shopProductVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopProductSlug() {
|
||||||
|
return shopProductSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductSlug(String shopProductSlug) {
|
||||||
|
this.shopProductSlug = shopProductSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopProductName() {
|
||||||
|
return shopProductName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductName(String shopProductName) {
|
||||||
|
this.shopProductName = shopProductName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopVariantLabel() {
|
||||||
|
return shopVariantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopVariantLabel(String shopVariantLabel) {
|
||||||
|
this.shopVariantLabel = shopVariantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopVariantColorName() {
|
||||||
|
return shopVariantColorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopVariantColorName(String shopVariantColorName) {
|
||||||
|
this.shopVariantColorName = shopVariantColorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopVariantColorHex() {
|
||||||
|
return shopVariantColorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopVariantColorHex(String shopVariantColorHex) {
|
||||||
|
this.shopVariantColorHex = shopVariantColorHex;
|
||||||
|
}
|
||||||
|
|
||||||
public String getColorCode() {
|
public String getColorCode() {
|
||||||
return colorCode;
|
return colorCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,16 @@ public class QuoteLineItem {
|
|||||||
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
@ColumnDefault("'PRINT_FILE'")
|
||||||
|
@Column(name = "line_item_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String lineItemType;
|
||||||
|
|
||||||
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String originalFilename;
|
private String originalFilename;
|
||||||
|
|
||||||
|
@Column(name = "display_name", length = Integer.MAX_VALUE)
|
||||||
|
private String displayName;
|
||||||
|
|
||||||
@ColumnDefault("1")
|
@ColumnDefault("1")
|
||||||
@Column(name = "quantity", nullable = false)
|
@Column(name = "quantity", nullable = false)
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
@@ -45,6 +52,31 @@ public class QuoteLineItem {
|
|||||||
@com.fasterxml.jackson.annotation.JsonIgnore
|
@com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
private FilamentVariant filamentVariant;
|
private FilamentVariant filamentVariant;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "shop_product_id")
|
||||||
|
@com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
private ShopProduct shopProduct;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "shop_product_variant_id")
|
||||||
|
@com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
private ShopProductVariant shopProductVariant;
|
||||||
|
|
||||||
|
@Column(name = "shop_product_slug", length = Integer.MAX_VALUE)
|
||||||
|
private String shopProductSlug;
|
||||||
|
|
||||||
|
@Column(name = "shop_product_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shopProductName;
|
||||||
|
|
||||||
|
@Column(name = "shop_variant_label", length = Integer.MAX_VALUE)
|
||||||
|
private String shopVariantLabel;
|
||||||
|
|
||||||
|
@Column(name = "shop_variant_color_name", length = Integer.MAX_VALUE)
|
||||||
|
private String shopVariantColorName;
|
||||||
|
|
||||||
|
@Column(name = "shop_variant_color_hex", length = Integer.MAX_VALUE)
|
||||||
|
private String shopVariantColorHex;
|
||||||
|
|
||||||
@Column(name = "material_code", length = Integer.MAX_VALUE)
|
@Column(name = "material_code", length = Integer.MAX_VALUE)
|
||||||
private String materialCode;
|
private String materialCode;
|
||||||
|
|
||||||
@@ -102,6 +134,41 @@ public class QuoteLineItem {
|
|||||||
@Column(name = "updated_at", nullable = false)
|
@Column(name = "updated_at", nullable = false)
|
||||||
private OffsetDateTime updatedAt;
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = now;
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = now;
|
||||||
|
}
|
||||||
|
if (quantity == null) {
|
||||||
|
quantity = 1;
|
||||||
|
}
|
||||||
|
if (lineItemType == null || lineItemType.isBlank()) {
|
||||||
|
lineItemType = "PRINT_FILE";
|
||||||
|
}
|
||||||
|
if ((displayName == null || displayName.isBlank()) && originalFilename != null && !originalFilename.isBlank()) {
|
||||||
|
displayName = originalFilename;
|
||||||
|
} else if ((displayName == null || displayName.isBlank()) && shopProductName != null && !shopProductName.isBlank()) {
|
||||||
|
displayName = shopProductName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
private void onUpdate() {
|
||||||
|
updatedAt = OffsetDateTime.now();
|
||||||
|
if (lineItemType == null || lineItemType.isBlank()) {
|
||||||
|
lineItemType = "PRINT_FILE";
|
||||||
|
}
|
||||||
|
if ((displayName == null || displayName.isBlank()) && originalFilename != null && !originalFilename.isBlank()) {
|
||||||
|
displayName = originalFilename;
|
||||||
|
} else if ((displayName == null || displayName.isBlank()) && shopProductName != null && !shopProductName.isBlank()) {
|
||||||
|
displayName = shopProductName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -126,6 +193,14 @@ public class QuoteLineItem {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLineItemType() {
|
||||||
|
return lineItemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLineItemType(String lineItemType) {
|
||||||
|
this.lineItemType = lineItemType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getOriginalFilename() {
|
public String getOriginalFilename() {
|
||||||
return originalFilename;
|
return originalFilename;
|
||||||
}
|
}
|
||||||
@@ -134,6 +209,14 @@ public class QuoteLineItem {
|
|||||||
this.originalFilename = originalFilename;
|
this.originalFilename = originalFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getQuantity() {
|
public Integer getQuantity() {
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
@@ -158,6 +241,62 @@ public class QuoteLineItem {
|
|||||||
this.filamentVariant = filamentVariant;
|
this.filamentVariant = filamentVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShopProduct getShopProduct() {
|
||||||
|
return shopProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProduct(ShopProduct shopProduct) {
|
||||||
|
this.shopProduct = shopProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductVariant getShopProductVariant() {
|
||||||
|
return shopProductVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductVariant(ShopProductVariant shopProductVariant) {
|
||||||
|
this.shopProductVariant = shopProductVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopProductSlug() {
|
||||||
|
return shopProductSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductSlug(String shopProductSlug) {
|
||||||
|
this.shopProductSlug = shopProductSlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopProductName() {
|
||||||
|
return shopProductName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopProductName(String shopProductName) {
|
||||||
|
this.shopProductName = shopProductName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopVariantLabel() {
|
||||||
|
return shopVariantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopVariantLabel(String shopVariantLabel) {
|
||||||
|
this.shopVariantLabel = shopVariantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopVariantColorName() {
|
||||||
|
return shopVariantColorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopVariantColorName(String shopVariantColorName) {
|
||||||
|
this.shopVariantColorName = shopVariantColorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopVariantColorHex() {
|
||||||
|
return shopVariantColorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShopVariantColorHex(String shopVariantColorHex) {
|
||||||
|
this.shopVariantColorHex = shopVariantColorHex;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMaterialCode() {
|
public String getMaterialCode() {
|
||||||
return materialCode;
|
return materialCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public class QuoteSession {
|
|||||||
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "status", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
@ColumnDefault("'PRINT_QUOTE'")
|
||||||
|
@Column(name = "session_type", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String sessionType;
|
||||||
|
|
||||||
@Column(name = "pricing_version", nullable = false, length = Integer.MAX_VALUE)
|
@Column(name = "pricing_version", nullable = false, length = Integer.MAX_VALUE)
|
||||||
private String pricingVersion;
|
private String pricingVersion;
|
||||||
|
|
||||||
@@ -70,6 +74,19 @@ public class QuoteSession {
|
|||||||
@Column(name = "cad_hourly_rate_chf", precision = 10, scale = 2)
|
@Column(name = "cad_hourly_rate_chf", precision = 10, scale = 2)
|
||||||
private BigDecimal cadHourlyRateChf;
|
private BigDecimal cadHourlyRateChf;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
if (sessionType == null || sessionType.isBlank()) {
|
||||||
|
sessionType = "PRINT_QUOTE";
|
||||||
|
}
|
||||||
|
if (supportsEnabled == null) {
|
||||||
|
supportsEnabled = false;
|
||||||
|
}
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = OffsetDateTime.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -86,6 +103,14 @@ public class QuoteSession {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSessionType() {
|
||||||
|
return sessionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionType(String sessionType) {
|
||||||
|
this.sessionType = sessionType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPricingVersion() {
|
public String getPricingVersion() {
|
||||||
return pricingVersion;
|
return pricingVersion;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,505 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Index;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.PrePersist;
|
||||||
|
import jakarta.persistence.PreUpdate;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "shop_category", indexes = {
|
||||||
|
@Index(name = "ix_shop_category_parent_sort", columnList = "parent_category_id, sort_order"),
|
||||||
|
@Index(name = "ix_shop_category_active_sort", columnList = "is_active, sort_order")
|
||||||
|
})
|
||||||
|
public class ShopCategory {
|
||||||
|
public static final List<String> SUPPORTED_LANGUAGES = List.of("it", "en", "de", "fr");
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "shop_category_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "parent_category_id")
|
||||||
|
private ShopCategory parentCategory;
|
||||||
|
|
||||||
|
@Column(name = "slug", nullable = false, unique = true, length = Integer.MAX_VALUE)
|
||||||
|
private String slug;
|
||||||
|
|
||||||
|
@Column(name = "name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "name_it", length = Integer.MAX_VALUE)
|
||||||
|
private String nameIt;
|
||||||
|
|
||||||
|
@Column(name = "name_en", length = Integer.MAX_VALUE)
|
||||||
|
private String nameEn;
|
||||||
|
|
||||||
|
@Column(name = "name_de", length = Integer.MAX_VALUE)
|
||||||
|
private String nameDe;
|
||||||
|
|
||||||
|
@Column(name = "name_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String nameFr;
|
||||||
|
|
||||||
|
@Column(name = "description", length = Integer.MAX_VALUE)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "description_it", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionIt;
|
||||||
|
|
||||||
|
@Column(name = "description_en", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionEn;
|
||||||
|
|
||||||
|
@Column(name = "description_de", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionDe;
|
||||||
|
|
||||||
|
@Column(name = "description_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionFr;
|
||||||
|
|
||||||
|
@Column(name = "seo_title", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_it", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleIt;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_en", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleEn;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_de", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleDe;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleFr;
|
||||||
|
|
||||||
|
@Column(name = "seo_description", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_it", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionIt;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_en", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionEn;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_de", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionDe;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionFr;
|
||||||
|
|
||||||
|
@Column(name = "og_title", length = Integer.MAX_VALUE)
|
||||||
|
private String ogTitle;
|
||||||
|
|
||||||
|
@Column(name = "og_description", length = Integer.MAX_VALUE)
|
||||||
|
private String ogDescription;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "indexable", nullable = false)
|
||||||
|
private Boolean indexable;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("0")
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = now;
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = now;
|
||||||
|
}
|
||||||
|
if (indexable == null) {
|
||||||
|
indexable = true;
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
if (sortOrder == null) {
|
||||||
|
sortOrder = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
private void onUpdate() {
|
||||||
|
updatedAt = OffsetDateTime.now();
|
||||||
|
if (indexable == null) {
|
||||||
|
indexable = true;
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
if (sortOrder == null) {
|
||||||
|
sortOrder = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopCategory getParentCategory() {
|
||||||
|
return parentCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentCategory(ShopCategory parentCategory) {
|
||||||
|
this.parentCategory = parentCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameIt() {
|
||||||
|
return nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameIt(String nameIt) {
|
||||||
|
this.nameIt = nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEn() {
|
||||||
|
return nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameEn(String nameEn) {
|
||||||
|
this.nameEn = nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameDe() {
|
||||||
|
return nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameDe(String nameDe) {
|
||||||
|
this.nameDe = nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFr() {
|
||||||
|
return nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameFr(String nameFr) {
|
||||||
|
this.nameFr = nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionIt() {
|
||||||
|
return descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionIt(String descriptionIt) {
|
||||||
|
this.descriptionIt = descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionEn() {
|
||||||
|
return descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionEn(String descriptionEn) {
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionDe() {
|
||||||
|
return descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionDe(String descriptionDe) {
|
||||||
|
this.descriptionDe = descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionFr() {
|
||||||
|
return descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionFr(String descriptionFr) {
|
||||||
|
this.descriptionFr = descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleIt() {
|
||||||
|
return seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleIt(String seoTitleIt) {
|
||||||
|
this.seoTitleIt = seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleEn() {
|
||||||
|
return seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleEn(String seoTitleEn) {
|
||||||
|
this.seoTitleEn = seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleDe() {
|
||||||
|
return seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleDe(String seoTitleDe) {
|
||||||
|
this.seoTitleDe = seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleFr() {
|
||||||
|
return seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleFr(String seoTitleFr) {
|
||||||
|
this.seoTitleFr = seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionIt() {
|
||||||
|
return seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionIt(String seoDescriptionIt) {
|
||||||
|
this.seoDescriptionIt = seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionEn() {
|
||||||
|
return seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionEn(String seoDescriptionEn) {
|
||||||
|
this.seoDescriptionEn = seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionDe() {
|
||||||
|
return seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionDe(String seoDescriptionDe) {
|
||||||
|
this.seoDescriptionDe = seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionFr() {
|
||||||
|
return seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionFr(String seoDescriptionFr) {
|
||||||
|
this.seoDescriptionFr = seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgTitle() {
|
||||||
|
return ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgTitle(String ogTitle) {
|
||||||
|
this.ogTitle = ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgDescription() {
|
||||||
|
return ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgDescription(String ogDescription) {
|
||||||
|
this.ogDescription = ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIndexable() {
|
||||||
|
return indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexable(Boolean indexable) {
|
||||||
|
this.indexable = indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 String getNameForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, name, nameIt, nameEn, nameDe, nameFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> nameIt = value;
|
||||||
|
case "en" -> nameEn = value;
|
||||||
|
case "de" -> nameDe = value;
|
||||||
|
case "fr" -> nameFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, description, descriptionIt, descriptionEn, descriptionDe, descriptionFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> descriptionIt = value;
|
||||||
|
case "en" -> descriptionEn = value;
|
||||||
|
case "de" -> descriptionDe = value;
|
||||||
|
case "fr" -> descriptionFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, seoTitle, seoTitleIt, seoTitleEn, seoTitleDe, seoTitleFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> seoTitleIt = value;
|
||||||
|
case "en" -> seoTitleEn = value;
|
||||||
|
case "de" -> seoTitleDe = value;
|
||||||
|
case "fr" -> seoTitleFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, seoDescription, seoDescriptionIt, seoDescriptionEn, seoDescriptionDe, seoDescriptionFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> seoDescriptionIt = value;
|
||||||
|
case "en" -> seoDescriptionEn = value;
|
||||||
|
case "de" -> seoDescriptionDe = value;
|
||||||
|
case "fr" -> seoDescriptionFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveLocalizedValue(String language,
|
||||||
|
String fallback,
|
||||||
|
String valueIt,
|
||||||
|
String valueEn,
|
||||||
|
String valueDe,
|
||||||
|
String valueFr) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String preferred = switch (normalizedLanguage) {
|
||||||
|
case "it" -> valueIt;
|
||||||
|
case "en" -> valueEn;
|
||||||
|
case "de" -> valueDe;
|
||||||
|
case "fr" -> valueFr;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
String resolved = firstNonBlank(preferred, fallback);
|
||||||
|
if (resolved != null) {
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
return firstNonBlank(valueIt, valueEn, valueDe, valueFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeLanguage(String language) {
|
||||||
|
if (language == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalized = language.trim().toLowerCase();
|
||||||
|
int separatorIndex = normalized.indexOf('-');
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
normalized = normalized.substring(0, separatorIndex);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,593 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Index;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.PrePersist;
|
||||||
|
import jakarta.persistence.PreUpdate;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "shop_product", indexes = {
|
||||||
|
@Index(name = "ix_shop_product_category_active_sort", columnList = "shop_category_id, is_active, sort_order"),
|
||||||
|
@Index(name = "ix_shop_product_featured_sort", columnList = "is_featured, is_active, sort_order")
|
||||||
|
})
|
||||||
|
public class ShopProduct {
|
||||||
|
public static final List<String> SUPPORTED_LANGUAGES = List.of("it", "en", "de", "fr");
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "shop_product_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@JoinColumn(name = "shop_category_id", nullable = false)
|
||||||
|
private ShopCategory category;
|
||||||
|
|
||||||
|
@Column(name = "slug", nullable = false, unique = true, length = Integer.MAX_VALUE)
|
||||||
|
private String slug;
|
||||||
|
|
||||||
|
@Column(name = "name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "name_it", length = Integer.MAX_VALUE)
|
||||||
|
private String nameIt;
|
||||||
|
|
||||||
|
@Column(name = "name_en", length = Integer.MAX_VALUE)
|
||||||
|
private String nameEn;
|
||||||
|
|
||||||
|
@Column(name = "name_de", length = Integer.MAX_VALUE)
|
||||||
|
private String nameDe;
|
||||||
|
|
||||||
|
@Column(name = "name_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String nameFr;
|
||||||
|
|
||||||
|
@Column(name = "excerpt", length = Integer.MAX_VALUE)
|
||||||
|
private String excerpt;
|
||||||
|
|
||||||
|
@Column(name = "excerpt_it", length = Integer.MAX_VALUE)
|
||||||
|
private String excerptIt;
|
||||||
|
|
||||||
|
@Column(name = "excerpt_en", length = Integer.MAX_VALUE)
|
||||||
|
private String excerptEn;
|
||||||
|
|
||||||
|
@Column(name = "excerpt_de", length = Integer.MAX_VALUE)
|
||||||
|
private String excerptDe;
|
||||||
|
|
||||||
|
@Column(name = "excerpt_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String excerptFr;
|
||||||
|
|
||||||
|
@Column(name = "description", length = Integer.MAX_VALUE)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "description_it", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionIt;
|
||||||
|
|
||||||
|
@Column(name = "description_en", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionEn;
|
||||||
|
|
||||||
|
@Column(name = "description_de", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionDe;
|
||||||
|
|
||||||
|
@Column(name = "description_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String descriptionFr;
|
||||||
|
|
||||||
|
@Column(name = "seo_title", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_it", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleIt;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_en", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleEn;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_de", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleDe;
|
||||||
|
|
||||||
|
@Column(name = "seo_title_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String seoTitleFr;
|
||||||
|
|
||||||
|
@Column(name = "seo_description", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_it", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionIt;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_en", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionEn;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_de", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionDe;
|
||||||
|
|
||||||
|
@Column(name = "seo_description_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String seoDescriptionFr;
|
||||||
|
|
||||||
|
@Column(name = "og_title", length = Integer.MAX_VALUE)
|
||||||
|
private String ogTitle;
|
||||||
|
|
||||||
|
@Column(name = "og_description", length = Integer.MAX_VALUE)
|
||||||
|
private String ogDescription;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "indexable", nullable = false)
|
||||||
|
private Boolean indexable;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "is_featured", nullable = false)
|
||||||
|
private Boolean isFeatured;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("0")
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = now;
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = now;
|
||||||
|
}
|
||||||
|
if (indexable == null) {
|
||||||
|
indexable = true;
|
||||||
|
}
|
||||||
|
if (isFeatured == null) {
|
||||||
|
isFeatured = false;
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
if (sortOrder == null) {
|
||||||
|
sortOrder = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
private void onUpdate() {
|
||||||
|
updatedAt = OffsetDateTime.now();
|
||||||
|
if (indexable == null) {
|
||||||
|
indexable = true;
|
||||||
|
}
|
||||||
|
if (isFeatured == null) {
|
||||||
|
isFeatured = false;
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
if (sortOrder == null) {
|
||||||
|
sortOrder = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopCategory getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(ShopCategory category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameIt() {
|
||||||
|
return nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameIt(String nameIt) {
|
||||||
|
this.nameIt = nameIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameEn() {
|
||||||
|
return nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameEn(String nameEn) {
|
||||||
|
this.nameEn = nameEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameDe() {
|
||||||
|
return nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameDe(String nameDe) {
|
||||||
|
this.nameDe = nameDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameFr() {
|
||||||
|
return nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameFr(String nameFr) {
|
||||||
|
this.nameFr = nameFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerpt() {
|
||||||
|
return excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerpt(String excerpt) {
|
||||||
|
this.excerpt = excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptIt() {
|
||||||
|
return excerptIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptIt(String excerptIt) {
|
||||||
|
this.excerptIt = excerptIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptEn() {
|
||||||
|
return excerptEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptEn(String excerptEn) {
|
||||||
|
this.excerptEn = excerptEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptDe() {
|
||||||
|
return excerptDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptDe(String excerptDe) {
|
||||||
|
this.excerptDe = excerptDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptFr() {
|
||||||
|
return excerptFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptFr(String excerptFr) {
|
||||||
|
this.excerptFr = excerptFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionIt() {
|
||||||
|
return descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionIt(String descriptionIt) {
|
||||||
|
this.descriptionIt = descriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionEn() {
|
||||||
|
return descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionEn(String descriptionEn) {
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionDe() {
|
||||||
|
return descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionDe(String descriptionDe) {
|
||||||
|
this.descriptionDe = descriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionFr() {
|
||||||
|
return descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionFr(String descriptionFr) {
|
||||||
|
this.descriptionFr = descriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleIt() {
|
||||||
|
return seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleIt(String seoTitleIt) {
|
||||||
|
this.seoTitleIt = seoTitleIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleEn() {
|
||||||
|
return seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleEn(String seoTitleEn) {
|
||||||
|
this.seoTitleEn = seoTitleEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleDe() {
|
||||||
|
return seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleDe(String seoTitleDe) {
|
||||||
|
this.seoTitleDe = seoTitleDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleFr() {
|
||||||
|
return seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleFr(String seoTitleFr) {
|
||||||
|
this.seoTitleFr = seoTitleFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionIt() {
|
||||||
|
return seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionIt(String seoDescriptionIt) {
|
||||||
|
this.seoDescriptionIt = seoDescriptionIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionEn() {
|
||||||
|
return seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionEn(String seoDescriptionEn) {
|
||||||
|
this.seoDescriptionEn = seoDescriptionEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionDe() {
|
||||||
|
return seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionDe(String seoDescriptionDe) {
|
||||||
|
this.seoDescriptionDe = seoDescriptionDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionFr() {
|
||||||
|
return seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionFr(String seoDescriptionFr) {
|
||||||
|
this.seoDescriptionFr = seoDescriptionFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgTitle() {
|
||||||
|
return ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgTitle(String ogTitle) {
|
||||||
|
this.ogTitle = ogTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOgDescription() {
|
||||||
|
return ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOgDescription(String ogDescription) {
|
||||||
|
this.ogDescription = ogDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIndexable() {
|
||||||
|
return indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndexable(Boolean indexable) {
|
||||||
|
this.indexable = indexable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsFeatured() {
|
||||||
|
return isFeatured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsFeatured(Boolean featured) {
|
||||||
|
isFeatured = featured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 String getNameForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, name, nameIt, nameEn, nameDe, nameFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> nameIt = value;
|
||||||
|
case "en" -> nameEn = value;
|
||||||
|
case "de" -> nameDe = value;
|
||||||
|
case "fr" -> nameFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExcerptForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, excerpt, excerptIt, excerptEn, excerptDe, excerptFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcerptForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> excerptIt = value;
|
||||||
|
case "en" -> excerptEn = value;
|
||||||
|
case "de" -> excerptDe = value;
|
||||||
|
case "fr" -> excerptFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, description, descriptionIt, descriptionEn, descriptionDe, descriptionFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> descriptionIt = value;
|
||||||
|
case "en" -> descriptionEn = value;
|
||||||
|
case "de" -> descriptionDe = value;
|
||||||
|
case "fr" -> descriptionFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitleForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, seoTitle, seoTitleIt, seoTitleEn, seoTitleDe, seoTitleFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitleForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> seoTitleIt = value;
|
||||||
|
case "en" -> seoTitleEn = value;
|
||||||
|
case "de" -> seoTitleDe = value;
|
||||||
|
case "fr" -> seoTitleFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescriptionForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(language, seoDescription, seoDescriptionIt, seoDescriptionEn, seoDescriptionDe, seoDescriptionFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescriptionForLanguage(String language, String value) {
|
||||||
|
switch (normalizeLanguage(language)) {
|
||||||
|
case "it" -> seoDescriptionIt = value;
|
||||||
|
case "en" -> seoDescriptionEn = value;
|
||||||
|
case "de" -> seoDescriptionDe = value;
|
||||||
|
case "fr" -> seoDescriptionFr = value;
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveLocalizedValue(String language,
|
||||||
|
String fallback,
|
||||||
|
String valueIt,
|
||||||
|
String valueEn,
|
||||||
|
String valueDe,
|
||||||
|
String valueFr) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String preferred = switch (normalizedLanguage) {
|
||||||
|
case "it" -> valueIt;
|
||||||
|
case "en" -> valueEn;
|
||||||
|
case "de" -> valueDe;
|
||||||
|
case "fr" -> valueFr;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
String resolved = firstNonBlank(preferred, fallback);
|
||||||
|
if (resolved != null) {
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
return firstNonBlank(valueIt, valueEn, valueDe, valueFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeLanguage(String language) {
|
||||||
|
if (language == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalized = language.trim().toLowerCase();
|
||||||
|
int separatorIndex = normalized.indexOf('-');
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
normalized = normalized.substring(0, separatorIndex);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Index;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
import jakarta.persistence.PrePersist;
|
||||||
|
import jakarta.persistence.PreUpdate;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "shop_product_model_asset", indexes = {
|
||||||
|
@Index(name = "ix_shop_product_model_asset_product", columnList = "shop_product_id")
|
||||||
|
})
|
||||||
|
public class ShopProductModelAsset {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "shop_product_model_asset_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@OneToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@JoinColumn(name = "shop_product_id", nullable = false, unique = true)
|
||||||
|
private ShopProduct product;
|
||||||
|
|
||||||
|
@Column(name = "original_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String originalFilename;
|
||||||
|
|
||||||
|
@Column(name = "stored_relative_path", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String storedRelativePath;
|
||||||
|
|
||||||
|
@Column(name = "stored_filename", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String storedFilename;
|
||||||
|
|
||||||
|
@Column(name = "file_size_bytes")
|
||||||
|
private Long fileSizeBytes;
|
||||||
|
|
||||||
|
@Column(name = "mime_type", length = Integer.MAX_VALUE)
|
||||||
|
private String mimeType;
|
||||||
|
|
||||||
|
@Column(name = "sha256_hex", length = Integer.MAX_VALUE)
|
||||||
|
private String sha256Hex;
|
||||||
|
|
||||||
|
@Column(name = "bounding_box_x_mm", precision = 10, scale = 3)
|
||||||
|
private BigDecimal boundingBoxXMm;
|
||||||
|
|
||||||
|
@Column(name = "bounding_box_y_mm", precision = 10, scale = 3)
|
||||||
|
private BigDecimal boundingBoxYMm;
|
||||||
|
|
||||||
|
@Column(name = "bounding_box_z_mm", precision = 10, scale = 3)
|
||||||
|
private BigDecimal boundingBoxZMm;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = now;
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
private void onUpdate() {
|
||||||
|
updatedAt = OffsetDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProduct getProduct() {
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProduct(ShopProduct product) {
|
||||||
|
this.product = product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalFilename() {
|
||||||
|
return originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalFilename(String originalFilename) {
|
||||||
|
this.originalFilename = originalFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredRelativePath() {
|
||||||
|
return storedRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredRelativePath(String storedRelativePath) {
|
||||||
|
this.storedRelativePath = storedRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStoredFilename() {
|
||||||
|
return storedFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredFilename(String storedFilename) {
|
||||||
|
this.storedFilename = storedFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getFileSizeBytes() {
|
||||||
|
return fileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSizeBytes(Long fileSizeBytes) {
|
||||||
|
this.fileSizeBytes = fileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMimeType() {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMimeType(String mimeType) {
|
||||||
|
this.mimeType = mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSha256Hex() {
|
||||||
|
return sha256Hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSha256Hex(String sha256Hex) {
|
||||||
|
this.sha256Hex = sha256Hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBoundingBoxXMm() {
|
||||||
|
return boundingBoxXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundingBoxXMm(BigDecimal boundingBoxXMm) {
|
||||||
|
this.boundingBoxXMm = boundingBoxXMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBoundingBoxYMm() {
|
||||||
|
return boundingBoxYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundingBoxYMm(BigDecimal boundingBoxYMm) {
|
||||||
|
this.boundingBoxYMm = boundingBoxYMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBoundingBoxZMm() {
|
||||||
|
return boundingBoxZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundingBoxZMm(BigDecimal boundingBoxZMm) {
|
||||||
|
this.boundingBoxZMm = boundingBoxZMm;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,318 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Index;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.PrePersist;
|
||||||
|
import jakarta.persistence.PreUpdate;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "shop_product_variant", indexes = {
|
||||||
|
@Index(name = "ix_shop_product_variant_product_active_sort", columnList = "shop_product_id, is_active, sort_order"),
|
||||||
|
@Index(name = "ix_shop_product_variant_sku", columnList = "sku")
|
||||||
|
})
|
||||||
|
public class ShopProductVariant {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
@Column(name = "shop_product_variant_id", nullable = false)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||||
|
@JoinColumn(name = "shop_product_id", nullable = false)
|
||||||
|
private ShopProduct product;
|
||||||
|
|
||||||
|
@Column(name = "sku", unique = true, length = Integer.MAX_VALUE)
|
||||||
|
private String sku;
|
||||||
|
|
||||||
|
@Column(name = "variant_label", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String variantLabel;
|
||||||
|
|
||||||
|
@Column(name = "color_name", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String colorName;
|
||||||
|
|
||||||
|
@Column(name = "color_label_it", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelIt;
|
||||||
|
|
||||||
|
@Column(name = "color_label_en", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelEn;
|
||||||
|
|
||||||
|
@Column(name = "color_label_de", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelDe;
|
||||||
|
|
||||||
|
@Column(name = "color_label_fr", length = Integer.MAX_VALUE)
|
||||||
|
private String colorLabelFr;
|
||||||
|
|
||||||
|
@Column(name = "color_hex", length = Integer.MAX_VALUE)
|
||||||
|
private String colorHex;
|
||||||
|
|
||||||
|
@Column(name = "internal_material_code", nullable = false, length = Integer.MAX_VALUE)
|
||||||
|
private String internalMaterialCode;
|
||||||
|
|
||||||
|
@ColumnDefault("0.00")
|
||||||
|
@Column(name = "price_chf", nullable = false, precision = 12, scale = 2)
|
||||||
|
private BigDecimal priceChf;
|
||||||
|
|
||||||
|
@ColumnDefault("false")
|
||||||
|
@Column(name = "is_default", nullable = false)
|
||||||
|
private Boolean isDefault;
|
||||||
|
|
||||||
|
@ColumnDefault("true")
|
||||||
|
@Column(name = "is_active", nullable = false)
|
||||||
|
private Boolean isActive;
|
||||||
|
|
||||||
|
@ColumnDefault("0")
|
||||||
|
@Column(name = "sort_order", nullable = false)
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_at", nullable = false)
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_at", nullable = false)
|
||||||
|
private OffsetDateTime updatedAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void onCreate() {
|
||||||
|
OffsetDateTime now = OffsetDateTime.now();
|
||||||
|
if (createdAt == null) {
|
||||||
|
createdAt = now;
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = now;
|
||||||
|
}
|
||||||
|
if (priceChf == null) {
|
||||||
|
priceChf = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
if (isDefault == null) {
|
||||||
|
isDefault = false;
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
if (sortOrder == null) {
|
||||||
|
sortOrder = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
private void onUpdate() {
|
||||||
|
updatedAt = OffsetDateTime.now();
|
||||||
|
if (priceChf == null) {
|
||||||
|
priceChf = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
if (isDefault == null) {
|
||||||
|
isDefault = false;
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
if (sortOrder == null) {
|
||||||
|
sortOrder = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProduct getProduct() {
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProduct(ShopProduct product) {
|
||||||
|
this.product = product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSku() {
|
||||||
|
return sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSku(String sku) {
|
||||||
|
this.sku = sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVariantLabel() {
|
||||||
|
return variantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariantLabel(String variantLabel) {
|
||||||
|
this.variantLabel = variantLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorName() {
|
||||||
|
return colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorName(String colorName) {
|
||||||
|
this.colorName = colorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelIt() {
|
||||||
|
return colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelIt(String colorLabelIt) {
|
||||||
|
this.colorLabelIt = colorLabelIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelEn() {
|
||||||
|
return colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelEn(String colorLabelEn) {
|
||||||
|
this.colorLabelEn = colorLabelEn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelDe() {
|
||||||
|
return colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelDe(String colorLabelDe) {
|
||||||
|
this.colorLabelDe = colorLabelDe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorLabelFr() {
|
||||||
|
return colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorLabelFr(String colorLabelFr) {
|
||||||
|
this.colorLabelFr = colorLabelFr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColorHex() {
|
||||||
|
return colorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorHex(String colorHex) {
|
||||||
|
this.colorHex = colorHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInternalMaterialCode() {
|
||||||
|
return internalMaterialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInternalMaterialCode(String internalMaterialCode) {
|
||||||
|
this.internalMaterialCode = internalMaterialCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPriceChf() {
|
||||||
|
return priceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriceChf(BigDecimal priceChf) {
|
||||||
|
this.priceChf = priceChf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsDefault() {
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDefault(Boolean aDefault) {
|
||||||
|
isDefault = aDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsActive(Boolean active) {
|
||||||
|
isActive = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSortOrder() {
|
||||||
|
return sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortOrder(Integer sortOrder) {
|
||||||
|
this.sortOrder = sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 String getColorLabelForLanguage(String language) {
|
||||||
|
return resolveLocalizedValue(
|
||||||
|
language,
|
||||||
|
colorName,
|
||||||
|
colorLabelIt,
|
||||||
|
colorLabelEn,
|
||||||
|
colorLabelDe,
|
||||||
|
colorLabelFr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveLocalizedValue(String language,
|
||||||
|
String fallback,
|
||||||
|
String valueIt,
|
||||||
|
String valueEn,
|
||||||
|
String valueDe,
|
||||||
|
String valueFr) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String preferred = switch (normalizedLanguage) {
|
||||||
|
case "it" -> valueIt;
|
||||||
|
case "en" -> valueEn;
|
||||||
|
case "de" -> valueDe;
|
||||||
|
case "fr" -> valueFr;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
String resolved = firstNonBlank(preferred, fallback);
|
||||||
|
if (resolved != null) {
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
return firstNonBlank(valueIt, valueEn, valueDe, valueFr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeLanguage(String language) {
|
||||||
|
if (language == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalized = language.trim().toLowerCase();
|
||||||
|
int separatorIndex = normalized.indexOf('-');
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
normalized = normalized.substring(0, separatorIndex);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -223,10 +223,15 @@ public class OrderEmailListener {
|
|||||||
order.getCreatedAt().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(locale))
|
order.getCreatedAt().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(locale))
|
||||||
);
|
);
|
||||||
templateData.put("totalCost", currencyFormatter.format(order.getTotalChf()));
|
templateData.put("totalCost", currencyFormatter.format(order.getTotalChf()));
|
||||||
|
templateData.put("logoUrl", buildLogoUrl());
|
||||||
templateData.put("currentYear", Year.now().getValue());
|
templateData.put("currentYear", Year.now().getValue());
|
||||||
return templateData;
|
return templateData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String buildLogoUrl() {
|
||||||
|
return frontendBaseUrl.replaceAll("/+$", "") + "/assets/images/brand-logo-yellow.svg";
|
||||||
|
}
|
||||||
|
|
||||||
private String applyOrderConfirmationTexts(Map<String, Object> templateData, String language, String orderNumber) {
|
private String applyOrderConfirmationTexts(Map<String, Object> templateData, String language, String orderNumber) {
|
||||||
return switch (language) {
|
return switch (language) {
|
||||||
case "en" -> {
|
case "en" -> {
|
||||||
|
|||||||
@@ -17,6 +17,19 @@ public interface MediaUsageRepository extends JpaRepository<MediaUsage, UUID> {
|
|||||||
List<MediaUsage> findByUsageTypeAndUsageKeyAndIsActiveTrueOrderBySortOrderAscCreatedAtAsc(String usageType,
|
List<MediaUsage> findByUsageTypeAndUsageKeyAndIsActiveTrueOrderBySortOrderAscCreatedAtAsc(String usageType,
|
||||||
String usageKey);
|
String usageKey);
|
||||||
|
|
||||||
|
List<MediaUsage> findByUsageTypeAndUsageKeyOrderBySortOrderAscCreatedAtAsc(String usageType,
|
||||||
|
String usageKey);
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
select usage from MediaUsage usage
|
||||||
|
where usage.usageType = :usageType
|
||||||
|
and usage.usageKey in :usageKeys
|
||||||
|
and usage.isActive = true
|
||||||
|
order by usage.usageKey asc, usage.sortOrder asc, usage.createdAt asc
|
||||||
|
""")
|
||||||
|
List<MediaUsage> findActiveByUsageTypeAndUsageKeys(@Param("usageType") String usageType,
|
||||||
|
@Param("usageKeys") Collection<String> usageKeys);
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
select usage from MediaUsage usage
|
select usage from MediaUsage usage
|
||||||
where usage.usageType = :usageType
|
where usage.usageType = :usageType
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ import java.util.UUID;
|
|||||||
public interface OrderItemRepository extends JpaRepository<OrderItem, UUID> {
|
public interface OrderItemRepository extends JpaRepository<OrderItem, UUID> {
|
||||||
List<OrderItem> findByOrder_Id(UUID orderId);
|
List<OrderItem> findByOrder_Id(UUID orderId);
|
||||||
boolean existsByFilamentVariant_Id(Long filamentVariantId);
|
boolean existsByFilamentVariant_Id(Long filamentVariantId);
|
||||||
|
boolean existsByShopProduct_Id(UUID shopProductId);
|
||||||
|
boolean existsByShopProductVariant_Id(UUID shopProductVariantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,30 @@
|
|||||||
package com.printcalculator.repository;
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
import com.printcalculator.entity.QuoteLineItem;
|
import com.printcalculator.entity.QuoteLineItem;
|
||||||
|
import org.springframework.data.jpa.repository.EntityGraph;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface QuoteLineItemRepository extends JpaRepository<QuoteLineItem, UUID> {
|
public interface QuoteLineItemRepository extends JpaRepository<QuoteLineItem, UUID> {
|
||||||
|
@EntityGraph(attributePaths = {"filamentVariant", "shopProduct", "shopProductVariant"})
|
||||||
List<QuoteLineItem> findByQuoteSessionId(UUID quoteSessionId);
|
List<QuoteLineItem> findByQuoteSessionId(UUID quoteSessionId);
|
||||||
|
|
||||||
|
@EntityGraph(attributePaths = {"filamentVariant", "shopProduct", "shopProductVariant"})
|
||||||
|
List<QuoteLineItem> findByQuoteSessionIdOrderByCreatedAtAsc(UUID quoteSessionId);
|
||||||
|
|
||||||
|
@EntityGraph(attributePaths = {"filamentVariant", "shopProduct", "shopProductVariant"})
|
||||||
|
Optional<QuoteLineItem> findByIdAndQuoteSession_Id(UUID lineItemId, UUID quoteSessionId);
|
||||||
|
|
||||||
|
@EntityGraph(attributePaths = {"shopProductVariant"})
|
||||||
|
Optional<QuoteLineItem> findFirstByQuoteSession_IdAndLineItemTypeAndShopProductVariant_Id(
|
||||||
|
UUID quoteSessionId,
|
||||||
|
String lineItemType,
|
||||||
|
UUID shopProductVariantId
|
||||||
|
);
|
||||||
boolean existsByFilamentVariant_Id(Long filamentVariantId);
|
boolean existsByFilamentVariant_Id(Long filamentVariantId);
|
||||||
|
boolean existsByShopProduct_Id(UUID shopProductId);
|
||||||
|
boolean existsByShopProductVariant_Id(UUID shopProductVariantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ import com.printcalculator.entity.QuoteSession;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface QuoteSessionRepository extends JpaRepository<QuoteSession, UUID> {
|
public interface QuoteSessionRepository extends JpaRepository<QuoteSession, UUID> {
|
||||||
List<QuoteSession> findByCreatedAtBefore(java.time.OffsetDateTime cutoff);
|
List<QuoteSession> findByCreatedAtBefore(java.time.OffsetDateTime cutoff);
|
||||||
|
|
||||||
List<QuoteSession> findByStatusInOrderByCreatedAtDesc(List<String> statuses);
|
List<QuoteSession> findByStatusInOrderByCreatedAtDesc(List<String> statuses);
|
||||||
|
|
||||||
|
Optional<QuoteSession> findByIdAndSessionType(UUID id, String sessionType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface ShopCategoryRepository extends JpaRepository<ShopCategory, UUID> {
|
||||||
|
Optional<ShopCategory> findBySlug(String slug);
|
||||||
|
|
||||||
|
Optional<ShopCategory> findBySlugIgnoreCase(String slug);
|
||||||
|
|
||||||
|
Optional<ShopCategory> findBySlugAndIsActiveTrue(String slug);
|
||||||
|
|
||||||
|
boolean existsBySlugIgnoreCase(String slug);
|
||||||
|
|
||||||
|
boolean existsByParentCategory_Id(UUID parentCategoryId);
|
||||||
|
|
||||||
|
List<ShopCategory> findAllByOrderBySortOrderAscNameAsc();
|
||||||
|
|
||||||
|
List<ShopCategory> findAllByIsActiveTrueOrderBySortOrderAscNameAsc();
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.ShopProductModelAsset;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface ShopProductModelAssetRepository extends JpaRepository<ShopProductModelAsset, UUID> {
|
||||||
|
Optional<ShopProductModelAsset> findByProduct_Id(UUID productId);
|
||||||
|
|
||||||
|
List<ShopProductModelAsset> findByProduct_IdIn(Collection<UUID> productIds);
|
||||||
|
|
||||||
|
void deleteByProduct_Id(UUID productId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface ShopProductRepository extends JpaRepository<ShopProduct, UUID> {
|
||||||
|
Optional<ShopProduct> findBySlug(String slug);
|
||||||
|
|
||||||
|
Optional<ShopProduct> findBySlugIgnoreCase(String slug);
|
||||||
|
|
||||||
|
Optional<ShopProduct> findBySlugAndIsActiveTrue(String slug);
|
||||||
|
|
||||||
|
boolean existsBySlugIgnoreCase(String slug);
|
||||||
|
|
||||||
|
List<ShopProduct> findAllByOrderBySortOrderAscNameAsc();
|
||||||
|
|
||||||
|
List<ShopProduct> findAllByOrderByIsFeaturedDescSortOrderAscNameAsc();
|
||||||
|
|
||||||
|
List<ShopProduct> findByCategory_IdOrderBySortOrderAscNameAsc(UUID categoryId);
|
||||||
|
|
||||||
|
List<ShopProduct> findAllByIsActiveTrueOrderByIsFeaturedDescSortOrderAscNameAsc();
|
||||||
|
|
||||||
|
boolean existsByCategory_Id(UUID categoryId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.printcalculator.repository;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.ShopProductVariant;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface ShopProductVariantRepository extends JpaRepository<ShopProductVariant, UUID> {
|
||||||
|
List<ShopProductVariant> findByProduct_IdOrderBySortOrderAscColorNameAsc(UUID productId);
|
||||||
|
|
||||||
|
List<ShopProductVariant> findByProduct_IdInOrderBySortOrderAscColorNameAsc(Collection<UUID> productIds);
|
||||||
|
|
||||||
|
List<ShopProductVariant> findByProduct_IdAndIsActiveTrueOrderBySortOrderAscColorNameAsc(UUID productId);
|
||||||
|
|
||||||
|
List<ShopProductVariant> findByProduct_IdInAndIsActiveTrueOrderBySortOrderAscColorNameAsc(Collection<UUID> productIds);
|
||||||
|
|
||||||
|
Optional<ShopProductVariant> findFirstByProduct_IdAndIsDefaultTrue(UUID productId);
|
||||||
|
|
||||||
|
boolean existsBySkuIgnoreCase(String sku);
|
||||||
|
|
||||||
|
boolean existsBySkuIgnoreCaseAndIdNot(String sku, UUID variantId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.printcalculator.security;
|
||||||
|
|
||||||
|
import com.printcalculator.config.AllowedOriginService;
|
||||||
|
import jakarta.servlet.FilterChain;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AdminCsrfProtectionFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
private static final Set<String> SAFE_METHODS = Set.of("GET", "HEAD", "OPTIONS", "TRACE");
|
||||||
|
|
||||||
|
private final AllowedOriginService allowedOriginService;
|
||||||
|
|
||||||
|
public AdminCsrfProtectionFilter(AllowedOriginService allowedOriginService) {
|
||||||
|
this.allowedOriginService = allowedOriginService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean shouldNotFilter(HttpServletRequest request) {
|
||||||
|
String path = resolvePath(request);
|
||||||
|
String method = request.getMethod() == null ? "" : request.getMethod().toUpperCase(Locale.ROOT);
|
||||||
|
return !path.startsWith("/api/admin/") || SAFE_METHODS.contains(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
String origin = request.getHeader(HttpHeaders.ORIGIN);
|
||||||
|
String referer = request.getHeader(HttpHeaders.REFERER);
|
||||||
|
|
||||||
|
if (allowedOriginService.isAllowed(origin) || allowedOriginService.isAllowed(referer)) {
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
response.getWriter().write("{\"error\":\"CSRF_INVALID\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolvePath(HttpServletRequest request) {
|
||||||
|
String path = request.getRequestURI();
|
||||||
|
String contextPath = request.getContextPath();
|
||||||
|
if (contextPath != null && !contextPath.isEmpty() && path.startsWith(contextPath)) {
|
||||||
|
return path.substring(contextPath.length());
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import java.util.*;
|
|||||||
@Service
|
@Service
|
||||||
public class OrderService {
|
public class OrderService {
|
||||||
private static final Path QUOTE_STORAGE_ROOT = Paths.get("storage_quotes").toAbsolutePath().normalize();
|
private static final Path QUOTE_STORAGE_ROOT = Paths.get("storage_quotes").toAbsolutePath().normalize();
|
||||||
|
private static final String SHOP_LINE_ITEM_TYPE = "SHOP_PRODUCT";
|
||||||
|
|
||||||
private final OrderRepository orderRepo;
|
private final OrderRepository orderRepo;
|
||||||
private final OrderItemRepository orderItemRepo;
|
private final OrderItemRepository orderItemRepo;
|
||||||
@@ -104,6 +105,7 @@ public class OrderService {
|
|||||||
|
|
||||||
Order order = new Order();
|
Order order = new Order();
|
||||||
order.setSourceQuoteSession(session);
|
order.setSourceQuoteSession(session);
|
||||||
|
order.setSourceType(resolveOrderSourceType(session));
|
||||||
order.setCustomer(customer);
|
order.setCustomer(customer);
|
||||||
order.setCustomerEmail(request.getCustomer().getEmail());
|
order.setCustomerEmail(request.getCustomer().getEmail());
|
||||||
order.setCustomerPhone(request.getCustomer().getPhone());
|
order.setCustomerPhone(request.getCustomer().getPhone());
|
||||||
@@ -172,12 +174,27 @@ public class OrderService {
|
|||||||
for (QuoteLineItem qItem : quoteItems) {
|
for (QuoteLineItem qItem : quoteItems) {
|
||||||
OrderItem oItem = new OrderItem();
|
OrderItem oItem = new OrderItem();
|
||||||
oItem.setOrder(order);
|
oItem.setOrder(order);
|
||||||
|
oItem.setItemType(qItem.getLineItemType() != null ? qItem.getLineItemType() : "PRINT_FILE");
|
||||||
oItem.setOriginalFilename(qItem.getOriginalFilename());
|
oItem.setOriginalFilename(qItem.getOriginalFilename());
|
||||||
|
oItem.setDisplayName(
|
||||||
|
qItem.getDisplayName() != null && !qItem.getDisplayName().isBlank()
|
||||||
|
? qItem.getDisplayName()
|
||||||
|
: qItem.getOriginalFilename()
|
||||||
|
);
|
||||||
int quantity = qItem.getQuantity() != null && qItem.getQuantity() > 0 ? qItem.getQuantity() : 1;
|
int quantity = qItem.getQuantity() != null && qItem.getQuantity() > 0 ? qItem.getQuantity() : 1;
|
||||||
oItem.setQuantity(quantity);
|
oItem.setQuantity(quantity);
|
||||||
oItem.setColorCode(qItem.getColorCode());
|
oItem.setColorCode(qItem.getColorCode());
|
||||||
oItem.setFilamentVariant(qItem.getFilamentVariant());
|
oItem.setFilamentVariant(qItem.getFilamentVariant());
|
||||||
if (qItem.getFilamentVariant() != null
|
oItem.setShopProduct(qItem.getShopProduct());
|
||||||
|
oItem.setShopProductVariant(qItem.getShopProductVariant());
|
||||||
|
oItem.setShopProductSlug(qItem.getShopProductSlug());
|
||||||
|
oItem.setShopProductName(qItem.getShopProductName());
|
||||||
|
oItem.setShopVariantLabel(qItem.getShopVariantLabel());
|
||||||
|
oItem.setShopVariantColorName(qItem.getShopVariantColorName());
|
||||||
|
oItem.setShopVariantColorHex(qItem.getShopVariantColorHex());
|
||||||
|
if (qItem.getMaterialCode() != null && !qItem.getMaterialCode().isBlank()) {
|
||||||
|
oItem.setMaterialCode(qItem.getMaterialCode());
|
||||||
|
} else if (qItem.getFilamentVariant() != null
|
||||||
&& qItem.getFilamentVariant().getFilamentMaterialType() != null
|
&& qItem.getFilamentVariant().getFilamentMaterialType() != null
|
||||||
&& qItem.getFilamentVariant().getFilamentMaterialType().getMaterialCode() != null) {
|
&& qItem.getFilamentVariant().getFilamentMaterialType().getMaterialCode() != null) {
|
||||||
oItem.setMaterialCode(qItem.getFilamentVariant().getFilamentMaterialType().getMaterialCode());
|
oItem.setMaterialCode(qItem.getFilamentVariant().getFilamentMaterialType().getMaterialCode());
|
||||||
@@ -219,18 +236,20 @@ public class OrderService {
|
|||||||
|
|
||||||
oItem = orderItemRepo.save(oItem);
|
oItem = orderItemRepo.save(oItem);
|
||||||
|
|
||||||
String relativePath = "orders/" + order.getId() + "/3d-files/" + oItem.getId() + "/" + storedFilename;
|
|
||||||
oItem.setStoredRelativePath(relativePath);
|
|
||||||
|
|
||||||
Path sourcePath = resolveStoredQuotePath(qItem.getStoredPath(), session.getId());
|
Path sourcePath = resolveStoredQuotePath(qItem.getStoredPath(), session.getId());
|
||||||
if (sourcePath == null || !Files.exists(sourcePath)) {
|
if (sourcePath == null || !Files.exists(sourcePath)) {
|
||||||
throw new IllegalStateException("Source file not available for quote line item " + qItem.getId());
|
if (requiresStoredSourceFile(qItem)) {
|
||||||
}
|
throw new IllegalStateException("Source file not available for quote line item " + qItem.getId());
|
||||||
try {
|
}
|
||||||
storageService.store(sourcePath, Paths.get(relativePath));
|
} else {
|
||||||
oItem.setFileSizeBytes(Files.size(sourcePath));
|
String relativePath = "orders/" + order.getId() + "/3d-files/" + oItem.getId() + "/" + storedFilename;
|
||||||
} catch (IOException e) {
|
oItem.setStoredRelativePath(relativePath);
|
||||||
throw new RuntimeException("Failed to copy quote file for line item " + qItem.getId(), e);
|
try {
|
||||||
|
storageService.store(sourcePath, Paths.get(relativePath));
|
||||||
|
oItem.setFileSizeBytes(Files.size(sourcePath));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to copy quote file for line item " + qItem.getId(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oItem = orderItemRepo.save(oItem);
|
oItem = orderItemRepo.save(oItem);
|
||||||
@@ -302,6 +321,12 @@ public class OrderService {
|
|||||||
return "stl";
|
return "stl";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean requiresStoredSourceFile(QuoteLineItem qItem) {
|
||||||
|
return !SHOP_LINE_ITEM_TYPE.equalsIgnoreCase(
|
||||||
|
qItem.getLineItemType() != null ? qItem.getLineItemType() : ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private Path resolveStoredQuotePath(String storedPath, UUID expectedSessionId) {
|
private Path resolveStoredQuotePath(String storedPath, UUID expectedSessionId) {
|
||||||
if (storedPath == null || storedPath.isBlank()) {
|
if (storedPath == null || storedPath.isBlank()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -319,6 +344,13 @@ public class OrderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveOrderSourceType(QuoteSession session) {
|
||||||
|
if (session != null && "SHOP_CART".equalsIgnoreCase(session.getSessionType())) {
|
||||||
|
return "SHOP";
|
||||||
|
}
|
||||||
|
return "CALCULATOR";
|
||||||
|
}
|
||||||
|
|
||||||
private String getDisplayOrderNumber(Order order) {
|
private String getDisplayOrderNumber(Order order) {
|
||||||
String orderNumber = order.getOrderNumber();
|
String orderNumber = order.getOrderNumber();
|
||||||
if (orderNumber != null && !orderNumber.isBlank()) {
|
if (orderNumber != null && !orderNumber.isBlank()) {
|
||||||
|
|||||||
@@ -161,10 +161,21 @@ public class AdminFilamentControllerService {
|
|||||||
String normalizedColorHex = normalizeAndValidateColorHex(payload.getColorHex());
|
String normalizedColorHex = normalizeAndValidateColorHex(payload.getColorHex());
|
||||||
String normalizedFinishType = normalizeAndValidateFinishType(payload.getFinishType(), payload.getIsMatte());
|
String normalizedFinishType = normalizeAndValidateFinishType(payload.getFinishType(), payload.getIsMatte());
|
||||||
String normalizedBrand = normalizeOptional(payload.getBrand());
|
String normalizedBrand = normalizeOptional(payload.getBrand());
|
||||||
|
String fallbackColorLabel = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getColorLabelIt()),
|
||||||
|
normalizeOptional(payload.getColorLabelEn()),
|
||||||
|
normalizeOptional(payload.getColorLabelDe()),
|
||||||
|
normalizeOptional(payload.getColorLabelFr()),
|
||||||
|
normalizedColorName
|
||||||
|
);
|
||||||
|
|
||||||
variant.setFilamentMaterialType(material);
|
variant.setFilamentMaterialType(material);
|
||||||
variant.setVariantDisplayName(normalizedDisplayName);
|
variant.setVariantDisplayName(normalizedDisplayName);
|
||||||
variant.setColorName(normalizedColorName);
|
variant.setColorName(normalizedColorName);
|
||||||
|
variant.setColorLabelIt(firstNonBlank(normalizeOptional(payload.getColorLabelIt()), fallbackColorLabel));
|
||||||
|
variant.setColorLabelEn(firstNonBlank(normalizeOptional(payload.getColorLabelEn()), fallbackColorLabel));
|
||||||
|
variant.setColorLabelDe(firstNonBlank(normalizeOptional(payload.getColorLabelDe()), fallbackColorLabel));
|
||||||
|
variant.setColorLabelFr(firstNonBlank(normalizeOptional(payload.getColorLabelFr()), fallbackColorLabel));
|
||||||
variant.setColorHex(normalizedColorHex);
|
variant.setColorHex(normalizedColorHex);
|
||||||
variant.setFinishType(normalizedFinishType);
|
variant.setFinishType(normalizedFinishType);
|
||||||
variant.setBrand(normalizedBrand);
|
variant.setBrand(normalizedBrand);
|
||||||
@@ -226,6 +237,18 @@ public class AdminFilamentControllerService {
|
|||||||
return normalized.isBlank() ? null : normalized;
|
return normalized.isBlank() ? null : normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private FilamentMaterialType validateAndResolveMaterial(AdminUpsertFilamentVariantRequest payload) {
|
private FilamentMaterialType validateAndResolveMaterial(AdminUpsertFilamentVariantRequest payload) {
|
||||||
if (payload == null || payload.getMaterialTypeId() == null) {
|
if (payload == null || payload.getMaterialTypeId() == null) {
|
||||||
throw new ResponseStatusException(BAD_REQUEST, "Material type id is required");
|
throw new ResponseStatusException(BAD_REQUEST, "Material type id is required");
|
||||||
@@ -306,6 +329,10 @@ public class AdminFilamentControllerService {
|
|||||||
|
|
||||||
dto.setVariantDisplayName(variant.getVariantDisplayName());
|
dto.setVariantDisplayName(variant.getVariantDisplayName());
|
||||||
dto.setColorName(variant.getColorName());
|
dto.setColorName(variant.getColorName());
|
||||||
|
dto.setColorLabelIt(variant.getColorLabelIt());
|
||||||
|
dto.setColorLabelEn(variant.getColorLabelEn());
|
||||||
|
dto.setColorLabelDe(variant.getColorLabelDe());
|
||||||
|
dto.setColorLabelFr(variant.getColorLabelFr());
|
||||||
dto.setColorHex(variant.getColorHex());
|
dto.setColorHex(variant.getColorHex());
|
||||||
dto.setFinishType(variant.getFinishType());
|
dto.setFinishType(variant.getFinishType());
|
||||||
dto.setBrand(variant.getBrand());
|
dto.setBrand(variant.getBrand());
|
||||||
|
|||||||
@@ -330,6 +330,18 @@ public class AdminMediaControllerService {
|
|||||||
mediaUsageRepository.delete(getUsageOrThrow(mediaUsageId));
|
mediaUsageRepository.delete(getUsageOrThrow(mediaUsageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AdminMediaUsageDto> getUsages(String usageType, String usageKey, UUID ownerId) {
|
||||||
|
String normalizedUsageType = requireUsageType(usageType);
|
||||||
|
String normalizedUsageKey = requireUsageKey(usageKey);
|
||||||
|
return mediaUsageRepository.findByUsageScope(normalizedUsageType, normalizedUsageKey, ownerId)
|
||||||
|
.stream()
|
||||||
|
.sorted(Comparator
|
||||||
|
.comparing(MediaUsage::getSortOrder, Comparator.nullsLast(Integer::compareTo))
|
||||||
|
.thenComparing(MediaUsage::getCreatedAt, Comparator.nullsLast(OffsetDateTime::compareTo)))
|
||||||
|
.map(this::toUsageDto)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
private List<MediaVariant> generateDerivedVariants(MediaAsset asset, Path sourceFile, Path tempDirectory) throws IOException {
|
private List<MediaVariant> generateDerivedVariants(MediaAsset asset, Path sourceFile, Path tempDirectory) throws IOException {
|
||||||
Path generatedDirectory = Files.createDirectories(tempDirectory.resolve("generated"));
|
Path generatedDirectory = Files.createDirectories(tempDirectory.resolve("generated"));
|
||||||
String storageFolder = extractStorageFolder(asset.getStorageKey());
|
String storageFolder = extractStorageFolder(asset.getStorageKey());
|
||||||
@@ -350,7 +362,27 @@ public class AdminMediaControllerService {
|
|||||||
}
|
}
|
||||||
String extension = GENERATED_FORMAT_EXTENSIONS.get(format);
|
String extension = GENERATED_FORMAT_EXTENSIONS.get(format);
|
||||||
Path outputFile = generatedDirectory.resolve(preset.name() + "." + extension);
|
Path outputFile = generatedDirectory.resolve(preset.name() + "." + extension);
|
||||||
mediaFfmpegService.generateVariant(sourceFile, outputFile, dimensions.widthPx(), dimensions.heightPx(), format);
|
try {
|
||||||
|
mediaFfmpegService.generateVariant(
|
||||||
|
sourceFile,
|
||||||
|
outputFile,
|
||||||
|
dimensions.widthPx(),
|
||||||
|
dimensions.heightPx(),
|
||||||
|
format
|
||||||
|
);
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (FORMAT_AVIF.equals(format)) {
|
||||||
|
skippedFormats.add(format);
|
||||||
|
logger.warn(
|
||||||
|
"Skipping AVIF variant generation for asset {} preset '{}' because FFmpeg AVIF generation failed: {}",
|
||||||
|
asset.getId(),
|
||||||
|
preset.name(),
|
||||||
|
e.getMessage()
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
MediaVariant variant = new MediaVariant();
|
MediaVariant variant = new MediaVariant();
|
||||||
variant.setMediaAsset(asset);
|
variant.setMediaAsset(asset);
|
||||||
@@ -370,7 +402,7 @@ public class AdminMediaControllerService {
|
|||||||
|
|
||||||
if (!skippedFormats.isEmpty()) {
|
if (!skippedFormats.isEmpty()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Skipping media formats for asset {} because FFmpeg encoders are unavailable: {}",
|
"Skipping media formats for asset {} because FFmpeg support is unavailable: {}",
|
||||||
asset.getId(),
|
asset.getId(),
|
||||||
String.join(", ", skippedFormats)
|
String.join(", ", skippedFormats)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -301,6 +301,7 @@ public class AdminOperationsControllerService {
|
|||||||
} else {
|
} else {
|
||||||
session = new QuoteSession();
|
session = new QuoteSession();
|
||||||
session.setStatus("CAD_ACTIVE");
|
session.setStatus("CAD_ACTIVE");
|
||||||
|
session.setSessionType("PRINT_QUOTE");
|
||||||
session.setPricingVersion("v1");
|
session.setPricingVersion("v1");
|
||||||
session.setMaterialCode("PLA");
|
session.setMaterialCode("PLA");
|
||||||
session.setNozzleDiameterMm(BigDecimal.valueOf(0.4));
|
session.setNozzleDiameterMm(BigDecimal.valueOf(0.4));
|
||||||
@@ -398,6 +399,7 @@ public class AdminOperationsControllerService {
|
|||||||
AdminQuoteSessionDto dto = new AdminQuoteSessionDto();
|
AdminQuoteSessionDto dto = new AdminQuoteSessionDto();
|
||||||
dto.setId(session.getId());
|
dto.setId(session.getId());
|
||||||
dto.setStatus(session.getStatus());
|
dto.setStatus(session.getStatus());
|
||||||
|
dto.setSessionType(session.getSessionType() != null ? session.getSessionType() : "PRINT_QUOTE");
|
||||||
dto.setMaterialCode(session.getMaterialCode());
|
dto.setMaterialCode(session.getMaterialCode());
|
||||||
dto.setCreatedAt(session.getCreatedAt());
|
dto.setCreatedAt(session.getCreatedAt());
|
||||||
dto.setExpiresAt(session.getExpiresAt());
|
dto.setExpiresAt(session.getExpiresAt());
|
||||||
|
|||||||
@@ -0,0 +1,467 @@
|
|||||||
|
package com.printcalculator.service.admin;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.AdminShopCategoryDto;
|
||||||
|
import com.printcalculator.dto.AdminShopCategoryRefDto;
|
||||||
|
import com.printcalculator.dto.AdminUpsertShopCategoryRequest;
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
import com.printcalculator.repository.ShopCategoryRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
|
import static org.springframework.http.HttpStatus.CONFLICT;
|
||||||
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AdminShopCategoryControllerService {
|
||||||
|
private static final String SHOP_CATEGORY_MEDIA_USAGE_TYPE = "SHOP_CATEGORY";
|
||||||
|
private static final Pattern DIACRITICS_PATTERN = Pattern.compile("\\p{M}+");
|
||||||
|
private static final Pattern NON_ALPHANUMERIC_PATTERN = Pattern.compile("[^a-z0-9]+");
|
||||||
|
private static final Pattern EDGE_DASH_PATTERN = Pattern.compile("(^-+|-+$)");
|
||||||
|
|
||||||
|
private final ShopCategoryRepository shopCategoryRepository;
|
||||||
|
private final ShopProductRepository shopProductRepository;
|
||||||
|
|
||||||
|
public AdminShopCategoryControllerService(ShopCategoryRepository shopCategoryRepository,
|
||||||
|
ShopProductRepository shopProductRepository) {
|
||||||
|
this.shopCategoryRepository = shopCategoryRepository;
|
||||||
|
this.shopProductRepository = shopProductRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminShopCategoryDto> getCategories() {
|
||||||
|
CategoryContext context = buildContext();
|
||||||
|
List<AdminShopCategoryDto> result = new ArrayList<>();
|
||||||
|
appendFlatCategories(null, 0, context, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminShopCategoryDto> getCategoryTree() {
|
||||||
|
return buildCategoryTree(null, 0, buildContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdminShopCategoryDto getCategory(UUID categoryId) {
|
||||||
|
CategoryContext context = buildContext();
|
||||||
|
ShopCategory category = context.categoriesById().get(categoryId);
|
||||||
|
if (category == null) {
|
||||||
|
throw new ResponseStatusException(NOT_FOUND, "Shop category not found");
|
||||||
|
}
|
||||||
|
return toDto(category, resolveDepth(category), context, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public AdminShopCategoryDto createCategory(AdminUpsertShopCategoryRequest payload) {
|
||||||
|
ensurePayload(payload);
|
||||||
|
LocalizedCategoryContent localizedContent = normalizeLocalizedCategoryContent(payload);
|
||||||
|
String normalizedSlug = normalizeAndValidateSlug(payload.getSlug(), localizedContent.defaultName());
|
||||||
|
ensureSlugAvailable(normalizedSlug, null);
|
||||||
|
|
||||||
|
ShopCategory category = new ShopCategory();
|
||||||
|
category.setCreatedAt(OffsetDateTime.now());
|
||||||
|
applyPayload(category, payload, localizedContent, normalizedSlug, null);
|
||||||
|
|
||||||
|
ShopCategory saved = shopCategoryRepository.save(category);
|
||||||
|
return getCategory(saved.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public AdminShopCategoryDto updateCategory(UUID categoryId, AdminUpsertShopCategoryRequest payload) {
|
||||||
|
ensurePayload(payload);
|
||||||
|
|
||||||
|
ShopCategory category = shopCategoryRepository.findById(categoryId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "Shop category not found"));
|
||||||
|
|
||||||
|
LocalizedCategoryContent localizedContent = normalizeLocalizedCategoryContent(payload);
|
||||||
|
String normalizedSlug = normalizeAndValidateSlug(payload.getSlug(), localizedContent.defaultName());
|
||||||
|
ensureSlugAvailable(normalizedSlug, category.getId());
|
||||||
|
|
||||||
|
applyPayload(category, payload, localizedContent, normalizedSlug, category.getId());
|
||||||
|
ShopCategory saved = shopCategoryRepository.save(category);
|
||||||
|
return getCategory(saved.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteCategory(UUID categoryId) {
|
||||||
|
ShopCategory category = shopCategoryRepository.findById(categoryId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "Shop category not found"));
|
||||||
|
|
||||||
|
if (shopCategoryRepository.existsByParentCategory_Id(categoryId)) {
|
||||||
|
throw new ResponseStatusException(CONFLICT, "Category has child categories and cannot be deleted");
|
||||||
|
}
|
||||||
|
if (shopProductRepository.existsByCategory_Id(categoryId)) {
|
||||||
|
throw new ResponseStatusException(CONFLICT, "Category has products and cannot be deleted");
|
||||||
|
}
|
||||||
|
|
||||||
|
shopCategoryRepository.delete(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyPayload(ShopCategory category,
|
||||||
|
AdminUpsertShopCategoryRequest payload,
|
||||||
|
LocalizedCategoryContent localizedContent,
|
||||||
|
String normalizedSlug,
|
||||||
|
UUID currentCategoryId) {
|
||||||
|
ShopCategory parentCategory = resolveParentCategory(payload.getParentCategoryId(), currentCategoryId);
|
||||||
|
|
||||||
|
category.setParentCategory(parentCategory);
|
||||||
|
category.setSlug(normalizedSlug);
|
||||||
|
category.setName(localizedContent.defaultName());
|
||||||
|
category.setNameIt(localizedContent.names().get("it"));
|
||||||
|
category.setNameEn(localizedContent.names().get("en"));
|
||||||
|
category.setNameDe(localizedContent.names().get("de"));
|
||||||
|
category.setNameFr(localizedContent.names().get("fr"));
|
||||||
|
category.setDescription(localizedContent.defaultDescription());
|
||||||
|
category.setDescriptionIt(localizedContent.descriptions().get("it"));
|
||||||
|
category.setDescriptionEn(localizedContent.descriptions().get("en"));
|
||||||
|
category.setDescriptionDe(localizedContent.descriptions().get("de"));
|
||||||
|
category.setDescriptionFr(localizedContent.descriptions().get("fr"));
|
||||||
|
category.setSeoTitle(localizedContent.defaultSeoTitle());
|
||||||
|
category.setSeoTitleIt(localizedContent.seoTitles().get("it"));
|
||||||
|
category.setSeoTitleEn(localizedContent.seoTitles().get("en"));
|
||||||
|
category.setSeoTitleDe(localizedContent.seoTitles().get("de"));
|
||||||
|
category.setSeoTitleFr(localizedContent.seoTitles().get("fr"));
|
||||||
|
category.setSeoDescription(localizedContent.defaultSeoDescription());
|
||||||
|
category.setSeoDescriptionIt(localizedContent.seoDescriptions().get("it"));
|
||||||
|
category.setSeoDescriptionEn(localizedContent.seoDescriptions().get("en"));
|
||||||
|
category.setSeoDescriptionDe(localizedContent.seoDescriptions().get("de"));
|
||||||
|
category.setSeoDescriptionFr(localizedContent.seoDescriptions().get("fr"));
|
||||||
|
category.setOgTitle(normalizeOptional(payload.getOgTitle()));
|
||||||
|
category.setOgDescription(normalizeOptional(payload.getOgDescription()));
|
||||||
|
category.setIndexable(payload.getIndexable() == null || payload.getIndexable());
|
||||||
|
category.setIsActive(payload.getIsActive() == null || payload.getIsActive());
|
||||||
|
category.setSortOrder(payload.getSortOrder() != null ? payload.getSortOrder() : 0);
|
||||||
|
category.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopCategory resolveParentCategory(UUID parentCategoryId, UUID currentCategoryId) {
|
||||||
|
if (parentCategoryId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (currentCategoryId != null && currentCategoryId.equals(parentCategoryId)) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Category cannot be its own parent");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShopCategory parentCategory = shopCategoryRepository.findById(parentCategoryId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(BAD_REQUEST, "Parent category not found"));
|
||||||
|
|
||||||
|
if (currentCategoryId != null) {
|
||||||
|
ShopCategory ancestor = parentCategory;
|
||||||
|
while (ancestor != null) {
|
||||||
|
if (currentCategoryId.equals(ancestor.getId())) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Category hierarchy would create a cycle");
|
||||||
|
}
|
||||||
|
ancestor = ancestor.getParentCategory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parentCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensurePayload(AdminUpsertShopCategoryRequest payload) {
|
||||||
|
if (payload == null) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Payload is required");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeAndValidateSlug(String slug, String fallbackName) {
|
||||||
|
String source = normalizeOptional(slug);
|
||||||
|
if (source == null) {
|
||||||
|
source = fallbackName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalized = Normalizer.normalize(source, Normalizer.Form.NFD);
|
||||||
|
normalized = DIACRITICS_PATTERN.matcher(normalized).replaceAll("");
|
||||||
|
normalized = normalized.toLowerCase(Locale.ROOT);
|
||||||
|
normalized = NON_ALPHANUMERIC_PATTERN.matcher(normalized).replaceAll("-");
|
||||||
|
normalized = EDGE_DASH_PATTERN.matcher(normalized).replaceAll("");
|
||||||
|
|
||||||
|
if (normalized.isBlank()) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Slug is invalid");
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureSlugAvailable(String slug, UUID currentCategoryId) {
|
||||||
|
shopCategoryRepository.findBySlugIgnoreCase(slug).ifPresent(existing -> {
|
||||||
|
if (currentCategoryId == null || !existing.getId().equals(currentCategoryId)) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Category slug already exists");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeOptional(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String normalized = value.trim();
|
||||||
|
return normalized.isBlank() ? null : normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeRequired(String value, String message) {
|
||||||
|
String normalized = normalizeOptional(value);
|
||||||
|
if (normalized == null) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, message);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalizedCategoryContent normalizeLocalizedCategoryContent(AdminUpsertShopCategoryRequest payload) {
|
||||||
|
String legacyName = normalizeOptional(payload.getName());
|
||||||
|
String fallbackName = firstNonBlank(
|
||||||
|
legacyName,
|
||||||
|
normalizeOptional(payload.getNameIt()),
|
||||||
|
normalizeOptional(payload.getNameEn()),
|
||||||
|
normalizeOptional(payload.getNameDe()),
|
||||||
|
normalizeOptional(payload.getNameFr())
|
||||||
|
);
|
||||||
|
if (fallbackName == null) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, "Category name is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> names = new LinkedHashMap<>();
|
||||||
|
names.put("it", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameIt()), fallbackName), "Italian category name is required"));
|
||||||
|
names.put("en", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameEn()), fallbackName), "English category name is required"));
|
||||||
|
names.put("de", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameDe()), fallbackName), "German category name is required"));
|
||||||
|
names.put("fr", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameFr()), fallbackName), "French category name is required"));
|
||||||
|
|
||||||
|
String fallbackDescription = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getDescription()),
|
||||||
|
normalizeOptional(payload.getDescriptionIt()),
|
||||||
|
normalizeOptional(payload.getDescriptionEn()),
|
||||||
|
normalizeOptional(payload.getDescriptionDe()),
|
||||||
|
normalizeOptional(payload.getDescriptionFr())
|
||||||
|
);
|
||||||
|
Map<String, String> descriptions = new LinkedHashMap<>();
|
||||||
|
descriptions.put("it", firstNonBlank(normalizeOptional(payload.getDescriptionIt()), fallbackDescription));
|
||||||
|
descriptions.put("en", firstNonBlank(normalizeOptional(payload.getDescriptionEn()), fallbackDescription));
|
||||||
|
descriptions.put("de", firstNonBlank(normalizeOptional(payload.getDescriptionDe()), fallbackDescription));
|
||||||
|
descriptions.put("fr", firstNonBlank(normalizeOptional(payload.getDescriptionFr()), fallbackDescription));
|
||||||
|
|
||||||
|
String fallbackSeoTitle = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getSeoTitle()),
|
||||||
|
normalizeOptional(payload.getSeoTitleIt()),
|
||||||
|
normalizeOptional(payload.getSeoTitleEn()),
|
||||||
|
normalizeOptional(payload.getSeoTitleDe()),
|
||||||
|
normalizeOptional(payload.getSeoTitleFr())
|
||||||
|
);
|
||||||
|
Map<String, String> seoTitles = new LinkedHashMap<>();
|
||||||
|
seoTitles.put("it", firstNonBlank(normalizeOptional(payload.getSeoTitleIt()), fallbackSeoTitle));
|
||||||
|
seoTitles.put("en", firstNonBlank(normalizeOptional(payload.getSeoTitleEn()), fallbackSeoTitle));
|
||||||
|
seoTitles.put("de", firstNonBlank(normalizeOptional(payload.getSeoTitleDe()), fallbackSeoTitle));
|
||||||
|
seoTitles.put("fr", firstNonBlank(normalizeOptional(payload.getSeoTitleFr()), fallbackSeoTitle));
|
||||||
|
|
||||||
|
String fallbackSeoDescription = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getSeoDescription()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionIt()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionEn()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionDe()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionFr())
|
||||||
|
);
|
||||||
|
Map<String, String> seoDescriptions = new LinkedHashMap<>();
|
||||||
|
seoDescriptions.put("it", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionIt()), fallbackSeoDescription), "Italian"));
|
||||||
|
seoDescriptions.put("en", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionEn()), fallbackSeoDescription), "English"));
|
||||||
|
seoDescriptions.put("de", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionDe()), fallbackSeoDescription), "German"));
|
||||||
|
seoDescriptions.put("fr", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionFr()), fallbackSeoDescription), "French"));
|
||||||
|
|
||||||
|
return new LocalizedCategoryContent(
|
||||||
|
names.get("it"),
|
||||||
|
firstNonBlank(descriptions.get("it"), fallbackDescription),
|
||||||
|
firstNonBlank(seoTitles.get("it"), fallbackSeoTitle),
|
||||||
|
firstNonBlank(seoDescriptions.get("it"), fallbackSeoDescription),
|
||||||
|
names,
|
||||||
|
descriptions,
|
||||||
|
seoTitles,
|
||||||
|
seoDescriptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String validateSeoDescriptionLength(String value, String languageLabel) {
|
||||||
|
if (value != null && value.length() > 160) {
|
||||||
|
throw new ResponseStatusException(BAD_REQUEST, languageLabel + " SEO description must be at most 160 characters");
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CategoryContext buildContext() {
|
||||||
|
List<ShopCategory> categories = shopCategoryRepository.findAllByOrderBySortOrderAscNameAsc();
|
||||||
|
List<ShopProduct> products = shopProductRepository.findAll();
|
||||||
|
|
||||||
|
Map<UUID, ShopCategory> categoriesById = categories.stream()
|
||||||
|
.collect(Collectors.toMap(ShopCategory::getId, category -> category, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId = new LinkedHashMap<>();
|
||||||
|
for (ShopCategory category : categories) {
|
||||||
|
UUID parentId = category.getParentCategory() != null ? category.getParentCategory().getId() : null;
|
||||||
|
childrenByParentId.computeIfAbsent(parentId, ignored -> new ArrayList<>()).add(category);
|
||||||
|
}
|
||||||
|
Comparator<ShopCategory> comparator = Comparator
|
||||||
|
.comparing(ShopCategory::getSortOrder, Comparator.nullsLast(Integer::compareTo))
|
||||||
|
.thenComparing(ShopCategory::getName, Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER));
|
||||||
|
childrenByParentId.values().forEach(children -> children.sort(comparator));
|
||||||
|
|
||||||
|
Map<UUID, Integer> directProductCounts = new LinkedHashMap<>();
|
||||||
|
for (ShopProduct product : products) {
|
||||||
|
if (product.getCategory() == null || product.getCategory().getId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
directProductCounts.merge(product.getCategory().getId(), 1, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<UUID, Integer> descendantProductCounts = new LinkedHashMap<>();
|
||||||
|
for (ShopCategory category : categories) {
|
||||||
|
resolveDescendantProductCount(category.getId(), childrenByParentId, directProductCounts, descendantProductCounts);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CategoryContext(categoriesById, childrenByParentId, directProductCounts, descendantProductCounts);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resolveDescendantProductCount(UUID categoryId,
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId,
|
||||||
|
Map<UUID, Integer> directProductCounts,
|
||||||
|
Map<UUID, Integer> descendantProductCounts) {
|
||||||
|
Integer cached = descendantProductCounts.get(categoryId);
|
||||||
|
if (cached != null) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
int total = directProductCounts.getOrDefault(categoryId, 0);
|
||||||
|
for (ShopCategory child : childrenByParentId.getOrDefault(categoryId, List.of())) {
|
||||||
|
total += resolveDescendantProductCount(child.getId(), childrenByParentId, directProductCounts, descendantProductCounts);
|
||||||
|
}
|
||||||
|
descendantProductCounts.put(categoryId, total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendFlatCategories(UUID parentId,
|
||||||
|
int depth,
|
||||||
|
CategoryContext context,
|
||||||
|
List<AdminShopCategoryDto> result) {
|
||||||
|
for (ShopCategory category : context.childrenByParentId().getOrDefault(parentId, List.of())) {
|
||||||
|
result.add(toDto(category, depth, context, false));
|
||||||
|
appendFlatCategories(category.getId(), depth + 1, context, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AdminShopCategoryDto> buildCategoryTree(UUID parentId, int depth, CategoryContext context) {
|
||||||
|
return context.childrenByParentId().getOrDefault(parentId, List.of()).stream()
|
||||||
|
.map(category -> toDto(category, depth, context, true))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminShopCategoryDto toDto(ShopCategory category,
|
||||||
|
int depth,
|
||||||
|
CategoryContext context,
|
||||||
|
boolean includeChildren) {
|
||||||
|
AdminShopCategoryDto dto = new AdminShopCategoryDto();
|
||||||
|
dto.setId(category.getId());
|
||||||
|
dto.setParentCategoryId(category.getParentCategory() != null ? category.getParentCategory().getId() : null);
|
||||||
|
dto.setParentCategoryName(category.getParentCategory() != null ? category.getParentCategory().getName() : null);
|
||||||
|
dto.setSlug(category.getSlug());
|
||||||
|
dto.setName(category.getName());
|
||||||
|
dto.setNameIt(category.getNameIt());
|
||||||
|
dto.setNameEn(category.getNameEn());
|
||||||
|
dto.setNameDe(category.getNameDe());
|
||||||
|
dto.setNameFr(category.getNameFr());
|
||||||
|
dto.setDescription(category.getDescription());
|
||||||
|
dto.setDescriptionIt(category.getDescriptionIt());
|
||||||
|
dto.setDescriptionEn(category.getDescriptionEn());
|
||||||
|
dto.setDescriptionDe(category.getDescriptionDe());
|
||||||
|
dto.setDescriptionFr(category.getDescriptionFr());
|
||||||
|
dto.setSeoTitle(category.getSeoTitle());
|
||||||
|
dto.setSeoTitleIt(category.getSeoTitleIt());
|
||||||
|
dto.setSeoTitleEn(category.getSeoTitleEn());
|
||||||
|
dto.setSeoTitleDe(category.getSeoTitleDe());
|
||||||
|
dto.setSeoTitleFr(category.getSeoTitleFr());
|
||||||
|
dto.setSeoDescription(category.getSeoDescription());
|
||||||
|
dto.setSeoDescriptionIt(category.getSeoDescriptionIt());
|
||||||
|
dto.setSeoDescriptionEn(category.getSeoDescriptionEn());
|
||||||
|
dto.setSeoDescriptionDe(category.getSeoDescriptionDe());
|
||||||
|
dto.setSeoDescriptionFr(category.getSeoDescriptionFr());
|
||||||
|
dto.setOgTitle(category.getOgTitle());
|
||||||
|
dto.setOgDescription(category.getOgDescription());
|
||||||
|
dto.setIndexable(category.getIndexable());
|
||||||
|
dto.setIsActive(category.getIsActive());
|
||||||
|
dto.setSortOrder(category.getSortOrder());
|
||||||
|
dto.setDepth(depth);
|
||||||
|
dto.setChildCount(context.childrenByParentId().getOrDefault(category.getId(), List.of()).size());
|
||||||
|
dto.setDirectProductCount(context.directProductCounts().getOrDefault(category.getId(), 0));
|
||||||
|
dto.setDescendantProductCount(context.descendantProductCounts().getOrDefault(category.getId(), 0));
|
||||||
|
dto.setMediaUsageType(SHOP_CATEGORY_MEDIA_USAGE_TYPE);
|
||||||
|
dto.setMediaUsageKey(category.getId().toString());
|
||||||
|
dto.setBreadcrumbs(buildBreadcrumbs(category));
|
||||||
|
dto.setChildren(includeChildren ? buildCategoryTree(category.getId(), depth + 1, context) : List.of());
|
||||||
|
dto.setCreatedAt(category.getCreatedAt());
|
||||||
|
dto.setUpdatedAt(category.getUpdatedAt());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AdminShopCategoryRefDto> buildBreadcrumbs(ShopCategory category) {
|
||||||
|
List<AdminShopCategoryRefDto> breadcrumbs = new ArrayList<>();
|
||||||
|
ShopCategory current = category;
|
||||||
|
while (current != null) {
|
||||||
|
AdminShopCategoryRefDto ref = new AdminShopCategoryRefDto();
|
||||||
|
ref.setId(current.getId());
|
||||||
|
ref.setSlug(current.getSlug());
|
||||||
|
ref.setName(current.getName());
|
||||||
|
breadcrumbs.add(ref);
|
||||||
|
current = current.getParentCategory();
|
||||||
|
}
|
||||||
|
java.util.Collections.reverse(breadcrumbs);
|
||||||
|
return breadcrumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resolveDepth(ShopCategory category) {
|
||||||
|
int depth = 0;
|
||||||
|
ShopCategory current = category != null ? category.getParentCategory() : null;
|
||||||
|
while (current != null) {
|
||||||
|
depth++;
|
||||||
|
current = current.getParentCategory();
|
||||||
|
}
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CategoryContext(
|
||||||
|
Map<UUID, ShopCategory> categoriesById,
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId,
|
||||||
|
Map<UUID, Integer> directProductCounts,
|
||||||
|
Map<UUID, Integer> descendantProductCounts
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record LocalizedCategoryContent(
|
||||||
|
String defaultName,
|
||||||
|
String defaultDescription,
|
||||||
|
String defaultSeoTitle,
|
||||||
|
String defaultSeoDescription,
|
||||||
|
Map<String, String> names,
|
||||||
|
Map<String, String> descriptions,
|
||||||
|
Map<String, String> seoTitles,
|
||||||
|
Map<String, String> seoDescriptions
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,907 @@
|
|||||||
|
package com.printcalculator.service.admin;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.AdminMediaUsageDto;
|
||||||
|
import com.printcalculator.dto.AdminShopProductDto;
|
||||||
|
import com.printcalculator.dto.AdminShopProductVariantDto;
|
||||||
|
import com.printcalculator.dto.AdminUpsertShopProductRequest;
|
||||||
|
import com.printcalculator.dto.AdminUpsertShopProductVariantRequest;
|
||||||
|
import com.printcalculator.dto.PublicMediaUsageDto;
|
||||||
|
import com.printcalculator.dto.ShopProductModelDto;
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
import com.printcalculator.entity.ShopProductModelAsset;
|
||||||
|
import com.printcalculator.entity.ShopProductVariant;
|
||||||
|
import com.printcalculator.model.ModelDimensions;
|
||||||
|
import com.printcalculator.repository.OrderItemRepository;
|
||||||
|
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||||
|
import com.printcalculator.repository.ShopCategoryRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductModelAssetRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductVariantRepository;
|
||||||
|
import com.printcalculator.service.SlicerService;
|
||||||
|
import com.printcalculator.service.media.PublicMediaQueryService;
|
||||||
|
import com.printcalculator.service.shop.ShopStorageService;
|
||||||
|
import com.printcalculator.service.storage.ClamAVService;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.safety.Safelist;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HexFormat;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AdminShopProductControllerService {
|
||||||
|
private static final String SHOP_PRODUCT_MEDIA_USAGE_TYPE = "SHOP_PRODUCT";
|
||||||
|
private static final Set<String> SUPPORTED_MODEL_EXTENSIONS = Set.of("stl", "3mf");
|
||||||
|
private static final Pattern HEX_COLOR_PATTERN = Pattern.compile("^#[0-9A-Fa-f]{6}$");
|
||||||
|
private static final Pattern DIACRITICS_PATTERN = Pattern.compile("\\p{M}+");
|
||||||
|
private static final Pattern NON_ALPHANUMERIC_PATTERN = Pattern.compile("[^a-z0-9]+");
|
||||||
|
private static final Pattern EDGE_DASH_PATTERN = Pattern.compile("(^-+|-+$)");
|
||||||
|
private static final Safelist PRODUCT_DESCRIPTION_SAFELIST = Safelist.none()
|
||||||
|
.addTags("p", "div", "br", "strong", "b", "em", "i", "u", "ul", "ol", "li", "a")
|
||||||
|
.addAttributes("a", "href")
|
||||||
|
.addProtocols("a", "href", "http", "https", "mailto", "tel");
|
||||||
|
|
||||||
|
private final ShopProductRepository shopProductRepository;
|
||||||
|
private final ShopCategoryRepository shopCategoryRepository;
|
||||||
|
private final ShopProductVariantRepository shopProductVariantRepository;
|
||||||
|
private final ShopProductModelAssetRepository shopProductModelAssetRepository;
|
||||||
|
private final QuoteLineItemRepository quoteLineItemRepository;
|
||||||
|
private final OrderItemRepository orderItemRepository;
|
||||||
|
private final PublicMediaQueryService publicMediaQueryService;
|
||||||
|
private final AdminMediaControllerService adminMediaControllerService;
|
||||||
|
private final ShopStorageService shopStorageService;
|
||||||
|
private final SlicerService slicerService;
|
||||||
|
private final ClamAVService clamAVService;
|
||||||
|
private final long maxModelFileSizeBytes;
|
||||||
|
|
||||||
|
public AdminShopProductControllerService(ShopProductRepository shopProductRepository,
|
||||||
|
ShopCategoryRepository shopCategoryRepository,
|
||||||
|
ShopProductVariantRepository shopProductVariantRepository,
|
||||||
|
ShopProductModelAssetRepository shopProductModelAssetRepository,
|
||||||
|
QuoteLineItemRepository quoteLineItemRepository,
|
||||||
|
OrderItemRepository orderItemRepository,
|
||||||
|
PublicMediaQueryService publicMediaQueryService,
|
||||||
|
AdminMediaControllerService adminMediaControllerService,
|
||||||
|
ShopStorageService shopStorageService,
|
||||||
|
SlicerService slicerService,
|
||||||
|
ClamAVService clamAVService,
|
||||||
|
@Value("${shop.model.max-file-size-bytes:104857600}") long maxModelFileSizeBytes) {
|
||||||
|
this.shopProductRepository = shopProductRepository;
|
||||||
|
this.shopCategoryRepository = shopCategoryRepository;
|
||||||
|
this.shopProductVariantRepository = shopProductVariantRepository;
|
||||||
|
this.shopProductModelAssetRepository = shopProductModelAssetRepository;
|
||||||
|
this.quoteLineItemRepository = quoteLineItemRepository;
|
||||||
|
this.orderItemRepository = orderItemRepository;
|
||||||
|
this.publicMediaQueryService = publicMediaQueryService;
|
||||||
|
this.adminMediaControllerService = adminMediaControllerService;
|
||||||
|
this.shopStorageService = shopStorageService;
|
||||||
|
this.slicerService = slicerService;
|
||||||
|
this.clamAVService = clamAVService;
|
||||||
|
this.maxModelFileSizeBytes = maxModelFileSizeBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AdminShopProductDto> getProducts() {
|
||||||
|
return toProductDtos(shopProductRepository.findAllByOrderByIsFeaturedDescSortOrderAscNameAsc());
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdminShopProductDto getProduct(UUID productId) {
|
||||||
|
ShopProduct product = shopProductRepository.findById(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product not found"));
|
||||||
|
return toProductDtos(List.of(product)).get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public AdminShopProductDto createProduct(AdminUpsertShopProductRequest payload) {
|
||||||
|
ensurePayload(payload);
|
||||||
|
LocalizedProductContent localizedContent = normalizeLocalizedProductContent(payload);
|
||||||
|
String normalizedSlug = normalizeAndValidateSlug(payload.getSlug(), localizedContent.defaultName());
|
||||||
|
ensureSlugAvailable(normalizedSlug, null);
|
||||||
|
|
||||||
|
ShopProduct product = new ShopProduct();
|
||||||
|
product.setCreatedAt(OffsetDateTime.now());
|
||||||
|
applyProductPayload(product, payload, localizedContent, normalizedSlug, resolveCategory(payload.getCategoryId()));
|
||||||
|
ShopProduct saved = shopProductRepository.save(product);
|
||||||
|
syncVariants(saved, payload.getVariants());
|
||||||
|
return getProduct(saved.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public AdminShopProductDto updateProduct(UUID productId, AdminUpsertShopProductRequest payload) {
|
||||||
|
ensurePayload(payload);
|
||||||
|
ShopProduct product = shopProductRepository.findById(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product not found"));
|
||||||
|
|
||||||
|
LocalizedProductContent localizedContent = normalizeLocalizedProductContent(payload);
|
||||||
|
String normalizedSlug = normalizeAndValidateSlug(payload.getSlug(), localizedContent.defaultName());
|
||||||
|
ensureSlugAvailable(normalizedSlug, productId);
|
||||||
|
|
||||||
|
applyProductPayload(product, payload, localizedContent, normalizedSlug, resolveCategory(payload.getCategoryId()));
|
||||||
|
ShopProduct saved = shopProductRepository.save(product);
|
||||||
|
syncVariants(saved, payload.getVariants());
|
||||||
|
return getProduct(saved.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteProduct(UUID productId) {
|
||||||
|
ShopProduct product = shopProductRepository.findById(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product not found"));
|
||||||
|
|
||||||
|
if (quoteLineItemRepository.existsByShopProduct_Id(productId)
|
||||||
|
|| orderItemRepository.existsByShopProduct_Id(productId)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.CONFLICT, "Product is already used in carts or orders and cannot be deleted");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ShopProductVariant> variants = shopProductVariantRepository.findByProduct_IdOrderBySortOrderAscColorNameAsc(productId);
|
||||||
|
for (ShopProductVariant variant : variants) {
|
||||||
|
if (quoteLineItemRepository.existsByShopProductVariant_Id(variant.getId())
|
||||||
|
|| orderItemRepository.existsByShopProductVariant_Id(variant.getId())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.CONFLICT, "One or more variants are already used in carts or orders and cannot be deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shopProductModelAssetRepository.findByProduct_Id(productId).ifPresent(asset -> {
|
||||||
|
deleteExistingModelFile(asset, productId);
|
||||||
|
shopProductModelAssetRepository.delete(asset);
|
||||||
|
});
|
||||||
|
if (!variants.isEmpty()) {
|
||||||
|
shopProductVariantRepository.deleteAll(variants);
|
||||||
|
}
|
||||||
|
shopProductRepository.delete(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public AdminShopProductDto uploadProductModel(UUID productId, MultipartFile file) throws IOException {
|
||||||
|
ShopProduct product = shopProductRepository.findById(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product not found"));
|
||||||
|
validateModelUpload(file);
|
||||||
|
|
||||||
|
Path tempDirectory = Files.createTempDirectory("shop-product-model-");
|
||||||
|
Path destination = null;
|
||||||
|
try {
|
||||||
|
String cleanedFilename = sanitizeOriginalFilename(file.getOriginalFilename());
|
||||||
|
String extension = resolveExtension(cleanedFilename);
|
||||||
|
Path uploadPath = tempDirectory.resolve("upload." + extension);
|
||||||
|
file.transferTo(uploadPath);
|
||||||
|
|
||||||
|
try (InputStream inputStream = Files.newInputStream(uploadPath)) {
|
||||||
|
clamAVService.scan(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path storageDir = shopStorageService.productModelStorageDir(productId);
|
||||||
|
destination = storageDir.resolve(UUID.randomUUID() + ".stl");
|
||||||
|
if ("3mf".equals(extension)) {
|
||||||
|
slicerService.convert3mfToPersistentStl(uploadPath.toFile(), destination);
|
||||||
|
} else {
|
||||||
|
Files.copy(uploadPath, destination, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelDimensions dimensions = slicerService.inspectModelDimensions(destination.toFile())
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unable to extract model dimensions"));
|
||||||
|
|
||||||
|
ShopProductModelAsset asset = shopProductModelAssetRepository.findByProduct_Id(productId)
|
||||||
|
.orElseGet(ShopProductModelAsset::new);
|
||||||
|
String previousStoredRelativePath = asset.getStoredRelativePath();
|
||||||
|
|
||||||
|
asset.setProduct(product);
|
||||||
|
asset.setOriginalFilename(buildDownloadFilename(cleanedFilename));
|
||||||
|
asset.setStoredFilename(destination.getFileName().toString());
|
||||||
|
asset.setStoredRelativePath(shopStorageService.toStoredPath(destination));
|
||||||
|
asset.setMimeType("model/stl");
|
||||||
|
asset.setFileSizeBytes(Files.size(destination));
|
||||||
|
asset.setSha256Hex(computeSha256(destination));
|
||||||
|
asset.setBoundingBoxXMm(BigDecimal.valueOf(dimensions.xMm()));
|
||||||
|
asset.setBoundingBoxYMm(BigDecimal.valueOf(dimensions.yMm()));
|
||||||
|
asset.setBoundingBoxZMm(BigDecimal.valueOf(dimensions.zMm()));
|
||||||
|
if (asset.getCreatedAt() == null) {
|
||||||
|
asset.setCreatedAt(OffsetDateTime.now());
|
||||||
|
}
|
||||||
|
asset.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
shopProductModelAssetRepository.save(asset);
|
||||||
|
deleteStoredRelativePath(previousStoredRelativePath, productId, asset.getStoredRelativePath());
|
||||||
|
|
||||||
|
return getProduct(productId);
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
deletePathQuietly(destination);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
deleteRecursively(tempDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteProductModel(UUID productId) {
|
||||||
|
shopProductRepository.findById(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product not found"));
|
||||||
|
ShopProductModelAsset asset = shopProductModelAssetRepository.findByProduct_Id(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product model not found"));
|
||||||
|
|
||||||
|
deleteExistingModelFile(asset, productId);
|
||||||
|
shopProductModelAssetRepository.delete(asset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductModelDownload getProductModel(UUID productId) {
|
||||||
|
ShopProduct product = shopProductRepository.findById(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product not found"));
|
||||||
|
ShopProductModelAsset asset = shopProductModelAssetRepository.findByProduct_Id(productId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product model not found"));
|
||||||
|
|
||||||
|
Path path = shopStorageService.resolveStoredProductPath(asset.getStoredRelativePath(), product.getId());
|
||||||
|
if (path == null || !Files.exists(path)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Shop product model not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProductModelDownload(path, asset.getOriginalFilename(), asset.getMimeType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncVariants(ShopProduct product, List<AdminUpsertShopProductVariantRequest> variantPayloads) {
|
||||||
|
List<AdminUpsertShopProductVariantRequest> normalizedPayloads = normalizeVariantPayloads(variantPayloads);
|
||||||
|
List<ShopProductVariant> existingVariants = shopProductVariantRepository.findByProduct_IdOrderBySortOrderAscColorNameAsc(product.getId());
|
||||||
|
Map<UUID, ShopProductVariant> existingById = existingVariants.stream()
|
||||||
|
.collect(Collectors.toMap(ShopProductVariant::getId, variant -> variant, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
|
||||||
|
Set<UUID> retainedIds = new LinkedHashSet<>();
|
||||||
|
List<ShopProductVariant> variantsToSave = new ArrayList<>();
|
||||||
|
|
||||||
|
for (AdminUpsertShopProductVariantRequest payload : normalizedPayloads) {
|
||||||
|
ShopProductVariant variant;
|
||||||
|
if (payload.getId() != null) {
|
||||||
|
variant = existingById.get(payload.getId());
|
||||||
|
if (variant == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant does not belong to the product");
|
||||||
|
}
|
||||||
|
retainedIds.add(variant.getId());
|
||||||
|
} else {
|
||||||
|
variant = new ShopProductVariant();
|
||||||
|
variant.setCreatedAt(OffsetDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
applyVariantPayload(variant, product, payload);
|
||||||
|
variantsToSave.add(variant);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ShopProductVariant> variantsToDelete = existingVariants.stream()
|
||||||
|
.filter(variant -> !retainedIds.contains(variant.getId()))
|
||||||
|
.toList();
|
||||||
|
for (ShopProductVariant variant : variantsToDelete) {
|
||||||
|
if (quoteLineItemRepository.existsByShopProductVariant_Id(variant.getId())
|
||||||
|
|| orderItemRepository.existsByShopProductVariant_Id(variant.getId())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.CONFLICT, "Variant is already used in carts or orders and cannot be removed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!variantsToDelete.isEmpty()) {
|
||||||
|
shopProductVariantRepository.deleteAll(variantsToDelete);
|
||||||
|
}
|
||||||
|
shopProductVariantRepository.saveAll(variantsToSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyProductPayload(ShopProduct product,
|
||||||
|
AdminUpsertShopProductRequest payload,
|
||||||
|
LocalizedProductContent localizedContent,
|
||||||
|
String normalizedSlug,
|
||||||
|
ShopCategory category) {
|
||||||
|
product.setCategory(category);
|
||||||
|
product.setSlug(normalizedSlug);
|
||||||
|
product.setName(localizedContent.defaultName());
|
||||||
|
product.setNameIt(localizedContent.names().get("it"));
|
||||||
|
product.setNameEn(localizedContent.names().get("en"));
|
||||||
|
product.setNameDe(localizedContent.names().get("de"));
|
||||||
|
product.setNameFr(localizedContent.names().get("fr"));
|
||||||
|
product.setExcerpt(localizedContent.defaultExcerpt());
|
||||||
|
product.setExcerptIt(localizedContent.excerpts().get("it"));
|
||||||
|
product.setExcerptEn(localizedContent.excerpts().get("en"));
|
||||||
|
product.setExcerptDe(localizedContent.excerpts().get("de"));
|
||||||
|
product.setExcerptFr(localizedContent.excerpts().get("fr"));
|
||||||
|
product.setDescription(localizedContent.defaultDescription());
|
||||||
|
product.setDescriptionIt(localizedContent.descriptions().get("it"));
|
||||||
|
product.setDescriptionEn(localizedContent.descriptions().get("en"));
|
||||||
|
product.setDescriptionDe(localizedContent.descriptions().get("de"));
|
||||||
|
product.setDescriptionFr(localizedContent.descriptions().get("fr"));
|
||||||
|
product.setSeoTitle(localizedContent.defaultSeoTitle());
|
||||||
|
product.setSeoTitleIt(localizedContent.seoTitles().get("it"));
|
||||||
|
product.setSeoTitleEn(localizedContent.seoTitles().get("en"));
|
||||||
|
product.setSeoTitleDe(localizedContent.seoTitles().get("de"));
|
||||||
|
product.setSeoTitleFr(localizedContent.seoTitles().get("fr"));
|
||||||
|
product.setSeoDescription(localizedContent.defaultSeoDescription());
|
||||||
|
product.setSeoDescriptionIt(localizedContent.seoDescriptions().get("it"));
|
||||||
|
product.setSeoDescriptionEn(localizedContent.seoDescriptions().get("en"));
|
||||||
|
product.setSeoDescriptionDe(localizedContent.seoDescriptions().get("de"));
|
||||||
|
product.setSeoDescriptionFr(localizedContent.seoDescriptions().get("fr"));
|
||||||
|
product.setOgTitle(localizedContent.defaultSeoTitle());
|
||||||
|
product.setOgDescription(localizedContent.defaultSeoDescription());
|
||||||
|
product.setIndexable(payload.getIndexable() == null || payload.getIndexable());
|
||||||
|
product.setIsFeatured(Boolean.TRUE.equals(payload.getIsFeatured()));
|
||||||
|
product.setIsActive(payload.getIsActive() == null || payload.getIsActive());
|
||||||
|
product.setSortOrder(payload.getSortOrder() != null ? payload.getSortOrder() : 0);
|
||||||
|
product.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyVariantPayload(ShopProductVariant variant,
|
||||||
|
ShopProduct product,
|
||||||
|
AdminUpsertShopProductVariantRequest payload) {
|
||||||
|
String normalizedColorName = normalizeRequired(payload.getColorName(), "Variant colorName is required");
|
||||||
|
String normalizedVariantLabel = normalizeOptional(payload.getVariantLabel());
|
||||||
|
String normalizedSku = normalizeOptional(payload.getSku());
|
||||||
|
String fallbackColorLabel = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getColorLabelIt()),
|
||||||
|
normalizeOptional(payload.getColorLabelEn()),
|
||||||
|
normalizeOptional(payload.getColorLabelDe()),
|
||||||
|
normalizeOptional(payload.getColorLabelFr()),
|
||||||
|
normalizedColorName
|
||||||
|
);
|
||||||
|
String normalizedMaterialCode = normalizeRequired(
|
||||||
|
payload.getInternalMaterialCode(),
|
||||||
|
"Variant internalMaterialCode is required"
|
||||||
|
).toUpperCase(Locale.ROOT);
|
||||||
|
|
||||||
|
BigDecimal price = payload.getPriceChf();
|
||||||
|
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant priceChf must be >= 0");
|
||||||
|
}
|
||||||
|
if (price.scale() > 2) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant priceChf must have at most 2 decimal places");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (normalizedSku != null) {
|
||||||
|
if (variant.getId() == null) {
|
||||||
|
if (shopProductVariantRepository.existsBySkuIgnoreCase(normalizedSku)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant SKU already exists");
|
||||||
|
}
|
||||||
|
} else if (shopProductVariantRepository.existsBySkuIgnoreCaseAndIdNot(normalizedSku, variant.getId())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant SKU already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variant.setProduct(product);
|
||||||
|
variant.setSku(normalizedSku);
|
||||||
|
variant.setVariantLabel(normalizedVariantLabel != null ? normalizedVariantLabel : normalizedColorName);
|
||||||
|
variant.setColorName(normalizedColorName);
|
||||||
|
variant.setColorLabelIt(firstNonBlank(normalizeOptional(payload.getColorLabelIt()), fallbackColorLabel));
|
||||||
|
variant.setColorLabelEn(firstNonBlank(normalizeOptional(payload.getColorLabelEn()), fallbackColorLabel));
|
||||||
|
variant.setColorLabelDe(firstNonBlank(normalizeOptional(payload.getColorLabelDe()), fallbackColorLabel));
|
||||||
|
variant.setColorLabelFr(firstNonBlank(normalizeOptional(payload.getColorLabelFr()), fallbackColorLabel));
|
||||||
|
variant.setColorHex(normalizeColorHex(payload.getColorHex()));
|
||||||
|
variant.setInternalMaterialCode(normalizedMaterialCode);
|
||||||
|
variant.setPriceChf(price);
|
||||||
|
variant.setIsDefault(Boolean.TRUE.equals(payload.getIsDefault()));
|
||||||
|
variant.setIsActive(payload.getIsActive() == null || payload.getIsActive());
|
||||||
|
variant.setSortOrder(payload.getSortOrder() != null ? payload.getSortOrder() : 0);
|
||||||
|
variant.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AdminUpsertShopProductVariantRequest> normalizeVariantPayloads(List<AdminUpsertShopProductVariantRequest> payloads) {
|
||||||
|
if (payloads == null || payloads.isEmpty()) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "At least one variant is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AdminUpsertShopProductVariantRequest> normalized = new ArrayList<>(payloads);
|
||||||
|
Set<String> variantKeys = new LinkedHashSet<>();
|
||||||
|
int defaultCount = 0;
|
||||||
|
for (AdminUpsertShopProductVariantRequest payload : normalized) {
|
||||||
|
if (payload == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant payload is required");
|
||||||
|
}
|
||||||
|
String colorName = normalizeRequired(payload.getColorName(), "Variant colorName is required");
|
||||||
|
String materialCode = normalizeRequired(
|
||||||
|
payload.getInternalMaterialCode(),
|
||||||
|
"Variant internalMaterialCode is required"
|
||||||
|
).toUpperCase(Locale.ROOT);
|
||||||
|
String variantKey = materialCode + "|" + colorName.toLowerCase(Locale.ROOT);
|
||||||
|
if (!variantKeys.add(variantKey)) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"Duplicate variant combination: " + materialCode + " / " + colorName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(payload.getIsDefault())) {
|
||||||
|
defaultCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaultCount > 1) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Only one variant can be default");
|
||||||
|
}
|
||||||
|
if (defaultCount == 0) {
|
||||||
|
AdminUpsertShopProductVariantRequest fallbackDefault = normalized.stream()
|
||||||
|
.filter(payload -> payload.getIsActive() == null || payload.getIsActive())
|
||||||
|
.findFirst()
|
||||||
|
.orElse(normalized.get(0));
|
||||||
|
fallbackDefault.setIsDefault(true);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AdminShopProductDto> toProductDtos(List<ShopProduct> products) {
|
||||||
|
if (products == null || products.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UUID> productIds = products.stream().map(ShopProduct::getId).toList();
|
||||||
|
Map<UUID, List<ShopProductVariant>> variantsByProductId = shopProductVariantRepository
|
||||||
|
.findByProduct_IdInOrderBySortOrderAscColorNameAsc(productIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
variant -> variant.getProduct().getId(),
|
||||||
|
LinkedHashMap::new,
|
||||||
|
Collectors.toList()
|
||||||
|
));
|
||||||
|
Map<UUID, ShopProductModelAsset> modelAssetsByProductId = shopProductModelAssetRepository.findByProduct_IdIn(productIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(asset -> asset.getProduct().getId(), asset -> asset, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
Map<String, List<PublicMediaUsageDto>> publicImagesByUsageKey = publicMediaQueryService.getUsageMediaMap(
|
||||||
|
SHOP_PRODUCT_MEDIA_USAGE_TYPE,
|
||||||
|
products.stream().map(this::mediaUsageKey).toList(),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
return products.stream()
|
||||||
|
.map(product -> {
|
||||||
|
String usageKey = mediaUsageKey(product);
|
||||||
|
return toProductDto(
|
||||||
|
product,
|
||||||
|
variantsByProductId.getOrDefault(product.getId(), List.of()),
|
||||||
|
modelAssetsByProductId.get(product.getId()),
|
||||||
|
publicImagesByUsageKey.getOrDefault(usageKey, List.of()),
|
||||||
|
adminMediaControllerService.getUsages(SHOP_PRODUCT_MEDIA_USAGE_TYPE, usageKey, null)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminShopProductDto toProductDto(ShopProduct product,
|
||||||
|
List<ShopProductVariant> variants,
|
||||||
|
ShopProductModelAsset modelAsset,
|
||||||
|
List<PublicMediaUsageDto> images,
|
||||||
|
List<AdminMediaUsageDto> mediaUsages) {
|
||||||
|
AdminShopProductDto dto = new AdminShopProductDto();
|
||||||
|
dto.setId(product.getId());
|
||||||
|
dto.setCategoryId(product.getCategory() != null ? product.getCategory().getId() : null);
|
||||||
|
dto.setCategoryName(product.getCategory() != null ? product.getCategory().getName() : null);
|
||||||
|
dto.setCategorySlug(product.getCategory() != null ? product.getCategory().getSlug() : null);
|
||||||
|
dto.setSlug(product.getSlug());
|
||||||
|
dto.setName(product.getName());
|
||||||
|
dto.setNameIt(product.getNameIt());
|
||||||
|
dto.setNameEn(product.getNameEn());
|
||||||
|
dto.setNameDe(product.getNameDe());
|
||||||
|
dto.setNameFr(product.getNameFr());
|
||||||
|
dto.setExcerpt(product.getExcerpt());
|
||||||
|
dto.setExcerptIt(product.getExcerptIt());
|
||||||
|
dto.setExcerptEn(product.getExcerptEn());
|
||||||
|
dto.setExcerptDe(product.getExcerptDe());
|
||||||
|
dto.setExcerptFr(product.getExcerptFr());
|
||||||
|
dto.setDescription(product.getDescription());
|
||||||
|
dto.setDescriptionIt(product.getDescriptionIt());
|
||||||
|
dto.setDescriptionEn(product.getDescriptionEn());
|
||||||
|
dto.setDescriptionDe(product.getDescriptionDe());
|
||||||
|
dto.setDescriptionFr(product.getDescriptionFr());
|
||||||
|
dto.setSeoTitle(product.getSeoTitle());
|
||||||
|
dto.setSeoTitleIt(product.getSeoTitleIt());
|
||||||
|
dto.setSeoTitleEn(product.getSeoTitleEn());
|
||||||
|
dto.setSeoTitleDe(product.getSeoTitleDe());
|
||||||
|
dto.setSeoTitleFr(product.getSeoTitleFr());
|
||||||
|
dto.setSeoDescription(product.getSeoDescription());
|
||||||
|
dto.setSeoDescriptionIt(product.getSeoDescriptionIt());
|
||||||
|
dto.setSeoDescriptionEn(product.getSeoDescriptionEn());
|
||||||
|
dto.setSeoDescriptionDe(product.getSeoDescriptionDe());
|
||||||
|
dto.setSeoDescriptionFr(product.getSeoDescriptionFr());
|
||||||
|
dto.setOgTitle(product.getOgTitle());
|
||||||
|
dto.setOgDescription(product.getOgDescription());
|
||||||
|
dto.setIndexable(product.getIndexable());
|
||||||
|
dto.setIsFeatured(product.getIsFeatured());
|
||||||
|
dto.setIsActive(product.getIsActive());
|
||||||
|
dto.setSortOrder(product.getSortOrder());
|
||||||
|
dto.setVariantCount(variants.size());
|
||||||
|
dto.setActiveVariantCount((int) variants.stream().filter(variant -> Boolean.TRUE.equals(variant.getIsActive())).count());
|
||||||
|
dto.setPriceFromChf(resolvePriceFrom(variants));
|
||||||
|
dto.setPriceToChf(resolvePriceTo(variants));
|
||||||
|
dto.setMediaUsageType(SHOP_PRODUCT_MEDIA_USAGE_TYPE);
|
||||||
|
dto.setMediaUsageKey(mediaUsageKey(product));
|
||||||
|
dto.setMediaUsages(mediaUsages);
|
||||||
|
dto.setImages(images);
|
||||||
|
dto.setModel3d(toModelDto(product, modelAsset));
|
||||||
|
dto.setVariants(variants.stream().map(this::toVariantDto).toList());
|
||||||
|
dto.setCreatedAt(product.getCreatedAt());
|
||||||
|
dto.setUpdatedAt(product.getUpdatedAt());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminShopProductVariantDto toVariantDto(ShopProductVariant variant) {
|
||||||
|
AdminShopProductVariantDto dto = new AdminShopProductVariantDto();
|
||||||
|
dto.setId(variant.getId());
|
||||||
|
dto.setSku(variant.getSku());
|
||||||
|
dto.setVariantLabel(variant.getVariantLabel());
|
||||||
|
dto.setColorName(variant.getColorName());
|
||||||
|
dto.setColorLabelIt(variant.getColorLabelIt());
|
||||||
|
dto.setColorLabelEn(variant.getColorLabelEn());
|
||||||
|
dto.setColorLabelDe(variant.getColorLabelDe());
|
||||||
|
dto.setColorLabelFr(variant.getColorLabelFr());
|
||||||
|
dto.setColorHex(variant.getColorHex());
|
||||||
|
dto.setInternalMaterialCode(variant.getInternalMaterialCode());
|
||||||
|
dto.setPriceChf(variant.getPriceChf());
|
||||||
|
dto.setIsDefault(variant.getIsDefault());
|
||||||
|
dto.setIsActive(variant.getIsActive());
|
||||||
|
dto.setSortOrder(variant.getSortOrder());
|
||||||
|
dto.setCreatedAt(variant.getCreatedAt());
|
||||||
|
dto.setUpdatedAt(variant.getUpdatedAt());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductModelDto toModelDto(ShopProduct product, ShopProductModelAsset asset) {
|
||||||
|
if (asset == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ShopProductModelDto(
|
||||||
|
"/api/admin/shop/products/" + product.getId() + "/model",
|
||||||
|
asset.getOriginalFilename(),
|
||||||
|
asset.getMimeType(),
|
||||||
|
asset.getFileSizeBytes(),
|
||||||
|
asset.getBoundingBoxXMm(),
|
||||||
|
asset.getBoundingBoxYMm(),
|
||||||
|
asset.getBoundingBoxZMm()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal resolvePriceFrom(List<ShopProductVariant> variants) {
|
||||||
|
return variants.stream()
|
||||||
|
.map(ShopProductVariant::getPriceChf)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(BigDecimal::compareTo)
|
||||||
|
.orElse(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal resolvePriceTo(List<ShopProductVariant> variants) {
|
||||||
|
return variants.stream()
|
||||||
|
.map(ShopProductVariant::getPriceChf)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.max(BigDecimal::compareTo)
|
||||||
|
.orElse(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopCategory resolveCategory(UUID categoryId) {
|
||||||
|
if (categoryId == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "categoryId is required");
|
||||||
|
}
|
||||||
|
return shopCategoryRepository.findById(categoryId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "Category not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensurePayload(AdminUpsertShopProductRequest payload) {
|
||||||
|
if (payload == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Payload is required");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalizedProductContent normalizeLocalizedProductContent(AdminUpsertShopProductRequest payload) {
|
||||||
|
String legacyName = normalizeOptional(payload.getName());
|
||||||
|
String fallbackName = firstNonBlank(
|
||||||
|
legacyName,
|
||||||
|
normalizeOptional(payload.getNameIt()),
|
||||||
|
normalizeOptional(payload.getNameEn()),
|
||||||
|
normalizeOptional(payload.getNameDe()),
|
||||||
|
normalizeOptional(payload.getNameFr())
|
||||||
|
);
|
||||||
|
if (fallbackName == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Product name is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> names = new LinkedHashMap<>();
|
||||||
|
names.put("it", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameIt()), fallbackName), "Italian product name is required"));
|
||||||
|
names.put("en", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameEn()), fallbackName), "English product name is required"));
|
||||||
|
names.put("de", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameDe()), fallbackName), "German product name is required"));
|
||||||
|
names.put("fr", normalizeRequired(firstNonBlank(normalizeOptional(payload.getNameFr()), fallbackName), "French product name is required"));
|
||||||
|
|
||||||
|
String fallbackExcerpt = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getExcerpt()),
|
||||||
|
normalizeOptional(payload.getExcerptIt()),
|
||||||
|
normalizeOptional(payload.getExcerptEn()),
|
||||||
|
normalizeOptional(payload.getExcerptDe()),
|
||||||
|
normalizeOptional(payload.getExcerptFr())
|
||||||
|
);
|
||||||
|
Map<String, String> excerpts = new LinkedHashMap<>();
|
||||||
|
excerpts.put("it", firstNonBlank(normalizeOptional(payload.getExcerptIt()), fallbackExcerpt));
|
||||||
|
excerpts.put("en", firstNonBlank(normalizeOptional(payload.getExcerptEn()), fallbackExcerpt));
|
||||||
|
excerpts.put("de", firstNonBlank(normalizeOptional(payload.getExcerptDe()), fallbackExcerpt));
|
||||||
|
excerpts.put("fr", firstNonBlank(normalizeOptional(payload.getExcerptFr()), fallbackExcerpt));
|
||||||
|
|
||||||
|
String fallbackDescription = firstNonBlank(
|
||||||
|
normalizeRichTextOptional(payload.getDescription()),
|
||||||
|
normalizeRichTextOptional(payload.getDescriptionIt()),
|
||||||
|
normalizeRichTextOptional(payload.getDescriptionEn()),
|
||||||
|
normalizeRichTextOptional(payload.getDescriptionDe()),
|
||||||
|
normalizeRichTextOptional(payload.getDescriptionFr())
|
||||||
|
);
|
||||||
|
Map<String, String> descriptions = new LinkedHashMap<>();
|
||||||
|
descriptions.put("it", firstNonBlank(normalizeRichTextOptional(payload.getDescriptionIt()), fallbackDescription));
|
||||||
|
descriptions.put("en", firstNonBlank(normalizeRichTextOptional(payload.getDescriptionEn()), fallbackDescription));
|
||||||
|
descriptions.put("de", firstNonBlank(normalizeRichTextOptional(payload.getDescriptionDe()), fallbackDescription));
|
||||||
|
descriptions.put("fr", firstNonBlank(normalizeRichTextOptional(payload.getDescriptionFr()), fallbackDescription));
|
||||||
|
|
||||||
|
String fallbackSeoTitle = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getSeoTitle()),
|
||||||
|
normalizeOptional(payload.getSeoTitleIt()),
|
||||||
|
normalizeOptional(payload.getSeoTitleEn()),
|
||||||
|
normalizeOptional(payload.getSeoTitleDe()),
|
||||||
|
normalizeOptional(payload.getSeoTitleFr())
|
||||||
|
);
|
||||||
|
Map<String, String> seoTitles = new LinkedHashMap<>();
|
||||||
|
seoTitles.put("it", firstNonBlank(normalizeOptional(payload.getSeoTitleIt()), fallbackSeoTitle));
|
||||||
|
seoTitles.put("en", firstNonBlank(normalizeOptional(payload.getSeoTitleEn()), fallbackSeoTitle));
|
||||||
|
seoTitles.put("de", firstNonBlank(normalizeOptional(payload.getSeoTitleDe()), fallbackSeoTitle));
|
||||||
|
seoTitles.put("fr", firstNonBlank(normalizeOptional(payload.getSeoTitleFr()), fallbackSeoTitle));
|
||||||
|
|
||||||
|
String fallbackSeoDescription = firstNonBlank(
|
||||||
|
normalizeOptional(payload.getSeoDescription()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionIt()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionEn()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionDe()),
|
||||||
|
normalizeOptional(payload.getSeoDescriptionFr())
|
||||||
|
);
|
||||||
|
Map<String, String> seoDescriptions = new LinkedHashMap<>();
|
||||||
|
seoDescriptions.put("it", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionIt()), fallbackSeoDescription), "Italian"));
|
||||||
|
seoDescriptions.put("en", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionEn()), fallbackSeoDescription), "English"));
|
||||||
|
seoDescriptions.put("de", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionDe()), fallbackSeoDescription), "German"));
|
||||||
|
seoDescriptions.put("fr", validateSeoDescriptionLength(firstNonBlank(normalizeOptional(payload.getSeoDescriptionFr()), fallbackSeoDescription), "French"));
|
||||||
|
|
||||||
|
return new LocalizedProductContent(
|
||||||
|
names.get("it"),
|
||||||
|
firstNonBlank(excerpts.get("it"), fallbackExcerpt),
|
||||||
|
firstNonBlank(descriptions.get("it"), fallbackDescription),
|
||||||
|
firstNonBlank(seoTitles.get("it"), fallbackSeoTitle),
|
||||||
|
firstNonBlank(seoDescriptions.get("it"), fallbackSeoDescription),
|
||||||
|
names,
|
||||||
|
excerpts,
|
||||||
|
descriptions,
|
||||||
|
seoTitles,
|
||||||
|
seoDescriptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureSlugAvailable(String slug, UUID currentProductId) {
|
||||||
|
shopProductRepository.findBySlugIgnoreCase(slug).ifPresent(existing -> {
|
||||||
|
if (currentProductId == null || !existing.getId().equals(currentProductId)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Product slug already exists");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeRequired(String value, String message) {
|
||||||
|
String normalized = normalizeOptional(value);
|
||||||
|
if (normalized == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, message);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeOptional(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String normalized = value.trim();
|
||||||
|
return normalized.isBlank() ? null : normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeRichTextOptional(String value) {
|
||||||
|
String normalized = normalizeOptional(value);
|
||||||
|
if (normalized == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sanitized = Jsoup.clean(
|
||||||
|
normalized,
|
||||||
|
"",
|
||||||
|
PRODUCT_DESCRIPTION_SAFELIST,
|
||||||
|
new Document.OutputSettings().prettyPrint(false)
|
||||||
|
).trim();
|
||||||
|
|
||||||
|
if (sanitized.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String plainText = Jsoup.parse(sanitized).text();
|
||||||
|
return plainText != null && !plainText.trim().isEmpty() ? sanitized : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeAndValidateSlug(String slug, String fallbackName) {
|
||||||
|
String source = normalizeOptional(slug);
|
||||||
|
if (source == null) {
|
||||||
|
source = fallbackName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalized = Normalizer.normalize(source, Normalizer.Form.NFD);
|
||||||
|
normalized = DIACRITICS_PATTERN.matcher(normalized).replaceAll("");
|
||||||
|
normalized = normalized.toLowerCase(Locale.ROOT);
|
||||||
|
normalized = NON_ALPHANUMERIC_PATTERN.matcher(normalized).replaceAll("-");
|
||||||
|
normalized = EDGE_DASH_PATTERN.matcher(normalized).replaceAll("");
|
||||||
|
if (normalized.isBlank()) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Slug is invalid");
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeColorHex(String value) {
|
||||||
|
String normalized = normalizeOptional(value);
|
||||||
|
if (normalized == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!HEX_COLOR_PATTERN.matcher(normalized).matches()) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Variant colorHex must be in format #RRGGBB");
|
||||||
|
}
|
||||||
|
return normalized.toUpperCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String validateSeoDescriptionLength(String value, String languageLabel) {
|
||||||
|
if (value != null && value.length() > 160) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, languageLabel + " SEO description must be at most 160 characters");
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateModelUpload(MultipartFile file) {
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "3D model file is required");
|
||||||
|
}
|
||||||
|
if (maxModelFileSizeBytes > 0 && file.getSize() > maxModelFileSizeBytes) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "3D model file exceeds size limit");
|
||||||
|
}
|
||||||
|
String extension = resolveExtension(sanitizeOriginalFilename(file.getOriginalFilename()));
|
||||||
|
if (!SUPPORTED_MODEL_EXTENSIONS.contains(extension)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported 3D model type. Allowed: stl, 3mf");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String sanitizeOriginalFilename(String originalFilename) {
|
||||||
|
String cleaned = StringUtils.cleanPath(originalFilename == null ? "" : originalFilename);
|
||||||
|
int separatorIndex = Math.max(cleaned.lastIndexOf('/'), cleaned.lastIndexOf('\\'));
|
||||||
|
String basename = separatorIndex >= 0 ? cleaned.substring(separatorIndex + 1) : cleaned;
|
||||||
|
basename = basename.replace("\r", "_").replace("\n", "_");
|
||||||
|
return basename.isBlank() ? "model.stl" : basename;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveExtension(String filename) {
|
||||||
|
int dotIndex = filename.lastIndexOf('.');
|
||||||
|
if (dotIndex < 0 || dotIndex == filename.length() - 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return filename.substring(dotIndex + 1).toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildDownloadFilename(String originalFilename) {
|
||||||
|
int dotIndex = originalFilename.lastIndexOf('.');
|
||||||
|
String base = dotIndex > 0 ? originalFilename.substring(0, dotIndex) : originalFilename;
|
||||||
|
return base + ".stl";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mediaUsageKey(ShopProduct product) {
|
||||||
|
return product.getId().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteExistingModelFile(ShopProductModelAsset asset, UUID productId) {
|
||||||
|
if (asset == null || asset.getStoredRelativePath() == null || asset.getStoredRelativePath().isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Path existingPath = shopStorageService.resolveStoredProductPath(asset.getStoredRelativePath(), productId);
|
||||||
|
if (existingPath == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(existingPath);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteStoredRelativePath(String storedRelativePath, UUID productId, String excludeStoredRelativePath) {
|
||||||
|
if (storedRelativePath == null || storedRelativePath.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Objects.equals(storedRelativePath, excludeStoredRelativePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Path existingPath = shopStorageService.resolveStoredProductPath(storedRelativePath, productId);
|
||||||
|
deletePathQuietly(existingPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String computeSha256(Path file) throws IOException {
|
||||||
|
MessageDigest digest;
|
||||||
|
try {
|
||||||
|
digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IOException("SHA-256 digest unavailable", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = Files.newInputStream(file)) {
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
int read;
|
||||||
|
while ((read = inputStream.read(buffer)) >= 0) {
|
||||||
|
if (read > 0) {
|
||||||
|
digest.update(buffer, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HexFormat.of().formatHex(digest.digest());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deletePathQuietly(Path path) {
|
||||||
|
if (path == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(path);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteRecursively(Path path) {
|
||||||
|
if (path == null || !Files.exists(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try (var walk = Files.walk(path)) {
|
||||||
|
walk.sorted(Comparator.reverseOrder()).forEach(current -> {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(current);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ProductModelDownload(Path path, String filename, String mimeType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record LocalizedProductContent(
|
||||||
|
String defaultName,
|
||||||
|
String defaultExcerpt,
|
||||||
|
String defaultDescription,
|
||||||
|
String defaultSeoTitle,
|
||||||
|
String defaultSeoDescription,
|
||||||
|
Map<String, String> names,
|
||||||
|
Map<String, String> excerpts,
|
||||||
|
Map<String, String> descriptions,
|
||||||
|
Map<String, String> seoTitles,
|
||||||
|
Map<String, String> seoDescriptions
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,685 @@
|
|||||||
|
package com.printcalculator.service.admin;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.printcalculator.dto.AdminTranslateShopProductRequest;
|
||||||
|
import com.printcalculator.dto.AdminTranslateShopProductResponse;
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import com.printcalculator.repository.ShopCategoryRepository;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.safety.Safelist;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class AdminShopProductTranslationService {
|
||||||
|
private static final List<String> SUPPORTED_LANGUAGES = List.of("it", "en", "de", "fr");
|
||||||
|
private static final Safelist PRODUCT_DESCRIPTION_SAFELIST = Safelist.none()
|
||||||
|
.addTags("p", "div", "br", "strong", "b", "em", "i", "u", "ul", "ol", "li", "a")
|
||||||
|
.addAttributes("a", "href")
|
||||||
|
.addProtocols("a", "href", "http", "https", "mailto", "tel");
|
||||||
|
private static final String DEFAULT_SHOP_CONTEXT = """
|
||||||
|
3D fab is a Swiss-based 3D printing shop and technical service.
|
||||||
|
The tone must be practical, clear, technical, and trustworthy.
|
||||||
|
Avoid hype, avoid invented claims, and avoid vague marketing filler.
|
||||||
|
Preserve all brand names, measurements, materials, SKUs, codes, and technical terminology exactly when they should not be translated.
|
||||||
|
When the source field is empty, return an empty string rather than inventing content.
|
||||||
|
For descriptions, preserve safe HTML structure when present and keep output ready for an ecommerce/admin form.
|
||||||
|
For SEO, prefer concise, natural phrases suitable for ecommerce and search snippets.
|
||||||
|
""";
|
||||||
|
|
||||||
|
private final ShopCategoryRepository shopCategoryRepository;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
private final HttpClient httpClient;
|
||||||
|
private final String apiKey;
|
||||||
|
private final String baseUrl;
|
||||||
|
private final String model;
|
||||||
|
private final Duration timeout;
|
||||||
|
private final String promptCacheKeyPrefix;
|
||||||
|
private final String additionalBusinessContext;
|
||||||
|
|
||||||
|
public AdminShopProductTranslationService(ShopCategoryRepository shopCategoryRepository,
|
||||||
|
ObjectMapper objectMapper,
|
||||||
|
@Value("${openai.translation.api-key:}") String apiKey,
|
||||||
|
@Value("${openai.translation.base-url:https://api.openai.com/v1}") String baseUrl,
|
||||||
|
@Value("${openai.translation.model:gpt-5.4}") String model,
|
||||||
|
@Value("${openai.translation.timeout-seconds:45}") long timeoutSeconds,
|
||||||
|
@Value("${openai.translation.prompt-cache-key-prefix:printcalc-shop-product-translation-v1}") String promptCacheKeyPrefix,
|
||||||
|
@Value("${openai.translation.business-context:}") String additionalBusinessContext) {
|
||||||
|
this.shopCategoryRepository = shopCategoryRepository;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
this.apiKey = apiKey != null ? apiKey.trim() : "";
|
||||||
|
this.baseUrl = normalizeBaseUrl(baseUrl);
|
||||||
|
this.model = model != null ? model.trim() : "";
|
||||||
|
this.timeout = Duration.ofSeconds(Math.max(timeoutSeconds, 5));
|
||||||
|
this.promptCacheKeyPrefix = promptCacheKeyPrefix != null && !promptCacheKeyPrefix.isBlank()
|
||||||
|
? promptCacheKeyPrefix.trim()
|
||||||
|
: "printcalc-shop-product-translation-v1";
|
||||||
|
this.additionalBusinessContext = additionalBusinessContext != null ? additionalBusinessContext.trim() : "";
|
||||||
|
this.httpClient = HttpClient.newBuilder()
|
||||||
|
.connectTimeout(this.timeout)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdminTranslateShopProductResponse translateProduct(AdminTranslateShopProductRequest payload) {
|
||||||
|
ensureConfigured();
|
||||||
|
NormalizedTranslationRequest normalizedRequest = normalizeRequest(payload);
|
||||||
|
List<String> targetLanguages = resolveTargetLanguages(normalizedRequest);
|
||||||
|
if (targetLanguages.isEmpty()) {
|
||||||
|
return emptyResponse(normalizedRequest.sourceLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(normalizedRequest.categoryId());
|
||||||
|
String businessContext = buildBusinessContext(categoryContext, normalizedRequest.materialCodes());
|
||||||
|
|
||||||
|
TranslationBundle generated = callOpenAiFunction(
|
||||||
|
"generate_product_translations",
|
||||||
|
"Generate translated product copy for the requested target languages.",
|
||||||
|
buildInstructions("Generate the first-pass translations.", businessContext),
|
||||||
|
buildGenerationInput(normalizedRequest, targetLanguages, categoryContext),
|
||||||
|
buildTranslationToolSchema(targetLanguages),
|
||||||
|
"generate"
|
||||||
|
);
|
||||||
|
|
||||||
|
TranslationBundle normalizedGenerated = sanitizeBundle(generated, targetLanguages);
|
||||||
|
List<String> validationNotes = buildValidationNotes(normalizedGenerated, targetLanguages);
|
||||||
|
|
||||||
|
TranslationBundle reviewed = callOpenAiFunction(
|
||||||
|
"review_product_translations",
|
||||||
|
"Review and correct translated product copy while preserving meaning, SEO limits, and technical terminology.",
|
||||||
|
buildInstructions("Review and correct the generated translations.", businessContext),
|
||||||
|
buildReviewInput(normalizedRequest, normalizedGenerated, targetLanguages, categoryContext, validationNotes),
|
||||||
|
buildTranslationToolSchema(targetLanguages),
|
||||||
|
"review"
|
||||||
|
);
|
||||||
|
|
||||||
|
TranslationBundle finalBundle = sanitizeBundle(reviewed, targetLanguages);
|
||||||
|
ensureRequiredTranslations(finalBundle, targetLanguages);
|
||||||
|
return toResponse(normalizedRequest.sourceLanguage(), targetLanguages, finalBundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureConfigured() {
|
||||||
|
if (apiKey.isBlank() || model.isBlank()) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.SERVICE_UNAVAILABLE,
|
||||||
|
"OpenAI translation is not configured on the backend"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private NormalizedTranslationRequest normalizeRequest(AdminTranslateShopProductRequest payload) {
|
||||||
|
if (payload == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Translation payload is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
String sourceLanguage = normalizeLanguage(payload.getSourceLanguage());
|
||||||
|
if (!SUPPORTED_LANGUAGES.contains(sourceLanguage)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported source language");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> names = normalizeLocalizedMap(payload.getNames(), false);
|
||||||
|
Map<String, String> excerpts = normalizeLocalizedMap(payload.getExcerpts(), false);
|
||||||
|
Map<String, String> descriptions = normalizeLocalizedMap(payload.getDescriptions(), true);
|
||||||
|
Map<String, String> seoTitles = normalizeLocalizedMap(payload.getSeoTitles(), false);
|
||||||
|
Map<String, String> seoDescriptions = normalizeLocalizedMap(payload.getSeoDescriptions(), false);
|
||||||
|
|
||||||
|
if (names.get(sourceLanguage).isBlank()) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
"The active source language must have a product name before translation"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> materialCodes = new LinkedHashSet<>();
|
||||||
|
if (payload.getMaterialCodes() != null) {
|
||||||
|
for (String materialCode : payload.getMaterialCodes()) {
|
||||||
|
String normalizedCode = normalizeOptional(materialCode);
|
||||||
|
if (normalizedCode != null) {
|
||||||
|
materialCodes.add(normalizedCode.toUpperCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NormalizedTranslationRequest(
|
||||||
|
payload.getCategoryId(),
|
||||||
|
sourceLanguage,
|
||||||
|
Boolean.TRUE.equals(payload.getOverwriteExisting()),
|
||||||
|
List.copyOf(materialCodes),
|
||||||
|
names,
|
||||||
|
excerpts,
|
||||||
|
descriptions,
|
||||||
|
seoTitles,
|
||||||
|
seoDescriptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> resolveTargetLanguages(NormalizedTranslationRequest request) {
|
||||||
|
List<String> targetLanguages = new ArrayList<>();
|
||||||
|
for (String language : SUPPORTED_LANGUAGES) {
|
||||||
|
if (language.equals(request.sourceLanguage())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (request.overwriteExisting() || needsTranslation(request, language)) {
|
||||||
|
targetLanguages.add(language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return targetLanguages;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needsTranslation(NormalizedTranslationRequest request, String language) {
|
||||||
|
return request.names().get(language).isBlank()
|
||||||
|
|| request.excerpts().get(language).isBlank()
|
||||||
|
|| normalizeRichTextOptional(request.descriptions().get(language)) == null
|
||||||
|
|| request.seoTitles().get(language).isBlank()
|
||||||
|
|| request.seoDescriptions().get(language).isBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CategoryContext loadCategoryContext(UUID categoryId) {
|
||||||
|
if (categoryId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ShopCategory category = shopCategoryRepository.findById(categoryId).orElse(null);
|
||||||
|
if (category == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new CategoryContext(
|
||||||
|
category.getSlug(),
|
||||||
|
Map.of(
|
||||||
|
"it", safeValue(category.getNameIt()),
|
||||||
|
"en", safeValue(category.getNameEn()),
|
||||||
|
"de", safeValue(category.getNameDe()),
|
||||||
|
"fr", safeValue(category.getNameFr())
|
||||||
|
),
|
||||||
|
Map.of(
|
||||||
|
"it", safeValue(category.getDescriptionIt()),
|
||||||
|
"en", safeValue(category.getDescriptionEn()),
|
||||||
|
"de", safeValue(category.getDescriptionDe()),
|
||||||
|
"fr", safeValue(category.getDescriptionFr())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildBusinessContext(CategoryContext categoryContext, List<String> materialCodes) {
|
||||||
|
StringBuilder context = new StringBuilder(DEFAULT_SHOP_CONTEXT);
|
||||||
|
if (!additionalBusinessContext.isBlank()) {
|
||||||
|
context.append('\n').append(additionalBusinessContext.trim());
|
||||||
|
}
|
||||||
|
if (categoryContext != null) {
|
||||||
|
context.append("\nCategory slug: ").append(categoryContext.slug());
|
||||||
|
context.append("\nCategory names: ").append(writeJson(categoryContext.names()));
|
||||||
|
if (categoryContext.descriptions().values().stream().anyMatch(value -> !value.isBlank())) {
|
||||||
|
context.append("\nCategory descriptions: ").append(writeJson(categoryContext.descriptions()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (materialCodes != null && !materialCodes.isEmpty()) {
|
||||||
|
context.append("\nMaterial codes present in the product: ").append(String.join(", ", materialCodes));
|
||||||
|
}
|
||||||
|
return context.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildInstructions(String task, String businessContext) {
|
||||||
|
return """
|
||||||
|
You are a senior ecommerce localization editor.
|
||||||
|
Task: %s
|
||||||
|
Return only the function call arguments that match the provided schema.
|
||||||
|
Always preserve meaning, HTML safety, and technical precision.
|
||||||
|
Never invent specifications or marketing claims not present in the source.
|
||||||
|
If a source field is empty, return an empty string for that field.
|
||||||
|
General context:
|
||||||
|
%s
|
||||||
|
""".formatted(task, businessContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildGenerationInput(NormalizedTranslationRequest request,
|
||||||
|
List<String> targetLanguages,
|
||||||
|
CategoryContext categoryContext) {
|
||||||
|
ObjectNode input = objectMapper.createObjectNode();
|
||||||
|
input.put("sourceLanguage", request.sourceLanguage());
|
||||||
|
input.set("targetLanguages", objectMapper.valueToTree(targetLanguages));
|
||||||
|
input.put("overwriteExisting", request.overwriteExisting());
|
||||||
|
input.set("source", localizedFieldNode(request, request.sourceLanguage()));
|
||||||
|
input.set("existingTranslations", existingTranslationsNode(request, targetLanguages));
|
||||||
|
input.set("materialCodes", objectMapper.valueToTree(request.materialCodes()));
|
||||||
|
if (categoryContext != null) {
|
||||||
|
input.put("categorySlug", categoryContext.slug());
|
||||||
|
input.set("categoryNames", objectMapper.valueToTree(categoryContext.names()));
|
||||||
|
}
|
||||||
|
return writeJson(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildReviewInput(NormalizedTranslationRequest request,
|
||||||
|
TranslationBundle generated,
|
||||||
|
List<String> targetLanguages,
|
||||||
|
CategoryContext categoryContext,
|
||||||
|
List<String> validationNotes) {
|
||||||
|
ObjectNode input = objectMapper.createObjectNode();
|
||||||
|
input.put("sourceLanguage", request.sourceLanguage());
|
||||||
|
input.set("targetLanguages", objectMapper.valueToTree(targetLanguages));
|
||||||
|
input.set("source", localizedFieldNode(request, request.sourceLanguage()));
|
||||||
|
input.set("generatedTranslations", generated.toJsonNode(objectMapper));
|
||||||
|
input.set("validationNotes", objectMapper.valueToTree(validationNotes));
|
||||||
|
input.set("materialCodes", objectMapper.valueToTree(request.materialCodes()));
|
||||||
|
if (categoryContext != null) {
|
||||||
|
input.put("categorySlug", categoryContext.slug());
|
||||||
|
input.set("categoryNames", objectMapper.valueToTree(categoryContext.names()));
|
||||||
|
}
|
||||||
|
return writeJson(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode localizedFieldNode(NormalizedTranslationRequest request, String language) {
|
||||||
|
ObjectNode node = objectMapper.createObjectNode();
|
||||||
|
node.put("name", request.names().get(language));
|
||||||
|
node.put("excerpt", request.excerpts().get(language));
|
||||||
|
node.put("description", request.descriptions().get(language));
|
||||||
|
node.put("seoTitle", request.seoTitles().get(language));
|
||||||
|
node.put("seoDescription", request.seoDescriptions().get(language));
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode existingTranslationsNode(NormalizedTranslationRequest request, List<String> targetLanguages) {
|
||||||
|
ObjectNode node = objectMapper.createObjectNode();
|
||||||
|
for (String language : targetLanguages) {
|
||||||
|
node.set(language, localizedFieldNode(request, language));
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode buildTranslationToolSchema(List<String> targetLanguages) {
|
||||||
|
ObjectNode root = objectMapper.createObjectNode();
|
||||||
|
root.put("type", "object");
|
||||||
|
root.put("additionalProperties", false);
|
||||||
|
|
||||||
|
ObjectNode properties = root.putObject("properties");
|
||||||
|
ObjectNode translations = properties.putObject("translations");
|
||||||
|
translations.put("type", "object");
|
||||||
|
translations.put("additionalProperties", false);
|
||||||
|
|
||||||
|
ObjectNode translationProperties = translations.putObject("properties");
|
||||||
|
ArrayNode requiredTranslations = translations.putArray("required");
|
||||||
|
for (String language : targetLanguages) {
|
||||||
|
translationProperties.set(language, buildTranslationSchemaForLanguage(language));
|
||||||
|
requiredTranslations.add(language);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayNode required = root.putArray("required");
|
||||||
|
required.add("translations");
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode buildTranslationSchemaForLanguage(String language) {
|
||||||
|
ObjectNode languageSchema = objectMapper.createObjectNode();
|
||||||
|
languageSchema.put("type", "object");
|
||||||
|
languageSchema.put("additionalProperties", false);
|
||||||
|
languageSchema.put("description", "Localized product copy for language " + language);
|
||||||
|
|
||||||
|
ObjectNode properties = languageSchema.putObject("properties");
|
||||||
|
addSchemaString(properties, "name", "Translated product name. Never empty.");
|
||||||
|
addSchemaString(properties, "excerpt", "Short excerpt. Empty string if source excerpt is empty.");
|
||||||
|
addSchemaString(properties, "description", "Product description as safe HTML or empty string if source description is empty.");
|
||||||
|
addSchemaString(properties, "seoTitle", "SEO title. Empty string if source SEO title is empty.");
|
||||||
|
addSchemaString(properties, "seoDescription", "SEO description, ideally under 160 characters. Empty string if source SEO description is empty.");
|
||||||
|
|
||||||
|
ArrayNode required = languageSchema.putArray("required");
|
||||||
|
required.add("name");
|
||||||
|
required.add("excerpt");
|
||||||
|
required.add("description");
|
||||||
|
required.add("seoTitle");
|
||||||
|
required.add("seoDescription");
|
||||||
|
return languageSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSchemaString(ObjectNode properties, String name, String description) {
|
||||||
|
ObjectNode property = properties.putObject(name);
|
||||||
|
property.put("type", "string");
|
||||||
|
property.put("description", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TranslationBundle callOpenAiFunction(String functionName,
|
||||||
|
String functionDescription,
|
||||||
|
String instructions,
|
||||||
|
String input,
|
||||||
|
ObjectNode parametersSchema,
|
||||||
|
String cacheSuffix) {
|
||||||
|
ObjectNode requestPayload = objectMapper.createObjectNode();
|
||||||
|
requestPayload.put("model", model);
|
||||||
|
requestPayload.put("instructions", instructions);
|
||||||
|
requestPayload.put("input", input);
|
||||||
|
requestPayload.put("tool_choice", "required");
|
||||||
|
requestPayload.put("temperature", 0.2);
|
||||||
|
requestPayload.put("store", false);
|
||||||
|
requestPayload.put("prompt_cache_key", promptCacheKeyPrefix + ":" + cacheSuffix);
|
||||||
|
|
||||||
|
ArrayNode tools = requestPayload.putArray("tools");
|
||||||
|
ObjectNode tool = tools.addObject();
|
||||||
|
tool.put("type", "function");
|
||||||
|
tool.put("name", functionName);
|
||||||
|
tool.put("description", functionDescription);
|
||||||
|
tool.put("strict", true);
|
||||||
|
tool.set("parameters", parametersSchema);
|
||||||
|
|
||||||
|
JsonNode responseNode = postResponsesRequest(requestPayload);
|
||||||
|
JsonNode output = responseNode.path("output");
|
||||||
|
if (output.isArray()) {
|
||||||
|
for (JsonNode item : output) {
|
||||||
|
if ("function_call".equals(item.path("type").asText())) {
|
||||||
|
String arguments = item.path("arguments").asText("");
|
||||||
|
if (arguments.isBlank()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JsonNode argumentsNode = objectMapper.readTree(arguments);
|
||||||
|
JsonNode translationsNode = argumentsNode.path("translations");
|
||||||
|
if (!translationsNode.isObject()) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
"OpenAI returned a function call without translations"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return TranslationBundle.fromJson(translationsNode);
|
||||||
|
} catch (JsonProcessingException exception) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
"OpenAI returned invalid JSON arguments",
|
||||||
|
exception
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
"OpenAI did not return the expected function call"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonNode postResponsesRequest(ObjectNode requestPayload) {
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(baseUrl + "/responses"))
|
||||||
|
.timeout(timeout)
|
||||||
|
.header("Authorization", "Bearer " + apiKey)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(writeJson(requestPayload)))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
JsonNode body = readJson(response.body());
|
||||||
|
if (response.statusCode() >= 400) {
|
||||||
|
String message = body.path("error").path("message").asText("").trim();
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
message.isBlank() ? "OpenAI translation request failed" : message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return body;
|
||||||
|
} catch (IOException exception) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
"Unable to read the OpenAI translation response",
|
||||||
|
exception
|
||||||
|
);
|
||||||
|
} catch (InterruptedException exception) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
"The OpenAI translation request was interrupted",
|
||||||
|
exception
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> buildValidationNotes(TranslationBundle bundle, List<String> targetLanguages) {
|
||||||
|
List<String> notes = new ArrayList<>();
|
||||||
|
for (String language : targetLanguages) {
|
||||||
|
if (bundle.names().getOrDefault(language, "").isBlank()) {
|
||||||
|
notes.add(language + ": translated name is empty and must be fixed");
|
||||||
|
}
|
||||||
|
String seoDescription = bundle.seoDescriptions().getOrDefault(language, "");
|
||||||
|
if (seoDescription.length() > 160) {
|
||||||
|
notes.add(language + ": seoDescription exceeds 160 characters and must be shortened");
|
||||||
|
}
|
||||||
|
String description = bundle.descriptions().getOrDefault(language, "");
|
||||||
|
if (!description.isBlank() && normalizeRichTextOptional(description) == null) {
|
||||||
|
notes.add(language + ": description lost meaningful text during sanitization");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (notes.isEmpty()) {
|
||||||
|
notes.add("No structural validation issues were found. Review naturalness, terminology, SEO clarity, and consistency.");
|
||||||
|
}
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TranslationBundle sanitizeBundle(TranslationBundle bundle, List<String> targetLanguages) {
|
||||||
|
Map<String, String> names = new LinkedHashMap<>();
|
||||||
|
Map<String, String> excerpts = new LinkedHashMap<>();
|
||||||
|
Map<String, String> descriptions = new LinkedHashMap<>();
|
||||||
|
Map<String, String> seoTitles = new LinkedHashMap<>();
|
||||||
|
Map<String, String> seoDescriptions = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (String language : targetLanguages) {
|
||||||
|
names.put(language, safeValue(bundle.names().get(language)));
|
||||||
|
excerpts.put(language, safeValue(bundle.excerpts().get(language)));
|
||||||
|
descriptions.put(language, safeDescription(bundle.descriptions().get(language)));
|
||||||
|
seoTitles.put(language, safeValue(bundle.seoTitles().get(language)));
|
||||||
|
seoDescriptions.put(language, limitSeoDescription(safeValue(bundle.seoDescriptions().get(language))));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TranslationBundle(names, excerpts, descriptions, seoTitles, seoDescriptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureRequiredTranslations(TranslationBundle bundle, List<String> targetLanguages) {
|
||||||
|
for (String language : targetLanguages) {
|
||||||
|
if (bundle.names().getOrDefault(language, "").isBlank()) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
"OpenAI did not return a valid translated name for " + language.toUpperCase(Locale.ROOT)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminTranslateShopProductResponse toResponse(String sourceLanguage,
|
||||||
|
List<String> targetLanguages,
|
||||||
|
TranslationBundle bundle) {
|
||||||
|
AdminTranslateShopProductResponse response = new AdminTranslateShopProductResponse();
|
||||||
|
response.setSourceLanguage(sourceLanguage);
|
||||||
|
response.setTargetLanguages(targetLanguages);
|
||||||
|
response.setNames(bundle.names());
|
||||||
|
response.setExcerpts(bundle.excerpts());
|
||||||
|
response.setDescriptions(bundle.descriptions());
|
||||||
|
response.setSeoTitles(bundle.seoTitles());
|
||||||
|
response.setSeoDescriptions(bundle.seoDescriptions());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AdminTranslateShopProductResponse emptyResponse(String sourceLanguage) {
|
||||||
|
AdminTranslateShopProductResponse response = new AdminTranslateShopProductResponse();
|
||||||
|
response.setSourceLanguage(sourceLanguage);
|
||||||
|
response.setTargetLanguages(List.of());
|
||||||
|
response.setNames(Map.of());
|
||||||
|
response.setExcerpts(Map.of());
|
||||||
|
response.setDescriptions(Map.of());
|
||||||
|
response.setSeoTitles(Map.of());
|
||||||
|
response.setSeoDescriptions(Map.of());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> normalizeLocalizedMap(Map<String, String> rawValues, boolean richText) {
|
||||||
|
Map<String, String> normalized = new LinkedHashMap<>();
|
||||||
|
for (String language : SUPPORTED_LANGUAGES) {
|
||||||
|
String value = rawValues != null ? rawValues.get(language) : null;
|
||||||
|
if (richText) {
|
||||||
|
normalized.put(language, normalizeRichTextOptional(value) != null ? normalizeRichTextOptional(value) : "");
|
||||||
|
} else {
|
||||||
|
normalized.put(language, safeValue(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String safeValue(String value) {
|
||||||
|
return value == null ? "" : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String safeDescription(String value) {
|
||||||
|
String normalized = normalizeRichTextOptional(value);
|
||||||
|
return normalized != null ? normalized : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String limitSeoDescription(String value) {
|
||||||
|
String normalized = safeValue(value);
|
||||||
|
if (normalized.length() <= 160) {
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
int lastSpace = normalized.lastIndexOf(' ', 157);
|
||||||
|
if (lastSpace >= 120) {
|
||||||
|
return normalized.substring(0, lastSpace).trim();
|
||||||
|
}
|
||||||
|
return normalized.substring(0, 160).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeOptional(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String normalized = value.trim();
|
||||||
|
return normalized.isBlank() ? null : normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeLanguage(String language) {
|
||||||
|
if (language == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalized = language.trim().toLowerCase(Locale.ROOT);
|
||||||
|
int separatorIndex = normalized.indexOf('-');
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
normalized = normalized.substring(0, separatorIndex);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeRichTextOptional(String value) {
|
||||||
|
String normalized = normalizeOptional(value);
|
||||||
|
if (normalized == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sanitized = Jsoup.clean(
|
||||||
|
normalized,
|
||||||
|
"",
|
||||||
|
PRODUCT_DESCRIPTION_SAFELIST,
|
||||||
|
new Document.OutputSettings().prettyPrint(false)
|
||||||
|
).trim();
|
||||||
|
if (sanitized.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String plainText = Jsoup.parse(sanitized).text();
|
||||||
|
return plainText != null && !plainText.trim().isEmpty() ? sanitized : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeBaseUrl(String rawBaseUrl) {
|
||||||
|
String normalized = rawBaseUrl != null && !rawBaseUrl.isBlank()
|
||||||
|
? rawBaseUrl.trim()
|
||||||
|
: "https://api.openai.com/v1";
|
||||||
|
while (normalized.endsWith("/")) {
|
||||||
|
normalized = normalized.substring(0, normalized.length() - 1);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String writeJson(Object value) {
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(value);
|
||||||
|
} catch (JsonProcessingException exception) {
|
||||||
|
throw new ResponseStatusException(
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
"Unable to serialize translation payload",
|
||||||
|
exception
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonNode readJson(String rawJson) throws IOException {
|
||||||
|
return objectMapper.readTree(rawJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
private record NormalizedTranslationRequest(UUID categoryId,
|
||||||
|
String sourceLanguage,
|
||||||
|
boolean overwriteExisting,
|
||||||
|
List<String> materialCodes,
|
||||||
|
Map<String, String> names,
|
||||||
|
Map<String, String> excerpts,
|
||||||
|
Map<String, String> descriptions,
|
||||||
|
Map<String, String> seoTitles,
|
||||||
|
Map<String, String> seoDescriptions) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CategoryContext(String slug,
|
||||||
|
Map<String, String> names,
|
||||||
|
Map<String, String> descriptions) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record TranslationBundle(Map<String, String> names,
|
||||||
|
Map<String, String> excerpts,
|
||||||
|
Map<String, String> descriptions,
|
||||||
|
Map<String, String> seoTitles,
|
||||||
|
Map<String, String> seoDescriptions) {
|
||||||
|
static TranslationBundle fromJson(JsonNode translationsNode) {
|
||||||
|
Map<String, String> names = new LinkedHashMap<>();
|
||||||
|
Map<String, String> excerpts = new LinkedHashMap<>();
|
||||||
|
Map<String, String> descriptions = new LinkedHashMap<>();
|
||||||
|
Map<String, String> seoTitles = new LinkedHashMap<>();
|
||||||
|
Map<String, String> seoDescriptions = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
translationsNode.fieldNames().forEachRemaining(language -> {
|
||||||
|
JsonNode localizedNode = translationsNode.path(language);
|
||||||
|
names.put(language, localizedNode.path("name").asText(""));
|
||||||
|
excerpts.put(language, localizedNode.path("excerpt").asText(""));
|
||||||
|
descriptions.put(language, localizedNode.path("description").asText(""));
|
||||||
|
seoTitles.put(language, localizedNode.path("seoTitle").asText(""));
|
||||||
|
seoDescriptions.put(language, localizedNode.path("seoDescription").asText(""));
|
||||||
|
});
|
||||||
|
|
||||||
|
return new TranslationBundle(names, excerpts, descriptions, seoTitles, seoDescriptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectNode toJsonNode(ObjectMapper objectMapper) {
|
||||||
|
ObjectNode root = objectMapper.createObjectNode();
|
||||||
|
ObjectNode translations = root.putObject("translations");
|
||||||
|
for (String language : names.keySet()) {
|
||||||
|
ObjectNode languageNode = translations.putObject(language);
|
||||||
|
languageNode.put("name", names.getOrDefault(language, ""));
|
||||||
|
languageNode.put("excerpt", excerpts.getOrDefault(language, ""));
|
||||||
|
languageNode.put("description", descriptions.getOrDefault(language, ""));
|
||||||
|
languageNode.put("seoTitle", seoTitles.getOrDefault(language, ""));
|
||||||
|
languageNode.put("seoDescription", seoDescriptions.getOrDefault(language, ""));
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,13 +29,18 @@ public class MediaFfmpegService {
|
|||||||
"WEBP", List.of("libwebp", "webp"),
|
"WEBP", List.of("libwebp", "webp"),
|
||||||
"AVIF", List.of("libaom-av1", "librav1e", "libsvtav1")
|
"AVIF", List.of("libaom-av1", "librav1e", "libsvtav1")
|
||||||
);
|
);
|
||||||
|
private static final Map<String, List<String>> REQUIRED_MUXERS = Map.of(
|
||||||
|
"AVIF", List.of("avif")
|
||||||
|
);
|
||||||
|
|
||||||
private final String ffmpegExecutable;
|
private final String ffmpegExecutable;
|
||||||
private final Set<String> availableEncoders;
|
private final Set<String> availableEncoders;
|
||||||
|
private final Set<String> availableMuxers;
|
||||||
|
|
||||||
public MediaFfmpegService(@Value("${media.ffmpeg.path:ffmpeg}") String ffmpegPath) {
|
public MediaFfmpegService(@Value("${media.ffmpeg.path:ffmpeg}") String ffmpegPath) {
|
||||||
this.ffmpegExecutable = resolveExecutable(ffmpegPath);
|
this.ffmpegExecutable = resolveExecutable(ffmpegPath);
|
||||||
this.availableEncoders = Collections.unmodifiableSet(loadAvailableEncoders());
|
this.availableEncoders = Collections.unmodifiableSet(loadAvailableEncoders());
|
||||||
|
this.availableMuxers = Collections.unmodifiableSet(loadAvailableMuxers());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateVariant(Path source, Path target, int widthPx, int heightPx, String format) throws IOException {
|
public void generateVariant(Path source, Path target, int widthPx, int heightPx, String format) throws IOException {
|
||||||
@@ -47,9 +52,13 @@ public class MediaFfmpegService {
|
|||||||
Path targetPath = sanitizeMediaPath(target, "target", false);
|
Path targetPath = sanitizeMediaPath(target, "target", false);
|
||||||
Files.createDirectories(targetPath.getParent());
|
Files.createDirectories(targetPath.getParent());
|
||||||
|
|
||||||
String encoder = resolveEncoder(format);
|
String normalizedFormat = normalizeFormat(format);
|
||||||
|
String encoder = resolveEncoder(normalizedFormat);
|
||||||
if (encoder == null) {
|
if (encoder == null) {
|
||||||
throw new IOException("FFmpeg encoder not available for media format " + format + ".");
|
throw new IOException("FFmpeg encoder not available for media format " + normalizedFormat + ".");
|
||||||
|
}
|
||||||
|
if (!hasRequiredMuxer(normalizedFormat)) {
|
||||||
|
throw new IOException("FFmpeg muxer not available for media format " + normalizedFormat + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> command = new ArrayList<>();
|
List<String> command = new ArrayList<>();
|
||||||
@@ -66,7 +75,7 @@ public class MediaFfmpegService {
|
|||||||
command.add("1");
|
command.add("1");
|
||||||
command.add("-an");
|
command.add("-an");
|
||||||
|
|
||||||
switch (format) {
|
switch (normalizedFormat) {
|
||||||
case "JPEG" -> {
|
case "JPEG" -> {
|
||||||
command.add("-c:v");
|
command.add("-c:v");
|
||||||
command.add(encoder);
|
command.add(encoder);
|
||||||
@@ -82,14 +91,14 @@ public class MediaFfmpegService {
|
|||||||
case "AVIF" -> {
|
case "AVIF" -> {
|
||||||
command.add("-c:v");
|
command.add("-c:v");
|
||||||
command.add(encoder);
|
command.add(encoder);
|
||||||
command.add("-still-picture");
|
|
||||||
command.add("1");
|
|
||||||
command.add("-crf");
|
command.add("-crf");
|
||||||
command.add("30");
|
command.add("30");
|
||||||
command.add("-b:v");
|
command.add("-b:v");
|
||||||
command.add("0");
|
command.add("0");
|
||||||
|
command.add("-f");
|
||||||
|
command.add("avif");
|
||||||
}
|
}
|
||||||
default -> throw new IllegalArgumentException("Unsupported media format: " + format);
|
default -> throw new IllegalArgumentException("Unsupported media format: " + normalizedFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
command.add(targetPath.toString());
|
command.add(targetPath.toString());
|
||||||
@@ -114,14 +123,16 @@ public class MediaFfmpegService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canEncode(String format) {
|
public boolean canEncode(String format) {
|
||||||
return resolveEncoder(format) != null;
|
String normalizedFormat = normalizeFormat(format);
|
||||||
|
return resolveEncoder(normalizedFormat) != null && hasRequiredMuxer(normalizedFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveEncoder(String format) {
|
private String resolveEncoder(String format) {
|
||||||
if (format == null) {
|
String normalizedFormat = normalizeFormat(format);
|
||||||
|
if (normalizedFormat == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<String> candidates = ENCODER_CANDIDATES.get(format.trim().toUpperCase(Locale.ROOT));
|
List<String> candidates = ENCODER_CANDIDATES.get(normalizedFormat);
|
||||||
if (candidates == null) {
|
if (candidates == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -131,6 +142,21 @@ public class MediaFfmpegService {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasRequiredMuxer(String format) {
|
||||||
|
List<String> requiredMuxers = REQUIRED_MUXERS.get(format);
|
||||||
|
if (requiredMuxers == null || requiredMuxers.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return requiredMuxers.stream().anyMatch(availableMuxers::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeFormat(String format) {
|
||||||
|
if (format == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return format.trim().toUpperCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
private Set<String> loadAvailableEncoders() {
|
private Set<String> loadAvailableEncoders() {
|
||||||
List<String> command = List.of(ffmpegExecutable, "-hide_banner", "-encoders");
|
List<String> command = List.of(ffmpegExecutable, "-hide_banner", "-encoders");
|
||||||
try {
|
try {
|
||||||
@@ -156,6 +182,31 @@ public class MediaFfmpegService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> loadAvailableMuxers() {
|
||||||
|
List<String> command = List.of(ffmpegExecutable, "-hide_banner", "-muxers");
|
||||||
|
try {
|
||||||
|
Process process = startValidatedProcess(command);
|
||||||
|
String output;
|
||||||
|
try (InputStream processStream = process.getInputStream()) {
|
||||||
|
output = new String(processStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
int exitCode = process.waitFor();
|
||||||
|
if (exitCode != 0) {
|
||||||
|
logger.warn("Unable to inspect FFmpeg muxers. Falling back to empty muxer list.");
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
return parseAvailableMuxers(output);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn(
|
||||||
|
"Unable to inspect FFmpeg muxers for executable '{}'. Falling back to empty muxer list. {}",
|
||||||
|
ffmpegExecutable,
|
||||||
|
e.getMessage()
|
||||||
|
);
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Process startValidatedProcess(List<String> command) throws IOException {
|
private Process startValidatedProcess(List<String> command) throws IOException {
|
||||||
// nosemgrep: java.lang.security.audit.command-injection-process-builder.command-injection-process-builder
|
// nosemgrep: java.lang.security.audit.command-injection-process-builder.command-injection-process-builder
|
||||||
return new ProcessBuilder(List.copyOf(command))
|
return new ProcessBuilder(List.copyOf(command))
|
||||||
@@ -266,6 +317,26 @@ public class MediaFfmpegService {
|
|||||||
return encoders;
|
return encoders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> parseAvailableMuxers(String output) {
|
||||||
|
if (output == null || output.isBlank()) {
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> muxers = new LinkedHashSet<>();
|
||||||
|
for (String line : output.split("\\R")) {
|
||||||
|
String trimmed = line.trim();
|
||||||
|
if (trimmed.isBlank() || trimmed.startsWith("--") || trimmed.startsWith("Muxers:")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] parts = trimmed.split("\\s+", 3);
|
||||||
|
if (parts.length < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
muxers.add(parts[1]);
|
||||||
|
}
|
||||||
|
return muxers;
|
||||||
|
}
|
||||||
|
|
||||||
private String truncate(String output) {
|
private String truncate(String output) {
|
||||||
if (output == null || output.isBlank()) {
|
if (output == null || output.isBlank()) {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ public class MediaStorageService {
|
|||||||
private final Path originalRootLocation;
|
private final Path originalRootLocation;
|
||||||
private final Path publicRootLocation;
|
private final Path publicRootLocation;
|
||||||
private final Path privateRootLocation;
|
private final Path privateRootLocation;
|
||||||
private final String publicBaseUrl;
|
private final String frontendBaseUrl;
|
||||||
|
|
||||||
public MediaStorageService(@Value("${media.storage.root:storage_media}") String storageRoot,
|
public MediaStorageService(@Value("${media.storage.root:storage_media}") String storageRoot,
|
||||||
@Value("${media.public.base-url:http://localhost:8080/media}") String publicBaseUrl) {
|
@Value("${app.frontend.base-url:${APP_FRONTEND_BASE_URL:http://localhost:8081}}") String frontendBaseUrl) {
|
||||||
this.normalizedRootLocation = Paths.get(storageRoot).toAbsolutePath().normalize();
|
this.normalizedRootLocation = Paths.get(storageRoot).toAbsolutePath().normalize();
|
||||||
this.originalRootLocation = normalizedRootLocation.resolve("original").normalize();
|
this.originalRootLocation = normalizedRootLocation.resolve("original").normalize();
|
||||||
this.publicRootLocation = normalizedRootLocation.resolve("public").normalize();
|
this.publicRootLocation = normalizedRootLocation.resolve("public").normalize();
|
||||||
this.privateRootLocation = normalizedRootLocation.resolve("private").normalize();
|
this.privateRootLocation = normalizedRootLocation.resolve("private").normalize();
|
||||||
this.publicBaseUrl = publicBaseUrl;
|
this.frontendBaseUrl = frontendBaseUrl;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,11 +73,12 @@ public class MediaStorageService {
|
|||||||
if (storageKey == null || storageKey.isBlank()) {
|
if (storageKey == null || storageKey.isBlank()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
String mediaBaseUrl = buildMediaBaseUrl();
|
||||||
String normalizedKey = storageKey.startsWith("/") ? storageKey.substring(1) : storageKey;
|
String normalizedKey = storageKey.startsWith("/") ? storageKey.substring(1) : storageKey;
|
||||||
if (publicBaseUrl.endsWith("/")) {
|
if (mediaBaseUrl.endsWith("/")) {
|
||||||
return publicBaseUrl + normalizedKey;
|
return mediaBaseUrl + normalizedKey;
|
||||||
}
|
}
|
||||||
return publicBaseUrl + "/" + normalizedKey;
|
return mediaBaseUrl + "/" + normalizedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copy(Path source, Path destination) throws IOException {
|
private void copy(Path source, Path destination) throws IOException {
|
||||||
@@ -127,4 +128,18 @@ public class MediaStorageService {
|
|||||||
}
|
}
|
||||||
return visibility.trim().toUpperCase(Locale.ROOT);
|
return visibility.trim().toUpperCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String buildMediaBaseUrl() {
|
||||||
|
String normalized = frontendBaseUrl != null ? frontendBaseUrl.trim() : "";
|
||||||
|
if (normalized.contains("localhost")){
|
||||||
|
return "http://localhost:8081";
|
||||||
|
}
|
||||||
|
if (normalized.isBlank()) {
|
||||||
|
normalized = "http://localhost:8081";
|
||||||
|
}
|
||||||
|
if (normalized.endsWith("/")) {
|
||||||
|
normalized = normalized.substring(0, normalized.length() - 1);
|
||||||
|
}
|
||||||
|
return normalized + "/media";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springframework.web.server.ResponseStatusException;
|
|||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -48,22 +49,40 @@ public class PublicMediaQueryService {
|
|||||||
public List<PublicMediaUsageDto> getUsageMedia(String usageType, String usageKey, String language) {
|
public List<PublicMediaUsageDto> getUsageMedia(String usageType, String usageKey, String language) {
|
||||||
String normalizedUsageType = normalizeUsageType(usageType);
|
String normalizedUsageType = normalizeUsageType(usageType);
|
||||||
String normalizedUsageKey = normalizeUsageKey(usageKey);
|
String normalizedUsageKey = normalizeUsageKey(usageKey);
|
||||||
|
return getUsageMediaMap(normalizedUsageType, List.of(normalizedUsageKey), language)
|
||||||
|
.getOrDefault(normalizedUsageKey, List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<PublicMediaUsageDto>> getUsageMediaMap(String usageType,
|
||||||
|
List<String> usageKeys,
|
||||||
|
String language) {
|
||||||
|
String normalizedUsageType = normalizeUsageType(usageType);
|
||||||
String normalizedLanguage = normalizeLanguage(language);
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
List<String> normalizedUsageKeys = (usageKeys == null
|
||||||
|
? List.<String>of()
|
||||||
|
: usageKeys)
|
||||||
|
.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(this::normalizeUsageKey)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (normalizedUsageKeys.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
|
||||||
List<MediaUsage> usages = mediaUsageRepository
|
List<MediaUsage> usages = mediaUsageRepository
|
||||||
.findByUsageTypeAndUsageKeyAndIsActiveTrueOrderBySortOrderAscCreatedAtAsc(
|
.findActiveByUsageTypeAndUsageKeys(normalizedUsageType, normalizedUsageKeys)
|
||||||
normalizedUsageType,
|
|
||||||
normalizedUsageKey
|
|
||||||
)
|
|
||||||
.stream()
|
.stream()
|
||||||
.filter(this::isPublicReadyUsage)
|
.filter(this::isPublicReadyUsage)
|
||||||
.sorted(Comparator
|
.sorted(Comparator
|
||||||
.comparing(MediaUsage::getSortOrder, Comparator.nullsLast(Integer::compareTo))
|
.comparing(MediaUsage::getUsageKey, Comparator.nullsLast(String::compareTo))
|
||||||
|
.thenComparing(MediaUsage::getSortOrder, Comparator.nullsLast(Integer::compareTo))
|
||||||
.thenComparing(MediaUsage::getCreatedAt, Comparator.nullsLast(OffsetDateTime::compareTo)))
|
.thenComparing(MediaUsage::getCreatedAt, Comparator.nullsLast(OffsetDateTime::compareTo)))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if (usages.isEmpty()) {
|
if (usages.isEmpty()) {
|
||||||
return List.of();
|
return Map.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UUID> assetIds = usages.stream()
|
List<UUID> assetIds = usages.stream()
|
||||||
@@ -79,13 +98,16 @@ public class PublicMediaQueryService {
|
|||||||
.filter(variant -> !Objects.equals("ORIGINAL", variant.getFormat()))
|
.filter(variant -> !Objects.equals("ORIGINAL", variant.getFormat()))
|
||||||
.collect(Collectors.groupingBy(variant -> variant.getMediaAsset().getId()));
|
.collect(Collectors.groupingBy(variant -> variant.getMediaAsset().getId()));
|
||||||
|
|
||||||
return usages.stream()
|
Map<String, List<PublicMediaUsageDto>> result = new LinkedHashMap<>();
|
||||||
.map(usage -> toDto(
|
for (MediaUsage usage : usages) {
|
||||||
usage,
|
result.computeIfAbsent(usage.getUsageKey(), ignored -> new java.util.ArrayList<>())
|
||||||
variantsByAssetId.getOrDefault(usage.getMediaAsset().getId(), List.of()),
|
.add(toDto(
|
||||||
normalizedLanguage
|
usage,
|
||||||
))
|
variantsByAssetId.getOrDefault(usage.getMediaAsset().getId(), List.of()),
|
||||||
.toList();
|
normalizedLanguage
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPublicReadyUsage(MediaUsage usage) {
|
private boolean isPublicReadyUsage(MediaUsage usage) {
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ public class AdminOrderControllerService {
|
|||||||
OrderDto dto = new OrderDto();
|
OrderDto dto = new OrderDto();
|
||||||
dto.setId(order.getId());
|
dto.setId(order.getId());
|
||||||
dto.setOrderNumber(getDisplayOrderNumber(order));
|
dto.setOrderNumber(getDisplayOrderNumber(order));
|
||||||
|
dto.setSourceType(order.getSourceType() != null ? order.getSourceType() : "CALCULATOR");
|
||||||
dto.setStatus(order.getStatus());
|
dto.setStatus(order.getStatus());
|
||||||
|
|
||||||
paymentRepo.findByOrder_Id(order.getId()).ifPresent(payment -> {
|
paymentRepo.findByOrder_Id(order.getId()).ifPresent(payment -> {
|
||||||
@@ -260,13 +261,38 @@ public class AdminOrderControllerService {
|
|||||||
List<OrderItemDto> itemDtos = items.stream().map(item -> {
|
List<OrderItemDto> itemDtos = items.stream().map(item -> {
|
||||||
OrderItemDto itemDto = new OrderItemDto();
|
OrderItemDto itemDto = new OrderItemDto();
|
||||||
itemDto.setId(item.getId());
|
itemDto.setId(item.getId());
|
||||||
|
itemDto.setItemType(item.getItemType() != null ? item.getItemType() : "PRINT_FILE");
|
||||||
itemDto.setOriginalFilename(item.getOriginalFilename());
|
itemDto.setOriginalFilename(item.getOriginalFilename());
|
||||||
|
itemDto.setDisplayName(
|
||||||
|
item.getDisplayName() != null && !item.getDisplayName().isBlank()
|
||||||
|
? item.getDisplayName()
|
||||||
|
: item.getOriginalFilename()
|
||||||
|
);
|
||||||
itemDto.setMaterialCode(item.getMaterialCode());
|
itemDto.setMaterialCode(item.getMaterialCode());
|
||||||
itemDto.setColorCode(item.getColorCode());
|
itemDto.setColorCode(item.getColorCode());
|
||||||
|
if (item.getShopProduct() != null) {
|
||||||
|
itemDto.setShopProductId(item.getShopProduct().getId());
|
||||||
|
}
|
||||||
|
if (item.getShopProductVariant() != null) {
|
||||||
|
itemDto.setShopProductVariantId(item.getShopProductVariant().getId());
|
||||||
|
}
|
||||||
|
itemDto.setShopProductSlug(item.getShopProductSlug());
|
||||||
|
itemDto.setShopProductName(item.getShopProductName());
|
||||||
|
itemDto.setShopVariantLabel(item.getShopVariantLabel());
|
||||||
|
itemDto.setShopVariantColorName(item.getShopVariantColorName());
|
||||||
|
itemDto.setShopVariantColorLabelIt(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelIt() : null);
|
||||||
|
itemDto.setShopVariantColorLabelEn(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelEn() : null);
|
||||||
|
itemDto.setShopVariantColorLabelDe(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelDe() : null);
|
||||||
|
itemDto.setShopVariantColorLabelFr(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelFr() : null);
|
||||||
|
itemDto.setShopVariantColorHex(item.getShopVariantColorHex());
|
||||||
if (item.getFilamentVariant() != null) {
|
if (item.getFilamentVariant() != null) {
|
||||||
itemDto.setFilamentVariantId(item.getFilamentVariant().getId());
|
itemDto.setFilamentVariantId(item.getFilamentVariant().getId());
|
||||||
itemDto.setFilamentVariantDisplayName(item.getFilamentVariant().getVariantDisplayName());
|
itemDto.setFilamentVariantDisplayName(item.getFilamentVariant().getVariantDisplayName());
|
||||||
itemDto.setFilamentColorName(item.getFilamentVariant().getColorName());
|
itemDto.setFilamentColorName(item.getFilamentVariant().getColorName());
|
||||||
|
itemDto.setFilamentColorLabelIt(item.getFilamentVariant().getColorLabelIt());
|
||||||
|
itemDto.setFilamentColorLabelEn(item.getFilamentVariant().getColorLabelEn());
|
||||||
|
itemDto.setFilamentColorLabelDe(item.getFilamentVariant().getColorLabelDe());
|
||||||
|
itemDto.setFilamentColorLabelFr(item.getFilamentVariant().getColorLabelFr());
|
||||||
itemDto.setFilamentColorHex(item.getFilamentVariant().getColorHex());
|
itemDto.setFilamentColorHex(item.getFilamentVariant().getColorHex());
|
||||||
}
|
}
|
||||||
itemDto.setQuality(item.getQuality());
|
itemDto.setQuality(item.getQuality());
|
||||||
|
|||||||
@@ -255,6 +255,7 @@ public class OrderControllerService {
|
|||||||
OrderDto dto = new OrderDto();
|
OrderDto dto = new OrderDto();
|
||||||
dto.setId(order.getId());
|
dto.setId(order.getId());
|
||||||
dto.setOrderNumber(getDisplayOrderNumber(order));
|
dto.setOrderNumber(getDisplayOrderNumber(order));
|
||||||
|
dto.setSourceType(order.getSourceType() != null ? order.getSourceType() : "CALCULATOR");
|
||||||
dto.setStatus(order.getStatus());
|
dto.setStatus(order.getStatus());
|
||||||
|
|
||||||
paymentRepo.findByOrder_Id(order.getId()).ifPresent(payment -> {
|
paymentRepo.findByOrder_Id(order.getId()).ifPresent(payment -> {
|
||||||
@@ -314,13 +315,38 @@ public class OrderControllerService {
|
|||||||
List<OrderItemDto> itemDtos = items.stream().map(item -> {
|
List<OrderItemDto> itemDtos = items.stream().map(item -> {
|
||||||
OrderItemDto itemDto = new OrderItemDto();
|
OrderItemDto itemDto = new OrderItemDto();
|
||||||
itemDto.setId(item.getId());
|
itemDto.setId(item.getId());
|
||||||
|
itemDto.setItemType(item.getItemType() != null ? item.getItemType() : "PRINT_FILE");
|
||||||
itemDto.setOriginalFilename(item.getOriginalFilename());
|
itemDto.setOriginalFilename(item.getOriginalFilename());
|
||||||
|
itemDto.setDisplayName(
|
||||||
|
item.getDisplayName() != null && !item.getDisplayName().isBlank()
|
||||||
|
? item.getDisplayName()
|
||||||
|
: item.getOriginalFilename()
|
||||||
|
);
|
||||||
itemDto.setMaterialCode(item.getMaterialCode());
|
itemDto.setMaterialCode(item.getMaterialCode());
|
||||||
itemDto.setColorCode(item.getColorCode());
|
itemDto.setColorCode(item.getColorCode());
|
||||||
|
if (item.getShopProduct() != null) {
|
||||||
|
itemDto.setShopProductId(item.getShopProduct().getId());
|
||||||
|
}
|
||||||
|
if (item.getShopProductVariant() != null) {
|
||||||
|
itemDto.setShopProductVariantId(item.getShopProductVariant().getId());
|
||||||
|
}
|
||||||
|
itemDto.setShopProductSlug(item.getShopProductSlug());
|
||||||
|
itemDto.setShopProductName(item.getShopProductName());
|
||||||
|
itemDto.setShopVariantLabel(item.getShopVariantLabel());
|
||||||
|
itemDto.setShopVariantColorName(item.getShopVariantColorName());
|
||||||
|
itemDto.setShopVariantColorLabelIt(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelIt() : null);
|
||||||
|
itemDto.setShopVariantColorLabelEn(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelEn() : null);
|
||||||
|
itemDto.setShopVariantColorLabelDe(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelDe() : null);
|
||||||
|
itemDto.setShopVariantColorLabelFr(item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelFr() : null);
|
||||||
|
itemDto.setShopVariantColorHex(item.getShopVariantColorHex());
|
||||||
if (item.getFilamentVariant() != null) {
|
if (item.getFilamentVariant() != null) {
|
||||||
itemDto.setFilamentVariantId(item.getFilamentVariant().getId());
|
itemDto.setFilamentVariantId(item.getFilamentVariant().getId());
|
||||||
itemDto.setFilamentVariantDisplayName(item.getFilamentVariant().getVariantDisplayName());
|
itemDto.setFilamentVariantDisplayName(item.getFilamentVariant().getVariantDisplayName());
|
||||||
itemDto.setFilamentColorName(item.getFilamentVariant().getColorName());
|
itemDto.setFilamentColorName(item.getFilamentVariant().getColorName());
|
||||||
|
itemDto.setFilamentColorLabelIt(item.getFilamentVariant().getColorLabelIt());
|
||||||
|
itemDto.setFilamentColorLabelEn(item.getFilamentVariant().getColorLabelEn());
|
||||||
|
itemDto.setFilamentColorLabelDe(item.getFilamentVariant().getColorLabelDe());
|
||||||
|
itemDto.setFilamentColorLabelFr(item.getFilamentVariant().getColorLabelFr());
|
||||||
itemDto.setFilamentColorHex(item.getFilamentVariant().getColorHex());
|
itemDto.setFilamentColorHex(item.getFilamentVariant().getColorHex());
|
||||||
}
|
}
|
||||||
itemDto.setQuality(item.getQuality());
|
itemDto.setQuality(item.getQuality());
|
||||||
|
|||||||
@@ -88,14 +88,9 @@ public class InvoicePdfRenderingService {
|
|||||||
vars.put("shippingAddressLine2", order.getShippingZip() + " " + order.getShippingCity() + ", " + order.getShippingCountryCode());
|
vars.put("shippingAddressLine2", order.getShippingZip() + " " + order.getShippingCity() + ", " + order.getShippingCountryCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, Object>> invoiceLineItems = items.stream().map(i -> {
|
List<Map<String, Object>> invoiceLineItems = items.stream()
|
||||||
Map<String, Object> line = new HashMap<>();
|
.map(this::toInvoiceLineItem)
|
||||||
line.put("description", "Stampa 3D: " + i.getOriginalFilename());
|
.collect(Collectors.toList());
|
||||||
line.put("quantity", i.getQuantity());
|
|
||||||
line.put("unitPriceFormatted", String.format("CHF %.2f", i.getUnitPriceChf()));
|
|
||||||
line.put("lineTotalFormatted", String.format("CHF %.2f", i.getLineTotalChf()));
|
|
||||||
return line;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (order.getCadTotalChf() != null && order.getCadTotalChf().compareTo(BigDecimal.ZERO) > 0) {
|
if (order.getCadTotalChf() != null && order.getCadTotalChf().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
BigDecimal cadHours = order.getCadHours() != null ? order.getCadHours() : BigDecimal.ZERO;
|
BigDecimal cadHours = order.getCadHours() != null ? order.getCadHours() : BigDecimal.ZERO;
|
||||||
@@ -157,4 +152,45 @@ public class InvoicePdfRenderingService {
|
|||||||
private String formatCadHours(BigDecimal hours) {
|
private String formatCadHours(BigDecimal hours) {
|
||||||
return hours.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
return hours.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> toInvoiceLineItem(OrderItem item) {
|
||||||
|
Map<String, Object> line = new HashMap<>();
|
||||||
|
line.put("description", buildLineDescription(item));
|
||||||
|
line.put("quantity", item.getQuantity());
|
||||||
|
line.put("unitPriceFormatted", String.format("CHF %.2f", item.getUnitPriceChf()));
|
||||||
|
line.put("lineTotalFormatted", String.format("CHF %.2f", item.getLineTotalChf()));
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildLineDescription(OrderItem item) {
|
||||||
|
if (item == null) {
|
||||||
|
return "Articolo";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("SHOP_PRODUCT".equalsIgnoreCase(item.getItemType())) {
|
||||||
|
String productName = firstNonBlank(
|
||||||
|
item.getDisplayName(),
|
||||||
|
item.getShopProductName(),
|
||||||
|
item.getOriginalFilename(),
|
||||||
|
"Prodotto shop"
|
||||||
|
);
|
||||||
|
String variantLabel = firstNonBlank(item.getShopVariantLabel(), item.getShopVariantColorName(), null);
|
||||||
|
return variantLabel != null ? productName + " - " + variantLabel : productName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileName = firstNonBlank(item.getDisplayName(), item.getOriginalFilename(), "File 3D");
|
||||||
|
return "Stampa 3D: " + fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String firstNonBlank(String... values) {
|
||||||
|
if (values == null || values.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,10 +72,14 @@ public class QuoteSessionItemService {
|
|||||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Cannot modify a converted session");
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Cannot modify a converted session");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String ext = quoteStorageService.getSafeExtension(file.getOriginalFilename(), "");
|
||||||
|
if (ext.isBlank()) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported file type. Allowed: stl, 3mf");
|
||||||
|
}
|
||||||
|
|
||||||
clamAVService.scan(file.getInputStream());
|
clamAVService.scan(file.getInputStream());
|
||||||
|
|
||||||
Path sessionStorageDir = quoteStorageService.sessionStorageDir(session.getId());
|
Path sessionStorageDir = quoteStorageService.sessionStorageDir(session.getId());
|
||||||
String ext = quoteStorageService.getSafeExtension(file.getOriginalFilename(), "stl");
|
|
||||||
String storedFilename = UUID.randomUUID() + "." + ext;
|
String storedFilename = UUID.randomUUID() + "." + ext;
|
||||||
Path persistentPath = quoteStorageService.resolveSessionPath(sessionStorageDir, storedFilename);
|
Path persistentPath = quoteStorageService.resolveSessionPath(sessionStorageDir, storedFilename);
|
||||||
|
|
||||||
@@ -237,7 +241,9 @@ public class QuoteSessionItemService {
|
|||||||
Path convertedPersistentPath) {
|
Path convertedPersistentPath) {
|
||||||
QuoteLineItem item = new QuoteLineItem();
|
QuoteLineItem item = new QuoteLineItem();
|
||||||
item.setQuoteSession(session);
|
item.setQuoteSession(session);
|
||||||
|
item.setLineItemType("PRINT_FILE");
|
||||||
item.setOriginalFilename(originalFilename);
|
item.setOriginalFilename(originalFilename);
|
||||||
|
item.setDisplayName(originalFilename);
|
||||||
item.setStoredPath(quoteStorageService.toStoredPath(persistentPath));
|
item.setStoredPath(quoteStorageService.toStoredPath(persistentPath));
|
||||||
item.setQuantity(normalizeQuantity(settings.getQuantity()));
|
item.setQuantity(normalizeQuantity(settings.getQuantity()));
|
||||||
item.setColorCode(selectedVariant.getColorName());
|
item.setColorCode(selectedVariant.getColorName());
|
||||||
|
|||||||
@@ -43,15 +43,53 @@ public class QuoteSessionResponseAssembler {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> emptyCart() {
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("session", null);
|
||||||
|
response.put("items", List.of());
|
||||||
|
response.put("printItemsTotalChf", BigDecimal.ZERO);
|
||||||
|
response.put("cadTotalChf", BigDecimal.ZERO);
|
||||||
|
response.put("itemsTotalChf", BigDecimal.ZERO);
|
||||||
|
response.put("baseSetupCostChf", BigDecimal.ZERO);
|
||||||
|
response.put("nozzleChangeCostChf", BigDecimal.ZERO);
|
||||||
|
response.put("setupCostChf", BigDecimal.ZERO);
|
||||||
|
response.put("shippingCostChf", BigDecimal.ZERO);
|
||||||
|
response.put("globalMachineCostChf", BigDecimal.ZERO);
|
||||||
|
response.put("grandTotalChf", BigDecimal.ZERO);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Object> toItemDto(QuoteLineItem item, QuoteSessionTotalsService.QuoteSessionTotals totals) {
|
private Map<String, Object> toItemDto(QuoteLineItem item, QuoteSessionTotalsService.QuoteSessionTotals totals) {
|
||||||
Map<String, Object> dto = new HashMap<>();
|
Map<String, Object> dto = new HashMap<>();
|
||||||
dto.put("id", item.getId());
|
dto.put("id", item.getId());
|
||||||
|
dto.put("lineItemType", item.getLineItemType() != null ? item.getLineItemType() : "PRINT_FILE");
|
||||||
dto.put("originalFilename", item.getOriginalFilename());
|
dto.put("originalFilename", item.getOriginalFilename());
|
||||||
|
dto.put(
|
||||||
|
"displayName",
|
||||||
|
item.getDisplayName() != null && !item.getDisplayName().isBlank()
|
||||||
|
? item.getDisplayName()
|
||||||
|
: item.getOriginalFilename()
|
||||||
|
);
|
||||||
dto.put("quantity", item.getQuantity());
|
dto.put("quantity", item.getQuantity());
|
||||||
dto.put("printTimeSeconds", item.getPrintTimeSeconds());
|
dto.put("printTimeSeconds", item.getPrintTimeSeconds());
|
||||||
dto.put("materialGrams", item.getMaterialGrams());
|
dto.put("materialGrams", item.getMaterialGrams());
|
||||||
dto.put("colorCode", item.getColorCode());
|
dto.put("colorCode", item.getColorCode());
|
||||||
dto.put("filamentVariantId", item.getFilamentVariant() != null ? item.getFilamentVariant().getId() : null);
|
dto.put("filamentVariantId", item.getFilamentVariant() != null ? item.getFilamentVariant().getId() : null);
|
||||||
|
dto.put("shopProductId", item.getShopProduct() != null ? item.getShopProduct().getId() : null);
|
||||||
|
dto.put("shopProductVariantId", item.getShopProductVariant() != null ? item.getShopProductVariant().getId() : null);
|
||||||
|
dto.put("shopProductSlug", item.getShopProductSlug());
|
||||||
|
dto.put("shopProductName", item.getShopProductName());
|
||||||
|
dto.put("shopVariantLabel", item.getShopVariantLabel());
|
||||||
|
dto.put("shopVariantColorName", item.getShopVariantColorName());
|
||||||
|
dto.put("shopVariantColorLabelIt", item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelIt() : null);
|
||||||
|
dto.put("shopVariantColorLabelEn", item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelEn() : null);
|
||||||
|
dto.put("shopVariantColorLabelDe", item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelDe() : null);
|
||||||
|
dto.put("shopVariantColorLabelFr", item.getShopProductVariant() != null ? item.getShopProductVariant().getColorLabelFr() : null);
|
||||||
|
dto.put("shopVariantColorHex", item.getShopVariantColorHex());
|
||||||
|
dto.put("filamentColorLabelIt", item.getFilamentVariant() != null ? item.getFilamentVariant().getColorLabelIt() : null);
|
||||||
|
dto.put("filamentColorLabelEn", item.getFilamentVariant() != null ? item.getFilamentVariant().getColorLabelEn() : null);
|
||||||
|
dto.put("filamentColorLabelDe", item.getFilamentVariant() != null ? item.getFilamentVariant().getColorLabelDe() : null);
|
||||||
|
dto.put("filamentColorLabelFr", item.getFilamentVariant() != null ? item.getFilamentVariant().getColorLabelFr() : null);
|
||||||
dto.put("materialCode", item.getMaterialCode());
|
dto.put("materialCode", item.getMaterialCode());
|
||||||
dto.put("quality", item.getQuality());
|
dto.put("quality", item.getQuality());
|
||||||
dto.put("nozzleDiameterMm", item.getNozzleDiameterMm());
|
dto.put("nozzleDiameterMm", item.getNozzleDiameterMm());
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public class QuoteStorageService {
|
|||||||
return switch (ext) {
|
return switch (ext) {
|
||||||
case "stl" -> "stl";
|
case "stl" -> "stl";
|
||||||
case "3mf" -> "3mf";
|
case "3mf" -> "3mf";
|
||||||
case "step", "stp" -> "step";
|
|
||||||
default -> fallback;
|
default -> fallback;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ public class CustomQuoteRequestNotificationService {
|
|||||||
@Value("${app.mail.contact-request.customer.enabled:true}")
|
@Value("${app.mail.contact-request.customer.enabled:true}")
|
||||||
private boolean contactRequestCustomerMailEnabled;
|
private boolean contactRequestCustomerMailEnabled;
|
||||||
|
|
||||||
|
@Value("${app.frontend.base-url:http://localhost:4200}")
|
||||||
|
private String frontendBaseUrl;
|
||||||
|
|
||||||
public CustomQuoteRequestNotificationService(EmailNotificationService emailNotificationService,
|
public CustomQuoteRequestNotificationService(EmailNotificationService emailNotificationService,
|
||||||
ContactRequestLocalizationService localizationService) {
|
ContactRequestLocalizationService localizationService) {
|
||||||
this.emailNotificationService = emailNotificationService;
|
this.emailNotificationService = emailNotificationService;
|
||||||
@@ -63,6 +66,7 @@ public class CustomQuoteRequestNotificationService {
|
|||||||
templateData.put("phone", safeValue(request.getPhone()));
|
templateData.put("phone", safeValue(request.getPhone()));
|
||||||
templateData.put("message", safeValue(request.getMessage()));
|
templateData.put("message", safeValue(request.getMessage()));
|
||||||
templateData.put("attachmentsCount", attachmentsCount);
|
templateData.put("attachmentsCount", attachmentsCount);
|
||||||
|
templateData.put("logoUrl", buildLogoUrl());
|
||||||
templateData.put("currentYear", Year.now().getValue());
|
templateData.put("currentYear", Year.now().getValue());
|
||||||
|
|
||||||
emailNotificationService.sendEmail(
|
emailNotificationService.sendEmail(
|
||||||
@@ -101,6 +105,7 @@ public class CustomQuoteRequestNotificationService {
|
|||||||
templateData.put("phone", safeValue(request.getPhone()));
|
templateData.put("phone", safeValue(request.getPhone()));
|
||||||
templateData.put("message", safeValue(request.getMessage()));
|
templateData.put("message", safeValue(request.getMessage()));
|
||||||
templateData.put("attachmentsCount", attachmentsCount);
|
templateData.put("attachmentsCount", attachmentsCount);
|
||||||
|
templateData.put("logoUrl", buildLogoUrl());
|
||||||
templateData.put("currentYear", Year.now().getValue());
|
templateData.put("currentYear", Year.now().getValue());
|
||||||
|
|
||||||
String subject = localizationService.applyCustomerContactRequestTexts(templateData, language, request.getId());
|
String subject = localizationService.applyCustomerContactRequestTexts(templateData, language, request.getId());
|
||||||
@@ -119,4 +124,11 @@ public class CustomQuoteRequestNotificationService {
|
|||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String buildLogoUrl() {
|
||||||
|
String baseUrl = frontendBaseUrl == null || frontendBaseUrl.isBlank()
|
||||||
|
? "http://localhost:4200"
|
||||||
|
: frontendBaseUrl;
|
||||||
|
return baseUrl.replaceAll("/+$", "") + "/assets/images/brand-logo-yellow.svg";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,717 @@
|
|||||||
|
package com.printcalculator.service.shop;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.PublicMediaUsageDto;
|
||||||
|
import com.printcalculator.dto.ShopCategoryDetailDto;
|
||||||
|
import com.printcalculator.dto.ShopCategoryRefDto;
|
||||||
|
import com.printcalculator.dto.ShopCategoryTreeDto;
|
||||||
|
import com.printcalculator.dto.ShopProductCatalogResponseDto;
|
||||||
|
import com.printcalculator.dto.ShopProductDetailDto;
|
||||||
|
import com.printcalculator.dto.ShopProductModelDto;
|
||||||
|
import com.printcalculator.dto.ShopProductSummaryDto;
|
||||||
|
import com.printcalculator.dto.ShopProductVariantOptionDto;
|
||||||
|
import com.printcalculator.entity.FilamentVariant;
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
import com.printcalculator.entity.ShopProductModelAsset;
|
||||||
|
import com.printcalculator.entity.ShopProductVariant;
|
||||||
|
import com.printcalculator.repository.FilamentVariantRepository;
|
||||||
|
import com.printcalculator.repository.ShopCategoryRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductModelAssetRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductVariantRepository;
|
||||||
|
import com.printcalculator.service.media.PublicMediaQueryService;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class PublicShopCatalogService {
|
||||||
|
private static final String SHOP_CATEGORY_MEDIA_USAGE_TYPE = "SHOP_CATEGORY";
|
||||||
|
private static final String SHOP_PRODUCT_MEDIA_USAGE_TYPE = "SHOP_PRODUCT";
|
||||||
|
|
||||||
|
private final ShopCategoryRepository shopCategoryRepository;
|
||||||
|
private final ShopProductRepository shopProductRepository;
|
||||||
|
private final ShopProductVariantRepository shopProductVariantRepository;
|
||||||
|
private final ShopProductModelAssetRepository shopProductModelAssetRepository;
|
||||||
|
private final FilamentVariantRepository filamentVariantRepository;
|
||||||
|
private final PublicMediaQueryService publicMediaQueryService;
|
||||||
|
private final ShopStorageService shopStorageService;
|
||||||
|
|
||||||
|
public PublicShopCatalogService(ShopCategoryRepository shopCategoryRepository,
|
||||||
|
ShopProductRepository shopProductRepository,
|
||||||
|
ShopProductVariantRepository shopProductVariantRepository,
|
||||||
|
ShopProductModelAssetRepository shopProductModelAssetRepository,
|
||||||
|
FilamentVariantRepository filamentVariantRepository,
|
||||||
|
PublicMediaQueryService publicMediaQueryService,
|
||||||
|
ShopStorageService shopStorageService) {
|
||||||
|
this.shopCategoryRepository = shopCategoryRepository;
|
||||||
|
this.shopProductRepository = shopProductRepository;
|
||||||
|
this.shopProductVariantRepository = shopProductVariantRepository;
|
||||||
|
this.shopProductModelAssetRepository = shopProductModelAssetRepository;
|
||||||
|
this.filamentVariantRepository = filamentVariantRepository;
|
||||||
|
this.publicMediaQueryService = publicMediaQueryService;
|
||||||
|
this.shopStorageService = shopStorageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopCategoryTreeDto> getCategories(String language) {
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(language);
|
||||||
|
return buildCategoryTree(null, categoryContext, language);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopCategoryDetailDto getCategory(String slug, String language) {
|
||||||
|
ShopCategory category = shopCategoryRepository.findBySlugAndIsActiveTrue(slug)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Category not found"));
|
||||||
|
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(language);
|
||||||
|
if (!categoryContext.categoriesById().containsKey(category.getId())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Category not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildCategoryDetail(category, categoryContext, language);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductCatalogResponseDto getProductCatalog(String categorySlug, Boolean featuredOnly, String language) {
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(language);
|
||||||
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, language);
|
||||||
|
|
||||||
|
ShopCategory selectedCategory = null;
|
||||||
|
if (categorySlug != null && !categorySlug.isBlank()) {
|
||||||
|
selectedCategory = categoryContext.categoriesBySlug().get(categorySlug.trim());
|
||||||
|
if (selectedCategory == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Category not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<UUID> allowedCategoryIds = selectedCategory == null
|
||||||
|
? categoryContext.categoriesById().keySet()
|
||||||
|
: resolveDescendantCategoryIds(selectedCategory.getId(), categoryContext.childrenByParentId());
|
||||||
|
|
||||||
|
List<ShopProductSummaryDto> products = productContext.entries().stream()
|
||||||
|
.filter(entry -> allowedCategoryIds.contains(entry.product().getCategory().getId()))
|
||||||
|
.filter(entry -> !Boolean.TRUE.equals(featuredOnly) || Boolean.TRUE.equals(entry.product().getIsFeatured()))
|
||||||
|
.map(entry -> toProductSummaryDto(
|
||||||
|
entry,
|
||||||
|
productContext.productMediaBySlug(),
|
||||||
|
productContext.variantColorHexByMaterialAndColor(),
|
||||||
|
language
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
ShopCategoryDetailDto selectedCategoryDetail = selectedCategory != null
|
||||||
|
? buildCategoryDetail(selectedCategory, categoryContext, language)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return new ShopProductCatalogResponseDto(
|
||||||
|
selectedCategory != null ? selectedCategory.getSlug() : null,
|
||||||
|
Boolean.TRUE.equals(featuredOnly),
|
||||||
|
selectedCategoryDetail,
|
||||||
|
products
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductDetailDto getProduct(String slug, String language) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(normalizedLanguage);
|
||||||
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, normalizedLanguage);
|
||||||
|
ProductEntry entry = requirePublicProductEntry(
|
||||||
|
productContext.entriesBySlug().get(slug),
|
||||||
|
categoryContext
|
||||||
|
);
|
||||||
|
return toProductDetailDto(
|
||||||
|
entry,
|
||||||
|
productContext.productMediaBySlug(),
|
||||||
|
productContext.variantColorHexByMaterialAndColor(),
|
||||||
|
normalizedLanguage
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductDetailDto getProductByPublicPath(String publicPathSegment, String language) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String normalizedPublicPath = normalizePublicPathSegment(publicPathSegment);
|
||||||
|
if (normalizedPublicPath == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(normalizedLanguage);
|
||||||
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, normalizedLanguage);
|
||||||
|
ProductEntry entry = requirePublicProductEntry(
|
||||||
|
productContext.entriesByPublicPath().get(normalizedPublicPath),
|
||||||
|
categoryContext
|
||||||
|
);
|
||||||
|
|
||||||
|
return toProductDetailDto(
|
||||||
|
entry,
|
||||||
|
productContext.productMediaBySlug(),
|
||||||
|
productContext.variantColorHexByMaterialAndColor(),
|
||||||
|
normalizedLanguage
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopProductDetailDto getProductByIdPrefix(String idPrefix, String language) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String normalizedIdPrefix = normalizeProductIdPrefix(idPrefix);
|
||||||
|
if (normalizedIdPrefix == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(normalizedLanguage);
|
||||||
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, normalizedLanguage);
|
||||||
|
ProductEntry entry = requirePublicProductEntry(
|
||||||
|
productContext.entriesByIdPrefix().get(normalizedIdPrefix),
|
||||||
|
categoryContext
|
||||||
|
);
|
||||||
|
|
||||||
|
return toProductDetailDto(
|
||||||
|
entry,
|
||||||
|
productContext.productMediaBySlug(),
|
||||||
|
productContext.variantColorHexByMaterialAndColor(),
|
||||||
|
normalizedLanguage
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductModelDownload getProductModelDownload(String slug) {
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(null);
|
||||||
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, null);
|
||||||
|
ProductEntry entry = productContext.entriesBySlug().get(slug);
|
||||||
|
if (entry == null || entry.modelAsset() == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product model not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Path path = shopStorageService.resolveStoredProductPath(
|
||||||
|
entry.modelAsset().getStoredRelativePath(),
|
||||||
|
entry.product().getId()
|
||||||
|
);
|
||||||
|
if (path == null || !Files.exists(path)) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product model not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProductModelDownload(
|
||||||
|
path,
|
||||||
|
entry.modelAsset().getOriginalFilename(),
|
||||||
|
entry.modelAsset().getMimeType()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CategoryContext loadCategoryContext(String language) {
|
||||||
|
List<ShopCategory> categories = shopCategoryRepository.findAllByIsActiveTrueOrderBySortOrderAscNameAsc();
|
||||||
|
|
||||||
|
Map<UUID, ShopCategory> categoriesById = categories.stream()
|
||||||
|
.collect(Collectors.toMap(ShopCategory::getId, category -> category, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
Map<String, ShopCategory> categoriesBySlug = categories.stream()
|
||||||
|
.collect(Collectors.toMap(ShopCategory::getSlug, category -> category, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId = buildChildrenByParentId(categories);
|
||||||
|
|
||||||
|
List<ProductEntry> publicProducts = loadPublicProducts(categoriesById.keySet());
|
||||||
|
Map<UUID, Integer> descendantProductCounts = resolveDescendantProductCounts(categories, childrenByParentId, publicProducts);
|
||||||
|
Map<String, List<PublicMediaUsageDto>> categoryMediaBySlug = publicMediaQueryService.getUsageMediaMap(
|
||||||
|
SHOP_CATEGORY_MEDIA_USAGE_TYPE,
|
||||||
|
categories.stream().map(this::categoryMediaUsageKey).toList(),
|
||||||
|
language
|
||||||
|
);
|
||||||
|
|
||||||
|
return new CategoryContext(
|
||||||
|
categoriesById,
|
||||||
|
categoriesBySlug,
|
||||||
|
childrenByParentId,
|
||||||
|
descendantProductCounts,
|
||||||
|
categoryMediaBySlug
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PublicProductContext loadPublicProductContext(CategoryContext categoryContext, String language) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
List<ProductEntry> entries = loadPublicProducts(categoryContext.categoriesById().keySet());
|
||||||
|
Map<String, List<PublicMediaUsageDto>> productMediaBySlug = publicMediaQueryService.getUsageMediaMap(
|
||||||
|
SHOP_PRODUCT_MEDIA_USAGE_TYPE,
|
||||||
|
entries.stream().map(entry -> productMediaUsageKey(entry.product())).toList(),
|
||||||
|
language
|
||||||
|
);
|
||||||
|
Map<String, String> variantColorHexByMaterialAndColor = buildFilamentVariantColorHexMap();
|
||||||
|
|
||||||
|
Map<String, ProductEntry> entriesBySlug = entries.stream()
|
||||||
|
.collect(Collectors.toMap(entry -> entry.product().getSlug(), entry -> entry, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
Map<String, ProductEntry> entriesByPublicPath = entries.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
entry -> normalizePublicPathSegment(ShopPublicPathSupport.buildProductPathSegment(entry.product(), normalizedLanguage)),
|
||||||
|
entry -> entry,
|
||||||
|
(left, right) -> left,
|
||||||
|
LinkedHashMap::new
|
||||||
|
));
|
||||||
|
Map<String, ProductEntry> entriesByIdPrefix = entries.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
entry -> normalizeProductIdPrefix(ShopPublicPathSupport.productIdPrefix(entry.product().getId())),
|
||||||
|
entry -> entry,
|
||||||
|
(left, right) -> left,
|
||||||
|
LinkedHashMap::new
|
||||||
|
));
|
||||||
|
|
||||||
|
return new PublicProductContext(
|
||||||
|
entries,
|
||||||
|
entriesBySlug,
|
||||||
|
entriesByPublicPath,
|
||||||
|
entriesByIdPrefix,
|
||||||
|
productMediaBySlug,
|
||||||
|
variantColorHexByMaterialAndColor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildFilamentVariantColorHexMap() {
|
||||||
|
Map<String, String> colorsByMaterialAndColor = new LinkedHashMap<>();
|
||||||
|
for (FilamentVariant variant : filamentVariantRepository.findByIsActiveTrue()) {
|
||||||
|
String materialCode = variant.getFilamentMaterialType() != null
|
||||||
|
? variant.getFilamentMaterialType().getMaterialCode()
|
||||||
|
: null;
|
||||||
|
String key = toMaterialAndColorKey(materialCode, variant.getColorName());
|
||||||
|
if (key == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String colorHex = trimToNull(variant.getColorHex());
|
||||||
|
if (colorHex == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
colorsByMaterialAndColor.putIfAbsent(key, colorHex);
|
||||||
|
}
|
||||||
|
return colorsByMaterialAndColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ProductEntry> loadPublicProducts(Collection<UUID> activeCategoryIds) {
|
||||||
|
List<ShopProduct> products = shopProductRepository.findAllByIsActiveTrueOrderByIsFeaturedDescSortOrderAscNameAsc();
|
||||||
|
if (products.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UUID> productIds = products.stream().map(ShopProduct::getId).toList();
|
||||||
|
Map<UUID, List<ShopProductVariant>> variantsByProductId = shopProductVariantRepository
|
||||||
|
.findByProduct_IdInAndIsActiveTrueOrderBySortOrderAscColorNameAsc(productIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
variant -> variant.getProduct().getId(),
|
||||||
|
LinkedHashMap::new,
|
||||||
|
Collectors.toList()
|
||||||
|
));
|
||||||
|
Map<UUID, ShopProductModelAsset> modelAssetByProductId = shopProductModelAssetRepository.findByProduct_IdIn(productIds)
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(asset -> asset.getProduct().getId(), asset -> asset, (left, right) -> left, LinkedHashMap::new));
|
||||||
|
|
||||||
|
return products.stream()
|
||||||
|
.filter(product -> product.getCategory() != null)
|
||||||
|
.filter(product -> activeCategoryIds.contains(product.getCategory().getId()))
|
||||||
|
.map(product -> {
|
||||||
|
List<ShopProductVariant> activeVariants = variantsByProductId.getOrDefault(product.getId(), List.of());
|
||||||
|
if (activeVariants.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ShopProductVariant defaultVariant = pickDefaultVariant(activeVariants);
|
||||||
|
return new ProductEntry(
|
||||||
|
product,
|
||||||
|
activeVariants,
|
||||||
|
defaultVariant,
|
||||||
|
modelAssetByProductId.get(product.getId())
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<UUID, List<ShopCategory>> buildChildrenByParentId(List<ShopCategory> categories) {
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId = new LinkedHashMap<>();
|
||||||
|
for (ShopCategory category : categories) {
|
||||||
|
UUID parentId = category.getParentCategory() != null ? category.getParentCategory().getId() : null;
|
||||||
|
childrenByParentId.computeIfAbsent(parentId, ignored -> new ArrayList<>()).add(category);
|
||||||
|
}
|
||||||
|
Comparator<ShopCategory> comparator = Comparator
|
||||||
|
.comparing(ShopCategory::getSortOrder, Comparator.nullsLast(Integer::compareTo))
|
||||||
|
.thenComparing(ShopCategory::getName, Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER));
|
||||||
|
childrenByParentId.values().forEach(children -> children.sort(comparator));
|
||||||
|
return childrenByParentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<UUID, Integer> resolveDescendantProductCounts(List<ShopCategory> categories,
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId,
|
||||||
|
List<ProductEntry> publicProducts) {
|
||||||
|
Map<UUID, Integer> directProductCounts = new LinkedHashMap<>();
|
||||||
|
for (ProductEntry entry : publicProducts) {
|
||||||
|
UUID categoryId = entry.product().getCategory().getId();
|
||||||
|
directProductCounts.merge(categoryId, 1, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<UUID, Integer> descendantCounts = new LinkedHashMap<>();
|
||||||
|
for (ShopCategory category : categories) {
|
||||||
|
resolveCategoryProductCount(category.getId(), childrenByParentId, directProductCounts, descendantCounts);
|
||||||
|
}
|
||||||
|
return descendantCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resolveCategoryProductCount(UUID categoryId,
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId,
|
||||||
|
Map<UUID, Integer> directProductCounts,
|
||||||
|
Map<UUID, Integer> descendantCounts) {
|
||||||
|
Integer cached = descendantCounts.get(categoryId);
|
||||||
|
if (cached != null) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
int total = directProductCounts.getOrDefault(categoryId, 0);
|
||||||
|
for (ShopCategory child : childrenByParentId.getOrDefault(categoryId, List.of())) {
|
||||||
|
total += resolveCategoryProductCount(child.getId(), childrenByParentId, directProductCounts, descendantCounts);
|
||||||
|
}
|
||||||
|
descendantCounts.put(categoryId, total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ShopCategoryTreeDto> buildCategoryTree(UUID parentId,
|
||||||
|
CategoryContext categoryContext,
|
||||||
|
String language) {
|
||||||
|
return categoryContext.childrenByParentId().getOrDefault(parentId, List.of()).stream()
|
||||||
|
.map(category -> new ShopCategoryTreeDto(
|
||||||
|
category.getId(),
|
||||||
|
category.getParentCategory() != null ? category.getParentCategory().getId() : null,
|
||||||
|
category.getSlug(),
|
||||||
|
category.getNameForLanguage(language),
|
||||||
|
category.getDescriptionForLanguage(language),
|
||||||
|
category.getSeoTitleForLanguage(language),
|
||||||
|
category.getSeoDescriptionForLanguage(language),
|
||||||
|
category.getOgTitle(),
|
||||||
|
category.getOgDescription(),
|
||||||
|
category.getIndexable(),
|
||||||
|
category.getSortOrder(),
|
||||||
|
categoryContext.descendantProductCounts().getOrDefault(category.getId(), 0),
|
||||||
|
selectPrimaryMedia(categoryContext.categoryMediaBySlug().get(categoryMediaUsageKey(category))),
|
||||||
|
buildCategoryTree(category.getId(), categoryContext, language)
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopCategoryDetailDto buildCategoryDetail(ShopCategory category,
|
||||||
|
CategoryContext categoryContext,
|
||||||
|
String language) {
|
||||||
|
List<PublicMediaUsageDto> images = categoryContext.categoryMediaBySlug().getOrDefault(categoryMediaUsageKey(category), List.of());
|
||||||
|
String localizedSeoTitle = category.getSeoTitleForLanguage(language);
|
||||||
|
String localizedSeoDescription = category.getSeoDescriptionForLanguage(language);
|
||||||
|
return new ShopCategoryDetailDto(
|
||||||
|
category.getId(),
|
||||||
|
category.getSlug(),
|
||||||
|
category.getNameForLanguage(language),
|
||||||
|
category.getDescriptionForLanguage(language),
|
||||||
|
localizedSeoTitle,
|
||||||
|
localizedSeoDescription,
|
||||||
|
category.getOgTitle(),
|
||||||
|
category.getOgDescription(),
|
||||||
|
category.getIndexable(),
|
||||||
|
category.getSortOrder(),
|
||||||
|
categoryContext.descendantProductCounts().getOrDefault(category.getId(), 0),
|
||||||
|
buildCategoryBreadcrumbs(category, language),
|
||||||
|
selectPrimaryMedia(images),
|
||||||
|
images,
|
||||||
|
buildCategoryTree(category.getId(), categoryContext, language)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ShopCategoryRefDto> buildCategoryBreadcrumbs(ShopCategory category, String language) {
|
||||||
|
List<ShopCategoryRefDto> breadcrumbs = new ArrayList<>();
|
||||||
|
ShopCategory current = category;
|
||||||
|
while (current != null) {
|
||||||
|
breadcrumbs.add(new ShopCategoryRefDto(
|
||||||
|
current.getId(),
|
||||||
|
current.getSlug(),
|
||||||
|
current.getNameForLanguage(language)
|
||||||
|
));
|
||||||
|
current = current.getParentCategory();
|
||||||
|
}
|
||||||
|
java.util.Collections.reverse(breadcrumbs);
|
||||||
|
return breadcrumbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<UUID> resolveDescendantCategoryIds(UUID rootId, Map<UUID, List<ShopCategory>> childrenByParentId) {
|
||||||
|
List<UUID> ids = new ArrayList<>();
|
||||||
|
collectDescendantCategoryIds(rootId, childrenByParentId, ids);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectDescendantCategoryIds(UUID categoryId,
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId,
|
||||||
|
List<UUID> accumulator) {
|
||||||
|
accumulator.add(categoryId);
|
||||||
|
for (ShopCategory child : childrenByParentId.getOrDefault(categoryId, List.of())) {
|
||||||
|
collectDescendantCategoryIds(child.getId(), childrenByParentId, accumulator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductSummaryDto toProductSummaryDto(ProductEntry entry,
|
||||||
|
Map<String, List<PublicMediaUsageDto>> productMediaBySlug,
|
||||||
|
Map<String, String> variantColorHexByMaterialAndColor,
|
||||||
|
String language) {
|
||||||
|
List<PublicMediaUsageDto> images = productMediaBySlug.getOrDefault(productMediaUsageKey(entry.product()), List.of());
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String publicPathSegment = ShopPublicPathSupport.buildProductPathSegment(entry.product(), normalizedLanguage);
|
||||||
|
Map<String, String> localizedPaths = ShopPublicPathSupport.buildLocalizedProductPaths(entry.product());
|
||||||
|
return new ShopProductSummaryDto(
|
||||||
|
entry.product().getId(),
|
||||||
|
entry.product().getSlug(),
|
||||||
|
entry.product().getNameForLanguage(language),
|
||||||
|
entry.product().getExcerptForLanguage(language),
|
||||||
|
entry.product().getIsFeatured(),
|
||||||
|
entry.product().getSortOrder(),
|
||||||
|
new ShopCategoryRefDto(
|
||||||
|
entry.product().getCategory().getId(),
|
||||||
|
entry.product().getCategory().getSlug(),
|
||||||
|
entry.product().getCategory().getNameForLanguage(language)
|
||||||
|
),
|
||||||
|
resolvePriceFrom(entry.variants()),
|
||||||
|
resolvePriceTo(entry.variants()),
|
||||||
|
toVariantDto(entry.defaultVariant(), entry.defaultVariant(), variantColorHexByMaterialAndColor, language),
|
||||||
|
selectPrimaryMedia(images),
|
||||||
|
toProductModelDto(entry),
|
||||||
|
publicPathSegment,
|
||||||
|
localizedPaths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductDetailDto toProductDetailDto(ProductEntry entry,
|
||||||
|
Map<String, List<PublicMediaUsageDto>> productMediaBySlug,
|
||||||
|
Map<String, String> variantColorHexByMaterialAndColor,
|
||||||
|
String language) {
|
||||||
|
List<PublicMediaUsageDto> images = productMediaBySlug.getOrDefault(productMediaUsageKey(entry.product()), List.of());
|
||||||
|
String localizedSeoTitle = entry.product().getSeoTitleForLanguage(language);
|
||||||
|
String localizedSeoDescription = entry.product().getSeoDescriptionForLanguage(language);
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String publicPathSegment = ShopPublicPathSupport.buildProductPathSegment(entry.product(), normalizedLanguage);
|
||||||
|
Map<String, String> localizedPaths = ShopPublicPathSupport.buildLocalizedProductPaths(entry.product());
|
||||||
|
return new ShopProductDetailDto(entry.product().getId(),
|
||||||
|
entry.product().getSlug(),
|
||||||
|
entry.product().getNameForLanguage(language),
|
||||||
|
entry.product().getExcerptForLanguage(language),
|
||||||
|
entry.product().getDescriptionForLanguage(language),
|
||||||
|
localizedSeoTitle,
|
||||||
|
localizedSeoDescription,
|
||||||
|
localizedSeoTitle,
|
||||||
|
localizedSeoDescription,
|
||||||
|
entry.product().getIndexable(),
|
||||||
|
entry.product().getIsFeatured(),
|
||||||
|
entry.product().getSortOrder(),
|
||||||
|
new ShopCategoryRefDto(
|
||||||
|
entry.product().getCategory().getId(),
|
||||||
|
entry.product().getCategory().getSlug(),
|
||||||
|
entry.product().getCategory().getNameForLanguage(language)
|
||||||
|
),
|
||||||
|
buildCategoryBreadcrumbs(entry.product().getCategory(), language),
|
||||||
|
resolvePriceFrom(entry.variants()),
|
||||||
|
resolvePriceTo(entry.variants()),
|
||||||
|
toVariantDto(entry.defaultVariant(), entry.defaultVariant(), variantColorHexByMaterialAndColor, language),
|
||||||
|
entry.variants().stream()
|
||||||
|
.map(variant -> toVariantDto(variant, entry.defaultVariant(), variantColorHexByMaterialAndColor, language))
|
||||||
|
.toList(),
|
||||||
|
selectPrimaryMedia(images),
|
||||||
|
images,
|
||||||
|
toProductModelDto(entry),
|
||||||
|
publicPathSegment,
|
||||||
|
localizedPaths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductVariantOptionDto toVariantDto(ShopProductVariant variant,
|
||||||
|
ShopProductVariant defaultVariant,
|
||||||
|
Map<String, String> variantColorHexByMaterialAndColor,
|
||||||
|
String language) {
|
||||||
|
if (variant == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String colorHex = trimToNull(variant.getColorHex());
|
||||||
|
if (colorHex == null) {
|
||||||
|
String key = toMaterialAndColorKey(variant.getInternalMaterialCode(), variant.getColorName());
|
||||||
|
colorHex = key != null ? variantColorHexByMaterialAndColor.get(key) : null;
|
||||||
|
}
|
||||||
|
return new ShopProductVariantOptionDto(
|
||||||
|
variant.getId(),
|
||||||
|
variant.getSku(),
|
||||||
|
variant.getVariantLabel(),
|
||||||
|
variant.getColorName(),
|
||||||
|
variant.getColorLabelForLanguage(language),
|
||||||
|
colorHex,
|
||||||
|
variant.getPriceChf(),
|
||||||
|
defaultVariant != null && Objects.equals(defaultVariant.getId(), variant.getId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String toMaterialAndColorKey(String materialCode, String colorName) {
|
||||||
|
String normalizedMaterialCode = normalizeMaterialCode(materialCode);
|
||||||
|
String normalizedColorName = normalizeColorName(colorName);
|
||||||
|
if (normalizedMaterialCode == null || normalizedColorName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return normalizedMaterialCode + "|" + normalizedColorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeMaterialCode(String materialCode) {
|
||||||
|
String raw = trimToNull(materialCode);
|
||||||
|
if (raw == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return raw.toUpperCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeColorName(String colorName) {
|
||||||
|
String raw = trimToNull(colorName);
|
||||||
|
if (raw == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return raw.toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProductEntry requirePublicProductEntry(ProductEntry entry, CategoryContext categoryContext) {
|
||||||
|
if (entry == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShopCategory category = entry.product().getCategory();
|
||||||
|
if (category == null || !categoryContext.categoriesById().containsKey(category.getId())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizePublicPathSegment(String publicPathSegment) {
|
||||||
|
String normalized = trimToNull(publicPathSegment);
|
||||||
|
if (normalized == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return normalized.toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeProductIdPrefix(String idPrefix) {
|
||||||
|
String normalized = trimToNull(idPrefix);
|
||||||
|
if (normalized == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
normalized = normalized.toLowerCase(Locale.ROOT);
|
||||||
|
return normalized.matches("^[0-9a-f]{8}$") ? normalized : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String trimToNull(String value) {
|
||||||
|
String raw = String.valueOf(value == null ? "" : value).trim();
|
||||||
|
if (raw.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeLanguage(String language) {
|
||||||
|
String normalized = trimToNull(language);
|
||||||
|
if (normalized == null) {
|
||||||
|
return "it";
|
||||||
|
}
|
||||||
|
normalized = normalized.toLowerCase(Locale.ROOT);
|
||||||
|
int separatorIndex = normalized.indexOf('-');
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
normalized = normalized.substring(0, separatorIndex);
|
||||||
|
}
|
||||||
|
return switch (normalized) {
|
||||||
|
case "en", "de", "fr" -> normalized;
|
||||||
|
default -> "it";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductModelDto toProductModelDto(ProductEntry entry) {
|
||||||
|
if (entry.modelAsset() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ShopProductModelDto(
|
||||||
|
"/api/shop/products/" + entry.product().getSlug() + "/model",
|
||||||
|
entry.modelAsset().getOriginalFilename(),
|
||||||
|
entry.modelAsset().getMimeType(),
|
||||||
|
entry.modelAsset().getFileSizeBytes(),
|
||||||
|
entry.modelAsset().getBoundingBoxXMm(),
|
||||||
|
entry.modelAsset().getBoundingBoxYMm(),
|
||||||
|
entry.modelAsset().getBoundingBoxZMm()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductVariant pickDefaultVariant(List<ShopProductVariant> variants) {
|
||||||
|
return variants.stream()
|
||||||
|
.filter(variant -> Boolean.TRUE.equals(variant.getIsDefault()))
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> variants.isEmpty() ? null : variants.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal resolvePriceFrom(List<ShopProductVariant> variants) {
|
||||||
|
return variants.stream()
|
||||||
|
.map(ShopProductVariant::getPriceChf)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.min(BigDecimal::compareTo)
|
||||||
|
.orElse(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal resolvePriceTo(List<ShopProductVariant> variants) {
|
||||||
|
return variants.stream()
|
||||||
|
.map(ShopProductVariant::getPriceChf)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.max(BigDecimal::compareTo)
|
||||||
|
.orElse(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PublicMediaUsageDto selectPrimaryMedia(List<PublicMediaUsageDto> images) {
|
||||||
|
if (images == null || images.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return images.stream()
|
||||||
|
.filter(image -> Boolean.TRUE.equals(image.getIsPrimary()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(images.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String categoryMediaUsageKey(ShopCategory category) {
|
||||||
|
return category.getId().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String productMediaUsageKey(ShopProduct product) {
|
||||||
|
return product.getId().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ProductModelDownload(Path path, String filename, String mimeType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CategoryContext(
|
||||||
|
Map<UUID, ShopCategory> categoriesById,
|
||||||
|
Map<String, ShopCategory> categoriesBySlug,
|
||||||
|
Map<UUID, List<ShopCategory>> childrenByParentId,
|
||||||
|
Map<UUID, Integer> descendantProductCounts,
|
||||||
|
Map<String, List<PublicMediaUsageDto>> categoryMediaBySlug
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record PublicProductContext(
|
||||||
|
List<ProductEntry> entries,
|
||||||
|
Map<String, ProductEntry> entriesBySlug,
|
||||||
|
Map<String, ProductEntry> entriesByPublicPath,
|
||||||
|
Map<String, ProductEntry> entriesByIdPrefix,
|
||||||
|
Map<String, List<PublicMediaUsageDto>> productMediaBySlug,
|
||||||
|
Map<String, String> variantColorHexByMaterialAndColor
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record ProductEntry(
|
||||||
|
ShopProduct product,
|
||||||
|
List<ShopProductVariant> variants,
|
||||||
|
ShopProductVariant defaultVariant,
|
||||||
|
ShopProductModelAsset modelAsset
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.printcalculator.service.shop;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.ResponseCookie;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ShopCartCookieService {
|
||||||
|
public static final String COOKIE_NAME = "shop_cart_session";
|
||||||
|
private static final String COOKIE_PATH = "/api/shop";
|
||||||
|
|
||||||
|
private final long cookieTtlDays;
|
||||||
|
private final boolean secureCookie;
|
||||||
|
private final String sameSite;
|
||||||
|
|
||||||
|
public ShopCartCookieService(
|
||||||
|
@Value("${shop.cart.cookie.ttl-days:30}") long cookieTtlDays,
|
||||||
|
@Value("${shop.cart.cookie.secure:false}") boolean secureCookie,
|
||||||
|
@Value("${shop.cart.cookie.same-site:Lax}") String sameSite
|
||||||
|
) {
|
||||||
|
this.cookieTtlDays = cookieTtlDays;
|
||||||
|
this.secureCookie = secureCookie;
|
||||||
|
this.sameSite = sameSite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<UUID> extractSessionId(HttpServletRequest request) {
|
||||||
|
Cookie[] cookies = request.getCookies();
|
||||||
|
if (cookies == null || cookies.length == 0) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Cookie cookie : cookies) {
|
||||||
|
if (!COOKIE_NAME.equals(cookie.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String value = cookie.getValue();
|
||||||
|
if (value == null || value.isBlank()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(UUID.fromString(value.trim()));
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCartCookie(HttpServletRequest request) {
|
||||||
|
Cookie[] cookies = request.getCookies();
|
||||||
|
if (cookies == null || cookies.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (Cookie cookie : cookies) {
|
||||||
|
if (COOKIE_NAME.equals(cookie.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseCookie buildSessionCookie(UUID sessionId) {
|
||||||
|
return ResponseCookie.from(COOKIE_NAME, sessionId.toString())
|
||||||
|
.path(COOKIE_PATH)
|
||||||
|
.httpOnly(true)
|
||||||
|
.secure(secureCookie)
|
||||||
|
.sameSite(sameSite)
|
||||||
|
.maxAge(Duration.ofDays(Math.max(cookieTtlDays, 1)))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseCookie buildClearCookie() {
|
||||||
|
return ResponseCookie.from(COOKIE_NAME, "")
|
||||||
|
.path(COOKIE_PATH)
|
||||||
|
.httpOnly(true)
|
||||||
|
.secure(secureCookie)
|
||||||
|
.sameSite(sameSite)
|
||||||
|
.maxAge(Duration.ZERO)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCookieTtlDays() {
|
||||||
|
return cookieTtlDays;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,362 @@
|
|||||||
|
package com.printcalculator.service.shop;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.ShopCartAddItemRequest;
|
||||||
|
import com.printcalculator.dto.ShopCartUpdateItemRequest;
|
||||||
|
import com.printcalculator.entity.QuoteLineItem;
|
||||||
|
import com.printcalculator.entity.QuoteSession;
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
import com.printcalculator.entity.ShopProductModelAsset;
|
||||||
|
import com.printcalculator.entity.ShopProductVariant;
|
||||||
|
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||||
|
import com.printcalculator.repository.QuoteSessionRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductModelAssetRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductVariantRepository;
|
||||||
|
import com.printcalculator.service.QuoteSessionTotalsService;
|
||||||
|
import com.printcalculator.service.quote.QuoteSessionResponseAssembler;
|
||||||
|
import com.printcalculator.service.quote.QuoteStorageService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class ShopCartService {
|
||||||
|
private static final String SHOP_CART_SESSION_TYPE = "SHOP_CART";
|
||||||
|
private static final String SHOP_LINE_ITEM_TYPE = "SHOP_PRODUCT";
|
||||||
|
private static final String ACTIVE_STATUS = "ACTIVE";
|
||||||
|
private static final String EXPIRED_STATUS = "EXPIRED";
|
||||||
|
private static final String CONVERTED_STATUS = "CONVERTED";
|
||||||
|
|
||||||
|
private final QuoteSessionRepository quoteSessionRepository;
|
||||||
|
private final QuoteLineItemRepository quoteLineItemRepository;
|
||||||
|
private final ShopProductVariantRepository shopProductVariantRepository;
|
||||||
|
private final ShopProductModelAssetRepository shopProductModelAssetRepository;
|
||||||
|
private final QuoteSessionTotalsService quoteSessionTotalsService;
|
||||||
|
private final QuoteSessionResponseAssembler quoteSessionResponseAssembler;
|
||||||
|
private final QuoteStorageService quoteStorageService;
|
||||||
|
private final ShopStorageService shopStorageService;
|
||||||
|
private final ShopCartCookieService shopCartCookieService;
|
||||||
|
|
||||||
|
public ShopCartService(
|
||||||
|
QuoteSessionRepository quoteSessionRepository,
|
||||||
|
QuoteLineItemRepository quoteLineItemRepository,
|
||||||
|
ShopProductVariantRepository shopProductVariantRepository,
|
||||||
|
ShopProductModelAssetRepository shopProductModelAssetRepository,
|
||||||
|
QuoteSessionTotalsService quoteSessionTotalsService,
|
||||||
|
QuoteSessionResponseAssembler quoteSessionResponseAssembler,
|
||||||
|
QuoteStorageService quoteStorageService,
|
||||||
|
ShopStorageService shopStorageService,
|
||||||
|
ShopCartCookieService shopCartCookieService
|
||||||
|
) {
|
||||||
|
this.quoteSessionRepository = quoteSessionRepository;
|
||||||
|
this.quoteLineItemRepository = quoteLineItemRepository;
|
||||||
|
this.shopProductVariantRepository = shopProductVariantRepository;
|
||||||
|
this.shopProductModelAssetRepository = shopProductModelAssetRepository;
|
||||||
|
this.quoteSessionTotalsService = quoteSessionTotalsService;
|
||||||
|
this.quoteSessionResponseAssembler = quoteSessionResponseAssembler;
|
||||||
|
this.quoteStorageService = quoteStorageService;
|
||||||
|
this.shopStorageService = shopStorageService;
|
||||||
|
this.shopCartCookieService = shopCartCookieService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CartResult loadCart(HttpServletRequest request) {
|
||||||
|
boolean hadCookie = shopCartCookieService.hasCartCookie(request);
|
||||||
|
Optional<QuoteSession> session = resolveValidCartSession(request);
|
||||||
|
if (session.isEmpty()) {
|
||||||
|
return CartResult.empty(quoteSessionResponseAssembler.emptyCart(), hadCookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
QuoteSession validSession = session.get();
|
||||||
|
touchSession(validSession);
|
||||||
|
return CartResult.withSession(buildCartResponse(validSession), validSession.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CartResult addItem(HttpServletRequest request, ShopCartAddItemRequest payload) {
|
||||||
|
int quantityToAdd = normalizeQuantity(payload != null ? payload.getQuantity() : null);
|
||||||
|
ShopProductVariant variant = getPurchasableVariant(payload != null ? payload.getShopProductVariantId() : null);
|
||||||
|
QuoteSession session = resolveValidCartSession(request).orElseGet(this::createCartSession);
|
||||||
|
touchSession(session);
|
||||||
|
|
||||||
|
QuoteLineItem lineItem = quoteLineItemRepository
|
||||||
|
.findFirstByQuoteSession_IdAndLineItemTypeAndShopProductVariant_Id(
|
||||||
|
session.getId(),
|
||||||
|
SHOP_LINE_ITEM_TYPE,
|
||||||
|
variant.getId()
|
||||||
|
)
|
||||||
|
.orElseGet(() -> buildShopLineItem(session, variant));
|
||||||
|
|
||||||
|
int existingQuantity = lineItem.getQuantity() != null && lineItem.getQuantity() > 0
|
||||||
|
? lineItem.getQuantity()
|
||||||
|
: 0;
|
||||||
|
int newQuantity = existingQuantity + quantityToAdd;
|
||||||
|
lineItem.setQuantity(newQuantity);
|
||||||
|
refreshLineItemSnapshot(lineItem, variant);
|
||||||
|
lineItem.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
quoteLineItemRepository.save(lineItem);
|
||||||
|
|
||||||
|
return CartResult.withSession(buildCartResponse(session), session.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CartResult updateItem(HttpServletRequest request, UUID lineItemId, ShopCartUpdateItemRequest payload) {
|
||||||
|
QuoteSession session = resolveValidCartSession(request)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Cart session not found"));
|
||||||
|
|
||||||
|
QuoteLineItem item = quoteLineItemRepository.findByIdAndQuoteSession_Id(lineItemId, session.getId())
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Cart item not found"));
|
||||||
|
|
||||||
|
if (!SHOP_LINE_ITEM_TYPE.equals(item.getLineItemType())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid cart item type");
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setQuantity(normalizeQuantity(payload != null ? payload.getQuantity() : null));
|
||||||
|
item.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
|
||||||
|
if (item.getShopProductVariant() != null) {
|
||||||
|
refreshLineItemSnapshot(item, item.getShopProductVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
quoteLineItemRepository.save(item);
|
||||||
|
touchSession(session);
|
||||||
|
return CartResult.withSession(buildCartResponse(session), session.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CartResult removeItem(HttpServletRequest request, UUID lineItemId) {
|
||||||
|
QuoteSession session = resolveValidCartSession(request)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Cart session not found"));
|
||||||
|
|
||||||
|
QuoteLineItem item = quoteLineItemRepository.findByIdAndQuoteSession_Id(lineItemId, session.getId())
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Cart item not found"));
|
||||||
|
|
||||||
|
quoteLineItemRepository.delete(item);
|
||||||
|
touchSession(session);
|
||||||
|
return CartResult.withSession(buildCartResponse(session), session.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public CartResult clearCart(HttpServletRequest request) {
|
||||||
|
boolean hadCookie = shopCartCookieService.hasCartCookie(request);
|
||||||
|
Optional<QuoteSession> session = resolveValidCartSession(request);
|
||||||
|
if (session.isPresent()) {
|
||||||
|
QuoteSession current = session.get();
|
||||||
|
quoteSessionRepository.delete(current);
|
||||||
|
}
|
||||||
|
return CartResult.empty(quoteSessionResponseAssembler.emptyCart(), hadCookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<QuoteSession> resolveValidCartSession(HttpServletRequest request) {
|
||||||
|
Optional<UUID> sessionId = shopCartCookieService.extractSessionId(request);
|
||||||
|
if (sessionId.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<QuoteSession> session = quoteSessionRepository.findByIdAndSessionType(sessionId.get(), SHOP_CART_SESSION_TYPE);
|
||||||
|
if (session.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QuoteSession quoteSession = session.get();
|
||||||
|
if (isSessionUnavailable(quoteSession)) {
|
||||||
|
if (!EXPIRED_STATUS.equals(quoteSession.getStatus()) && !CONVERTED_STATUS.equals(quoteSession.getStatus())) {
|
||||||
|
quoteSession.setStatus(EXPIRED_STATUS);
|
||||||
|
quoteSessionRepository.save(quoteSession);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(quoteSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuoteSession createCartSession() {
|
||||||
|
QuoteSession session = new QuoteSession();
|
||||||
|
session.setStatus(ACTIVE_STATUS);
|
||||||
|
session.setSessionType(SHOP_CART_SESSION_TYPE);
|
||||||
|
session.setPricingVersion("v1");
|
||||||
|
session.setMaterialCode("SHOP");
|
||||||
|
session.setSupportsEnabled(false);
|
||||||
|
session.setCreatedAt(OffsetDateTime.now());
|
||||||
|
session.setExpiresAt(nowPlusCookieTtl());
|
||||||
|
session.setSetupCostChf(BigDecimal.ZERO);
|
||||||
|
return quoteSessionRepository.save(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> buildCartResponse(QuoteSession session) {
|
||||||
|
List<QuoteLineItem> items = quoteLineItemRepository.findByQuoteSessionIdOrderByCreatedAtAsc(session.getId());
|
||||||
|
QuoteSessionTotalsService.QuoteSessionTotals totals = quoteSessionTotalsService.compute(session, items);
|
||||||
|
return quoteSessionResponseAssembler.assemble(session, items, totals);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuoteLineItem buildShopLineItem(QuoteSession session, ShopProductVariant variant) {
|
||||||
|
ShopProduct product = variant.getProduct();
|
||||||
|
ShopProductModelAsset modelAsset = product != null ? shopProductModelAssetRepository.findByProduct_Id(product.getId()).orElse(null) : null;
|
||||||
|
|
||||||
|
QuoteLineItem item = new QuoteLineItem();
|
||||||
|
item.setQuoteSession(session);
|
||||||
|
item.setStatus("READY");
|
||||||
|
item.setLineItemType(SHOP_LINE_ITEM_TYPE);
|
||||||
|
item.setQuantity(0);
|
||||||
|
item.setCreatedAt(OffsetDateTime.now());
|
||||||
|
item.setUpdatedAt(OffsetDateTime.now());
|
||||||
|
item.setSupportsEnabled(false);
|
||||||
|
item.setInfillPercent(0);
|
||||||
|
item.setPricingBreakdown(new HashMap<>());
|
||||||
|
|
||||||
|
refreshLineItemSnapshot(item, variant);
|
||||||
|
applyModelAssetSnapshot(item, session, modelAsset);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshLineItemSnapshot(QuoteLineItem item, ShopProductVariant variant) {
|
||||||
|
ShopProduct product = variant.getProduct();
|
||||||
|
ShopCategory category = product != null ? product.getCategory() : null;
|
||||||
|
|
||||||
|
item.setShopProduct(product);
|
||||||
|
item.setShopProductVariant(variant);
|
||||||
|
item.setShopProductSlug(product != null ? product.getSlug() : null);
|
||||||
|
item.setShopProductName(product != null ? product.getName() : null);
|
||||||
|
item.setShopVariantLabel(variant.getVariantLabel());
|
||||||
|
item.setShopVariantColorName(variant.getColorName());
|
||||||
|
item.setShopVariantColorHex(variant.getColorHex());
|
||||||
|
item.setDisplayName(product != null ? product.getName() : item.getDisplayName());
|
||||||
|
item.setColorCode(variant.getColorName());
|
||||||
|
item.setMaterialCode(variant.getInternalMaterialCode());
|
||||||
|
item.setQuality(null);
|
||||||
|
item.setUnitPriceChf(variant.getPriceChf() != null ? variant.getPriceChf() : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
Map<String, Object> breakdown = item.getPricingBreakdown() != null
|
||||||
|
? new HashMap<>(item.getPricingBreakdown())
|
||||||
|
: new HashMap<>();
|
||||||
|
breakdown.put("type", SHOP_LINE_ITEM_TYPE);
|
||||||
|
breakdown.put("unitPriceChf", item.getUnitPriceChf());
|
||||||
|
item.setPricingBreakdown(breakdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyModelAssetSnapshot(QuoteLineItem item, QuoteSession session, ShopProductModelAsset modelAsset) {
|
||||||
|
if (modelAsset == null) {
|
||||||
|
if (item.getOriginalFilename() == null || item.getOriginalFilename().isBlank()) {
|
||||||
|
item.setOriginalFilename(item.getShopProductSlug() != null ? item.getShopProductSlug() : "shop-product");
|
||||||
|
}
|
||||||
|
item.setBoundingBoxXMm(BigDecimal.ZERO);
|
||||||
|
item.setBoundingBoxYMm(BigDecimal.ZERO);
|
||||||
|
item.setBoundingBoxZMm(BigDecimal.ZERO);
|
||||||
|
item.setStoredPath(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setOriginalFilename(modelAsset.getOriginalFilename());
|
||||||
|
item.setBoundingBoxXMm(modelAsset.getBoundingBoxXMm() != null ? modelAsset.getBoundingBoxXMm() : BigDecimal.ZERO);
|
||||||
|
item.setBoundingBoxYMm(modelAsset.getBoundingBoxYMm() != null ? modelAsset.getBoundingBoxYMm() : BigDecimal.ZERO);
|
||||||
|
item.setBoundingBoxZMm(modelAsset.getBoundingBoxZMm() != null ? modelAsset.getBoundingBoxZMm() : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
String copiedStoredPath = copyModelAssetIntoSession(session, modelAsset);
|
||||||
|
item.setStoredPath(copiedStoredPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String copyModelAssetIntoSession(QuoteSession session, ShopProductModelAsset modelAsset) {
|
||||||
|
if (session == null || modelAsset == null || modelAsset.getProduct() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Path source = shopStorageService.resolveStoredProductPath(
|
||||||
|
modelAsset.getStoredRelativePath(),
|
||||||
|
modelAsset.getProduct().getId()
|
||||||
|
);
|
||||||
|
if (source == null || !Files.exists(source)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Path sessionDir = quoteStorageService.sessionStorageDir(session.getId());
|
||||||
|
String extension = quoteStorageService.getSafeExtension(modelAsset.getOriginalFilename(), "stl");
|
||||||
|
Path destination = quoteStorageService.resolveSessionPath(
|
||||||
|
sessionDir,
|
||||||
|
UUID.randomUUID() + "." + extension
|
||||||
|
);
|
||||||
|
Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
return quoteStorageService.toStoredPath(destination);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopProductVariant getPurchasableVariant(UUID variantId) {
|
||||||
|
if (variantId == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "shopProductVariantId is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
ShopProductVariant variant = shopProductVariantRepository.findById(variantId)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Variant not found"));
|
||||||
|
|
||||||
|
ShopProduct product = variant.getProduct();
|
||||||
|
ShopCategory category = product != null ? product.getCategory() : null;
|
||||||
|
if (product == null
|
||||||
|
|| category == null
|
||||||
|
|| !Boolean.TRUE.equals(variant.getIsActive())
|
||||||
|
|| !Boolean.TRUE.equals(product.getIsActive())
|
||||||
|
|| !Boolean.TRUE.equals(category.getIsActive())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Variant not available");
|
||||||
|
}
|
||||||
|
|
||||||
|
return variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void touchSession(QuoteSession session) {
|
||||||
|
session.setStatus(ACTIVE_STATUS);
|
||||||
|
session.setExpiresAt(nowPlusCookieTtl());
|
||||||
|
quoteSessionRepository.save(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OffsetDateTime nowPlusCookieTtl() {
|
||||||
|
return OffsetDateTime.now().plusDays(Math.max(shopCartCookieService.getCookieTtlDays(), 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSessionUnavailable(QuoteSession session) {
|
||||||
|
if (session == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!SHOP_CART_SESSION_TYPE.equalsIgnoreCase(session.getSessionType())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!ACTIVE_STATUS.equalsIgnoreCase(session.getStatus())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (CONVERTED_STATUS.equalsIgnoreCase(session.getStatus())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
OffsetDateTime expiresAt = session.getExpiresAt();
|
||||||
|
return expiresAt != null && expiresAt.isBefore(OffsetDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int normalizeQuantity(Integer quantity) {
|
||||||
|
if (quantity == null || quantity < 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CartResult(Map<String, Object> response, UUID sessionId, boolean clearCookie) {
|
||||||
|
public static CartResult withSession(Map<String, Object> response, UUID sessionId, boolean clearCookie) {
|
||||||
|
return new CartResult(response, sessionId, clearCookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CartResult empty(Map<String, Object> response, boolean clearCookie) {
|
||||||
|
return new CartResult(response, null, clearCookie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.printcalculator.service.shop;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
final class ShopPublicPathSupport {
|
||||||
|
private static final String PRODUCT_ROUTE_PREFIX = "/shop/p/";
|
||||||
|
|
||||||
|
private ShopPublicPathSupport() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static String buildProductPathSegment(ShopProduct product, String language) {
|
||||||
|
String localizedName = product.getNameForLanguage(language);
|
||||||
|
String idPrefix = productIdPrefix(product.getId());
|
||||||
|
String tail = firstNonBlank(slugify(localizedName), slugify(product.getSlug()), "product");
|
||||||
|
return idPrefix.isBlank() ? tail : idPrefix + "-" + tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, String> buildLocalizedProductPaths(ShopProduct product) {
|
||||||
|
Map<String, String> localizedPaths = new LinkedHashMap<>();
|
||||||
|
for (String language : ShopProduct.SUPPORTED_LANGUAGES) {
|
||||||
|
localizedPaths.put(language, "/" + language + PRODUCT_ROUTE_PREFIX + buildProductPathSegment(product, language));
|
||||||
|
}
|
||||||
|
return localizedPaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String productIdPrefix(UUID productId) {
|
||||||
|
if (productId == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String raw = productId.toString().trim().toLowerCase(Locale.ROOT);
|
||||||
|
int dashIndex = raw.indexOf('-');
|
||||||
|
if (dashIndex > 0) {
|
||||||
|
return raw.substring(0, dashIndex);
|
||||||
|
}
|
||||||
|
return raw.length() >= 8 ? raw.substring(0, 8) : raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String slugify(String rawValue) {
|
||||||
|
String safeValue = rawValue == null ? "" : rawValue;
|
||||||
|
String normalized = Normalizer.normalize(safeValue, Normalizer.Form.NFD)
|
||||||
|
.replaceAll("\\p{M}+", "")
|
||||||
|
.toLowerCase(Locale.ROOT)
|
||||||
|
.replaceAll("[^a-z0-9]+", "-")
|
||||||
|
.replaceAll("^-+|-+$", "")
|
||||||
|
.replaceAll("-{2,}", "-");
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String firstNonBlank(String... values) {
|
||||||
|
if (values == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (String value : values) {
|
||||||
|
if (value != null && !value.isBlank()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
package com.printcalculator.service.shop;
|
||||||
|
|
||||||
|
import com.printcalculator.entity.ShopCategory;
|
||||||
|
import com.printcalculator.entity.ShopProduct;
|
||||||
|
import com.printcalculator.repository.ShopCategoryRepository;
|
||||||
|
import com.printcalculator.repository.ShopProductRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public class ShopSitemapService {
|
||||||
|
private static final List<String> SUPPORTED_LANGUAGES = ShopProduct.SUPPORTED_LANGUAGES;
|
||||||
|
private static final String DEFAULT_LANGUAGE = "it";
|
||||||
|
private static final DateTimeFormatter LASTMOD_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
|
private static final Map<String, String> HREFLANG_BY_LANGUAGE = Map.of(
|
||||||
|
"it", "it-CH",
|
||||||
|
"en", "en-CH",
|
||||||
|
"de", "de-CH",
|
||||||
|
"fr", "fr-CH"
|
||||||
|
);
|
||||||
|
|
||||||
|
private final ShopCategoryRepository shopCategoryRepository;
|
||||||
|
private final ShopProductRepository shopProductRepository;
|
||||||
|
private final String frontendBaseUrl;
|
||||||
|
private final Duration cacheTtl;
|
||||||
|
private final Clock clock;
|
||||||
|
|
||||||
|
private volatile CachedSitemap cachedSitemap;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ShopSitemapService(ShopCategoryRepository shopCategoryRepository,
|
||||||
|
ShopProductRepository shopProductRepository,
|
||||||
|
@Value("${app.frontend.base-url:http://localhost:4200}") String frontendBaseUrl,
|
||||||
|
@Value("${app.sitemap.shop.cache-seconds:3600}") long cacheSeconds) {
|
||||||
|
this(shopCategoryRepository, shopProductRepository, frontendBaseUrl, cacheSeconds, Clock.systemUTC());
|
||||||
|
}
|
||||||
|
|
||||||
|
ShopSitemapService(ShopCategoryRepository shopCategoryRepository,
|
||||||
|
ShopProductRepository shopProductRepository,
|
||||||
|
String frontendBaseUrl,
|
||||||
|
long cacheSeconds,
|
||||||
|
Clock clock) {
|
||||||
|
this.shopCategoryRepository = shopCategoryRepository;
|
||||||
|
this.shopProductRepository = shopProductRepository;
|
||||||
|
this.frontendBaseUrl = normalizeBaseUrl(frontendBaseUrl);
|
||||||
|
this.cacheTtl = cacheSeconds > 0 ? Duration.ofSeconds(cacheSeconds) : Duration.ZERO;
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShopSitemapXml() {
|
||||||
|
Instant now = Instant.now(clock);
|
||||||
|
CachedSitemap current = cachedSitemap;
|
||||||
|
if (current != null && now.isBefore(current.expiresAt())) {
|
||||||
|
return current.xml();
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
current = cachedSitemap;
|
||||||
|
now = Instant.now(clock);
|
||||||
|
if (current != null && now.isBefore(current.expiresAt())) {
|
||||||
|
return current.xml();
|
||||||
|
}
|
||||||
|
|
||||||
|
String xml = buildSitemapXml();
|
||||||
|
Instant expiresAt = cacheTtl.isZero() ? now : now.plus(cacheTtl);
|
||||||
|
cachedSitemap = new CachedSitemap(xml, expiresAt);
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildSitemapXml() {
|
||||||
|
List<ShopCategory> activeCategories = shopCategoryRepository.findAllByIsActiveTrueOrderBySortOrderAscNameAsc();
|
||||||
|
Set<UUID> activeCategoryIds = activeCategories.stream()
|
||||||
|
.map(ShopCategory::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
List<ShopProduct> activeProducts = shopProductRepository.findAllByIsActiveTrueOrderByIsFeaturedDescSortOrderAscNameAsc();
|
||||||
|
|
||||||
|
StringBuilder xml = new StringBuilder(16_384);
|
||||||
|
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||||
|
xml.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" ");
|
||||||
|
xml.append("xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n");
|
||||||
|
|
||||||
|
appendCategoryUrls(xml, activeCategories);
|
||||||
|
appendProductUrls(xml, activeProducts, activeCategoryIds);
|
||||||
|
|
||||||
|
xml.append("</urlset>\n");
|
||||||
|
return xml.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendCategoryUrls(StringBuilder xml, List<ShopCategory> categories) {
|
||||||
|
for (ShopCategory category : categories) {
|
||||||
|
if (!Boolean.TRUE.equals(category.getIndexable())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String encodedSlug = pathEncodeSegment(category.getSlug());
|
||||||
|
Map<String, String> hrefByLanguage = new LinkedHashMap<>();
|
||||||
|
for (String language : SUPPORTED_LANGUAGES) {
|
||||||
|
hrefByLanguage.put(language, frontendBaseUrl + "/" + language + "/shop/" + encodedSlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
appendUrlEntry(xml, hrefByLanguage, category.getUpdatedAt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendProductUrls(StringBuilder xml,
|
||||||
|
List<ShopProduct> products,
|
||||||
|
Set<UUID> activeCategoryIds) {
|
||||||
|
for (ShopProduct product : products) {
|
||||||
|
if (!Boolean.TRUE.equals(product.getIndexable())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (product.getCategory() == null || !activeCategoryIds.contains(product.getCategory().getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> hrefByLanguage = new LinkedHashMap<>();
|
||||||
|
for (String language : SUPPORTED_LANGUAGES) {
|
||||||
|
String publicSegment = ShopPublicPathSupport.buildProductPathSegment(product, language);
|
||||||
|
hrefByLanguage.put(language, frontendBaseUrl + "/" + language + "/shop/p/" + pathEncodeSegment(publicSegment));
|
||||||
|
}
|
||||||
|
|
||||||
|
appendUrlEntry(xml, hrefByLanguage, product.getUpdatedAt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendUrlEntry(StringBuilder xml,
|
||||||
|
Map<String, String> hrefByLanguage,
|
||||||
|
OffsetDateTime lastmod) {
|
||||||
|
String defaultHref = hrefByLanguage.get(DEFAULT_LANGUAGE);
|
||||||
|
if (defaultHref == null || defaultHref.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String locLanguage : SUPPORTED_LANGUAGES) {
|
||||||
|
String locHref = hrefByLanguage.get(locLanguage);
|
||||||
|
if (locHref == null || locHref.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
appendLocalizedUrlEntry(xml, locHref, hrefByLanguage, defaultHref, lastmod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendLocalizedUrlEntry(StringBuilder xml,
|
||||||
|
String locHref,
|
||||||
|
Map<String, String> hrefByLanguage,
|
||||||
|
String defaultHref,
|
||||||
|
OffsetDateTime lastmod) {
|
||||||
|
xml.append(" <url>\n");
|
||||||
|
xml.append(" <loc>").append(xmlEscape(locHref)).append("</loc>\n");
|
||||||
|
|
||||||
|
for (String language : SUPPORTED_LANGUAGES) {
|
||||||
|
String href = hrefByLanguage.get(language);
|
||||||
|
if (href == null || href.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
xml.append(" <xhtml:link rel=\"alternate\" hreflang=\"")
|
||||||
|
.append(HREFLANG_BY_LANGUAGE.getOrDefault(language, language))
|
||||||
|
.append("\" href=\"")
|
||||||
|
.append(xmlEscape(href))
|
||||||
|
.append("\" />\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
xml.append(" <xhtml:link rel=\"alternate\" hreflang=\"x-default\" href=\"")
|
||||||
|
.append(xmlEscape(defaultHref))
|
||||||
|
.append("\" />\n");
|
||||||
|
|
||||||
|
if (lastmod != null) {
|
||||||
|
xml.append(" <lastmod>").append(LASTMOD_FORMATTER.format(lastmod)).append("</lastmod>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
xml.append(" </url>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String pathEncodeSegment(String rawSegment) {
|
||||||
|
String safeSegment = rawSegment == null ? "" : rawSegment;
|
||||||
|
return URLEncoder.encode(safeSegment, StandardCharsets.UTF_8).replace("+", "%20");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String xmlEscape(String value) {
|
||||||
|
return String.valueOf(value)
|
||||||
|
.replace("&", "&")
|
||||||
|
.replace("<", "<")
|
||||||
|
.replace(">", ">")
|
||||||
|
.replace("\"", """)
|
||||||
|
.replace("'", "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeBaseUrl(String baseUrl) {
|
||||||
|
String normalized = (baseUrl == null ? "" : baseUrl).trim();
|
||||||
|
if (normalized.isBlank()) {
|
||||||
|
return "http://localhost:4200";
|
||||||
|
}
|
||||||
|
while (normalized.endsWith("/")) {
|
||||||
|
normalized = normalized.substring(0, normalized.length() - 1);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CachedSitemap(String xml, Instant expiresAt) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.printcalculator.service.shop;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.InvalidPathException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ShopStorageService {
|
||||||
|
private final Path storageRoot;
|
||||||
|
|
||||||
|
public ShopStorageService(@Value("${shop.storage.root:storage_shop}") String storageRoot) {
|
||||||
|
this.storageRoot = Paths.get(storageRoot).toAbsolutePath().normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path productModelStorageDir(UUID productId) throws IOException {
|
||||||
|
Path dir = storageRoot.resolve(Path.of("products", productId.toString(), "3d-models")).normalize();
|
||||||
|
if (!dir.startsWith(storageRoot)) {
|
||||||
|
throw new IOException("Invalid shop product storage path");
|
||||||
|
}
|
||||||
|
Files.createDirectories(dir);
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path resolveStoredProductPath(String storedRelativePath, UUID expectedProductId) {
|
||||||
|
if (storedRelativePath == null || storedRelativePath.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Path raw = Path.of(storedRelativePath).normalize();
|
||||||
|
Path resolved = raw.isAbsolute() ? raw : storageRoot.resolve(raw).normalize();
|
||||||
|
Path expectedPrefix = storageRoot.resolve(Path.of("products", expectedProductId.toString())).normalize();
|
||||||
|
if (!resolved.startsWith(expectedPrefix)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
|
} catch (InvalidPathException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toStoredPath(Path absolutePath) {
|
||||||
|
return storageRoot.relativize(absolutePath.toAbsolutePath().normalize()).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,5 +9,4 @@ admin.session.ttl-minutes=480
|
|||||||
|
|
||||||
# Local media storage served by a local static server on port 8081.
|
# Local media storage served by a local static server on port 8081.
|
||||||
media.storage.root=/Users/joe/IdeaProjects/print-calculator/storage_media
|
media.storage.root=/Users/joe/IdeaProjects/print-calculator/storage_media
|
||||||
media.public.base-url=http://localhost:8081
|
|
||||||
media.ffmpeg.path=ffmpeg
|
media.ffmpeg.path=ffmpeg
|
||||||
|
|||||||
@@ -28,9 +28,13 @@ clamav.enabled=${CLAMAV_ENABLED:false}
|
|||||||
|
|
||||||
# Media configuration
|
# Media configuration
|
||||||
media.storage.root=${MEDIA_STORAGE_ROOT:storage_media}
|
media.storage.root=${MEDIA_STORAGE_ROOT:storage_media}
|
||||||
media.public.base-url=${MEDIA_PUBLIC_BASE_URL:http://localhost:8080/media}
|
|
||||||
media.ffmpeg.path=${MEDIA_FFMPEG_PATH:ffmpeg}
|
media.ffmpeg.path=${MEDIA_FFMPEG_PATH:ffmpeg}
|
||||||
media.upload.max-file-size-bytes=${MEDIA_UPLOAD_MAX_FILE_SIZE_BYTES:26214400}
|
media.upload.max-file-size-bytes=${MEDIA_UPLOAD_MAX_FILE_SIZE_BYTES:26214400}
|
||||||
|
shop.model.max-file-size-bytes=${SHOP_MODEL_MAX_FILE_SIZE_BYTES:104857600}
|
||||||
|
shop.storage.root=${SHOP_STORAGE_ROOT:storage_shop}
|
||||||
|
shop.cart.cookie.ttl-days=${SHOP_CART_COOKIE_TTL_DAYS:30}
|
||||||
|
shop.cart.cookie.secure=${SHOP_CART_COOKIE_SECURE:false}
|
||||||
|
shop.cart.cookie.same-site=${SHOP_CART_COOKIE_SAME_SITE:Lax}
|
||||||
|
|
||||||
# TWINT Configuration
|
# TWINT Configuration
|
||||||
payment.twint.url=${TWINT_PAYMENT_URL:https://go.twint.ch/1/e/tw?tw=acq.gERQQytOTnyIMuQHUqn4hlxgciHE5X7nnqHnNSPAr2OF2K3uBlXJDr2n9JU3sgxa.}
|
payment.twint.url=${TWINT_PAYMENT_URL:https://go.twint.ch/1/e/tw?tw=acq.gERQQytOTnyIMuQHUqn4hlxgciHE5X7nnqHnNSPAr2OF2K3uBlXJDr2n9JU3sgxa.}
|
||||||
@@ -52,6 +56,14 @@ app.mail.contact-request.admin.enabled=${APP_MAIL_CONTACT_REQUEST_ADMIN_ENABLED:
|
|||||||
app.mail.contact-request.admin.address=${APP_MAIL_CONTACT_REQUEST_ADMIN_ADDRESS:info@3d-fab.ch}
|
app.mail.contact-request.admin.address=${APP_MAIL_CONTACT_REQUEST_ADMIN_ADDRESS:info@3d-fab.ch}
|
||||||
app.mail.contact-request.customer.enabled=${APP_MAIL_CONTACT_REQUEST_CUSTOMER_ENABLED:true}
|
app.mail.contact-request.customer.enabled=${APP_MAIL_CONTACT_REQUEST_CUSTOMER_ENABLED:true}
|
||||||
app.frontend.base-url=${APP_FRONTEND_BASE_URL:http://localhost:4200}
|
app.frontend.base-url=${APP_FRONTEND_BASE_URL:http://localhost:4200}
|
||||||
|
app.cors.additional-allowed-origins=${APP_CORS_ADDITIONAL_ALLOWED_ORIGINS:}
|
||||||
|
app.sitemap.shop.cache-seconds=${APP_SITEMAP_SHOP_CACHE_SECONDS:3600}
|
||||||
|
openai.translation.api-key=${OPENAI_API_KEY:}
|
||||||
|
openai.translation.base-url=${OPENAI_BASE_URL:https://api.openai.com/v1}
|
||||||
|
openai.translation.model=${OPENAI_TRANSLATION_MODEL:gpt-5.4}
|
||||||
|
openai.translation.timeout-seconds=${OPENAI_TRANSLATION_TIMEOUT_SECONDS:45}
|
||||||
|
openai.translation.prompt-cache-key-prefix=${OPENAI_TRANSLATION_PROMPT_CACHE_KEY_PREFIX:printcalc-shop-product-translation-v1}
|
||||||
|
openai.translation.business-context=${OPENAI_TRANSLATION_BUSINESS_CONTEXT:}
|
||||||
|
|
||||||
# Admin back-office authentication
|
# Admin back-office authentication
|
||||||
admin.password=${ADMIN_PASSWORD}
|
admin.password=${ADMIN_PASSWORD}
|
||||||
|
|||||||
@@ -25,6 +25,21 @@
|
|||||||
color: #222222;
|
color: #222222;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
text-align: center;
|
||||||
|
border-bottom: 1px solid #eeeeee;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: block;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
color: #444444;
|
color: #444444;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
@@ -63,7 +78,10 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Nuova richiesta di contatto</h1>
|
<div class="header">
|
||||||
|
<img class="brand-logo" th:src="${logoUrl}" src="https://example.com/assets/images/brand-logo-yellow.svg" alt="3D-Fab">
|
||||||
|
<h1>Nuova richiesta di contatto</h1>
|
||||||
|
</div>
|
||||||
<p>E' stata ricevuta una nuova richiesta dal form contatti/su misura.</p>
|
<p>E' stata ricevuta una nuova richiesta dal form contatti/su misura.</p>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@@ -25,6 +25,21 @@
|
|||||||
color: #222222;
|
color: #222222;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
text-align: center;
|
||||||
|
border-bottom: 1px solid #eeeeee;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: block;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
margin-top: 18px;
|
margin-top: 18px;
|
||||||
color: #222222;
|
color: #222222;
|
||||||
@@ -69,7 +84,10 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 th:text="${headlineText}">We received your contact request</h1>
|
<div class="header">
|
||||||
|
<img class="brand-logo" th:src="${logoUrl}" src="https://example.com/assets/images/brand-logo-yellow.svg" alt="3D-Fab">
|
||||||
|
<h1 th:text="${headlineText}">We received your contact request</h1>
|
||||||
|
</div>
|
||||||
<p th:text="${greetingText}">Hi customer,</p>
|
<p th:text="${greetingText}">Hi customer,</p>
|
||||||
<p th:text="${introText}">Thank you for contacting us. Our team will reply as soon as possible.</p>
|
<p th:text="${introText}">Thank you for contacting us. Our team will reply as soon as possible.</p>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -27,8 +27,17 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: block;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.header h1 {
|
.header h1 {
|
||||||
color: #333333;
|
color: #333333;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
@@ -67,6 +76,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
<img class="brand-logo" th:src="${logoUrl}" src="https://example.com/assets/images/brand-logo-yellow.svg" alt="3D-Fab">
|
||||||
<h1 th:text="${headlineText}">Thank you for your order #00000000</h1>
|
<h1 th:text="${headlineText}">Thank you for your order #00000000</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,17 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: block;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.header h1 {
|
.header h1 {
|
||||||
color: #333333;
|
color: #333333;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
@@ -70,6 +79,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
<img class="brand-logo" th:src="${logoUrl}" src="https://example.com/assets/images/brand-logo-yellow.svg" alt="3D-Fab">
|
||||||
<h1 th:text="${headlineText}">Your order #00000000 has been shipped</h1>
|
<h1 th:text="${headlineText}">Your order #00000000 has been shipped</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,17 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: block;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.header h1 {
|
.header h1 {
|
||||||
color: #333333;
|
color: #333333;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
@@ -70,6 +79,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
<img class="brand-logo" th:src="${logoUrl}" src="https://example.com/assets/images/brand-logo-yellow.svg" alt="3D-Fab">
|
||||||
<h1 th:text="${headlineText}">Payment confirmed for order #00000000</h1>
|
<h1 th:text="${headlineText}">Payment confirmed for order #00000000</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,17 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand-logo {
|
||||||
|
display: block;
|
||||||
|
width: 220px;
|
||||||
|
max-width: 220px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.header h1 {
|
.header h1 {
|
||||||
color: #333333;
|
color: #333333;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
@@ -70,6 +79,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
<img class="brand-logo" th:src="${logoUrl}" src="https://example.com/assets/images/brand-logo-yellow.svg" alt="3D-Fab">
|
||||||
<h1 th:text="${headlineText}">Payment reported for order #00000000</h1>
|
<h1 th:text="${headlineText}">Payment reported for order #00000000</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.printcalculator.controller;
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.config.AllowedOriginService;
|
||||||
|
import com.printcalculator.config.CorsConfig;
|
||||||
import com.printcalculator.config.SecurityConfig;
|
import com.printcalculator.config.SecurityConfig;
|
||||||
import com.printcalculator.controller.admin.AdminAuthController;
|
import com.printcalculator.controller.admin.AdminAuthController;
|
||||||
|
import com.printcalculator.security.AdminCsrfProtectionFilter;
|
||||||
import com.printcalculator.security.AdminLoginThrottleService;
|
import com.printcalculator.security.AdminLoginThrottleService;
|
||||||
import com.printcalculator.security.AdminSessionAuthenticationFilter;
|
import com.printcalculator.security.AdminSessionAuthenticationFilter;
|
||||||
import com.printcalculator.security.AdminSessionService;
|
import com.printcalculator.security.AdminSessionService;
|
||||||
@@ -19,13 +22,18 @@ import org.springframework.test.web.servlet.MvcResult;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@WebMvcTest(controllers = AdminAuthController.class)
|
@WebMvcTest(controllers = AdminAuthController.class)
|
||||||
@Import({
|
@Import({
|
||||||
|
CorsConfig.class,
|
||||||
|
AllowedOriginService.class,
|
||||||
SecurityConfig.class,
|
SecurityConfig.class,
|
||||||
|
AdminCsrfProtectionFilter.class,
|
||||||
AdminSessionAuthenticationFilter.class,
|
AdminSessionAuthenticationFilter.class,
|
||||||
AdminSessionService.class,
|
AdminSessionService.class,
|
||||||
AdminLoginThrottleService.class
|
AdminLoginThrottleService.class
|
||||||
@@ -37,6 +45,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
})
|
})
|
||||||
class AdminAuthSecurityTest {
|
class AdminAuthSecurityTest {
|
||||||
|
|
||||||
|
private static final String ALLOWED_ORIGIN = "http://localhost:4200";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
@@ -47,6 +57,7 @@ class AdminAuthSecurityTest {
|
|||||||
req.setRemoteAddr("10.0.0.1");
|
req.setRemoteAddr("10.0.0.1");
|
||||||
return req;
|
return req;
|
||||||
})
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content("{\"password\":\"test-admin-password\"}"))
|
.content("{\"password\":\"test-admin-password\"}"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
@@ -69,6 +80,7 @@ class AdminAuthSecurityTest {
|
|||||||
req.setRemoteAddr("10.0.0.2");
|
req.setRemoteAddr("10.0.0.2");
|
||||||
return req;
|
return req;
|
||||||
})
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content("{\"password\":\"wrong-password\"}"))
|
.content("{\"password\":\"wrong-password\"}"))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().isUnauthorized())
|
||||||
@@ -83,6 +95,7 @@ class AdminAuthSecurityTest {
|
|||||||
req.setRemoteAddr("10.0.0.3");
|
req.setRemoteAddr("10.0.0.3");
|
||||||
return req;
|
return req;
|
||||||
})
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content("{\"password\":\"wrong-password\"}"))
|
.content("{\"password\":\"wrong-password\"}"))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().isUnauthorized())
|
||||||
@@ -93,12 +106,36 @@ class AdminAuthSecurityTest {
|
|||||||
req.setRemoteAddr("10.0.0.3");
|
req.setRemoteAddr("10.0.0.3");
|
||||||
return req;
|
return req;
|
||||||
})
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content("{\"password\":\"wrong-password\"}"))
|
.content("{\"password\":\"wrong-password\"}"))
|
||||||
.andExpect(status().isTooManyRequests())
|
.andExpect(status().isTooManyRequests())
|
||||||
.andExpect(jsonPath("$.authenticated").value(false));
|
.andExpect(jsonPath("$.authenticated").value(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void loginWithoutTrustedOrigin_ShouldReturnForbidden() throws Exception {
|
||||||
|
mockMvc.perform(post("/api/admin/auth/login")
|
||||||
|
.with(req -> {
|
||||||
|
req.setRemoteAddr("10.0.0.30");
|
||||||
|
return req;
|
||||||
|
})
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"password\":\"test-admin-password\"}"))
|
||||||
|
.andExpect(status().isForbidden())
|
||||||
|
.andExpect(jsonPath("$.error").value("CSRF_INVALID"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void preflightFromAllowedOrigin_ShouldExposeCorsHeaders() throws Exception {
|
||||||
|
mockMvc.perform(options("/api/admin/auth/login")
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
|
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, ALLOWED_ORIGIN))
|
||||||
|
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void adminAccessWithoutCookie_ShouldReturn401() throws Exception {
|
void adminAccessWithoutCookie_ShouldReturn401() throws Exception {
|
||||||
mockMvc.perform(get("/api/admin/auth/me"))
|
mockMvc.perform(get("/api/admin/auth/me"))
|
||||||
@@ -112,6 +149,7 @@ class AdminAuthSecurityTest {
|
|||||||
req.setRemoteAddr("10.0.0.4");
|
req.setRemoteAddr("10.0.0.4");
|
||||||
return req;
|
return req;
|
||||||
})
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content("{\"password\":\"test-admin-password\"}"))
|
.content("{\"password\":\"test-admin-password\"}"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package com.printcalculator.controller.admin;
|
||||||
|
|
||||||
|
import com.printcalculator.config.AllowedOriginService;
|
||||||
|
import com.printcalculator.config.CorsConfig;
|
||||||
|
import com.printcalculator.config.SecurityConfig;
|
||||||
|
import com.printcalculator.service.order.AdminOrderControllerService;
|
||||||
|
import com.printcalculator.security.AdminCsrfProtectionFilter;
|
||||||
|
import com.printcalculator.security.AdminLoginThrottleService;
|
||||||
|
import com.printcalculator.security.AdminSessionAuthenticationFilter;
|
||||||
|
import com.printcalculator.security.AdminSessionService;
|
||||||
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
|
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@WebMvcTest(controllers = {AdminAuthController.class, AdminOrderController.class})
|
||||||
|
@Import({
|
||||||
|
CorsConfig.class,
|
||||||
|
AllowedOriginService.class,
|
||||||
|
SecurityConfig.class,
|
||||||
|
AdminCsrfProtectionFilter.class,
|
||||||
|
AdminSessionAuthenticationFilter.class,
|
||||||
|
AdminSessionService.class,
|
||||||
|
AdminLoginThrottleService.class,
|
||||||
|
AdminOrderControllerSecurityTest.TransactionTestConfig.class
|
||||||
|
})
|
||||||
|
@TestPropertySource(properties = {
|
||||||
|
"admin.password=test-admin-password",
|
||||||
|
"admin.session.secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
"admin.session.ttl-minutes=60"
|
||||||
|
})
|
||||||
|
class AdminOrderControllerSecurityTest {
|
||||||
|
|
||||||
|
private static final String ALLOWED_ORIGIN = "http://localhost:4200";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private AdminOrderControllerService adminOrderControllerService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void confirmationDocument_withoutAdminCookie_shouldReturn401() throws Exception {
|
||||||
|
UUID orderId = UUID.randomUUID();
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/admin/orders/{orderId}/documents/confirmation", orderId))
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void confirmationDocument_withAdminCookie_shouldReturnPdf() throws Exception {
|
||||||
|
UUID orderId = UUID.randomUUID();
|
||||||
|
when(adminOrderControllerService.downloadOrderConfirmation(orderId))
|
||||||
|
.thenReturn(ResponseEntity.ok()
|
||||||
|
.contentType(MediaType.APPLICATION_PDF)
|
||||||
|
.body("confirmation".getBytes()));
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/admin/orders/{orderId}/documents/confirmation", orderId)
|
||||||
|
.cookie(loginAndExtractCookie()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().bytes("confirmation".getBytes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void invoiceDocument_withAdminCookie_shouldReturnPdf() throws Exception {
|
||||||
|
UUID orderId = UUID.randomUUID();
|
||||||
|
when(adminOrderControllerService.downloadOrderInvoice(orderId))
|
||||||
|
.thenReturn(ResponseEntity.ok()
|
||||||
|
.contentType(MediaType.APPLICATION_PDF)
|
||||||
|
.body("invoice".getBytes()));
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/admin/orders/{orderId}/documents/invoice", orderId)
|
||||||
|
.cookie(loginAndExtractCookie()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().bytes("invoice".getBytes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cookie loginAndExtractCookie() throws Exception {
|
||||||
|
MvcResult login = mockMvc.perform(post("/api/admin/auth/login")
|
||||||
|
.with(req -> {
|
||||||
|
req.setRemoteAddr("10.0.0.44");
|
||||||
|
return req;
|
||||||
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"password\":\"test-admin-password\"}"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andReturn();
|
||||||
|
|
||||||
|
String setCookie = login.getResponse().getHeader(HttpHeaders.SET_COOKIE);
|
||||||
|
assertNotNull(setCookie);
|
||||||
|
String[] parts = setCookie.split(";", 2);
|
||||||
|
String[] keyValue = parts[0].split("=", 2);
|
||||||
|
return new Cookie(keyValue[0], keyValue.length > 1 ? keyValue[1] : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
static class TransactionTestConfig {
|
||||||
|
@Bean
|
||||||
|
PlatformTransactionManager transactionManager() {
|
||||||
|
return new AbstractPlatformTransactionManager() {
|
||||||
|
@Override
|
||||||
|
protected Object doGetTransaction() {
|
||||||
|
return new Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doBegin(Object transaction, TransactionDefinition definition) {
|
||||||
|
// No-op transaction manager for WebMvc security tests.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doCommit(DefaultTransactionStatus status) {
|
||||||
|
// No-op transaction manager for WebMvc security tests.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doRollback(DefaultTransactionStatus status) {
|
||||||
|
// No-op transaction manager for WebMvc security tests.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package com.printcalculator.controller.admin;
|
||||||
|
|
||||||
|
import com.printcalculator.config.AllowedOriginService;
|
||||||
|
import com.printcalculator.config.CorsConfig;
|
||||||
|
import com.printcalculator.config.SecurityConfig;
|
||||||
|
import com.printcalculator.dto.AdminTranslateShopProductResponse;
|
||||||
|
import com.printcalculator.service.admin.AdminShopProductControllerService;
|
||||||
|
import com.printcalculator.service.admin.AdminShopProductTranslationService;
|
||||||
|
import com.printcalculator.security.AdminCsrfProtectionFilter;
|
||||||
|
import com.printcalculator.security.AdminLoginThrottleService;
|
||||||
|
import com.printcalculator.security.AdminSessionAuthenticationFilter;
|
||||||
|
import com.printcalculator.security.AdminSessionService;
|
||||||
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
|
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@WebMvcTest(controllers = {AdminAuthController.class, AdminShopProductController.class})
|
||||||
|
@Import({
|
||||||
|
CorsConfig.class,
|
||||||
|
AllowedOriginService.class,
|
||||||
|
SecurityConfig.class,
|
||||||
|
AdminCsrfProtectionFilter.class,
|
||||||
|
AdminSessionAuthenticationFilter.class,
|
||||||
|
AdminSessionService.class,
|
||||||
|
AdminLoginThrottleService.class,
|
||||||
|
AdminShopProductControllerSecurityTest.TransactionTestConfig.class
|
||||||
|
})
|
||||||
|
@TestPropertySource(properties = {
|
||||||
|
"admin.password=test-admin-password",
|
||||||
|
"admin.session.secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
"admin.session.ttl-minutes=60"
|
||||||
|
})
|
||||||
|
class AdminShopProductControllerSecurityTest {
|
||||||
|
|
||||||
|
private static final String ALLOWED_ORIGIN = "http://localhost:4200";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private AdminShopProductControllerService adminShopProductControllerService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private AdminShopProductTranslationService adminShopProductTranslationService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void translateProduct_withoutAdminCookie_shouldReturn401() throws Exception {
|
||||||
|
mockMvc.perform(post("/api/admin/shop/products/translate")
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"sourceLanguage\":\"it\",\"names\":{\"it\":\"Supporto cavo\"}}"))
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void translateProduct_withAdminCookieAndMissingOrigin_shouldReturn403() throws Exception {
|
||||||
|
mockMvc.perform(post("/api/admin/shop/products/translate")
|
||||||
|
.cookie(loginAndExtractCookie())
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"sourceLanguage\":\"it\",\"names\":{\"it\":\"Supporto cavo\"}}"))
|
||||||
|
.andExpect(status().isForbidden())
|
||||||
|
.andExpect(jsonPath("$.error").value("CSRF_INVALID"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void translateProduct_withAdminCookie_shouldReturnTranslations() throws Exception {
|
||||||
|
AdminTranslateShopProductResponse response = new AdminTranslateShopProductResponse();
|
||||||
|
response.setSourceLanguage("it");
|
||||||
|
response.setTargetLanguages(List.of("en", "de", "fr"));
|
||||||
|
response.setNames(Map.of("en", "Desk cable clip"));
|
||||||
|
response.setExcerpts(Map.of());
|
||||||
|
response.setDescriptions(Map.of());
|
||||||
|
response.setSeoTitles(Map.of());
|
||||||
|
response.setSeoDescriptions(Map.of());
|
||||||
|
|
||||||
|
when(adminShopProductTranslationService.translateProduct(org.mockito.ArgumentMatchers.any()))
|
||||||
|
.thenReturn(response);
|
||||||
|
|
||||||
|
mockMvc.perform(post("/api/admin/shop/products/translate")
|
||||||
|
.cookie(loginAndExtractCookie())
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("""
|
||||||
|
{
|
||||||
|
"sourceLanguage":"it",
|
||||||
|
"overwriteExisting":false,
|
||||||
|
"materialCodes":["PLA"],
|
||||||
|
"names":{"it":"Supporto cavo"},
|
||||||
|
"excerpts":{"it":"Accessorio tecnico"},
|
||||||
|
"descriptions":{"it":"<p>Descrizione</p>"},
|
||||||
|
"seoTitles":{"it":"SEO IT"},
|
||||||
|
"seoDescriptions":{"it":"SEO description IT"}
|
||||||
|
}
|
||||||
|
"""))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.sourceLanguage").value("it"))
|
||||||
|
.andExpect(jsonPath("$.targetLanguages[0]").value("en"))
|
||||||
|
.andExpect(jsonPath("$.names.en").value("Desk cable clip"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cookie loginAndExtractCookie() throws Exception {
|
||||||
|
MvcResult login = mockMvc.perform(post("/api/admin/auth/login")
|
||||||
|
.with(req -> {
|
||||||
|
req.setRemoteAddr("10.0.0.44");
|
||||||
|
return req;
|
||||||
|
})
|
||||||
|
.header(HttpHeaders.ORIGIN, ALLOWED_ORIGIN)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content("{\"password\":\"test-admin-password\"}"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andReturn();
|
||||||
|
|
||||||
|
String setCookie = login.getResponse().getHeader(HttpHeaders.SET_COOKIE);
|
||||||
|
assertNotNull(setCookie);
|
||||||
|
String[] parts = setCookie.split(";", 2);
|
||||||
|
String[] keyValue = parts[0].split("=", 2);
|
||||||
|
return new Cookie(keyValue[0], keyValue.length > 1 ? keyValue[1] : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
static class TransactionTestConfig {
|
||||||
|
@Bean
|
||||||
|
PlatformTransactionManager transactionManager() {
|
||||||
|
return new AbstractPlatformTransactionManager() {
|
||||||
|
@Override
|
||||||
|
protected Object doGetTransaction() {
|
||||||
|
return new Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doBegin(Object transaction, TransactionDefinition definition) {
|
||||||
|
// No-op transaction manager for WebMvc security tests.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doCommit(DefaultTransactionStatus status) {
|
||||||
|
// No-op transaction manager for WebMvc security tests.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doRollback(DefaultTransactionStatus status) {
|
||||||
|
// No-op transaction manager for WebMvc security tests.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class FilamentVariantTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getColorLabelForLanguageShouldReturnLocalizedValue() {
|
||||||
|
FilamentVariant variant = new FilamentVariant();
|
||||||
|
variant.setColorName("Orange");
|
||||||
|
variant.setColorLabelIt("Arancione");
|
||||||
|
variant.setColorLabelEn("Orange");
|
||||||
|
variant.setColorLabelDe("Orange");
|
||||||
|
variant.setColorLabelFr("Orange");
|
||||||
|
|
||||||
|
assertEquals("Arancione", variant.getColorLabelForLanguage("it"));
|
||||||
|
assertEquals("Orange", variant.getColorLabelForLanguage("en"));
|
||||||
|
assertEquals("Orange", variant.getColorLabelForLanguage("de-CH"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getColorLabelForLanguageShouldFallbackToColorName() {
|
||||||
|
FilamentVariant variant = new FilamentVariant();
|
||||||
|
variant.setColorName("Orange");
|
||||||
|
|
||||||
|
assertEquals("Orange", variant.getColorLabelForLanguage("it"));
|
||||||
|
assertEquals("Orange", variant.getColorLabelForLanguage("fr"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class ShopCategoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void localizedAccessorsShouldReturnLanguageSpecificValues() {
|
||||||
|
ShopCategory category = new ShopCategory();
|
||||||
|
category.setName("Desk accessories");
|
||||||
|
category.setNameIt("Accessori da scrivania");
|
||||||
|
category.setNameEn("Desk accessories");
|
||||||
|
category.setNameDe("Schreibtischzubehor");
|
||||||
|
category.setNameFr("Accessoires de bureau");
|
||||||
|
category.setDescription("Legacy description");
|
||||||
|
category.setDescriptionIt("Organizer e accessori stampati per la scrivania.");
|
||||||
|
category.setDescriptionEn("Printed desk organizers and accessories.");
|
||||||
|
category.setDescriptionDe("Gedruckte Organizer und Zubehor fur den Schreibtisch.");
|
||||||
|
category.setDescriptionFr("Accessoires et organiseurs imprimes pour le bureau.");
|
||||||
|
category.setSeoTitle("Legacy SEO title");
|
||||||
|
category.setSeoTitleIt("Accessori da scrivania stampati in 3D");
|
||||||
|
category.setSeoTitleEn("3D printed desk accessories");
|
||||||
|
category.setSeoTitleDe("3D-gedruckte Schreibtischaccessoires");
|
||||||
|
category.setSeoTitleFr("Accessoires de bureau imprimes en 3D");
|
||||||
|
category.setSeoDescription("Legacy SEO description");
|
||||||
|
category.setSeoDescriptionIt("Accessori da scrivania personalizzati e funzionali.");
|
||||||
|
category.setSeoDescriptionEn("Functional custom desk accessories.");
|
||||||
|
category.setSeoDescriptionDe("Funktionale personalisierte Schreibtischaccessoires.");
|
||||||
|
category.setSeoDescriptionFr("Accessoires de bureau fonctionnels et personnalises.");
|
||||||
|
|
||||||
|
assertEquals("Accessori da scrivania", category.getNameForLanguage("it"));
|
||||||
|
assertEquals("Desk accessories", category.getNameForLanguage("en"));
|
||||||
|
assertEquals("Schreibtischzubehor", category.getNameForLanguage("de"));
|
||||||
|
assertEquals("Accessoires de bureau", category.getNameForLanguage("fr"));
|
||||||
|
assertEquals("Gedruckte Organizer und Zubehor fur den Schreibtisch.", category.getDescriptionForLanguage("de"));
|
||||||
|
assertEquals("3D printed desk accessories", category.getSeoTitleForLanguage("en"));
|
||||||
|
assertEquals("Accessoires de bureau fonctionnels et personnalises.", category.getSeoDescriptionForLanguage("fr"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void localizedAccessorsShouldFallbackToLegacyValues() {
|
||||||
|
ShopCategory category = new ShopCategory();
|
||||||
|
category.setName("Desk accessories");
|
||||||
|
category.setDescription("Printed desk organizers and accessories.");
|
||||||
|
category.setSeoTitle("3D printed desk accessories");
|
||||||
|
category.setSeoDescription("Functional custom desk accessories.");
|
||||||
|
|
||||||
|
assertEquals("Desk accessories", category.getNameForLanguage("it"));
|
||||||
|
assertEquals("Printed desk organizers and accessories.", category.getDescriptionForLanguage("de"));
|
||||||
|
assertEquals("3D printed desk accessories", category.getSeoTitleForLanguage("fr-CH"));
|
||||||
|
assertEquals("Functional custom desk accessories.", category.getSeoDescriptionForLanguage("en-US"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class ShopProductTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void localizedAccessorsShouldReturnLanguageSpecificValues() {
|
||||||
|
ShopProduct product = new ShopProduct();
|
||||||
|
product.setName("Desk Cable Clip");
|
||||||
|
product.setNameIt("Fermacavo da scrivania");
|
||||||
|
product.setNameEn("Desk Cable Clip");
|
||||||
|
product.setNameDe("Schreibtisch-Kabelclip");
|
||||||
|
product.setNameFr("Clip de cable de bureau");
|
||||||
|
product.setExcerpt("Legacy excerpt");
|
||||||
|
product.setExcerptIt("Clip compatta per i cavi sulla scrivania.");
|
||||||
|
product.setExcerptEn("Compact clip to keep desk cables in place.");
|
||||||
|
product.setExcerptDe("Kompakter Clip fur ordentliche Kabel auf dem Schreibtisch.");
|
||||||
|
product.setExcerptFr("Clip compact pour garder les cables du bureau en ordre.");
|
||||||
|
product.setDescription("Legacy description");
|
||||||
|
product.setDescriptionIt("Supporto con base stabile e passaggio cavi frontale.");
|
||||||
|
product.setDescriptionEn("Stable desk clip with front cable routing.");
|
||||||
|
product.setDescriptionDe("Stabiler Tischclip mit frontaler Kabelfuhrung.");
|
||||||
|
product.setDescriptionFr("Clip de bureau stable avec passage frontal des cables.");
|
||||||
|
|
||||||
|
assertEquals("Fermacavo da scrivania", product.getNameForLanguage("it"));
|
||||||
|
assertEquals("Desk Cable Clip", product.getNameForLanguage("en"));
|
||||||
|
assertEquals("Schreibtisch-Kabelclip", product.getNameForLanguage("de"));
|
||||||
|
assertEquals("Clip de cable de bureau", product.getNameForLanguage("fr"));
|
||||||
|
assertEquals("Compact clip to keep desk cables in place.", product.getExcerptForLanguage("en"));
|
||||||
|
assertEquals("Clip compact pour garder les cables du bureau en ordre.", product.getExcerptForLanguage("fr"));
|
||||||
|
assertEquals("Stabiler Tischclip mit frontaler Kabelfuhrung.", product.getDescriptionForLanguage("de"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void localizedAccessorsShouldFallbackToLegacyValues() {
|
||||||
|
ShopProduct product = new ShopProduct();
|
||||||
|
product.setName("Desk Cable Clip");
|
||||||
|
product.setExcerpt("Compact desk cable clip.");
|
||||||
|
product.setDescription("Stable clip with front cable channel.");
|
||||||
|
|
||||||
|
assertEquals("Desk Cable Clip", product.getNameForLanguage("it"));
|
||||||
|
assertEquals("Compact desk cable clip.", product.getExcerptForLanguage("de"));
|
||||||
|
assertEquals("Stable clip with front cable channel.", product.getDescriptionForLanguage("fr-CH"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.printcalculator.entity;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class ShopProductVariantTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getColorLabelForLanguageShouldReturnLocalizedValue() {
|
||||||
|
ShopProductVariant variant = new ShopProductVariant();
|
||||||
|
variant.setColorName("Gray");
|
||||||
|
variant.setColorLabelIt("Grigio");
|
||||||
|
variant.setColorLabelEn("Gray");
|
||||||
|
variant.setColorLabelDe("Grau");
|
||||||
|
variant.setColorLabelFr("Gris");
|
||||||
|
|
||||||
|
assertEquals("Grigio", variant.getColorLabelForLanguage("it"));
|
||||||
|
assertEquals("Gray", variant.getColorLabelForLanguage("en"));
|
||||||
|
assertEquals("Grau", variant.getColorLabelForLanguage("de"));
|
||||||
|
assertEquals("Gris", variant.getColorLabelForLanguage("fr-CH"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getColorLabelForLanguageShouldFallbackToColorName() {
|
||||||
|
ShopProductVariant variant = new ShopProductVariant();
|
||||||
|
variant.setColorName("Gray");
|
||||||
|
|
||||||
|
assertEquals("Gray", variant.getColorLabelForLanguage("it"));
|
||||||
|
assertEquals("Gray", variant.getColorLabelForLanguage("de"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user