initial commit
Change-Id: I96a6146540a58c05a014acbba38e7be770db072b
This commit is contained in:
11
.devcontainer/Dockerfile
Normal file
11
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Not actually used by the devcontainer, but it is used by gitpod
|
||||||
|
ARG VARIANT=17-bullseye
|
||||||
|
FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}
|
||||||
|
ARG NODE_VERSION="none"
|
||||||
|
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
||||||
|
ARG USER=vscode
|
||||||
|
VOLUME /home/$USER/.m2
|
||||||
|
VOLUME /home/$USER/.gradle
|
||||||
|
ARG JAVA_VERSION=17.0.7-ms
|
||||||
|
RUN sudo mkdir /home/$USER/.m2 /home/$USER/.gradle && sudo chown $USER:$USER /home/$USER/.m2 /home/$USER/.gradle
|
||||||
|
RUN bash -lc '. /usr/local/sdkman/bin/sdkman-init.sh && sdk install java $JAVA_VERSION && sdk use java $JAVA_VERSION'
|
||||||
25
.devcontainer/devcontainer.json
Normal file
25
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "Java",
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/java:1": {
|
||||||
|
"version": "21-oracle",
|
||||||
|
"jdkDistro": "oracle"
|
||||||
|
},
|
||||||
|
"ghcr.io/devcontainers/features/azure-cli:1": {},
|
||||||
|
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
||||||
|
"ghcr.io/devcontainers/features/github-cli:1": {}
|
||||||
|
},
|
||||||
|
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {},
|
||||||
|
"extensions": [
|
||||||
|
"redhat.vscode-xml",
|
||||||
|
"visualstudioexptteam.vscodeintellicode",
|
||||||
|
"vscjava.vscode-java-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"remoteUser": "vscode"
|
||||||
|
}
|
||||||
24
.editorconfig
Normal file
24
.editorconfig
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
[*.{java,xml}]
|
||||||
|
indent_size = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
indent_style = tab
|
||||||
|
tab_width = 4
|
||||||
|
|
||||||
|
[{pom,wro}.xml]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
[*.{html,sql,less}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.gradle]
|
||||||
|
indent_size = 2
|
||||||
6
.gitattributes
vendored
Normal file
6
.gitattributes
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/mvnw text eol=lf
|
||||||
|
*.cmd text eol=crlf
|
||||||
|
*.java text eol=lf
|
||||||
|
|
||||||
|
/gradlew text eol=lf
|
||||||
|
*.bat text eol=crlf
|
||||||
84
.gitea/workflows/build-push.yml
Normal file
84
.gitea/workflows/build-push.yml
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
name: Build and Push to ACR
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ dev ]
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
AZURE_FEDERATED_TOKEN_FILE: /var/run/secrets/azure/tokens/azure-identity-token
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build and Push
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: >-
|
||||||
|
github.ref != 'refs/heads/main' && (
|
||||||
|
github.event_name == 'workflow_dispatch' ||
|
||||||
|
(github.event_name == 'push' && github.event.before != '0000000000000000000000000000000000000000')
|
||||||
|
)
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Azure CLI
|
||||||
|
run: |
|
||||||
|
command -v az &>/dev/null || curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||||
|
|
||||||
|
- name: Install Docker CLI
|
||||||
|
run: |
|
||||||
|
command -v docker &>/dev/null || (apt-get update -qq && apt-get install -y docker.io)
|
||||||
|
docker --version
|
||||||
|
|
||||||
|
- name: Azure login (OIDC)
|
||||||
|
run: |
|
||||||
|
az login \
|
||||||
|
--service-principal \
|
||||||
|
--username "$AZURE_CLIENT_ID" \
|
||||||
|
--tenant "$AZURE_TENANT_ID" \
|
||||||
|
--federated-token "$(cat $AZURE_FEDERATED_TOKEN_FILE)"
|
||||||
|
echo "✓ Azure login successful"
|
||||||
|
|
||||||
|
- name: Get ACR details
|
||||||
|
run: |
|
||||||
|
ACR_NAME=$(az acr list --query "[0].name" -o tsv)
|
||||||
|
ACR_NAME="${ACR_NAME:-bstagecjotdevacr}"
|
||||||
|
echo "ACR_NAME=$ACR_NAME" >> $GITHUB_ENV
|
||||||
|
echo "ACR_LOGIN_SERVER=${ACR_NAME}.azurecr.io" >> $GITHUB_ENV
|
||||||
|
echo "✓ Using ACR: ${ACR_NAME}.azurecr.io"
|
||||||
|
|
||||||
|
- name: ACR Login
|
||||||
|
run: |
|
||||||
|
ACR_TOKEN=$(az acr login --name "$ACR_NAME" --expose-token --output tsv --query accessToken)
|
||||||
|
docker login "$ACR_LOGIN_SERVER" \
|
||||||
|
--username 00000000-0000-0000-0000-000000000000 \
|
||||||
|
--password "$ACR_TOKEN"
|
||||||
|
echo "✓ ACR login successful"
|
||||||
|
|
||||||
|
- name: Build and Push Docker image
|
||||||
|
run: |
|
||||||
|
IMAGE_TAG="${{ gitea.sha }}"
|
||||||
|
IMAGE_FULL="${ACR_LOGIN_SERVER}/demo-principal-1:${IMAGE_TAG}"
|
||||||
|
IMAGE_LATEST="${ACR_LOGIN_SERVER}/demo-principal-1:latest"
|
||||||
|
docker build -t "$IMAGE_FULL" -t "$IMAGE_LATEST" .
|
||||||
|
docker push "$IMAGE_FULL"
|
||||||
|
docker push "$IMAGE_LATEST"
|
||||||
|
echo "IMAGE_FULL=$IMAGE_FULL" >> $GITHUB_ENV
|
||||||
|
echo "✓ Pushed: $IMAGE_FULL"
|
||||||
|
|
||||||
|
- name: Build Summary
|
||||||
|
run: |
|
||||||
|
echo "### ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| | |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Service** | demo-principal-1 |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Commit** | ${{ gitea.sha }} |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| **Image** | $IMAGE_FULL |" >> $GITHUB_STEP_SUMMARY
|
||||||
186
.gitea/workflows/deploy.yml
Normal file
186
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
name: Deploy to Orchestrator
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Build and Push to ACR"]
|
||||||
|
types: [completed]
|
||||||
|
branches: [ "dev", "staging", "prod" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
environment:
|
||||||
|
description: 'Target environment'
|
||||||
|
required: true
|
||||||
|
default: 'dev'
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- dev
|
||||||
|
- staging
|
||||||
|
- prod
|
||||||
|
|
||||||
|
env:
|
||||||
|
PO_API_URL: https://api.dev.orchestrator.crucible.kyndemo.live
|
||||||
|
PO_ORG_ID: crucible
|
||||||
|
PO_AUTH_TOKEN: ${{ secrets.PO_AUTH_TOKEN }}
|
||||||
|
# ONE ORCHESTRATOR PROJECT PER APPLICATION.
|
||||||
|
#
|
||||||
|
# This used to be the shared `apps-cluster` project with one environment per app, which
|
||||||
|
# made every app a peer of every other: the Orchestrator tab on any component listed the
|
||||||
|
# entire estate, and an app had exactly one environment named after itself, so there was
|
||||||
|
# nowhere for dev/staging/prod to live.
|
||||||
|
#
|
||||||
|
# That shape existed to avoid a Terraform pull request against config/projects.tf for every
|
||||||
|
# scaffolded app. That constraint turned out not to be real -- `octl create project`,
|
||||||
|
# `octl create runner-rule` and `octl create environment` are all runtime operations, so
|
||||||
|
# the workflow below builds the whole thing on first deploy and needs no repository change.
|
||||||
|
PROJECT_ID: demo-principal-1
|
||||||
|
# The runner a project's workloads execute on. This is NOT cosmetic: the Kubernetes and
|
||||||
|
# Helm providers are ambient, so a workload lands in whichever cluster its runner lives in,
|
||||||
|
# and Terraform state is keyed per runner. A project bound to the wrong runner deploys to
|
||||||
|
# the wrong cluster, and repointing it afterwards orphans the state it already owns.
|
||||||
|
PO_RUNNER_ID: crucible-orchestrator-dev-apps-dev-runner
|
||||||
|
OCTL_VERSION: 1.0.0
|
||||||
|
IMAGE: bstagecjotdevacr.azurecr.io/demo-principal-1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
guard:
|
||||||
|
name: Platform guard
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
ready: ${{ steps.check.outputs.ready }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Check platform initialized
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
if [ -f ".platform/initialized.md" ]; then
|
||||||
|
echo "ready=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "ready=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "Skipping: .platform/initialized.md not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
name: Deploy to Orchestrator
|
||||||
|
needs: guard
|
||||||
|
if: >-
|
||||||
|
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && needs.guard.outputs.ready == 'true') ||
|
||||||
|
(github.event_name == 'workflow_dispatch')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install octl
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
curl -fsSLo /tmp/octl.tar.gz \
|
||||||
|
"https://github.com/stellwerk-labs/platform-orchestrator-cli/releases/download/v${OCTL_VERSION}/platform-orchestrator-cli_${OCTL_VERSION}_linux_amd64.tar.gz"
|
||||||
|
tar xzf /tmp/octl.tar.gz -C /tmp
|
||||||
|
install -m 755 /tmp/octl /usr/local/bin/octl
|
||||||
|
octl --version
|
||||||
|
|
||||||
|
- name: Derive environment
|
||||||
|
run: |
|
||||||
|
# The environment is now a STAGE of this application -- dev, staging, prod -- because
|
||||||
|
# the project is the application. It used to be the component id, which was the only
|
||||||
|
# option while every app shared one project and had to be distinguishable inside it.
|
||||||
|
DISPATCH_ENV="${{ github.event.inputs.environment }}"
|
||||||
|
if [ -n "$DISPATCH_ENV" ]; then
|
||||||
|
ENV_ID="$DISPATCH_ENV"
|
||||||
|
else
|
||||||
|
# On a workflow_run the branch is the triggering run's, not this job's checkout.
|
||||||
|
BRANCH="${{ github.event.workflow_run.head_branch }}"
|
||||||
|
BRANCH="${BRANCH:-${GITHUB_REF_NAME}}"
|
||||||
|
case "$BRANCH" in
|
||||||
|
staging) ENV_ID=staging ;;
|
||||||
|
prod|main|master) ENV_ID=prod ;;
|
||||||
|
*) ENV_ID=dev ;;
|
||||||
|
esac
|
||||||
|
echo "Branch '$BRANCH' maps to environment '$ENV_ID'"
|
||||||
|
fi
|
||||||
|
echo "ENV_ID=$ENV_ID" >> $GITHUB_ENV
|
||||||
|
echo "Deploying $PROJECT_ID to environment: $ENV_ID"
|
||||||
|
|
||||||
|
- name: Ensure the project and its runner binding exist
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# Created on first deploy rather than by a pull request against config/projects.tf.
|
||||||
|
# None of this needs a repository change: project, runner rule and environment are
|
||||||
|
# all runtime objects.
|
||||||
|
#
|
||||||
|
# Neither create is idempotent, so both fall through to a read on the second run.
|
||||||
|
octl create project "$PROJECT_ID" \
|
||||||
|
--set display_name='demo-principal-1' || \
|
||||||
|
octl get project "$PROJECT_ID"
|
||||||
|
|
||||||
|
# The runner rule is what routes this project's deployments to the apps cluster.
|
||||||
|
# Creating it twice would leave two rules matching the same project, so it is
|
||||||
|
# created only when absent -- `create` would happily add a duplicate.
|
||||||
|
if octl get runner-rules -o json 2>/dev/null | grep -q "\"project_id\": *\"$PROJECT_ID\""; then
|
||||||
|
echo "Runner rule for '$PROJECT_ID' already exists."
|
||||||
|
else
|
||||||
|
octl create runner-rule \
|
||||||
|
--set project_id="$PROJECT_ID" \
|
||||||
|
--set runner_id="$PO_RUNNER_ID" \
|
||||||
|
--no-prompt
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Ensure the environment exists
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# Project and environment ids are POSITIONAL; only env_type_id and display_name go
|
||||||
|
# through --set. `dev` and `stable` are the only environment TYPES that exist, so
|
||||||
|
# staging rides on the dev type -- the type governs policy, the id governs identity.
|
||||||
|
case "$ENV_ID" in
|
||||||
|
prod) ENV_TYPE=stable ;;
|
||||||
|
*) ENV_TYPE=dev ;;
|
||||||
|
esac
|
||||||
|
octl create environment "$PROJECT_ID" "$ENV_ID" \
|
||||||
|
--set env_type_id="$ENV_TYPE" \
|
||||||
|
--set display_name="$ENV_ID" || \
|
||||||
|
octl get environment "$PROJECT_ID" "$ENV_ID"
|
||||||
|
|
||||||
|
- name: Deploy the Score workload
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# `octl score deploy` is ADDITIVE — it adds or updates a workload in the manifest and
|
||||||
|
# never removes one. That is the opposite of `octl deploy`, where omission is
|
||||||
|
# deletion. Do not substitute one for the other.
|
||||||
|
# No --show-logs: octl 1.0.0 has no such flag and exits 1 with `unknown flag`
|
||||||
|
# BEFORE contacting the orchestrator, so the whole deploy dies on an argument
|
||||||
|
# typo. Its nearest relatives are --runner-logs-level (default `info`, already
|
||||||
|
# what we want) and --skip-logs (which suppresses storage). Neither streams the
|
||||||
|
# runner's logs into this job, so there is nothing to substitute -- the runner
|
||||||
|
# logs are read from the orchestrator, not from here.
|
||||||
|
# The tag must be the commit the BUILD built, and it must be the WHOLE sha.
|
||||||
|
#
|
||||||
|
# build-push.yml tags with `` -- all 40 characters -- so the
|
||||||
|
# 7-character `${GITHUB_SHA:0:7}` this used to pass named a tag that has never
|
||||||
|
# existed in the registry.
|
||||||
|
#
|
||||||
|
# And on a workflow_run, GITHUB_SHA is the DEFAULT branch's head, while the build
|
||||||
|
# that produced the image ran on `dev`. They coincide only while the branches are
|
||||||
|
# level. `workflow_run.head_sha` is the triggering run's own commit, which is by
|
||||||
|
# definition the one that was built; `github.sha` covers the workflow_dispatch case,
|
||||||
|
# where there is no triggering run.
|
||||||
|
IMAGE_TAG="${{ github.event.workflow_run.head_sha || github.sha }}"
|
||||||
|
echo "Deploying ${IMAGE}:${IMAGE_TAG}"
|
||||||
|
|
||||||
|
octl score deploy "$PROJECT_ID" "$ENV_ID" score.yaml \
|
||||||
|
--default-image "${IMAGE}:${IMAGE_TAG}" \
|
||||||
|
--no-prompt
|
||||||
|
|
||||||
|
- name: Deployment summary
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
# Same commit the deploy step resolved, abbreviated for reading only -- the
|
||||||
|
# deployed tag is the full sha.
|
||||||
|
DEPLOYED_SHA="${{ github.event.workflow_run.head_sha || github.sha }}"
|
||||||
|
SHORT_SHA="${DEPLOYED_SHA:0:7}"
|
||||||
|
echo "## Deployment Result" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Project | \`$PROJECT_ID\` |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Environment | \`$ENV_ID\` |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "| Commit | \`$SHORT_SHA\` |" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "[View in Orchestrator Console](https://console.dev.orchestrator.crucible.kyndemo.live/orgs/$PO_ORG_ID/projects/$PROJECT_ID/environments/$ENV_ID)" >> $GITHUB_STEP_SUMMARY
|
||||||
161
.gitea/workflows/integration-test.yml
Normal file
161
.gitea/workflows/integration-test.yml
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
|
||||||
|
name: Integration Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# ── Job 1: Platform Conformance ───────────────────────────────────────────
|
||||||
|
platform-check:
|
||||||
|
name: Platform Conformance
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Validate catalog-info.yaml
|
||||||
|
run: |
|
||||||
|
if [ ! -f catalog-info.yaml ]; then
|
||||||
|
echo "✗ catalog-info.yaml not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
python3 -c "import yaml; list(yaml.safe_load_all(open('catalog-info.yaml')))" 2>/dev/null \
|
||||||
|
|| (pip install pyyaml -q && python3 -c "import yaml; list(yaml.safe_load_all(open('catalog-info.yaml')))")
|
||||||
|
echo "✓ catalog-info.yaml is valid YAML"
|
||||||
|
|
||||||
|
- name: Check platform initialized
|
||||||
|
run: |
|
||||||
|
if [ -f ".platform/initialized.md" ]; then
|
||||||
|
echo "✓ Platform initialized"
|
||||||
|
else
|
||||||
|
echo "⚠ .platform/initialized.md not found — skipping guard"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── Job 2: Unit Tests + Container Smoke ───────────────────────────────────
|
||||||
|
smoke-test:
|
||||||
|
name: Unit Tests + Container Smoke
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: platform-check
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Free disk space
|
||||||
|
run: |
|
||||||
|
docker system prune -f 2>/dev/null || true
|
||||||
|
df -h / 2>/dev/null || true
|
||||||
|
|
||||||
|
- name: Install Docker CLI
|
||||||
|
run: command -v docker &>/dev/null || (apt-get update -qq && apt-get install -y docker.io)
|
||||||
|
|
||||||
|
- name: Build container image
|
||||||
|
run: |
|
||||||
|
if [ -f Dockerfile ]; then
|
||||||
|
docker build -t ci-image:test .
|
||||||
|
else
|
||||||
|
echo "No Dockerfile found — skipping container smoke test"
|
||||||
|
echo "SKIP_SMOKE=true" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Start service and wait for health
|
||||||
|
if: env.SKIP_SMOKE != 'true'
|
||||||
|
run: |
|
||||||
|
CONTAINER_NAME="ci-${GITHUB_RUN_ID}"
|
||||||
|
|
||||||
|
# Nothing sets CONTAINER_PORT, so this used to be 8080 on every run, for every
|
||||||
|
# application. That is fine for Spring Boot and wrong for everything else -- an
|
||||||
|
# Express app on 3000 was probed on 8080, found nothing, and failed the smoke test
|
||||||
|
# after burning the full 180 second health timeout.
|
||||||
|
#
|
||||||
|
# score.yaml is the one file in this repository that knows the answer: the agent
|
||||||
|
# writes targetPort from the port it detected in the application's own source. So
|
||||||
|
# read it, exactly as the health-path probe below discovers its path instead of
|
||||||
|
# assuming one. Both defaults stay as a last resort for a repo without a score.yaml.
|
||||||
|
PORT="${CONTAINER_PORT:-}"
|
||||||
|
if [ -z "${PORT}" ] && [ -f score.yaml ]; then
|
||||||
|
PORT=$(grep -oE 'targetPort:[[:space:]]*[0-9]+' score.yaml | head -1 | tr -dc '0-9')
|
||||||
|
[ -n "${PORT}" ] && echo "Detected container port ${PORT} from score.yaml"
|
||||||
|
fi
|
||||||
|
PORT="${PORT:-8080}"
|
||||||
|
echo "CONTAINER_NAME=${CONTAINER_NAME}" >> $GITHUB_ENV
|
||||||
|
echo "CONTAINER_PORT=${PORT}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
docker run -d --name "${CONTAINER_NAME}" -e OTEL_SDK_DISABLED=true ci-image:test
|
||||||
|
|
||||||
|
for i in $(seq 1 10); do
|
||||||
|
CONTAINER_IP=$(docker inspect "${CONTAINER_NAME}" --format '{{.NetworkSettings.IPAddress}}' 2>/dev/null)
|
||||||
|
[ -n "${CONTAINER_IP}" ] && break
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "CONTAINER_IP=${CONTAINER_IP}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# This factory renovates arbitrary applications, so it cannot know the health path
|
||||||
|
# in advance. The previous hardcoded /health is wrong for the single most likely
|
||||||
|
# input: a Spring Boot app serves /actuator/health and 404s on /health, so the
|
||||||
|
# smoke test sat through its full 180s timeout against a container that was up and
|
||||||
|
# answering the whole time.
|
||||||
|
#
|
||||||
|
# Probe candidates instead, and settle on whichever answers. `/` is last and is a
|
||||||
|
# legitimate result -- it proves the container serves HTTP, which is all this test
|
||||||
|
# claims. HEALTH_ENDPOINT still wins if the caller sets it.
|
||||||
|
CANDIDATES="${HEALTH_ENDPOINT:-} /actuator/health /health /healthz /health/live /api/health /"
|
||||||
|
echo "Probing for a health endpoint on ${CONTAINER_IP}:${PORT} (up to 180s)..."
|
||||||
|
DEADLINE=$(($(date +%s) + 180))
|
||||||
|
HEALTH_PATH=""
|
||||||
|
while [ -z "${HEALTH_PATH}" ]; do
|
||||||
|
for c in ${CANDIDATES}; do
|
||||||
|
if curl -sf -o /dev/null "http://${CONTAINER_IP}:${PORT}${c}" 2>/dev/null; then
|
||||||
|
HEALTH_PATH="$c"; break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[ -n "${HEALTH_PATH}" ] && break
|
||||||
|
if [ $(date +%s) -ge $DEADLINE ]; then
|
||||||
|
echo "Timeout: no candidate path answered (${CANDIDATES})"
|
||||||
|
docker logs "${CONTAINER_NAME}" 2>&1 | tail -30
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! docker ps --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | grep -q Up; then
|
||||||
|
echo "Container exited:"
|
||||||
|
docker logs "${CONTAINER_NAME}" 2>&1 | tail -30
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo " still waiting..."; sleep 3
|
||||||
|
done
|
||||||
|
echo "HEALTH_PATH=${HEALTH_PATH}" >> $GITHUB_ENV
|
||||||
|
echo "✓ Service healthy at ${CONTAINER_IP}:${PORT}${HEALTH_PATH}"
|
||||||
|
|
||||||
|
- name: Validate health response
|
||||||
|
if: env.SKIP_SMOKE != 'true'
|
||||||
|
run: |
|
||||||
|
curl -sf "http://${CONTAINER_IP}:${CONTAINER_PORT}${HEALTH_PATH}" > /tmp/health.json
|
||||||
|
echo "Health response:"
|
||||||
|
cat /tmp/health.json
|
||||||
|
echo ""
|
||||||
|
echo "✓ Container smoke test: PASSED"
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: docker rm -f "ci-${GITHUB_RUN_ID}" 2>/dev/null || true
|
||||||
|
|
||||||
|
- name: Post commit status
|
||||||
|
if: always()
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
JOB_STATUS: ${{ job.status }}
|
||||||
|
run: |
|
||||||
|
STATE=$([[ "$JOB_STATUS" == "success" ]] && echo "success" || echo "failure")
|
||||||
|
DESC=$([[ "$STATE" == "success" ]] && echo "All checks passed" || echo "Some checks failed")
|
||||||
|
curl -sf -X POST \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \
|
||||||
|
-d "{\"state\":\"${STATE}\",\"context\":\"Integration Test / Unit Tests + Container Smoke (workflow_dispatch)\",\"description\":\"${DESC}\"}" \
|
||||||
|
|| true
|
||||||
445
.gitea/workflows/sonar.yaml
Normal file
445
.gitea/workflows/sonar.yaml
Normal file
@@ -0,0 +1,445 @@
|
|||||||
|
|
||||||
|
name: SonarQube Analysis
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ gitea.workflow }}-${{ gitea.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sonarqube:
|
||||||
|
name: Build, Test & Analyse
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
env:
|
||||||
|
SONAR_PROJECT_KEY: demo-principal-1
|
||||||
|
SONAR_ADMIN_TOKEN: ${{ secrets.SONAR_ADMIN_TOKEN }}
|
||||||
|
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
||||||
|
BACKSTAGE_CLEANUP_TOKEN: ${{ secrets.BACKSTAGE_CLEANUP_TOKEN }}
|
||||||
|
BACKSTAGE_URL: https://backstage.dev.crucible.kyndemo.live
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# This factory renovates arbitrary applications, so the analysis cannot assume one of
|
||||||
|
# them. Everything below used to be Maven unconditionally, and the very first Java step
|
||||||
|
# was `chmod +x mvnw` -- which on a Node repository fails with
|
||||||
|
# "cannot access 'mvnw': No such file or directory" and takes the whole run with it.
|
||||||
|
#
|
||||||
|
# Two paths, chosen from what is actually in the repository:
|
||||||
|
#
|
||||||
|
# maven pom.xml present -> mvnw verify + sonar-maven-plugin, with JaCoCo
|
||||||
|
# cli anything else -> sonar-scanner CLI, which analyses JS/TS, Python, Go
|
||||||
|
# and more without needing that language's build
|
||||||
|
#
|
||||||
|
# `cli` rather than `node` because the fallback is genuinely language-agnostic: a Python
|
||||||
|
# or Go repository gets analysed too, just without coverage. Only Node adds a test step,
|
||||||
|
# because it is the one runtime whose coverage format the scanner reads for free.
|
||||||
|
- name: Detect project type
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -f pom.xml ]; then
|
||||||
|
KIND=maven
|
||||||
|
else
|
||||||
|
KIND=cli
|
||||||
|
fi
|
||||||
|
echo "PROJECT_KIND=${KIND}" >> $GITHUB_ENV
|
||||||
|
echo "Detected project kind: ${KIND}"
|
||||||
|
if [ "${KIND}" = "cli" ] && [ -f package.json ]; then
|
||||||
|
echo "HAS_NPM=true" >> $GITHUB_ENV
|
||||||
|
echo "package.json present — will run tests for coverage."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Deliberately NOT gated on PROJECT_KIND. Maven needs it to build, and sonar-scanner is
|
||||||
|
# itself a Java program that ships no JRE -- so on the CLI path a Node image without
|
||||||
|
# java would fail inside the scanner's wrapper script with a bare "java: not found".
|
||||||
|
# Installing it once here is cheaper than diagnosing that.
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '17'
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Make Maven wrapper executable
|
||||||
|
if: env.PROJECT_KIND == 'maven'
|
||||||
|
run: chmod +x mvnw
|
||||||
|
|
||||||
|
- name: Cache Maven packages
|
||||||
|
if: env.PROJECT_KIND == 'maven'
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.m2/repository
|
||||||
|
key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
|
||||||
|
restore-keys: maven-${{ runner.os }}-
|
||||||
|
|
||||||
|
# The sonar-maven-plugin caches here. The CLI scanner keeps its own cache under
|
||||||
|
# ~/.sonar too, so this is useful on both paths -- but the key must not be keyed on
|
||||||
|
# pom.xml, which does not exist on the CLI path and would collapse every non-Maven
|
||||||
|
# repository onto one shared key.
|
||||||
|
- name: Cache SonarQube analysis data
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.sonar/cache
|
||||||
|
key: sonar-${{ runner.os }}-${{ hashFiles('**/pom.xml', '**/package-lock.json', '**/go.sum', '**/requirements.txt') }}
|
||||||
|
restore-keys: sonar-${{ runner.os }}-
|
||||||
|
|
||||||
|
- name: Validate required secrets
|
||||||
|
run: |
|
||||||
|
[[ -n "$SONAR_ADMIN_TOKEN" ]] || { echo "::error::SONAR_ADMIN_TOKEN is not set"; exit 1; }
|
||||||
|
[[ -n "$SONAR_HOST_URL" ]] || { echo "::error::SONAR_HOST_URL is not set"; exit 1; }
|
||||||
|
[[ -n "$SONAR_PROJECT_KEY" ]] || { echo "::error::SONAR_PROJECT_KEY is not set"; exit 1; }
|
||||||
|
|
||||||
|
SONAR_HOST_URL="${SONAR_HOST_URL%/}"
|
||||||
|
|
||||||
|
AUTH_RESPONSE=$(curl -s -o /tmp/sonar-auth-response.json -w "%{http_code}" \
|
||||||
|
-u "${SONAR_ADMIN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/authentication/validate")
|
||||||
|
|
||||||
|
if [[ "$AUTH_RESPONSE" != "200" ]]; then
|
||||||
|
echo "::error::SonarQube is unreachable or returned HTTP ${AUTH_RESPONSE} — check SONAR_HOST_URL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TOKEN_VALID=$(jq -r '.valid' /tmp/sonar-auth-response.json 2>/dev/null || echo "false")
|
||||||
|
if [[ "$TOKEN_VALID" != "true" ]]; then
|
||||||
|
echo "::error::SONAR_ADMIN_TOKEN is invalid or has been revoked (SonarQube returned valid=false)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ SONAR_ADMIN_TOKEN verified against ${SONAR_HOST_URL}"
|
||||||
|
|
||||||
|
- name: Bootstrap SonarQube project and generate scan token
|
||||||
|
id: sonar-bootstrap
|
||||||
|
run: |
|
||||||
|
PROJECT_COUNT=$(curl -sf \
|
||||||
|
-u "${SONAR_ADMIN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/projects/search?projects=${SONAR_PROJECT_KEY}" \
|
||||||
|
| jq '.paging.total')
|
||||||
|
|
||||||
|
if [[ "$PROJECT_COUNT" == "0" ]]; then
|
||||||
|
echo "Project '${SONAR_PROJECT_KEY}' not found — creating it..."
|
||||||
|
curl -sf -X POST \
|
||||||
|
-u "${SONAR_ADMIN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/projects/create" \
|
||||||
|
--data-urlencode "name=${SONAR_PROJECT_KEY}" \
|
||||||
|
--data-urlencode "project=${SONAR_PROJECT_KEY}" \
|
||||||
|
--data-urlencode "mainBranch=main" \
|
||||||
|
--data-urlencode "visibility=private"
|
||||||
|
echo "✅ Project created."
|
||||||
|
else
|
||||||
|
echo "✅ Project '${SONAR_PROJECT_KEY}' already exists — skipping creation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The token name MUST be unique per run. It used to be `gitea-scan-<projectKey>`,
|
||||||
|
# shared by every job analysing this project, and each job both revokes that name
|
||||||
|
# before generating and revokes it again on cleanup. Concurrent jobs therefore
|
||||||
|
# destroyed each other's credentials and every analysis failed with
|
||||||
|
# `Not authorized. Please check the user token in 'sonar.token'` -- an error that
|
||||||
|
# reads like a permissions problem and is not one. Observed on reno-rehearsal-6,
|
||||||
|
# where three overlapping jobs failed in a chain:
|
||||||
|
#
|
||||||
|
# 18:37:39 job A generates the shared name
|
||||||
|
# 18:37:40 job B revokes it, generates its own
|
||||||
|
# 18:38:16 job C revokes it, generates its own
|
||||||
|
# 18:38:53 job A analysis -> Not authorized (killed at 18:37:40)
|
||||||
|
# 18:38:53 job A cleanup revokes the name -> kills job C's live token
|
||||||
|
# 18:39:26 job C analysis -> Not authorized (killed at 18:38:53)
|
||||||
|
#
|
||||||
|
# The `concurrency:` block above does not prevent this: Gitea Actions does not
|
||||||
|
# honour it, so the overlap is real no matter what the workflow declares. Scoping
|
||||||
|
# the name to the run id removes the shared resource instead of relying on
|
||||||
|
# serialisation, and the cleanup step revokes that same per-run name so tokens
|
||||||
|
# still do not accumulate.
|
||||||
|
TOKEN_NAME="gitea-scan-${SONAR_PROJECT_KEY}-${GITHUB_RUN_ID}"
|
||||||
|
echo "TOKEN_NAME=${TOKEN_NAME}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
curl -sf -X POST \
|
||||||
|
-u "${SONAR_ADMIN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/user_tokens/revoke" \
|
||||||
|
--data-urlencode "name=${TOKEN_NAME}" \
|
||||||
|
> /dev/null 2>&1 || true
|
||||||
|
|
||||||
|
SCAN_TOKEN=$(curl -sf -X POST \
|
||||||
|
-u "${SONAR_ADMIN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/user_tokens/generate" \
|
||||||
|
--data-urlencode "name=${TOKEN_NAME}" \
|
||||||
|
--data-urlencode "type=PROJECT_ANALYSIS_TOKEN" \
|
||||||
|
--data-urlencode "projectKey=${SONAR_PROJECT_KEY}" \
|
||||||
|
| jq -r '.token')
|
||||||
|
|
||||||
|
# `jq -r` prints the string "null" for a missing key, which is non-empty and would
|
||||||
|
# sail past a bare -n test, then fail much later as an authorisation error.
|
||||||
|
if [[ -z "$SCAN_TOKEN" || "$SCAN_TOKEN" == "null" ]]; then
|
||||||
|
echo "::error::Failed to generate scan token '${TOKEN_NAME}'"; exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ Scan token generated for project '${SONAR_PROJECT_KEY}'"
|
||||||
|
echo "::add-mask::${SCAN_TOKEN}"
|
||||||
|
echo "SCAN_TOKEN=${SCAN_TOKEN}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
# Spring projects carry io.spring.nohttp, a Checkstyle rule that fails the build on any
|
||||||
|
# `http://` URL anywhere under ${basedir}. The platform artifacts this factory adds
|
||||||
|
# contain one legitimately -- the in-cluster OTLP collector, which is plaintext by
|
||||||
|
# design and has no https:// form -- so the app's own quality gate rejects the
|
||||||
|
# modernisation:
|
||||||
|
#
|
||||||
|
# [ERROR] score.yaml:[7,37] (extension) NoHttp: http:// URLs are not allowed
|
||||||
|
# [ERROR] overlays/otel/kustomization.yaml:[13,81] ...
|
||||||
|
# [ERROR] overlays/otel/patches/otel-patch.yaml:[17,19] ...
|
||||||
|
#
|
||||||
|
# The two -D properties on the build below cannot fix it: the SuppressionFilter in
|
||||||
|
# nohttp-checkstyle.xml reads a FIXED path, ${config_loc}/nohttp-checkstyle-suppressions.xml,
|
||||||
|
# so the only lever is the content of that file. Hence editing it rather than passing
|
||||||
|
# a flag.
|
||||||
|
#
|
||||||
|
# Scoped deliberately: `checks="NoHttp"` only, and only the paths this platform owns.
|
||||||
|
# Every other Checkstyle rule still applies to them, and NoHttp still applies to all
|
||||||
|
# application source -- which is the rule's actual purpose.
|
||||||
|
- name: Allowlist platform artifacts for nohttp
|
||||||
|
if: env.PROJECT_KIND == 'maven'
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
SUPPRESSIONS=src/checkstyle/nohttp-checkstyle-suppressions.xml
|
||||||
|
if [ ! -f "$SUPPRESSIONS" ]; then
|
||||||
|
echo "No nohttp suppressions file — project does not use nohttp, nothing to do."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if grep -q 'crucible-platform-artifacts' "$SUPPRESSIONS"; then
|
||||||
|
echo "Platform artifacts already allowlisted."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
grep -q '</suppressions>' "$SUPPRESSIONS" || {
|
||||||
|
echo "::error::$SUPPRESSIONS has no closing </suppressions> tag"; exit 1; }
|
||||||
|
|
||||||
|
# awk, not python3 or sed -i: this job runs in whatever image the app's build needs,
|
||||||
|
# so only POSIX tooling is safe to assume.
|
||||||
|
awk '
|
||||||
|
/<\/suppressions>/ && !inserted {
|
||||||
|
print "\t<!-- crucible-platform-artifacts: in-cluster OTLP endpoints are http:// by design -->";
|
||||||
|
print "\t<suppress files=\"score\\.yaml\" checks=\"NoHttp\"/>";
|
||||||
|
print "\t<suppress files=\"catalog-info\\.yaml\" checks=\"NoHttp\"/>";
|
||||||
|
print "\t<suppress files=\"overlays[\\\\/].*\" checks=\"NoHttp\"/>";
|
||||||
|
print "\t<suppress files=\"\\.platform[\\\\/].*\" checks=\"NoHttp\"/>";
|
||||||
|
print "\t<suppress files=\"\\.gitea[\\\\/].*\" checks=\"NoHttp\"/>";
|
||||||
|
print "\t<suppress files=\"k6[\\\\/].*\" checks=\"NoHttp\"/>";
|
||||||
|
inserted = 1
|
||||||
|
}
|
||||||
|
{ print }
|
||||||
|
' "$SUPPRESSIONS" > "$SUPPRESSIONS.new" && mv "$SUPPRESSIONS.new" "$SUPPRESSIONS"
|
||||||
|
|
||||||
|
echo "Allowlisted platform artifacts for NoHttp:"
|
||||||
|
cat "$SUPPRESSIONS"
|
||||||
|
|
||||||
|
- name: Build and test
|
||||||
|
if: env.PROJECT_KIND == 'maven'
|
||||||
|
run: |
|
||||||
|
./mvnw -B verify \
|
||||||
|
-Dtest='!PostgresIntegrationTests,!MySqlIntegrationTests' \
|
||||||
|
-Dnohttp.checkstyle.suppressions.file=src/checkstyle/nohttp-checkstyle-suppressions.xml \
|
||||||
|
-Dcheckstyle.suppressionsFile=src/checkstyle/nohttp-checkstyle-suppressions.xml
|
||||||
|
|
||||||
|
- name: SonarQube analysis
|
||||||
|
if: env.PROJECT_KIND == 'maven'
|
||||||
|
run: |
|
||||||
|
./mvnw -B org.sonarsource.scanner.maven:sonar-maven-plugin:4.0.0.4121:sonar \
|
||||||
|
-Dsonar.projectKey="${SONAR_PROJECT_KEY}" \
|
||||||
|
-Dsonar.host.url="${SONAR_HOST_URL}" \
|
||||||
|
-Dsonar.token="${SCAN_TOKEN}" \
|
||||||
|
-Dsonar.java.source=17 \
|
||||||
|
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
|
||||||
|
|
||||||
|
# ── Non-Maven path ────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
# Everything below runs only when there is no pom.xml, and feeds the SAME quality gate:
|
||||||
|
# the scan token, the gate poll, the Backstage notification and the token revoke are all
|
||||||
|
# language-agnostic and are not duplicated.
|
||||||
|
|
||||||
|
- name: Set up Node
|
||||||
|
if: env.PROJECT_KIND == 'cli' && env.HAS_NPM == 'true'
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
# Tests must not fail the job. A quality gate reports on what it measured; a repository
|
||||||
|
# with no test script, or one whose suite needs a database this job does not have, still
|
||||||
|
# deserves to be analysed. Coverage simply goes unreported, and the gate says so.
|
||||||
|
- name: Install and test
|
||||||
|
if: env.PROJECT_KIND == 'cli' && env.HAS_NPM == 'true'
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
# Prisma validates DATABASE_URL when the client is constructed, and construction
|
||||||
|
# happens at import time -- including in suites that mock every query and never
|
||||||
|
# open a connection. A placeholder is enough to let those run; nothing here
|
||||||
|
# connects to it. Without it the RealWorld service tests fail on
|
||||||
|
# `Environment variable not found: DATABASE_URL` (7 of 27), which is not a finding
|
||||||
|
# about the code, and coverage goes unreported for a suite that would have passed.
|
||||||
|
DATABASE_URL: postgresql://test:test@localhost:5432/test
|
||||||
|
run: |
|
||||||
|
set -uo pipefail
|
||||||
|
if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
||||||
|
npm test --if-present -- --coverage 2>/dev/null || npm test --if-present || true
|
||||||
|
if [ -f coverage/lcov.info ]; then
|
||||||
|
echo "SONAR_LCOV=coverage/lcov.info" >> $GITHUB_ENV
|
||||||
|
echo "Found coverage/lcov.info — it will be reported."
|
||||||
|
else
|
||||||
|
echo "::notice::No coverage/lcov.info produced; analysing without coverage."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: SonarQube analysis (scanner CLI)
|
||||||
|
if: env.PROJECT_KIND == 'cli'
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# Pinned. `latest` would move the analyser under a quality gate that is supposed to
|
||||||
|
# mean the same thing from one run to the next.
|
||||||
|
SCANNER_VERSION=6.2.1.4610
|
||||||
|
SCANNER_DIR="sonar-scanner-${SCANNER_VERSION}-linux-x64"
|
||||||
|
|
||||||
|
# This job runs in whatever image the application's build needs, so unzip is not a
|
||||||
|
# given -- the same reason the nohttp step above uses awk rather than python3.
|
||||||
|
command -v unzip >/dev/null 2>&1 || {
|
||||||
|
(apt-get update -qq && apt-get install -y -qq unzip) >/dev/null 2>&1 \
|
||||||
|
|| { echo "::error::unzip is unavailable and could not be installed"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
curl -sSLo /tmp/sonar-scanner.zip \
|
||||||
|
"https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SCANNER_VERSION}-linux-x64.zip"
|
||||||
|
unzip -q /tmp/sonar-scanner.zip -d /opt
|
||||||
|
export PATH="/opt/${SCANNER_DIR}/bin:${PATH}"
|
||||||
|
|
||||||
|
# The scanner is a Java program and ships no JRE. Most build images have one; if
|
||||||
|
# this repository's does not, say so plainly rather than surface a bare
|
||||||
|
# "java: not found" from inside the wrapper script.
|
||||||
|
command -v java >/dev/null 2>&1 || {
|
||||||
|
echo "::error::sonar-scanner needs a JRE and none is on PATH in this image."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Excluded because they are this platform's artifacts, not the application's code,
|
||||||
|
# and counting them would move the gate for reasons the developer cannot act on.
|
||||||
|
# Mirrors the nohttp allowlist on the Maven path.
|
||||||
|
ARGS=(
|
||||||
|
-Dsonar.projectKey="${SONAR_PROJECT_KEY}"
|
||||||
|
-Dsonar.host.url="${SONAR_HOST_URL}"
|
||||||
|
-Dsonar.token="${SCAN_TOKEN}"
|
||||||
|
-Dsonar.sources=.
|
||||||
|
-Dsonar.exclusions="**/node_modules/**,**/coverage/**,**/dist/**,**/build/**,k6/**,overlays/**,.platform/**,.gitea/**"
|
||||||
|
)
|
||||||
|
if [ -n "${SONAR_LCOV:-}" ]; then
|
||||||
|
ARGS+=(-Dsonar.javascript.lcov.reportPaths="${SONAR_LCOV}")
|
||||||
|
fi
|
||||||
|
sonar-scanner "${ARGS[@]}"
|
||||||
|
|
||||||
|
- name: Quality Gate check
|
||||||
|
id: quality-gate
|
||||||
|
run: |
|
||||||
|
echo "Waiting for SonarQube to process the analysis..."
|
||||||
|
for i in $(seq 1 24); do
|
||||||
|
RESPONSE=$(curl -sf -u "${SCAN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/qualitygates/project_status?projectKey=${SONAR_PROJECT_KEY}" || true)
|
||||||
|
STATUS=$(echo "$RESPONSE" | jq -r '.projectStatus.status' 2>/dev/null || echo "NONE")
|
||||||
|
if [[ "$STATUS" =~ ^(OK|ERROR|WARN)$ ]]; then break; fi
|
||||||
|
echo " Status: ${STATUS:-pending} — retrying in 5s..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "══════════════════════════════════════════"
|
||||||
|
echo " Quality Gate: $STATUS"
|
||||||
|
echo "══════════════════════════════════════════"
|
||||||
|
|
||||||
|
echo "$RESPONSE" | jq -r '
|
||||||
|
.projectStatus.conditions[] |
|
||||||
|
if .status == "ERROR" then " ❌ \(.metricKey): \(.actualValue) (threshold: \(.errorThreshold), comparator: \(.comparator))"
|
||||||
|
elif .status == "WARN" then " ⚠️ \(.metricKey): \(.actualValue) (threshold: \(.errorThreshold), comparator: \(.comparator))"
|
||||||
|
else " ✅ \(.metricKey): \(.actualValue)"
|
||||||
|
end'
|
||||||
|
|
||||||
|
echo "══════════════════════════════════════════"
|
||||||
|
|
||||||
|
FAILED=$(echo "$RESPONSE" | jq '[.projectStatus.conditions[] | select(.status == "ERROR")] | length')
|
||||||
|
if [[ "$FAILED" -gt 0 ]]; then
|
||||||
|
echo "::error::Quality Gate FAILED — $FAILED metric(s) did not meet threshold"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Notify Backstage on quality gate failure
|
||||||
|
if: always() && steps.quality-gate.outcome == 'failure'
|
||||||
|
run: |
|
||||||
|
echo "--- Backstage notification debug ---"
|
||||||
|
echo "BACKSTAGE_URL: ${BACKSTAGE_URL:-<not set>}"
|
||||||
|
echo "BACKSTAGE_CLEANUP_TOKEN set: $([[ -n "$BACKSTAGE_CLEANUP_TOKEN" ]] && echo yes || echo no)"
|
||||||
|
echo "SONAR_PROJECT_KEY: ${SONAR_PROJECT_KEY:-<not set>}"
|
||||||
|
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF:-<not set>}"
|
||||||
|
|
||||||
|
if [[ -z "$BACKSTAGE_URL" ]]; then
|
||||||
|
echo "::error::BACKSTAGE_URL is not set — cannot send notification"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$BACKSTAGE_CLEANUP_TOKEN" ]]; then
|
||||||
|
echo "::error::BACKSTAGE_CLEANUP_TOKEN is not set — cannot send notification"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Built with jq rather than a quoted heredoc-by-hand. The previous version
|
||||||
|
# interpolated shell variables into a \"-escaped string and got one line wrong --
|
||||||
|
# `"description": "Quality gate failed for ...` was unescaped, so bash closed the
|
||||||
|
# string early and tried to run `gate` as a command. Nobody saw it because this
|
||||||
|
# step only runs when the quality gate fails. jq also escapes the branch name and
|
||||||
|
# project key, which are attacker-adjacent (a branch may contain a quote).
|
||||||
|
PAYLOAD=$(jq -nc \
|
||||||
|
--arg project "${SONAR_PROJECT_KEY}" \
|
||||||
|
--arg branch "${GITHUB_HEAD_REF}" \
|
||||||
|
--arg link "${SONAR_HOST_URL}/dashboard?id=${SONAR_PROJECT_KEY}" \
|
||||||
|
'{
|
||||||
|
recipients: { type: "entity", entityRef: "group:default/platform-engineering" },
|
||||||
|
payload: {
|
||||||
|
title: "SonarQube Quality Gate Failed",
|
||||||
|
description: "Quality gate failed for \($project) on branch \($branch).",
|
||||||
|
link: $link,
|
||||||
|
severity: "high",
|
||||||
|
topic: "sonarqube-quality-gate"
|
||||||
|
}
|
||||||
|
}')
|
||||||
|
|
||||||
|
echo "Sending notification to: ${BACKSTAGE_URL}/api/notifications"
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl -s -o /tmp/bs-notify-response.json -w "%{http_code}" \
|
||||||
|
-X POST "${BACKSTAGE_URL}/api/notifications" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer ${BACKSTAGE_CLEANUP_TOKEN}" \
|
||||||
|
-d "${PAYLOAD}")
|
||||||
|
|
||||||
|
echo "HTTP response code: ${HTTP_CODE}"
|
||||||
|
echo "Response body:"
|
||||||
|
cat /tmp/bs-notify-response.json 2>/dev/null || echo "<empty response>"
|
||||||
|
|
||||||
|
if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then
|
||||||
|
echo "✅ Backstage notification sent"
|
||||||
|
else
|
||||||
|
echo "⚠️ Backstage notification failed (HTTP ${HTTP_CODE})"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Revoke scan token
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
# Revoke THIS run's token, never the bare `gitea-scan-<projectKey>` name -- that
|
||||||
|
# name belongs to no single job, and revoking it here is what killed a concurrent
|
||||||
|
# job's live credential. TOKEN_NAME is empty if bootstrap never ran, in which case
|
||||||
|
# there is nothing to revoke and a blank name would be a no-op request at best.
|
||||||
|
if [[ -z "${TOKEN_NAME:-}" ]]; then
|
||||||
|
echo "No scan token was generated — nothing to revoke."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
curl -sf -X POST \
|
||||||
|
-u "${SONAR_ADMIN_TOKEN}:" \
|
||||||
|
"${SONAR_HOST_URL}/api/user_tokens/revoke" \
|
||||||
|
--data-urlencode "name=${TOKEN_NAME}" \
|
||||||
|
&& echo "✅ Scan token revoked (${TOKEN_NAME})" \
|
||||||
|
|| echo "⚠️ Token revocation failed"
|
||||||
2
.github/dco.yml
vendored
Normal file
2
.github/dco.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
require:
|
||||||
|
members: false
|
||||||
31
.github/workflows/deploy-and-test-cluster.yml
vendored
Normal file
31
.github/workflows/deploy-and-test-cluster.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: Deploy and Test Cluster
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'k8s/**'
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'k8s/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy-and-test-cluster:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out the repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Create k8s Kind Cluster
|
||||||
|
uses: helm/kind-action@v1
|
||||||
|
|
||||||
|
- name: Deploy application
|
||||||
|
run: |
|
||||||
|
kubectl apply -f k8s/
|
||||||
|
|
||||||
|
- name: Wait for Pods to be ready
|
||||||
|
run: |
|
||||||
|
kubectl wait --for=condition=ready pod -l app=demo-db --timeout=180s
|
||||||
|
kubectl wait --for=condition=ready pod -l app=petclinic --timeout=180s
|
||||||
|
|
||||||
31
.github/workflows/gradle-build.yml
vendored
Normal file
31
.github/workflows/gradle-build.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# This workflow will build a Java project with Gradle, and cache/restore any dependencies to improve the workflow execution time
|
||||||
|
# For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-gradle
|
||||||
|
|
||||||
|
name: Java CI with Gradle
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
java: [ '17' ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up JDK ${{matrix.java}}
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: ${{matrix.java}}
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
- name: Setup Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: ./gradlew build
|
||||||
29
.github/workflows/maven-build.yml
vendored
Normal file
29
.github/workflows/maven-build.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
|
# For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-maven
|
||||||
|
|
||||||
|
name: Java CI with Maven
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
java: [ '17' ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up JDK ${{matrix.java}}
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: ${{matrix.java}}
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
- name: Build with Maven Wrapper
|
||||||
|
run: ./mvnw -B verify
|
||||||
48
.gitignore
vendored
Normal file
48
.gitignore
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
HELP.md
|
||||||
|
pom.xml.bak
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.attach_pid*
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### CSS ###
|
||||||
|
_site/
|
||||||
|
*.css
|
||||||
|
!petclinic.css
|
||||||
9
.gitpod.yml
Normal file
9
.gitpod.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
image:
|
||||||
|
file: ./.devcontainer/Dockerfile
|
||||||
|
tasks:
|
||||||
|
- before: sudo usermod -a -G sdkman gitpod && sudo usermod -a -G nvm gitpod && sudo chown -R gitpod /usr/local/sdkman /usr/local/share/nvm
|
||||||
|
- init: ./mvnw install
|
||||||
|
vscode:
|
||||||
|
extensions:
|
||||||
|
- vscjava.vscode-java-pack
|
||||||
|
- redhat.vscode-xml
|
||||||
3
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
3
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
wrapperVersion=3.3.4
|
||||||
|
distributionType=only-script
|
||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip
|
||||||
9
.platform/initialized.md
Normal file
9
.platform/initialized.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Platform Initialized
|
||||||
|
|
||||||
|
This file marks the repository as platform-initialized for the Humanitec v2 deploy workflow.
|
||||||
|
|
||||||
|
Created by the Backstage Application Renovation Factory template.
|
||||||
|
|
||||||
|
**Profile**: `stateless`
|
||||||
|
**Component**: `demo-principal-1`
|
||||||
|
**Project**: `cjot-platform`
|
||||||
202
LICENSE.txt
Normal file
202
LICENSE.txt
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
https://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
178
README.md
Normal file
178
README.md
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
# Spring PetClinic Sample Application [](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml)[](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml)
|
||||||
|
|
||||||
|
[](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918)
|
||||||
|
|
||||||
|
## Understanding the Spring Petclinic application with a few diagrams
|
||||||
|
|
||||||
|
See the presentation here:
|
||||||
|
[Spring Petclinic Sample Application (legacy slides)](https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application?slide=20)
|
||||||
|
|
||||||
|
> **Note:** These slides refer to a legacy, pre–Spring Boot version of Petclinic and may not reflect the current Spring Boot–based implementation.
|
||||||
|
> For up-to-date information, please refer to this repository and its documentation.
|
||||||
|
|
||||||
|
|
||||||
|
## Run Petclinic locally
|
||||||
|
|
||||||
|
Spring Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/).
|
||||||
|
Java 17 or later is required for the build, and the application can run with Java 17 or newer.
|
||||||
|
|
||||||
|
You first need to clone the project locally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||||
|
cd spring-petclinic
|
||||||
|
```
|
||||||
|
If you are using Maven, you can start the application on the command-line as follows:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./mvnw spring-boot:run
|
||||||
|
```
|
||||||
|
With Gradle, the command is as follows:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./gradlew bootRun
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then access the Petclinic at <http://localhost:8080/>.
|
||||||
|
|
||||||
|
<img width="1042" alt="petclinic-screenshot" src="https://cloud.githubusercontent.com/assets/838318/19727082/2aee6d6c-9b8e-11e6-81fe-e889a5ddfded.png">
|
||||||
|
|
||||||
|
You can, of course, run Petclinic in your favorite IDE.
|
||||||
|
See below for more details.
|
||||||
|
|
||||||
|
## Building a Container
|
||||||
|
|
||||||
|
There is no `Dockerfile` in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin:
|
||||||
|
|
||||||
|
## Running the Container Image
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./mvnw spring-boot:build-image
|
||||||
|
docker images | grep petclinic
|
||||||
|
docker run -p 8080:8080 docker.io/library/spring-petclinic:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## In case you find a bug/suggested improvement for Spring Petclinic
|
||||||
|
|
||||||
|
Our issue tracker is available [here](https://github.com/spring-projects/spring-petclinic/issues).
|
||||||
|
|
||||||
|
## Database configuration
|
||||||
|
|
||||||
|
In its default configuration, Petclinic uses an in-memory database (H2) which
|
||||||
|
gets populated at startup with data. The h2 console is exposed at `http://localhost:8080/h2-console`,
|
||||||
|
and it is possible to inspect the content of the database using the `jdbc:h2:mem:<uuid>` URL. The UUID is printed at startup to the console.
|
||||||
|
|
||||||
|
A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Note that whenever the database type changes, the app needs to run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL. See the [Spring Boot documentation](https://docs.spring.io/spring-boot/how-to/properties-and-configuration.html#howto.properties-and-configuration.set-active-spring-profiles) for more detail on how to set the active profile.
|
||||||
|
|
||||||
|
You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:9.7
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:18.4
|
||||||
|
```
|
||||||
|
|
||||||
|
Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt)
|
||||||
|
and [PostgreSQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/postgres/petclinic_db_setup_postgres.txt).
|
||||||
|
|
||||||
|
Instead of vanilla `docker` you can also use the provided `docker-compose.yml` file to start the database containers. Each one has a service named after the Spring profile:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up mysql
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up postgres
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test Applications
|
||||||
|
|
||||||
|
At development time we recommend you use the test applications set up as `main()` methods in `PetClinicIntegrationTests` (using the default H2 database and also adding Spring Boot Devtools), `MySqlTestApplication` and `PostgresIntegrationTests`. These are set up so that you can run the apps in your IDE to get fast feedback and also run the same classes as integration tests against the respective database. The MySql integration tests use Testcontainers to start the database in a Docker container, and the Postgres tests use Docker Compose to do the same thing.
|
||||||
|
|
||||||
|
## Compiling the CSS
|
||||||
|
|
||||||
|
There is a `petclinic.css` in `src/main/resources/static/resources/css`. It was generated from the `petclinic.scss` source, combined with the [Bootstrap](https://getbootstrap.com/) library. If you make changes to the `scss`, or upgrade Bootstrap, you will need to re-compile the CSS resources using the Maven profile "css", i.e. `./mvnw package -P css`. There is no build profile for Gradle to compile the CSS.
|
||||||
|
|
||||||
|
## Working with Petclinic in your IDE
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
The following items should be installed in your system:
|
||||||
|
|
||||||
|
- Java 17 or newer (full JDK, not a JRE)
|
||||||
|
- [Git command line tool](https://help.github.com/articles/set-up-git)
|
||||||
|
- Your preferred IDE
|
||||||
|
- Eclipse with the m2e plugin. Note: when m2e is available, there is a m2 icon in `Help -> About` dialog. If m2e is
|
||||||
|
not there, follow the installation process [here](https://www.eclipse.org/m2e/)
|
||||||
|
- [Spring Tools Suite](https://spring.io/tools) (STS)
|
||||||
|
- [IntelliJ IDEA](https://www.jetbrains.com/idea/)
|
||||||
|
- [VS Code](https://code.visualstudio.com)
|
||||||
|
|
||||||
|
### Steps
|
||||||
|
|
||||||
|
1. On the command line run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Inside Eclipse or STS:
|
||||||
|
|
||||||
|
Open the project via `File -> Import -> Maven -> Existing Maven project`, then select the root directory of the cloned repo.
|
||||||
|
|
||||||
|
Then either build on the command line `./mvnw generate-resources` or use the Eclipse launcher (right-click on project and `Run As -> Maven install`) to generate the CSS. Run the application's main method by right-clicking on it and choosing `Run As -> Java Application`.
|
||||||
|
|
||||||
|
1. Inside IntelliJ IDEA:
|
||||||
|
|
||||||
|
In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button.
|
||||||
|
|
||||||
|
- CSS files are generated from the Maven build. You can build them on the command line `./mvnw generate-resources` or right-click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
|
||||||
|
|
||||||
|
- A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right-clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
|
||||||
|
|
||||||
|
1. Navigate to the Petclinic
|
||||||
|
|
||||||
|
Visit [http://localhost:8080](http://localhost:8080) in your browser.
|
||||||
|
|
||||||
|
## Looking for something in particular?
|
||||||
|
|
||||||
|
|Spring Boot Configuration | Class or Java property files |
|
||||||
|
|--------------------------|---|
|
||||||
|
|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|
||||||
|
|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
|
||||||
|
|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
|
||||||
|
|
||||||
|
## Interesting Spring Petclinic branches and forks
|
||||||
|
|
||||||
|
The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic)
|
||||||
|
GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. There are
|
||||||
|
[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in the GitHub org
|
||||||
|
[spring-petclinic](https://github.com/spring-petclinic). If you are interested in using a different technology stack to implement the Pet Clinic, please join the community there.
|
||||||
|
|
||||||
|
## Interaction with other open-source projects
|
||||||
|
|
||||||
|
One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
|
||||||
|
Here is a list of them:
|
||||||
|
|
||||||
|
| Name | Issue |
|
||||||
|
|------|-------|
|
||||||
|
| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://github.com/spring-projects/spring-framework/issues/14889) and [SPR-10257](https://github.com/spring-projects/spring-framework/issues/14890) |
|
||||||
|
| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
|
||||||
|
| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://github.com/spring-projects/spring-data-jpa/issues/704) |
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, feature requests and submitting pull requests.
|
||||||
|
|
||||||
|
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin.
|
||||||
|
For additional details, please refer to the blog post [Hello DCO, Goodbye CLA: Simplifying Contributions to Spring](https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
93
build.gradle
Normal file
93
build.gradle
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'checkstyle'
|
||||||
|
id 'org.springframework.boot' version '4.1.0'
|
||||||
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
|
id 'org.graalvm.buildtools.native' version '1.1.2'
|
||||||
|
id 'org.cyclonedx.bom' version '3.2.4'
|
||||||
|
id 'io.spring.javaformat' version '0.0.47'
|
||||||
|
id "io.spring.nohttp" version "0.0.11"
|
||||||
|
}
|
||||||
|
|
||||||
|
gradle.startParameter.excludedTaskNames += [ "checkFormatAot", "checkFormatAotTest" ]
|
||||||
|
|
||||||
|
group = 'org.springframework.samples'
|
||||||
|
version = '4.0.0-SNAPSHOT'
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.checkstyleVersion = "12.3.1"
|
||||||
|
ext.springJavaformatCheckstyleVersion = "0.0.47"
|
||||||
|
ext.webjarsLocatorLiteVersion = "1.1.3"
|
||||||
|
ext.webjarsFontawesomeVersion = "4.7.0"
|
||||||
|
ext.webjarsBootstrapVersion = "5.3.8"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-cache'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
|
implementation 'javax.cache:cache-api'
|
||||||
|
implementation 'jakarta.xml.bind:jakarta.xml.bind-api'
|
||||||
|
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
|
runtimeOnly "org.webjars:webjars-locator-lite:${webjarsLocatorLiteVersion}"
|
||||||
|
runtimeOnly "org.webjars.npm:bootstrap:${webjarsBootstrapVersion}"
|
||||||
|
runtimeOnly "org.webjars.npm:font-awesome:${webjarsFontawesomeVersion}"
|
||||||
|
runtimeOnly 'com.github.ben-manes.caffeine:caffeine'
|
||||||
|
runtimeOnly 'com.h2database:h2'
|
||||||
|
runtimeOnly 'com.mysql:mysql-connector-j'
|
||||||
|
runtimeOnly 'org.postgresql:postgresql'
|
||||||
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-restclient-test'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-docker-compose'
|
||||||
|
testImplementation 'org.testcontainers:testcontainers-junit-jupiter'
|
||||||
|
testImplementation 'org.testcontainers:testcontainers-mysql'
|
||||||
|
checkstyle "io.spring.javaformat:spring-javaformat-checkstyle:${springJavaformatCheckstyleVersion}"
|
||||||
|
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('test') {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named("cyclonedxDirectBom").configure {
|
||||||
|
dependsOn("compileJava")
|
||||||
|
skipConfigs = [".*[Tt]est.*"]
|
||||||
|
}
|
||||||
|
|
||||||
|
checkstyle {
|
||||||
|
configDirectory = project.file('src/checkstyle')
|
||||||
|
configFile = file('src/checkstyle/nohttp-checkstyle.xml')
|
||||||
|
}
|
||||||
|
|
||||||
|
checkstyleNohttp {
|
||||||
|
configDirectory = project.file('src/checkstyle')
|
||||||
|
configFile = file('src/checkstyle/nohttp-checkstyle.xml')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named("formatMain").configure { dependsOn("checkstyleMain") }
|
||||||
|
tasks.named("formatMain").configure { dependsOn("checkstyleNohttp") }
|
||||||
|
|
||||||
|
tasks.named("formatTest").configure { dependsOn("checkstyleTest") }
|
||||||
|
tasks.named("formatTest").configure { dependsOn("checkstyleNohttp") }
|
||||||
|
|
||||||
|
checkstyleAot.enabled = false
|
||||||
|
checkstyleAotTest.enabled = false
|
||||||
|
|
||||||
|
checkFormatAot.enabled = false
|
||||||
|
checkFormatAotTest.enabled = false
|
||||||
|
|
||||||
|
formatAot.enabled = false
|
||||||
|
formatAotTest.enabled = false
|
||||||
65
catalog-info.yaml
Normal file
65
catalog-info.yaml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
apiVersion: backstage.io/v1alpha1
|
||||||
|
kind: Component
|
||||||
|
metadata:
|
||||||
|
name: demo-principal-1
|
||||||
|
description: 'demo-principal-1 — renovated onto the crucible platform orchestrator'
|
||||||
|
annotations:
|
||||||
|
gitea.kyndemo.live/project-slug: validate/demo-principal-1
|
||||||
|
gitea.kyndemo.live/repo-slug: validate/demo-principal-1
|
||||||
|
# The orchestrator names each environment's namespace ns-xxxxx at deploy time, so a
|
||||||
|
# namespace can never be known here -- pinning one only hides the workload. Omitted
|
||||||
|
# deliberately: the Kubernetes plugin then searches every namespace it is given.
|
||||||
|
#
|
||||||
|
# kubernetes-id matches the label the score-workload module propagates from the Score
|
||||||
|
# metadata.labels block. The previous selector, app.humanitec.io/name=..., was a
|
||||||
|
# Humanitec SaaS label that nothing on this platform has ever set.
|
||||||
|
backstage.io/kubernetes-id: demo-principal-1
|
||||||
|
backstage.io/techdocs-ref: dir:.
|
||||||
|
# Vestigial key names, live values. These drive the Orchestrator tab, which reads
|
||||||
|
# humanitec.dev/orgId and humanitec.dev/projectId; renaming the keys would break every
|
||||||
|
# entity already in the catalog, so the names stay and the values point at crucible.
|
||||||
|
humanitec.dev/orgId: crucible
|
||||||
|
# THE PROJECT IS THE APPLICATION. This was `apps-cluster`, a single project shared by
|
||||||
|
# every renovated app, which is why the Orchestrator tab on any one component listed the
|
||||||
|
# whole estate -- the tab shows a project's environments, and every app's environment
|
||||||
|
# lived in that one project. Now each app owns a project, so the tab shows this app's
|
||||||
|
# stages and nothing else. The deploy workflow creates the project, its runner rule and
|
||||||
|
# its environments on first deploy.
|
||||||
|
humanitec.dev/projectId: demo-principal-1
|
||||||
|
# The environments are now STAGES of this application -- dev, staging, prod -- rather
|
||||||
|
# than one environment named after the component.
|
||||||
|
humanitec.dev/appId: demo-principal-1
|
||||||
|
cjot.io/target-domain: apps
|
||||||
|
sonarqube.org/project-key: demo-principal-1
|
||||||
|
grafana/grafana-instance: "default"
|
||||||
|
grafana/alert-label-selector: "app=demo-principal-1"
|
||||||
|
grafana/dashboard-selector: "uid == 'otel-app-observability-v2'"
|
||||||
|
grafana.com/dashboard-url: "https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-app=demo-principal-1"
|
||||||
|
tags:
|
||||||
|
- platform-orchestrator
|
||||||
|
- renovation
|
||||||
|
links:
|
||||||
|
# console.humanitec.dev is the dead SaaS. This is the live crucible console, deep-linked
|
||||||
|
# to the per-application environment the deploy workflow creates.
|
||||||
|
- url: https://console.dev.orchestrator.crucible.kyndemo.live/orgs/crucible/projects/demo-principal-1/environments/dev
|
||||||
|
title: Orchestrator Console
|
||||||
|
icon: dashboard
|
||||||
|
- url: https://demo-principal-1.apps.dev.crucible.kyndemo.live
|
||||||
|
title: Live Application
|
||||||
|
icon: web
|
||||||
|
- url: https://gitea.kyndemo.live/validate/demo-principal-1
|
||||||
|
title: Source Repository
|
||||||
|
icon: github
|
||||||
|
- url: https://gitea.kyndemo.live/validate/demo-principal-1/actions
|
||||||
|
title: CI/CD Pipelines
|
||||||
|
icon: code
|
||||||
|
- url: https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-app=demo-principal-1
|
||||||
|
title: Grafana Dashboard
|
||||||
|
icon: dashboard
|
||||||
|
spec:
|
||||||
|
type: service
|
||||||
|
lifecycle: experimental
|
||||||
|
owner: platform-engineering
|
||||||
|
dependsOn:
|
||||||
|
- resource:default/cjot-aks
|
||||||
11
config/nohttp/allowlist.lines
Normal file
11
config/nohttp/allowlist.lines
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Platform-scaffolded internal cluster URLs (not reachable over HTTPS)
|
||||||
|
// These use Kubernetes service DNS which only supports plain HTTP inside the cluster
|
||||||
|
^http://.*\.svc\.cluster\.local.*$
|
||||||
|
|
||||||
|
// OpenTelemetry collector endpoints (gRPC/HTTP on internal cluster network)
|
||||||
|
^http://otel-collector.*$
|
||||||
|
^http://.*otel.*$
|
||||||
|
|
||||||
|
// k6 load test target URLs (internal service mesh)
|
||||||
|
^http://frontend\..*$
|
||||||
|
^http://localhost.*$
|
||||||
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:9.7
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=
|
||||||
|
- MYSQL_ALLOW_EMPTY_PASSWORD=true
|
||||||
|
- MYSQL_USER=petclinic
|
||||||
|
- MYSQL_PASSWORD=petclinic
|
||||||
|
- MYSQL_DATABASE=petclinic
|
||||||
|
volumes:
|
||||||
|
- "./conf.d:/etc/mysql/conf.d:ro"
|
||||||
|
postgres:
|
||||||
|
image: postgres:18.4
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
environment:
|
||||||
|
- POSTGRES_PASSWORD=petclinic
|
||||||
|
- POSTGRES_USER=petclinic
|
||||||
|
- POSTGRES_DB=petclinic
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
9
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
9
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
retries=0
|
||||||
|
retryBackOffMs=500
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
248
gradlew
vendored
Executable file
248
gradlew
vendored
Executable file
@@ -0,0 +1,248 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
82
gradlew.bat
vendored
Normal file
82
gradlew.bat
vendored
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||||
|
setlocal EnableExtensions
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
"%COMSPEC%" /c exit 1
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
"%COMSPEC%" /c exit 1
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||||
|
@rem which allows us to clear the local environment before executing the java command
|
||||||
|
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||||
|
|
||||||
|
:exitWithErrorLevel
|
||||||
|
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||||
|
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||||
73
k8s/db.yml
Normal file
73
k8s/db.yml
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: demo-db
|
||||||
|
type: servicebinding.io/postgresql
|
||||||
|
stringData:
|
||||||
|
type: "postgresql"
|
||||||
|
provider: "postgresql"
|
||||||
|
host: "demo-db"
|
||||||
|
port: "5432"
|
||||||
|
database: "petclinic"
|
||||||
|
username: "user"
|
||||||
|
password: "pass"
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: demo-db
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 5432
|
||||||
|
selector:
|
||||||
|
app: demo-db
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: demo-db
|
||||||
|
labels:
|
||||||
|
app: demo-db
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: demo-db
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: demo-db
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: postgres:18.4
|
||||||
|
name: postgresql
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: demo-db
|
||||||
|
key: username
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: demo-db
|
||||||
|
key: password
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: demo-db
|
||||||
|
key: database
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
name: postgresql
|
||||||
|
livenessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: postgresql
|
||||||
|
readinessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: postgresql
|
||||||
|
startupProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: postgresql
|
||||||
64
k8s/petclinic.yml
Normal file
64
k8s/petclinic.yml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: petclinic
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 8080
|
||||||
|
selector:
|
||||||
|
app: petclinic
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: petclinic
|
||||||
|
labels:
|
||||||
|
app: petclinic
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: petclinic
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: petclinic
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: workload
|
||||||
|
image: dsyer/petclinic
|
||||||
|
env:
|
||||||
|
- name: SPRING_PROFILES_ACTIVE
|
||||||
|
value: postgres
|
||||||
|
- name: SERVICE_BINDING_ROOT
|
||||||
|
value: /bindings
|
||||||
|
- name: SPRING_APPLICATION_JSON
|
||||||
|
value: |
|
||||||
|
{
|
||||||
|
"management.endpoint.health.probes.add-additional-paths": true
|
||||||
|
}
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 8080
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /livez
|
||||||
|
port: http
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /readyz
|
||||||
|
port: http
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /bindings/secret
|
||||||
|
name: binding
|
||||||
|
readOnly: true
|
||||||
|
volumes:
|
||||||
|
- name: binding
|
||||||
|
projected:
|
||||||
|
sources:
|
||||||
|
- secret:
|
||||||
|
name: demo-db
|
||||||
295
mvnw
vendored
Executable file
295
mvnw
vendored
Executable file
@@ -0,0 +1,295 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
# KIND, either express or implied. See the License for the
|
||||||
|
# specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Apache Maven Wrapper startup batch script, version 3.3.4
|
||||||
|
#
|
||||||
|
# Optional ENV vars
|
||||||
|
# -----------------
|
||||||
|
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||||
|
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||||
|
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||||
|
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
set -euf
|
||||||
|
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||||
|
|
||||||
|
# OS specific support.
|
||||||
|
native_path() { printf %s\\n "$1"; }
|
||||||
|
case "$(uname)" in
|
||||||
|
CYGWIN* | MINGW*)
|
||||||
|
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||||
|
native_path() { cygpath --path --windows "$1"; }
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# set JAVACMD and JAVACCMD
|
||||||
|
set_java_home() {
|
||||||
|
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||||
|
if [ -n "${JAVA_HOME-}" ]; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||||
|
|
||||||
|
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||||
|
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||||
|
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="$(
|
||||||
|
'set' +e
|
||||||
|
'unset' -f command 2>/dev/null
|
||||||
|
'command' -v java
|
||||||
|
)" || :
|
||||||
|
JAVACCMD="$(
|
||||||
|
'set' +e
|
||||||
|
'unset' -f command 2>/dev/null
|
||||||
|
'command' -v javac
|
||||||
|
)" || :
|
||||||
|
|
||||||
|
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||||
|
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# hash string like Java String::hashCode
|
||||||
|
hash_string() {
|
||||||
|
str="${1:-}" h=0
|
||||||
|
while [ -n "$str" ]; do
|
||||||
|
char="${str%"${str#?}"}"
|
||||||
|
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||||
|
str="${str#?}"
|
||||||
|
done
|
||||||
|
printf %x\\n $h
|
||||||
|
}
|
||||||
|
|
||||||
|
verbose() { :; }
|
||||||
|
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||||
|
|
||||||
|
die() {
|
||||||
|
printf %s\\n "$1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
trim() {
|
||||||
|
# MWRAPPER-139:
|
||||||
|
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||||
|
# Needed for removing poorly interpreted newline sequences when running in more
|
||||||
|
# exotic environments such as mingw bash on Windows.
|
||||||
|
printf "%s" "${1}" | tr -d '[:space:]'
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptDir="$(dirname "$0")"
|
||||||
|
scriptName="$(basename "$0")"
|
||||||
|
|
||||||
|
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||||
|
while IFS="=" read -r key value; do
|
||||||
|
case "${key-}" in
|
||||||
|
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||||
|
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||||
|
esac
|
||||||
|
done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||||
|
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||||
|
|
||||||
|
case "${distributionUrl##*/}" in
|
||||||
|
maven-mvnd-*bin.*)
|
||||||
|
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||||
|
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||||
|
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||||
|
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||||
|
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||||
|
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||||
|
*)
|
||||||
|
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||||
|
distributionPlatform=linux-amd64
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||||
|
;;
|
||||||
|
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||||
|
*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||||
|
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||||
|
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||||
|
distributionUrlName="${distributionUrl##*/}"
|
||||||
|
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||||
|
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||||
|
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||||
|
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||||
|
|
||||||
|
exec_maven() {
|
||||||
|
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||||
|
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -d "$MAVEN_HOME" ]; then
|
||||||
|
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||||
|
exec_maven "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "${distributionUrl-}" in
|
||||||
|
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||||
|
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# prepare tmp dir
|
||||||
|
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||||
|
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||||
|
trap clean HUP INT TERM EXIT
|
||||||
|
else
|
||||||
|
die "cannot create temp dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||||
|
|
||||||
|
# Download and Install Apache Maven
|
||||||
|
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||||
|
verbose "Downloading from: $distributionUrl"
|
||||||
|
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||||
|
|
||||||
|
# select .zip or .tar.gz
|
||||||
|
if ! command -v unzip >/dev/null; then
|
||||||
|
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||||
|
distributionUrlName="${distributionUrl##*/}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# verbose opt
|
||||||
|
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||||
|
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||||
|
|
||||||
|
# normalize http auth
|
||||||
|
case "${MVNW_PASSWORD:+has-password}" in
|
||||||
|
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||||
|
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||||
|
verbose "Found wget ... using wget"
|
||||||
|
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||||
|
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||||
|
verbose "Found curl ... using curl"
|
||||||
|
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||||
|
elif set_java_home; then
|
||||||
|
verbose "Falling back to use Java to download"
|
||||||
|
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||||
|
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||||
|
cat >"$javaSource" <<-END
|
||||||
|
public class Downloader extends java.net.Authenticator
|
||||||
|
{
|
||||||
|
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||||
|
{
|
||||||
|
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||||
|
}
|
||||||
|
public static void main( String[] args ) throws Exception
|
||||||
|
{
|
||||||
|
setDefault( new Downloader() );
|
||||||
|
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END
|
||||||
|
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||||
|
verbose " - Compiling Downloader.java ..."
|
||||||
|
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||||
|
verbose " - Running Downloader.java ..."
|
||||||
|
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||||
|
if [ -n "${distributionSha256Sum-}" ]; then
|
||||||
|
distributionSha256Result=false
|
||||||
|
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||||
|
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||||
|
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||||
|
exit 1
|
||||||
|
elif command -v sha256sum >/dev/null; then
|
||||||
|
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
|
||||||
|
distributionSha256Result=true
|
||||||
|
fi
|
||||||
|
elif command -v shasum >/dev/null; then
|
||||||
|
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||||
|
distributionSha256Result=true
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||||
|
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ $distributionSha256Result = false ]; then
|
||||||
|
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||||
|
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# unzip and move
|
||||||
|
if command -v unzip >/dev/null; then
|
||||||
|
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||||
|
else
|
||||||
|
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
||||||
|
actualDistributionDir=""
|
||||||
|
|
||||||
|
# First try the expected directory name (for regular distributions)
|
||||||
|
if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
|
||||||
|
if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
|
||||||
|
actualDistributionDir="$distributionUrlNameMain"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If not found, search for any directory with the Maven executable (for snapshots)
|
||||||
|
if [ -z "$actualDistributionDir" ]; then
|
||||||
|
# enable globbing to iterate over items
|
||||||
|
set +f
|
||||||
|
for dir in "$TMP_DOWNLOAD_DIR"/*; do
|
||||||
|
if [ -d "$dir" ]; then
|
||||||
|
if [ -f "$dir/bin/$MVN_CMD" ]; then
|
||||||
|
actualDistributionDir="$(basename "$dir")"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
set -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$actualDistributionDir" ]; then
|
||||||
|
verbose "Contents of $TMP_DOWNLOAD_DIR:"
|
||||||
|
verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
|
||||||
|
die "Could not find Maven distribution directory in extracted archive"
|
||||||
|
fi
|
||||||
|
|
||||||
|
verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
||||||
|
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
|
||||||
|
mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||||
|
|
||||||
|
clean || :
|
||||||
|
exec_maven "$@"
|
||||||
189
mvnw.cmd
vendored
Normal file
189
mvnw.cmd
vendored
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
<# : batch portion
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@REM or more contributor license agreements. See the NOTICE file
|
||||||
|
@REM distributed with this work for additional information
|
||||||
|
@REM regarding copyright ownership. The ASF licenses this file
|
||||||
|
@REM to you under the Apache License, Version 2.0 (the
|
||||||
|
@REM "License"); you may not use this file except in compliance
|
||||||
|
@REM with the License. You may obtain a copy of the License at
|
||||||
|
@REM
|
||||||
|
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@REM
|
||||||
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
|
@REM software distributed under the License is distributed on an
|
||||||
|
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@REM KIND, either express or implied. See the License for the
|
||||||
|
@REM specific language governing permissions and limitations
|
||||||
|
@REM under the License.
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Apache Maven Wrapper startup batch script, version 3.3.4
|
||||||
|
@REM
|
||||||
|
@REM Optional ENV vars
|
||||||
|
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||||
|
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||||
|
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||||
|
@SET __MVNW_CMD__=
|
||||||
|
@SET __MVNW_ERROR__=
|
||||||
|
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||||
|
@SET PSModulePath=
|
||||||
|
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||||
|
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||||
|
)
|
||||||
|
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||||
|
@SET __MVNW_PSMODULEP_SAVE=
|
||||||
|
@SET __MVNW_ARG0_NAME__=
|
||||||
|
@SET MVNW_USERNAME=
|
||||||
|
@SET MVNW_PASSWORD=
|
||||||
|
@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*)
|
||||||
|
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||||
|
@GOTO :EOF
|
||||||
|
: end batch / begin powershell #>
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
if ($env:MVNW_VERBOSE -eq "true") {
|
||||||
|
$VerbosePreference = "Continue"
|
||||||
|
}
|
||||||
|
|
||||||
|
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||||
|
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||||
|
if (!$distributionUrl) {
|
||||||
|
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||||
|
"maven-mvnd-*" {
|
||||||
|
$USE_MVND = $true
|
||||||
|
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||||
|
$MVN_CMD = "mvnd.cmd"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
$USE_MVND = $false
|
||||||
|
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||||
|
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||||
|
if ($env:MVNW_REPOURL) {
|
||||||
|
$MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||||
|
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')"
|
||||||
|
}
|
||||||
|
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||||
|
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||||
|
|
||||||
|
$MAVEN_M2_PATH = "$HOME/.m2"
|
||||||
|
if ($env:MAVEN_USER_HOME) {
|
||||||
|
$MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
|
||||||
|
New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$MAVEN_WRAPPER_DISTS = $null
|
||||||
|
if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
|
||||||
|
$MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
|
||||||
|
} else {
|
||||||
|
$MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
|
||||||
|
}
|
||||||
|
|
||||||
|
$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
|
||||||
|
$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||||
|
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||||
|
|
||||||
|
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||||
|
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||||
|
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||||
|
exit $?
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||||
|
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||||
|
}
|
||||||
|
|
||||||
|
# prepare tmp dir
|
||||||
|
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||||
|
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||||
|
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||||
|
trap {
|
||||||
|
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||||
|
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||||
|
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||||
|
|
||||||
|
# Download and Install Apache Maven
|
||||||
|
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||||
|
Write-Verbose "Downloading from: $distributionUrl"
|
||||||
|
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||||
|
|
||||||
|
$webclient = New-Object System.Net.WebClient
|
||||||
|
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||||
|
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||||
|
}
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||||
|
|
||||||
|
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||||
|
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||||
|
if ($distributionSha256Sum) {
|
||||||
|
if ($USE_MVND) {
|
||||||
|
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||||
|
}
|
||||||
|
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||||
|
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||||
|
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# unzip and move
|
||||||
|
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||||
|
|
||||||
|
# Find the actual extracted directory name (handles snapshots where filename != directory name)
|
||||||
|
$actualDistributionDir = ""
|
||||||
|
|
||||||
|
# First try the expected directory name (for regular distributions)
|
||||||
|
$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
|
||||||
|
$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
|
||||||
|
if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
|
||||||
|
$actualDistributionDir = $distributionUrlNameMain
|
||||||
|
}
|
||||||
|
|
||||||
|
# If not found, search for any directory with the Maven executable (for snapshots)
|
||||||
|
if (!$actualDistributionDir) {
|
||||||
|
Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
|
||||||
|
$testPath = Join-Path $_.FullName "bin/$MVN_CMD"
|
||||||
|
if (Test-Path -Path $testPath -PathType Leaf) {
|
||||||
|
$actualDistributionDir = $_.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$actualDistributionDir) {
|
||||||
|
Write-Error "Could not find Maven distribution directory in extracted archive"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
|
||||||
|
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||||
|
try {
|
||||||
|
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||||
|
} catch {
|
||||||
|
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||||
|
Write-Error "fail to move MAVEN_HOME"
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||||
|
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||||
440
pom.xml
Normal file
440
pom.xml
Normal file
@@ -0,0 +1,440 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>4.1.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>org.springframework.samples</groupId>
|
||||||
|
<artifactId>spring-petclinic</artifactId>
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>petclinic</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- Generic properties -->
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<!-- Important for reproducible builds. Update using e.g. ./mvnw versions:set -DnewVersion=... -->
|
||||||
|
<project.build.outputTimestamp>2024-11-28T14:37:52Z</project.build.outputTimestamp>
|
||||||
|
|
||||||
|
<!-- Web dependencies -->
|
||||||
|
<webjars-locator.version>1.1.3</webjars-locator.version>
|
||||||
|
<webjars-bootstrap.version>5.3.8</webjars-bootstrap.version>
|
||||||
|
<webjars-font-awesome.version>4.7.0</webjars-font-awesome.version>
|
||||||
|
|
||||||
|
<!-- Checkstyle needs to stay on v12 since v13 sets minimal jdk to 21 - https://checkstyle.org/releasenotes.html#Release_13.0.0 -->
|
||||||
|
<checkstyle.version>12.3.1</checkstyle.version>
|
||||||
|
<jacoco.version>0.8.15</jacoco.version>
|
||||||
|
<libsass.version>0.3.4</libsass.version>
|
||||||
|
<lifecycle-mapping>1.0.0</lifecycle-mapping>
|
||||||
|
<maven-checkstyle.version>3.6.0</maven-checkstyle.version>
|
||||||
|
<nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version>
|
||||||
|
<spring-format.version>0.0.47</spring-format.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spring and Spring Boot dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-cache</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.cache</groupId>
|
||||||
|
<artifactId>cache-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||||
|
<artifactId>caffeine</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.webjars</groupId>
|
||||||
|
<artifactId>webjars-locator-lite</artifactId>
|
||||||
|
<version>${webjars-locator.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.webjars.npm</groupId>
|
||||||
|
<artifactId>bootstrap</artifactId>
|
||||||
|
<version>${webjars-bootstrap.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.webjars.npm</groupId>
|
||||||
|
<artifactId>font-awesome</artifactId>
|
||||||
|
<version>${webjars-font-awesome.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-restclient</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-restclient-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-testcontainers</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-docker-compose</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-cache-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>testcontainers-junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>testcontainers-mysql</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce-java</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<requireJavaVersion>
|
||||||
|
<message>This build requires at least Java ${java.version}, update your JVM, and run the build again</message>
|
||||||
|
<version>${java.version}</version>
|
||||||
|
</requireJavaVersion>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.spring.javaformat</groupId>
|
||||||
|
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||||
|
<version>${spring-format.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>validate</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>validate</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>${maven-checkstyle.version}</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.puppycrawl.tools</groupId>
|
||||||
|
<artifactId>checkstyle</artifactId>
|
||||||
|
<version>${checkstyle.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.spring.nohttp</groupId>
|
||||||
|
<artifactId>nohttp-checkstyle</artifactId>
|
||||||
|
<version>${nohttp-checkstyle.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>nohttp-checkstyle-validation</id>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<configuration>
|
||||||
|
<configLocation>src/checkstyle/nohttp-checkstyle.xml</configLocation>
|
||||||
|
<sourceDirectories>${basedir}</sourceDirectories>
|
||||||
|
<includes>**/*</includes>
|
||||||
|
<excludes>**/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class</excludes>
|
||||||
|
<propertyExpansion>config_loc=${basedir}/src/checkstyle/</propertyExpansion>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.graalvm.buildtools</groupId>
|
||||||
|
<artifactId>native-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<!-- Spring Boot Actuator displays build-related information
|
||||||
|
if a META-INF/build-info.properties file is present -->
|
||||||
|
<goals>
|
||||||
|
<goal>build-info</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<additionalProperties>
|
||||||
|
<encoding.source>${project.build.sourceEncoding}</encoding.source>
|
||||||
|
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
|
||||||
|
<java.source>${java.version}</java.source>
|
||||||
|
<java.target>${java.version}</java.target>
|
||||||
|
</additionalProperties>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>${jacoco.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>prepare-package</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Spring Boot Actuator displays build-related information if a git.properties file is
|
||||||
|
present at the classpath -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.github.git-commit-id</groupId>
|
||||||
|
<artifactId>git-commit-id-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
||||||
|
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- Spring Boot Actuator displays sbom-related information if a CycloneDX SBOM file is
|
||||||
|
present at the classpath -->
|
||||||
|
<plugin>
|
||||||
|
<?m2e ignore?>
|
||||||
|
<groupId>org.cyclonedx</groupId>
|
||||||
|
<artifactId>cyclonedx-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>css</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>unpack</id>
|
||||||
|
<goals>
|
||||||
|
<goal>unpack</goal>
|
||||||
|
</goals>
|
||||||
|
<?m2e execute onConfiguration,onIncremental?>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>org.webjars.npm</groupId>
|
||||||
|
<artifactId>bootstrap</artifactId>
|
||||||
|
<version>${webjars-bootstrap.version}</version>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
<outputDirectory>${project.build.directory}/webjars</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.gitlab.haynes</groupId>
|
||||||
|
<artifactId>libsass-maven-plugin</artifactId>
|
||||||
|
<version>${libsass.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<inputPath>${basedir}/src/main/scss/</inputPath>
|
||||||
|
<outputPath>${basedir}/src/main/resources/static/resources/css/</outputPath>
|
||||||
|
<includePath>${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/</includePath>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<?m2e execute onConfiguration,onIncremental?>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>m2e</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>m2e.version</name>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<!-- This plugin's configuration is used to store Eclipse m2e settings
|
||||||
|
only. It has no influence on the Maven build itself. -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.eclipse.m2e</groupId>
|
||||||
|
<artifactId>lifecycle-mapping</artifactId>
|
||||||
|
<version>${lifecycle-mapping}</version>
|
||||||
|
<configuration>
|
||||||
|
<lifecycleMappingMetadata>
|
||||||
|
<pluginExecutions>
|
||||||
|
<pluginExecution>
|
||||||
|
<pluginExecutionFilter>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<versionRange>[1,)</versionRange>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</pluginExecutionFilter>
|
||||||
|
<action>
|
||||||
|
<ignore></ignore>
|
||||||
|
</action>
|
||||||
|
</pluginExecution>
|
||||||
|
<pluginExecution>
|
||||||
|
<pluginExecutionFilter>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<versionRange>[1,)</versionRange>
|
||||||
|
<goals>
|
||||||
|
<goal>build-info</goal>
|
||||||
|
</goals>
|
||||||
|
</pluginExecutionFilter>
|
||||||
|
<action>
|
||||||
|
<ignore></ignore>
|
||||||
|
</action>
|
||||||
|
</pluginExecution>
|
||||||
|
<pluginExecution>
|
||||||
|
<pluginExecutionFilter>
|
||||||
|
<groupId>io.spring.javaformat</groupId>
|
||||||
|
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||||
|
<versionRange>[0,)</versionRange>
|
||||||
|
<goals>
|
||||||
|
<goal>validate</goal>
|
||||||
|
</goals>
|
||||||
|
</pluginExecutionFilter>
|
||||||
|
<action>
|
||||||
|
<ignore></ignore>
|
||||||
|
</action>
|
||||||
|
</pluginExecution>
|
||||||
|
</pluginExecutions>
|
||||||
|
</lifecycleMappingMetadata>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
||||||
55
score.yaml
Normal file
55
score.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
apiVersion: score.dev/v1b1
|
||||||
|
metadata:
|
||||||
|
name: demo-principal-1
|
||||||
|
labels:
|
||||||
|
app: demo-principal-1
|
||||||
|
|
||||||
|
containers:
|
||||||
|
main:
|
||||||
|
image: .
|
||||||
|
variables:
|
||||||
|
# The Watcher's OTel work lands in overlays/otel/, which only ArgoCD reads. On the
|
||||||
|
# orchestrator path nothing consumes that overlay, so without these variables the
|
||||||
|
# renovated app emits no telemetry at all and never appears in Grafana.
|
||||||
|
OTEL_SERVICE_NAME: "demo-principal-1"
|
||||||
|
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.monitoring.svc.cluster.local:4318"
|
||||||
|
OTEL_EXPORTER_OTLP_PROTOCOL: "http/protobuf"
|
||||||
|
OTEL_RESOURCE_ATTRIBUTES: "service.name=demo-principal-1"
|
||||||
|
OTEL_METRICS_EXPORTER: "otlp"
|
||||||
|
OTEL_TRACES_EXPORTER: "otlp"
|
||||||
|
OTEL_LOGS_EXPORTER: "none"
|
||||||
|
|
||||||
|
service:
|
||||||
|
ports:
|
||||||
|
web:
|
||||||
|
port: 80
|
||||||
|
targetPort: 8080
|
||||||
|
|
||||||
|
resources:
|
||||||
|
env:
|
||||||
|
type: environment
|
||||||
|
|
||||||
|
# Gives the renovated workload a public HTTPS URL. Without this the deploy still goes
|
||||||
|
# green and the pod still runs -- there is simply no Ingress, no certificate and no
|
||||||
|
# hostname, so the demo's payoff (curl the renovated app) has nothing to hit.
|
||||||
|
#
|
||||||
|
# hostname is hardcoded to the apps domain deliberately: it is the only domain the apps
|
||||||
|
# cluster serves, and both the wildcard A record (*.apps.dev) and the cert-manager
|
||||||
|
# ClusterIssuer are scoped to exactly it.
|
||||||
|
#
|
||||||
|
# service_port is the Score `service.ports.web.port` below (80), NOT the container port.
|
||||||
|
# An Ingress naming a Service or port that does not exist fails at neither plan nor
|
||||||
|
# apply -- it surfaces only as nginx answering 503.
|
||||||
|
#
|
||||||
|
# CAVEAT: modernization-factory's generate_score_yaml rewrites BOTH `port` and
|
||||||
|
# `targetPort` to the detected application port whenever that port is not 8080. An app
|
||||||
|
# on 3000 therefore ends up with a Service on 3000 and this Ingress pointing at a port
|
||||||
|
# that no longer exists. Apps already listening on 8080 (Spring PetClinic among them)
|
||||||
|
# skip that patch entirely and are unaffected.
|
||||||
|
ingress:
|
||||||
|
type: workload-ingress
|
||||||
|
params:
|
||||||
|
name: demo-principal-1
|
||||||
|
hostname: demo-principal-1.apps.dev.crucible.kyndemo.live
|
||||||
|
service_name: demo-principal-1
|
||||||
|
service_port: 80
|
||||||
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'spring-petclinic'
|
||||||
11
src/checkstyle/nohttp-checkstyle-suppressions.xml
Normal file
11
src/checkstyle/nohttp-checkstyle-suppressions.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE suppressions PUBLIC
|
||||||
|
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
||||||
|
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||||
|
<suppressions>
|
||||||
|
<suppress files="node_modules[\\/].*" checks=".*"/>
|
||||||
|
<suppress files="node[\\/].*" checks=".*"/>
|
||||||
|
<suppress files="build[\\/].*" checks=".*"/>
|
||||||
|
<suppress files="target[\\/].*" checks=".*"/>
|
||||||
|
<suppress files=".+\.(jar|git|ico|p12|gif|jks|jpg|svg|log)" checks="NoHttp"/>
|
||||||
|
</suppressions>
|
||||||
10
src/checkstyle/nohttp-checkstyle.xml
Normal file
10
src/checkstyle/nohttp-checkstyle.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE module PUBLIC
|
||||||
|
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
|
||||||
|
"https://checkstyle.org/dtds/configuration_1_2.dtd">
|
||||||
|
<module name="com.puppycrawl.tools.checkstyle.Checker">
|
||||||
|
<module name="io.spring.nohttp.checkstyle.check.NoHttpCheck"/>
|
||||||
|
<module name="SuppressionFilter">
|
||||||
|
<property name="file" value="${config_loc}/nohttp-checkstyle-suppressions.xml"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PetClinic Spring Boot Application.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@ImportRuntimeHints(PetClinicRuntimeHints.class)
|
||||||
|
public class PetClinicApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(PetClinicApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.samples.petclinic;
|
||||||
|
|
||||||
|
import org.springframework.aot.hint.RuntimeHints;
|
||||||
|
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||||
|
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||||
|
import org.springframework.samples.petclinic.model.Person;
|
||||||
|
import org.springframework.samples.petclinic.vet.Vet;
|
||||||
|
|
||||||
|
public class PetClinicRuntimeHints implements RuntimeHintsRegistrar {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
|
hints.resources().registerPattern("db/*"); // https://github.com/spring-projects/spring-boot/issues/32654
|
||||||
|
hints.resources().registerPattern("db/*/*"); // nested db/{h2,mysql,postgres}
|
||||||
|
hints.resources().registerPattern("messages/*");
|
||||||
|
hints.resources().registerPattern("mysql-default-conf");
|
||||||
|
hints.reflection().registerType(BaseEntity.class, typeHint -> typeHint.withJavaSerialization(true));
|
||||||
|
hints.reflection().registerType(Person.class, typeHint -> typeHint.withJavaSerialization(true));
|
||||||
|
hints.reflection().registerType(Vet.class, typeHint -> typeHint.withJavaSerialization(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple JavaBean domain object with an id property. Used as a base class for objects
|
||||||
|
* needing this property.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
@MappedSuperclass
|
||||||
|
public class BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNew() {
|
||||||
|
return this.id == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as
|
||||||
|
* a base class for objects needing these properties.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
@MappedSuperclass
|
||||||
|
public class NamedEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@NotBlank
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String name = this.getName();
|
||||||
|
return name != null ? name : "<null>";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple JavaBean domain object representing an person.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
*/
|
||||||
|
@MappedSuperclass
|
||||||
|
public class Person extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(length = 30)
|
||||||
|
@Size(max = 30)
|
||||||
|
@NotBlank
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@Column(length = 30)
|
||||||
|
@Size(max = 30)
|
||||||
|
@NotBlank
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return this.firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return this.lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The classes in this package represent utilities used by the domain.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.model;
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.springframework.core.style.ToStringCreator;
|
||||||
|
import org.springframework.samples.petclinic.model.Person;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.OrderBy;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.Pattern;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple JavaBean domain object representing an owner.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @author Oliver Drotbohm
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "owners")
|
||||||
|
public class Owner extends Person {
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@NotBlank
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@NotBlank
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@NotBlank
|
||||||
|
@Pattern(regexp = "\\d{10}", message = "{telephone.invalid}")
|
||||||
|
private String telephone;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "owner_id")
|
||||||
|
@OrderBy("name")
|
||||||
|
private final List<Pet> pets = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return this.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return this.city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTelephone() {
|
||||||
|
return this.telephone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTelephone(String telephone) {
|
||||||
|
this.telephone = telephone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pet> getPets() {
|
||||||
|
return this.pets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPet(Pet pet) {
|
||||||
|
if (pet.isNew()) {
|
||||||
|
getPets().add(pet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Pet with the given name, or null if none found for this Owner.
|
||||||
|
* @param name to test
|
||||||
|
* @return the Pet with the given name, or null if no such Pet exists for this Owner
|
||||||
|
*/
|
||||||
|
public Pet getPet(String name) {
|
||||||
|
return getPet(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Pet with the given id, or null if none found for this Owner.
|
||||||
|
* @param id to test
|
||||||
|
* @return the Pet with the given id, or null if no such Pet exists for this Owner
|
||||||
|
*/
|
||||||
|
public Pet getPet(Integer id) {
|
||||||
|
for (Pet pet : getPets()) {
|
||||||
|
if (!pet.isNew()) {
|
||||||
|
Integer compId = pet.getId();
|
||||||
|
if (Objects.equals(compId, id)) {
|
||||||
|
return pet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Pet with the given name, or null if none found for this Owner.
|
||||||
|
* @param name to test
|
||||||
|
* @param ignoreNew whether to ignore new pets (pets that are not saved yet)
|
||||||
|
* @return the Pet with the given name, or null if no such Pet exists for this Owner
|
||||||
|
*/
|
||||||
|
public Pet getPet(String name, boolean ignoreNew) {
|
||||||
|
for (Pet pet : getPets()) {
|
||||||
|
String compName = pet.getName();
|
||||||
|
if (compName != null && compName.equalsIgnoreCase(name)) {
|
||||||
|
if (!ignoreNew || !pet.isNew()) {
|
||||||
|
return pet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringCreator(this).append("id", this.getId())
|
||||||
|
.append("new", this.isNew())
|
||||||
|
.append("lastName", this.getLastName())
|
||||||
|
.append("firstName", this.getFirstName())
|
||||||
|
.append("address", this.address)
|
||||||
|
.append("city", this.city)
|
||||||
|
.append("telephone", this.telephone)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given {@link Visit} to the {@link Pet} with the given identifier.
|
||||||
|
* @param petId the identifier of the {@link Pet}, must not be {@literal null}.
|
||||||
|
* @param visit the visit to add, must not be {@literal null}.
|
||||||
|
*/
|
||||||
|
public void addVisit(Integer petId, Visit visit) {
|
||||||
|
|
||||||
|
Assert.notNull(petId, "Pet identifier must not be null!");
|
||||||
|
Assert.notNull(visit, "Visit must not be null!");
|
||||||
|
|
||||||
|
Pet pet = getPet(petId);
|
||||||
|
|
||||||
|
Assert.notNull(pet, "Invalid Pet identifier!");
|
||||||
|
|
||||||
|
pet.addVisit(visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
class OwnerController {
|
||||||
|
|
||||||
|
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||||
|
|
||||||
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
public OwnerController(OwnerRepository owners) {
|
||||||
|
this.owners = owners;
|
||||||
|
}
|
||||||
|
|
||||||
|
@InitBinder
|
||||||
|
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||||
|
dataBinder.setDisallowedFields("id", "*.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("owner")
|
||||||
|
public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
|
||||||
|
return ownerId == null ? new Owner()
|
||||||
|
: this.owners.findById(ownerId)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Owner not found with id: " + ownerId
|
||||||
|
+ ". Please ensure the ID is correct " + "and the owner exists in the database."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/owners/new")
|
||||||
|
public String initCreationForm() {
|
||||||
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/owners/new")
|
||||||
|
public String processCreationForm(@Valid Owner owner, BindingResult result, RedirectAttributes redirectAttributes) {
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
redirectAttributes.addFlashAttribute("error", "There was an error in creating the owner.");
|
||||||
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.owners.save(owner);
|
||||||
|
redirectAttributes.addFlashAttribute("message", "New Owner Created");
|
||||||
|
return "redirect:/owners/" + owner.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/owners/find")
|
||||||
|
public String initFindForm() {
|
||||||
|
return "owners/findOwners";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/owners")
|
||||||
|
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
|
||||||
|
Model model) {
|
||||||
|
// allow parameterless GET request for /owners to return all records
|
||||||
|
String lastName = owner.getLastName();
|
||||||
|
if (lastName == null) {
|
||||||
|
lastName = ""; // empty string signifies broadest possible search
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lastName = lastName.strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
// find owners by last name
|
||||||
|
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, lastName);
|
||||||
|
if (ownersResults.isEmpty()) {
|
||||||
|
// no owners found
|
||||||
|
result.rejectValue("lastName", "notFound", "not found");
|
||||||
|
return "owners/findOwners";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ownersResults.getTotalElements() == 1) {
|
||||||
|
// 1 owner found
|
||||||
|
owner = ownersResults.iterator().next();
|
||||||
|
return "redirect:/owners/" + owner.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
// multiple owners found
|
||||||
|
return addPaginationModel(page, model, ownersResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String addPaginationModel(int page, Model model, Page<Owner> paginated) {
|
||||||
|
List<Owner> listOwners = paginated.getContent();
|
||||||
|
model.addAttribute("currentPage", page);
|
||||||
|
model.addAttribute("totalPages", paginated.getTotalPages());
|
||||||
|
model.addAttribute("totalItems", paginated.getTotalElements());
|
||||||
|
model.addAttribute("listOwners", listOwners);
|
||||||
|
return "owners/ownersList";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
|
||||||
|
int pageSize = 5;
|
||||||
|
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||||
|
return owners.findByLastNameStartingWith(lastname, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/owners/{ownerId}/edit")
|
||||||
|
public String initUpdateOwnerForm() {
|
||||||
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/owners/{ownerId}/edit")
|
||||||
|
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId,
|
||||||
|
RedirectAttributes redirectAttributes) {
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
redirectAttributes.addFlashAttribute("error", "There was an error in updating the owner.");
|
||||||
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Objects.equals(owner.getId(), ownerId)) {
|
||||||
|
result.rejectValue("id", "mismatch", "The owner ID in the form does not match the URL.");
|
||||||
|
redirectAttributes.addFlashAttribute("error", "Owner ID mismatch. Please try again.");
|
||||||
|
return "redirect:/owners/{ownerId}/edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
owner.setId(ownerId);
|
||||||
|
this.owners.save(owner);
|
||||||
|
redirectAttributes.addFlashAttribute("message", "Owner Values Updated");
|
||||||
|
return "redirect:/owners/{ownerId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom handler for displaying an owner.
|
||||||
|
* @param ownerId the ID of the owner to display
|
||||||
|
* @return a ModelMap with the model attributes for the view
|
||||||
|
*/
|
||||||
|
@GetMapping("/owners/{ownerId}")
|
||||||
|
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
|
||||||
|
ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
||||||
|
Optional<Owner> optionalOwner = this.owners.findById(ownerId);
|
||||||
|
Owner owner = optionalOwner.orElseThrow(() -> new IllegalArgumentException(
|
||||||
|
"Owner not found with id: " + ownerId + ". Please ensure the ID is correct "));
|
||||||
|
mav.addObject(owner);
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository class for <code>Owner</code> domain objects. All method names are compliant
|
||||||
|
* with Spring Data naming conventions so this interface can easily be extended for Spring
|
||||||
|
* Data. See:
|
||||||
|
* https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
public interface OwnerRepository extends JpaRepository<Owner, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||||
|
* whose last name <i>starts</i> with the given name.
|
||||||
|
* @param lastName Value to search for
|
||||||
|
* @return a Collection of matching {@link Owner}s (or an empty Collection if none
|
||||||
|
* found)
|
||||||
|
*/
|
||||||
|
Page<Owner> findByLastNameStartingWith(String lastName, Pageable pageable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an {@link Owner} from the data store by id.
|
||||||
|
* <p>
|
||||||
|
* This method returns an {@link Optional} containing the {@link Owner} if found. If
|
||||||
|
* no {@link Owner} is found with the provided id, it will return an empty
|
||||||
|
* {@link Optional}.
|
||||||
|
* </p>
|
||||||
|
* @param id the id to search for
|
||||||
|
* @return an {@link Optional} containing the {@link Owner} if found, or an empty
|
||||||
|
* {@link Optional} if not found.
|
||||||
|
* @throws IllegalArgumentException if the id is null (assuming null is not a valid
|
||||||
|
* input for id)
|
||||||
|
*/
|
||||||
|
Optional<Owner> findById(Integer id);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.OrderBy;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple business object representing a pet.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "pets")
|
||||||
|
public class Pet extends NamedEntity {
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private LocalDate birthDate;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "type_id")
|
||||||
|
private PetType type;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "pet_id")
|
||||||
|
@OrderBy("date ASC")
|
||||||
|
private final Set<Visit> visits = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
public void setBirthDate(LocalDate birthDate) {
|
||||||
|
this.birthDate = birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getBirthDate() {
|
||||||
|
return this.birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PetType getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(PetType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Visit> getVisits() {
|
||||||
|
return this.visits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisit(Visit visit) {
|
||||||
|
getVisits().add(visit);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/owners/{ownerId}")
|
||||||
|
class PetController {
|
||||||
|
|
||||||
|
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
|
||||||
|
|
||||||
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
private final PetTypeRepository types;
|
||||||
|
|
||||||
|
public PetController(OwnerRepository owners, PetTypeRepository types) {
|
||||||
|
this.owners = owners;
|
||||||
|
this.types = types;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("types")
|
||||||
|
public Collection<PetType> populatePetTypes() {
|
||||||
|
return this.types.findPetTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("owner")
|
||||||
|
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
|
||||||
|
Optional<Owner> optionalOwner = this.owners.findById(ownerId);
|
||||||
|
Owner owner = optionalOwner.orElseThrow(() -> new IllegalArgumentException(
|
||||||
|
"Owner not found with id: " + ownerId + ". Please ensure the ID is correct "));
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("pet")
|
||||||
|
public Pet findPet(@PathVariable("ownerId") int ownerId,
|
||||||
|
@PathVariable(name = "petId", required = false) Integer petId) {
|
||||||
|
|
||||||
|
if (petId == null) {
|
||||||
|
return new Pet();
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Owner> optionalOwner = this.owners.findById(ownerId);
|
||||||
|
Owner owner = optionalOwner.orElseThrow(() -> new IllegalArgumentException(
|
||||||
|
"Owner not found with id: " + ownerId + ". Please ensure the ID is correct "));
|
||||||
|
return owner.getPet(petId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@InitBinder("owner")
|
||||||
|
public void initOwnerBinder(WebDataBinder dataBinder) {
|
||||||
|
dataBinder.setDisallowedFields("id", "*.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@InitBinder("pet")
|
||||||
|
public void initPetBinder(WebDataBinder dataBinder) {
|
||||||
|
dataBinder.setValidator(new PetValidator());
|
||||||
|
dataBinder.setDisallowedFields("id", "*.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/pets/new")
|
||||||
|
public String initCreationForm(Owner owner, ModelMap model) {
|
||||||
|
Pet pet = new Pet();
|
||||||
|
owner.addPet(pet);
|
||||||
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/pets/new")
|
||||||
|
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result,
|
||||||
|
RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
|
if (StringUtils.hasText(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
|
||||||
|
result.rejectValue("name", "duplicate", "already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
if (pet.getBirthDate() != null && pet.getBirthDate().isAfter(currentDate)) {
|
||||||
|
result.rejectValue("birthDate", "typeMismatch.birthDate");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
owner.addPet(pet);
|
||||||
|
this.owners.saveAndFlush(owner);
|
||||||
|
}
|
||||||
|
catch (DataIntegrityViolationException ex) {
|
||||||
|
if (!isDuplicatePetNameViolation(ex)) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
result.rejectValue("name", "duplicate", "already exists");
|
||||||
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
redirectAttributes.addFlashAttribute("message", "New Pet has been Added");
|
||||||
|
return "redirect:/owners/{ownerId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/pets/{petId}/edit")
|
||||||
|
public String initUpdateForm() {
|
||||||
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/pets/{petId}/edit")
|
||||||
|
public String processUpdateForm(Owner owner, @Valid Pet pet, BindingResult result,
|
||||||
|
RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
|
String petName = pet.getName();
|
||||||
|
|
||||||
|
// checking if the pet name already exists for the owner
|
||||||
|
if (StringUtils.hasText(petName)) {
|
||||||
|
Pet existingPet = owner.getPet(petName, false);
|
||||||
|
if (existingPet != null && !Objects.equals(existingPet.getId(), pet.getId())) {
|
||||||
|
result.rejectValue("name", "duplicate", "already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
if (pet.getBirthDate() != null && pet.getBirthDate().isAfter(currentDate)) {
|
||||||
|
result.rejectValue("birthDate", "typeMismatch.birthDate");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
updatePetDetails(owner, pet);
|
||||||
|
}
|
||||||
|
catch (DataIntegrityViolationException ex) {
|
||||||
|
if (!isDuplicatePetNameViolation(ex)) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
result.rejectValue("name", "duplicate", "already exists");
|
||||||
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
}
|
||||||
|
redirectAttributes.addFlashAttribute("message", "Pet details has been edited");
|
||||||
|
return "redirect:/owners/{ownerId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the pet details if it exists or adds a new pet to the owner.
|
||||||
|
* @param owner The owner of the pet
|
||||||
|
* @param pet The pet with updated details
|
||||||
|
*/
|
||||||
|
private void updatePetDetails(Owner owner, Pet pet) {
|
||||||
|
Integer id = pet.getId();
|
||||||
|
Assert.state(id != null, "'pet.getId()' must not be null");
|
||||||
|
Pet existingPet = owner.getPet(id);
|
||||||
|
if (existingPet != null) {
|
||||||
|
// Update existing pet's properties
|
||||||
|
existingPet.setName(pet.getName());
|
||||||
|
existingPet.setBirthDate(pet.getBirthDate());
|
||||||
|
existingPet.setType(pet.getType());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
owner.addPet(pet);
|
||||||
|
}
|
||||||
|
this.owners.saveAndFlush(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDuplicatePetNameViolation(DataIntegrityViolationException ex) {
|
||||||
|
String message = ex.getMessage();
|
||||||
|
return message != null && message.toLowerCase().contains("unique_owner_pet_name");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller Can be Cat, Dog, Hamster...
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "types")
|
||||||
|
public class PetType extends NamedEntity {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import org.springframework.format.Formatter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting
|
||||||
|
* from Spring 3.0, Formatters have come as an improvement in comparison to legacy
|
||||||
|
* PropertyEditors. See the following links for more details: - The Spring ref doc:
|
||||||
|
* https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#format
|
||||||
|
*
|
||||||
|
* @author Mark Fisher
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Michael Isvy
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class PetTypeFormatter implements Formatter<PetType> {
|
||||||
|
|
||||||
|
private final PetTypeRepository types;
|
||||||
|
|
||||||
|
public PetTypeFormatter(PetTypeRepository types) {
|
||||||
|
this.types = types;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String print(PetType petType, Locale locale) {
|
||||||
|
String name = petType.getName();
|
||||||
|
return name != null ? name : "<null>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PetType parse(String text, Locale locale) throws ParseException {
|
||||||
|
Collection<PetType> findPetTypes = this.types.findPetTypes();
|
||||||
|
for (PetType type : findPetTypes) {
|
||||||
|
if (Objects.equals(type.getName(), text)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ParseException("type not found: " + text, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository class for <code>PetType</code> domain objects.
|
||||||
|
*
|
||||||
|
* @author Patrick Baumgartner
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface PetTypeRepository extends JpaRepository<PetType, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all {@link PetType}s from the data store.
|
||||||
|
* @return a Collection of {@link PetType}s.
|
||||||
|
*/
|
||||||
|
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
||||||
|
List<PetType> findPetTypes();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
import org.springframework.validation.Validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>Validator</code> for <code>Pet</code> forms.
|
||||||
|
* <p>
|
||||||
|
* We're not using Bean Validation annotations here because it is easier to define such
|
||||||
|
* validation rule in Java.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
public class PetValidator implements Validator {
|
||||||
|
|
||||||
|
private static final String REQUIRED = "required";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(Object obj, Errors errors) {
|
||||||
|
Pet pet = (Pet) obj;
|
||||||
|
String name = pet.getName();
|
||||||
|
// name validation
|
||||||
|
if (!StringUtils.hasText(name)) {
|
||||||
|
errors.rejectValue("name", REQUIRED, REQUIRED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// type validation
|
||||||
|
if (pet.isNew() && pet.getType() == null) {
|
||||||
|
errors.rejectValue("type", REQUIRED, REQUIRED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// birth date validation
|
||||||
|
if (pet.getBirthDate() == null) {
|
||||||
|
errors.rejectValue("birthDate", REQUIRED, REQUIRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Validator validates *just* Pet instances
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean supports(Class<?> clazz) {
|
||||||
|
return Pet.class.isAssignableFrom(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple JavaBean domain object representing a visit.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "visits")
|
||||||
|
public class Visit extends BaseEntity {
|
||||||
|
|
||||||
|
@Column(name = "visit_date")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private LocalDate date;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of Visit for tomorrow
|
||||||
|
*/
|
||||||
|
public Visit() {
|
||||||
|
this.date = LocalDate.now().plusDays(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getDate() {
|
||||||
|
return this.date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(LocalDate date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
* @author Michael Isvy
|
||||||
|
* @author Dave Syer
|
||||||
|
* @author Wick Dynex
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
class VisitController {
|
||||||
|
|
||||||
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
public VisitController(OwnerRepository owners) {
|
||||||
|
this.owners = owners;
|
||||||
|
}
|
||||||
|
|
||||||
|
@InitBinder
|
||||||
|
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||||
|
dataBinder.setDisallowedFields("id", "*.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before each and every @RequestMapping annotated method. 2 goals: - Make sure
|
||||||
|
* we always have fresh data - Since we do not use the session scope, make sure that
|
||||||
|
* Pet object always has an id (Even though id is not part of the form fields)
|
||||||
|
* @param petId
|
||||||
|
* @return Pet
|
||||||
|
*/
|
||||||
|
@ModelAttribute("visit")
|
||||||
|
public Visit loadPetWithVisit(@PathVariable("ownerId") int ownerId, @PathVariable("petId") int petId,
|
||||||
|
Map<String, Object> model) {
|
||||||
|
Optional<Owner> optionalOwner = owners.findById(ownerId);
|
||||||
|
Owner owner = optionalOwner.orElseThrow(() -> new IllegalArgumentException(
|
||||||
|
"Owner not found with id: " + ownerId + ". Please ensure the ID is correct "));
|
||||||
|
|
||||||
|
Pet pet = owner.getPet(petId);
|
||||||
|
if (pet == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Pet with id " + petId + " not found for owner with id " + ownerId + ".");
|
||||||
|
}
|
||||||
|
model.put("pet", pet);
|
||||||
|
model.put("owner", owner);
|
||||||
|
|
||||||
|
Visit visit = new Visit();
|
||||||
|
pet.addVisit(visit);
|
||||||
|
return visit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("minVisitDate")
|
||||||
|
public LocalDate minVisitDate() {
|
||||||
|
return LocalDate.now().plusDays(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is
|
||||||
|
// called
|
||||||
|
@GetMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||||
|
public String initNewVisitForm() {
|
||||||
|
return "pets/createOrUpdateVisitForm";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
|
||||||
|
// called
|
||||||
|
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||||
|
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
|
||||||
|
BindingResult result, RedirectAttributes redirectAttributes) {
|
||||||
|
if (visit.getDate() != null && !visit.getDate().isAfter(LocalDate.now())) {
|
||||||
|
result.rejectValue("date", "typeMismatch.visitDate");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.hasErrors()) {
|
||||||
|
return "pets/createOrUpdateVisitForm";
|
||||||
|
}
|
||||||
|
|
||||||
|
owner.addVisit(petId, visit);
|
||||||
|
this.owners.save(owner);
|
||||||
|
redirectAttributes.addFlashAttribute("message", "Your visit has been booked");
|
||||||
|
return "redirect:/owners/{ownerId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic;
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.samples.petclinic.system;
|
||||||
|
|
||||||
|
import org.springframework.boot.cache.autoconfigure.JCacheManagerCustomizer;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.cache.configuration.MutableConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache configuration intended for caches providing the JCache API. This configuration
|
||||||
|
* creates the used cache for the application and enables statistics that become
|
||||||
|
* accessible via JMX.
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableCaching
|
||||||
|
class CacheConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JCacheManagerCustomizer petclinicCacheConfigurationCustomizer() {
|
||||||
|
return cm -> cm.createCache("vets", cacheConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a simple configuration that enable statistics via the JCache programmatic
|
||||||
|
* configuration API.
|
||||||
|
* <p>
|
||||||
|
* Within the configuration object that is provided by the JCache API standard, there
|
||||||
|
* is only a very limited set of configuration options. The really relevant
|
||||||
|
* configuration options (like the size limit) must be set via a configuration
|
||||||
|
* mechanism that is provided by the selected JCache implementation.
|
||||||
|
*/
|
||||||
|
private javax.cache.configuration.Configuration<Object, Object> cacheConfiguration() {
|
||||||
|
return new MutableConfiguration<>().setStatisticsEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.system;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller used to showcase what happens when an exception is thrown
|
||||||
|
*
|
||||||
|
* @author Michael Isvy
|
||||||
|
* <p/>
|
||||||
|
* Also see how a view that resolves to "error" has been added ("error.html").
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
class CrashController {
|
||||||
|
|
||||||
|
@GetMapping("/oups")
|
||||||
|
public String triggerException() {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Expected: controller used to showcase what " + "happens when an exception is thrown");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.springframework.samples.petclinic.system;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.LocaleResolver;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
||||||
|
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures internationalization (i18n) support for the application.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Handles loading language-specific messages, tracking the user's language, and allowing
|
||||||
|
* language changes via the URL parameter (e.g., <code>?lang=de</code>).
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Anuj Ashok Potdar
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class WebConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses session storage to remember the user’s language setting across requests.
|
||||||
|
* Defaults to English if nothing is specified.
|
||||||
|
* @return session-based {@link LocaleResolver}
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public LocaleResolver localeResolver() {
|
||||||
|
SessionLocaleResolver resolver = new SessionLocaleResolver();
|
||||||
|
resolver.setDefaultLocale(Locale.ENGLISH);
|
||||||
|
return resolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows the app to switch languages using a URL parameter like
|
||||||
|
* <code>?lang=es</code>.
|
||||||
|
* @return a {@link LocaleChangeInterceptor} that handles the change
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public LocaleChangeInterceptor localeChangeInterceptor() {
|
||||||
|
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
|
||||||
|
interceptor.setParamName("lang");
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the locale change interceptor so it can run on each request.
|
||||||
|
* @param registry where interceptors are added
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(localeChangeInterceptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.samples.petclinic.system;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
class WelcomeController {
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public String welcome() {
|
||||||
|
return "welcome";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.system;
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models a {@link Vet Vet's} specialty (for example, dentistry).
|
||||||
|
*
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "specialties")
|
||||||
|
public class Specialty extends NamedEntity {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
|
import org.springframework.samples.petclinic.model.Person;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.JoinTable;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.xml.bind.annotation.XmlElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple JavaBean domain object representing a veterinarian.
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "vets")
|
||||||
|
public class Vet extends Person {
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
|
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "specialty_id"))
|
||||||
|
private Set<Specialty> specialties;
|
||||||
|
|
||||||
|
protected Set<Specialty> getSpecialtiesInternal() {
|
||||||
|
if (this.specialties == null) {
|
||||||
|
this.specialties = new HashSet<>();
|
||||||
|
}
|
||||||
|
return this.specialties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public List<Specialty> getSpecialties() {
|
||||||
|
return getSpecialtiesInternal().stream()
|
||||||
|
.sorted(Comparator.comparing(NamedEntity::getName))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNrOfSpecialties() {
|
||||||
|
return getSpecialtiesInternal().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSpecialty(Specialty specialty) {
|
||||||
|
getSpecialtiesInternal().add(specialty);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Mark Fisher
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
class VetController {
|
||||||
|
|
||||||
|
private final VetRepository vetRepository;
|
||||||
|
|
||||||
|
public VetController(VetRepository vetRepository) {
|
||||||
|
this.vetRepository = vetRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/vets.html")
|
||||||
|
public String showVetList(@RequestParam(defaultValue = "1") int page, Model model) {
|
||||||
|
Page<Vet> paginated = findPaginated(page);
|
||||||
|
return addPaginationModel(page, paginated, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String addPaginationModel(int page, Page<Vet> paginated, Model model) {
|
||||||
|
List<Vet> listVets = paginated.getContent();
|
||||||
|
model.addAttribute("currentPage", page);
|
||||||
|
model.addAttribute("totalPages", paginated.getTotalPages());
|
||||||
|
model.addAttribute("totalItems", paginated.getTotalElements());
|
||||||
|
model.addAttribute("listVets", listVets);
|
||||||
|
return "vets/vetList";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Page<Vet> findPaginated(int page) {
|
||||||
|
int pageSize = 5;
|
||||||
|
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||||
|
return vetRepository.findAll(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping({ "/vets" })
|
||||||
|
public @ResponseBody Vets showResourcesVetList() {
|
||||||
|
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
||||||
|
// objects so it is simpler for JSon/Object mapping
|
||||||
|
Vets vets = new Vets();
|
||||||
|
vets.getVetList().addAll(this.vetRepository.findAll());
|
||||||
|
return vets;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository class for <code>Vet</code> domain objects All method names are compliant
|
||||||
|
* with Spring Data naming conventions so this interface can easily be extended for Spring
|
||||||
|
* Data. See:
|
||||||
|
* https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
|
||||||
|
*
|
||||||
|
* @author Ken Krebs
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
|
* @author Michael Isvy
|
||||||
|
*/
|
||||||
|
public interface VetRepository extends Repository<Vet, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all <code>Vet</code>s from the data store.
|
||||||
|
* @return a <code>Collection</code> of <code>Vet</code>s
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
@Cacheable("vets")
|
||||||
|
Collection<Vet> findAll() throws DataAccessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all <code>Vet</code>s from data store in Pages
|
||||||
|
* @param pageable
|
||||||
|
* @return
|
||||||
|
* @throws DataAccessException
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
@Cacheable("vets")
|
||||||
|
Page<Vet> findAll(Pageable pageable) throws DataAccessException;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jakarta.xml.bind.annotation.XmlElement;
|
||||||
|
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple domain object representing a list of veterinarians. Mostly here to be used for
|
||||||
|
* the 'vets' {@link org.springframework.web.servlet.view.xml.MarshallingView}.
|
||||||
|
*
|
||||||
|
* @author Arjen Poutsma
|
||||||
|
*/
|
||||||
|
@XmlRootElement
|
||||||
|
public class Vets {
|
||||||
|
|
||||||
|
private List<Vet> vets;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public List<Vet> getVetList() {
|
||||||
|
if (vets == null) {
|
||||||
|
vets = new ArrayList<>();
|
||||||
|
}
|
||||||
|
return vets;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2025 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
7
src/main/resources/application-mysql.properties
Normal file
7
src/main/resources/application-mysql.properties
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# database init, supports mysql too
|
||||||
|
database=mysql
|
||||||
|
spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost/petclinic}
|
||||||
|
spring.datasource.username=${MYSQL_USER:petclinic}
|
||||||
|
spring.datasource.password=${MYSQL_PASS:petclinic}
|
||||||
|
# SQL is written to be idempotent so this is safe
|
||||||
|
spring.sql.init.mode=always
|
||||||
7
src/main/resources/application-postgres.properties
Normal file
7
src/main/resources/application-postgres.properties
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# database init, supports postgres too
|
||||||
|
database=postgres
|
||||||
|
spring.datasource.url=${POSTGRES_URL:jdbc:postgresql://localhost/petclinic}
|
||||||
|
spring.datasource.username=${POSTGRES_USER:petclinic}
|
||||||
|
spring.datasource.password=${POSTGRES_PASS:petclinic}
|
||||||
|
# SQL is written to be idempotent so this is safe
|
||||||
|
spring.sql.init.mode=always
|
||||||
29
src/main/resources/application.properties
Normal file
29
src/main/resources/application.properties
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# database init, supports mysql too
|
||||||
|
database=h2
|
||||||
|
spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql
|
||||||
|
spring.sql.init.data-locations=classpath*:db/${database}/data.sql
|
||||||
|
|
||||||
|
# Web
|
||||||
|
spring.thymeleaf.mode=HTML
|
||||||
|
|
||||||
|
# JPA
|
||||||
|
spring.jpa.hibernate.ddl-auto=none
|
||||||
|
spring.jpa.open-in-view=false
|
||||||
|
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategySnakeCaseImpl
|
||||||
|
spring.jpa.properties.hibernate.default_batch_fetch_size=16
|
||||||
|
|
||||||
|
# Internationalization
|
||||||
|
spring.messages.basename=messages/messages
|
||||||
|
|
||||||
|
# Actuator
|
||||||
|
# Expose all actuator endpoints for monitoring and management purposes
|
||||||
|
# Don't do this in production, only for development and testing
|
||||||
|
management.endpoints.web.exposure.include=*
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
logging.level.org.springframework=INFO
|
||||||
|
# logging.level.org.springframework.web=DEBUG
|
||||||
|
# logging.level.org.springframework.context.annotation=TRACE
|
||||||
|
|
||||||
|
# Maximum time static resources should be cached
|
||||||
|
spring.web.resources.cache.cachecontrol.max-age=12h
|
||||||
15
src/main/resources/banner.txt
Normal file
15
src/main/resources/banner.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|\ _,,,--,,_
|
||||||
|
/,`.-'`' ._ \-;;,_
|
||||||
|
_______ __|,4- ) )_ .;.(__`'-'__ ___ __ _ ___ _______
|
||||||
|
| | '---''(_/._)-'(_\_) | | | | | | | | |
|
||||||
|
| _ | ___|_ _| | | | | |_| | | | __ _ _
|
||||||
|
| |_| | |___ | | | | | | | | | | \ \ \ \
|
||||||
|
| ___| ___| | | | _| |___| | _ | | _| \ \ \ \
|
||||||
|
| | | |___ | | | |_| | | | | | | |_ ) ) ) )
|
||||||
|
|___| |_______| |___| |_______|_______|___|_| |__|___|_______| / / / /
|
||||||
|
==================================================================/_/_/_/
|
||||||
|
|
||||||
|
:: Built with Spring Boot :: ${spring-boot.version}
|
||||||
|
|
||||||
53
src/main/resources/db/h2/data.sql
Normal file
53
src/main/resources/db/h2/data.sql
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
INSERT INTO vets VALUES (default, 'James', 'Carter');
|
||||||
|
INSERT INTO vets VALUES (default, 'Helen', 'Leary');
|
||||||
|
INSERT INTO vets VALUES (default, 'Linda', 'Douglas');
|
||||||
|
INSERT INTO vets VALUES (default, 'Rafael', 'Ortega');
|
||||||
|
INSERT INTO vets VALUES (default, 'Henry', 'Stevens');
|
||||||
|
INSERT INTO vets VALUES (default, 'Sharon', 'Jenkins');
|
||||||
|
|
||||||
|
INSERT INTO specialties VALUES (default, 'radiology');
|
||||||
|
INSERT INTO specialties VALUES (default, 'surgery');
|
||||||
|
INSERT INTO specialties VALUES (default, 'dentistry');
|
||||||
|
|
||||||
|
INSERT INTO vet_specialties VALUES (2, 1);
|
||||||
|
INSERT INTO vet_specialties VALUES (3, 2);
|
||||||
|
INSERT INTO vet_specialties VALUES (3, 3);
|
||||||
|
INSERT INTO vet_specialties VALUES (4, 2);
|
||||||
|
INSERT INTO vet_specialties VALUES (5, 1);
|
||||||
|
|
||||||
|
INSERT INTO types VALUES (default, 'cat');
|
||||||
|
INSERT INTO types VALUES (default, 'dog');
|
||||||
|
INSERT INTO types VALUES (default, 'lizard');
|
||||||
|
INSERT INTO types VALUES (default, 'snake');
|
||||||
|
INSERT INTO types VALUES (default, 'bird');
|
||||||
|
INSERT INTO types VALUES (default, 'hamster');
|
||||||
|
|
||||||
|
INSERT INTO owners VALUES (default, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023');
|
||||||
|
INSERT INTO owners VALUES (default, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749');
|
||||||
|
INSERT INTO owners VALUES (default, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763');
|
||||||
|
INSERT INTO owners VALUES (default, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198');
|
||||||
|
INSERT INTO owners VALUES (default, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765');
|
||||||
|
INSERT INTO owners VALUES (default, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654');
|
||||||
|
INSERT INTO owners VALUES (default, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387');
|
||||||
|
INSERT INTO owners VALUES (default, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683');
|
||||||
|
INSERT INTO owners VALUES (default, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||||
|
INSERT INTO owners VALUES (default, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||||
|
|
||||||
|
INSERT INTO pets VALUES (default, 'Leo', '2010-09-07', 1, 1);
|
||||||
|
INSERT INTO pets VALUES (default, 'Basil', '2012-08-06', 6, 2);
|
||||||
|
INSERT INTO pets VALUES (default, 'Rosy', '2011-04-17', 2, 3);
|
||||||
|
INSERT INTO pets VALUES (default, 'Jewel', '2010-03-07', 2, 3);
|
||||||
|
INSERT INTO pets VALUES (default, 'Iggy', '2010-11-30', 3, 4);
|
||||||
|
INSERT INTO pets VALUES (default, 'George', '2010-01-20', 4, 5);
|
||||||
|
INSERT INTO pets VALUES (default, 'Samantha', '2012-09-04', 1, 6);
|
||||||
|
INSERT INTO pets VALUES (default, 'Max', '2012-09-04', 1, 6);
|
||||||
|
INSERT INTO pets VALUES (default, 'Lucky', '2011-08-06', 5, 7);
|
||||||
|
INSERT INTO pets VALUES (default, 'Mulligan', '2007-02-24', 2, 8);
|
||||||
|
INSERT INTO pets VALUES (default, 'Freddy', '2010-03-09', 5, 9);
|
||||||
|
INSERT INTO pets VALUES (default, 'Lucky', '2010-06-24', 2, 10);
|
||||||
|
INSERT INTO pets VALUES (default, 'Sly', '2012-06-08', 1, 10);
|
||||||
|
|
||||||
|
INSERT INTO visits VALUES (default, 7, '2013-01-01', 'rabies shot');
|
||||||
|
INSERT INTO visits VALUES (default, 8, '2013-01-02', 'rabies shot');
|
||||||
|
INSERT INTO visits VALUES (default, 8, '2013-01-03', 'neutered');
|
||||||
|
INSERT INTO visits VALUES (default, 7, '2013-01-04', 'spayed');
|
||||||
65
src/main/resources/db/h2/schema.sql
Normal file
65
src/main/resources/db/h2/schema.sql
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
DROP TABLE vet_specialties IF EXISTS;
|
||||||
|
DROP TABLE vets IF EXISTS;
|
||||||
|
DROP TABLE specialties IF EXISTS;
|
||||||
|
DROP TABLE visits IF EXISTS;
|
||||||
|
DROP TABLE pets IF EXISTS;
|
||||||
|
DROP TABLE types IF EXISTS;
|
||||||
|
DROP TABLE owners IF EXISTS;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE vets (
|
||||||
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
first_name VARCHAR(30),
|
||||||
|
last_name VARCHAR(30)
|
||||||
|
);
|
||||||
|
CREATE INDEX vets_last_name ON vets (last_name);
|
||||||
|
|
||||||
|
CREATE TABLE specialties (
|
||||||
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name VARCHAR(80)
|
||||||
|
);
|
||||||
|
CREATE INDEX specialties_name ON specialties (name);
|
||||||
|
|
||||||
|
CREATE TABLE vet_specialties (
|
||||||
|
vet_id INTEGER NOT NULL,
|
||||||
|
specialty_id INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets (id);
|
||||||
|
ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties (id);
|
||||||
|
|
||||||
|
CREATE TABLE types (
|
||||||
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name VARCHAR(80)
|
||||||
|
);
|
||||||
|
CREATE INDEX types_name ON types (name);
|
||||||
|
|
||||||
|
CREATE TABLE owners (
|
||||||
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
first_name VARCHAR(30),
|
||||||
|
last_name VARCHAR_IGNORECASE(30),
|
||||||
|
address VARCHAR(255),
|
||||||
|
city VARCHAR(80),
|
||||||
|
telephone VARCHAR(20)
|
||||||
|
);
|
||||||
|
CREATE INDEX owners_last_name ON owners (last_name);
|
||||||
|
|
||||||
|
CREATE TABLE pets (
|
||||||
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name VARCHAR_IGNORECASE(30),
|
||||||
|
birth_date DATE,
|
||||||
|
type_id INTEGER NOT NULL,
|
||||||
|
owner_id INTEGER
|
||||||
|
);
|
||||||
|
ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id);
|
||||||
|
ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id);
|
||||||
|
ALTER TABLE pets ADD CONSTRAINT unique_owner_pet_name UNIQUE (owner_id, name);
|
||||||
|
CREATE INDEX pets_name ON pets (name);
|
||||||
|
|
||||||
|
CREATE TABLE visits (
|
||||||
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
pet_id INTEGER,
|
||||||
|
visit_date DATE,
|
||||||
|
description VARCHAR(255)
|
||||||
|
);
|
||||||
|
ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
||||||
|
CREATE INDEX visits_pet_id ON visits (pet_id);
|
||||||
53
src/main/resources/db/mysql/data.sql
Normal file
53
src/main/resources/db/mysql/data.sql
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
INSERT IGNORE INTO vets VALUES (1, 'James', 'Carter');
|
||||||
|
INSERT IGNORE INTO vets VALUES (2, 'Helen', 'Leary');
|
||||||
|
INSERT IGNORE INTO vets VALUES (3, 'Linda', 'Douglas');
|
||||||
|
INSERT IGNORE INTO vets VALUES (4, 'Rafael', 'Ortega');
|
||||||
|
INSERT IGNORE INTO vets VALUES (5, 'Henry', 'Stevens');
|
||||||
|
INSERT IGNORE INTO vets VALUES (6, 'Sharon', 'Jenkins');
|
||||||
|
|
||||||
|
INSERT IGNORE INTO specialties VALUES (1, 'radiology');
|
||||||
|
INSERT IGNORE INTO specialties VALUES (2, 'surgery');
|
||||||
|
INSERT IGNORE INTO specialties VALUES (3, 'dentistry');
|
||||||
|
|
||||||
|
INSERT IGNORE INTO vet_specialties VALUES (2, 1);
|
||||||
|
INSERT IGNORE INTO vet_specialties VALUES (3, 2);
|
||||||
|
INSERT IGNORE INTO vet_specialties VALUES (3, 3);
|
||||||
|
INSERT IGNORE INTO vet_specialties VALUES (4, 2);
|
||||||
|
INSERT IGNORE INTO vet_specialties VALUES (5, 1);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO types VALUES (1, 'cat');
|
||||||
|
INSERT IGNORE INTO types VALUES (2, 'dog');
|
||||||
|
INSERT IGNORE INTO types VALUES (3, 'lizard');
|
||||||
|
INSERT IGNORE INTO types VALUES (4, 'snake');
|
||||||
|
INSERT IGNORE INTO types VALUES (5, 'bird');
|
||||||
|
INSERT IGNORE INTO types VALUES (6, 'hamster');
|
||||||
|
|
||||||
|
INSERT IGNORE INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023');
|
||||||
|
INSERT IGNORE INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749');
|
||||||
|
INSERT IGNORE INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763');
|
||||||
|
INSERT IGNORE INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198');
|
||||||
|
INSERT IGNORE INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765');
|
||||||
|
INSERT IGNORE INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654');
|
||||||
|
INSERT IGNORE INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387');
|
||||||
|
INSERT IGNORE INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683');
|
||||||
|
INSERT IGNORE INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||||
|
INSERT IGNORE INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||||
|
|
||||||
|
INSERT IGNORE INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1);
|
||||||
|
INSERT IGNORE INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2);
|
||||||
|
INSERT IGNORE INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3);
|
||||||
|
INSERT IGNORE INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3);
|
||||||
|
INSERT IGNORE INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4);
|
||||||
|
INSERT IGNORE INTO pets VALUES (6, 'George', '2000-01-20', 4, 5);
|
||||||
|
INSERT IGNORE INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6);
|
||||||
|
INSERT IGNORE INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6);
|
||||||
|
INSERT IGNORE INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7);
|
||||||
|
INSERT IGNORE INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8);
|
||||||
|
INSERT IGNORE INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9);
|
||||||
|
INSERT IGNORE INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10);
|
||||||
|
INSERT IGNORE INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot');
|
||||||
|
INSERT IGNORE INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot');
|
||||||
|
INSERT IGNORE INTO visits VALUES (3, 8, '2009-06-04', 'neutered');
|
||||||
|
INSERT IGNORE INTO visits VALUES (4, 7, '2008-09-04', 'spayed');
|
||||||
36
src/main/resources/db/mysql/petclinic_db_setup_mysql.txt
Normal file
36
src/main/resources/db/mysql/petclinic_db_setup_mysql.txt
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
================================================================================
|
||||||
|
=== Spring PetClinic sample application - MySQL Configuration ===
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
@author Sam Brannen
|
||||||
|
@author Costin Leau
|
||||||
|
@author Dave Syer
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
1) Download and install the MySQL database (e.g., MySQL Community Server 5.1.x),
|
||||||
|
which can be found here: https://dev.mysql.com/downloads/. Or run the
|
||||||
|
"docker-compose.yml" from the root of the project (if you have docker installed
|
||||||
|
locally):
|
||||||
|
|
||||||
|
$ docker-compose up
|
||||||
|
...
|
||||||
|
mysql_1_eedb4818d817 | MySQL init process done. Ready for start up.
|
||||||
|
...
|
||||||
|
|
||||||
|
2) (Once only) create the PetClinic database and user by executing the "db/mysql/user.sql"
|
||||||
|
scripts. You can connect to the database running in the docker container using
|
||||||
|
`mysql -u root -h localhost --protocol tcp`, but you don't need to run the script there
|
||||||
|
because the petclinic user is already set up if you use the provided `docker-compose.yml`.
|
||||||
|
|
||||||
|
3) Run the app with `spring.profiles.active=mysql` (e.g. as a System property via the command
|
||||||
|
line, but any way that sets that property in a Spring Boot app should work). For example use
|
||||||
|
|
||||||
|
mvn spring-boot:run -Dspring-boot.run.profiles=mysql
|
||||||
|
|
||||||
|
To activate the profile on the command line.
|
||||||
|
|
||||||
|
N.B. the "petclinic" database has to exist for the app to work with the JDBC URL value
|
||||||
|
as it is configured by default. This condition is taken care of automatically by the
|
||||||
|
docker-compose configuration provided, or by the `user.sql` script if you run that as
|
||||||
|
root.
|
||||||
56
src/main/resources/db/mysql/schema.sql
Normal file
56
src/main/resources/db/mysql/schema.sql
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS vets (
|
||||||
|
id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
first_name VARCHAR(30),
|
||||||
|
last_name VARCHAR(30),
|
||||||
|
INDEX(last_name)
|
||||||
|
) engine=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS specialties (
|
||||||
|
id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(80),
|
||||||
|
INDEX(name)
|
||||||
|
) engine=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS vet_specialties (
|
||||||
|
vet_id INT(4) UNSIGNED NOT NULL,
|
||||||
|
specialty_id INT(4) UNSIGNED NOT NULL,
|
||||||
|
FOREIGN KEY (vet_id) REFERENCES vets(id),
|
||||||
|
FOREIGN KEY (specialty_id) REFERENCES specialties(id),
|
||||||
|
UNIQUE (vet_id,specialty_id)
|
||||||
|
) engine=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS types (
|
||||||
|
id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(80),
|
||||||
|
INDEX(name)
|
||||||
|
) engine=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS owners (
|
||||||
|
id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
first_name VARCHAR(30),
|
||||||
|
last_name VARCHAR(30),
|
||||||
|
address VARCHAR(255),
|
||||||
|
city VARCHAR(80),
|
||||||
|
telephone VARCHAR(20),
|
||||||
|
INDEX(last_name)
|
||||||
|
) engine=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS pets (
|
||||||
|
id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(30),
|
||||||
|
birth_date DATE,
|
||||||
|
type_id INT(4) UNSIGNED NOT NULL,
|
||||||
|
owner_id INT(4) UNSIGNED,
|
||||||
|
INDEX(name),
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES owners(id),
|
||||||
|
FOREIGN KEY (type_id) REFERENCES types(id),
|
||||||
|
UNIQUE (owner_id, name)
|
||||||
|
) engine=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS visits (
|
||||||
|
id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
pet_id INT(4) UNSIGNED,
|
||||||
|
visit_date DATE,
|
||||||
|
description VARCHAR(255),
|
||||||
|
FOREIGN KEY (pet_id) REFERENCES pets(id)
|
||||||
|
) engine=InnoDB;
|
||||||
11
src/main/resources/db/mysql/user.sql
Normal file
11
src/main/resources/db/mysql/user.sql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
CREATE DATABASE IF NOT EXISTS petclinic;
|
||||||
|
|
||||||
|
ALTER DATABASE petclinic
|
||||||
|
DEFAULT CHARACTER SET utf8
|
||||||
|
DEFAULT COLLATE utf8_general_ci;
|
||||||
|
|
||||||
|
CREATE USER IF NOT EXISTS 'petclinic'@'%' IDENTIFIED BY 'petclinic';
|
||||||
|
|
||||||
|
GRANT ALL PRIVILEGES ON petclinic.* TO 'petclinic'@'%';
|
||||||
|
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
53
src/main/resources/db/postgres/data.sql
Normal file
53
src/main/resources/db/postgres/data.sql
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
INSERT INTO vets (first_name, last_name) SELECT 'James', 'Carter' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=1);
|
||||||
|
INSERT INTO vets (first_name, last_name) SELECT 'Helen', 'Leary' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=2);
|
||||||
|
INSERT INTO vets (first_name, last_name) SELECT 'Linda', 'Douglas' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=3);
|
||||||
|
INSERT INTO vets (first_name, last_name) SELECT 'Rafael', 'Ortega' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=4);
|
||||||
|
INSERT INTO vets (first_name, last_name) SELECT 'Henry', 'Stevens' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=5);
|
||||||
|
INSERT INTO vets (first_name, last_name) SELECT 'Sharon', 'Jenkins' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=6);
|
||||||
|
|
||||||
|
INSERT INTO specialties (name) SELECT 'radiology' WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='radiology');
|
||||||
|
INSERT INTO specialties (name) SELECT 'surgery' WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='surgery');
|
||||||
|
INSERT INTO specialties (name) SELECT 'dentistry' WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='dentistry');
|
||||||
|
|
||||||
|
INSERT INTO vet_specialties VALUES (2, 1) ON CONFLICT (vet_id, specialty_id) DO NOTHING;
|
||||||
|
INSERT INTO vet_specialties VALUES (3, 2) ON CONFLICT (vet_id, specialty_id) DO NOTHING;
|
||||||
|
INSERT INTO vet_specialties VALUES (3, 3) ON CONFLICT (vet_id, specialty_id) DO NOTHING;
|
||||||
|
INSERT INTO vet_specialties VALUES (4, 2) ON CONFLICT (vet_id, specialty_id) DO NOTHING;
|
||||||
|
INSERT INTO vet_specialties VALUES (5, 1) ON CONFLICT (vet_id, specialty_id) DO NOTHING;
|
||||||
|
|
||||||
|
INSERT INTO types (name) SELECT 'cat' WHERE NOT EXISTS (SELECT * FROM types WHERE name='cat');
|
||||||
|
INSERT INTO types (name) SELECT 'dog' WHERE NOT EXISTS (SELECT * FROM types WHERE name='dog');
|
||||||
|
INSERT INTO types (name) SELECT 'lizard' WHERE NOT EXISTS (SELECT * FROM types WHERE name='lizard');
|
||||||
|
INSERT INTO types (name) SELECT 'snake' WHERE NOT EXISTS (SELECT * FROM types WHERE name='snake');
|
||||||
|
INSERT INTO types (name) SELECT 'bird' WHERE NOT EXISTS (SELECT * FROM types WHERE name='bird');
|
||||||
|
INSERT INTO types (name) SELECT 'hamster' WHERE NOT EXISTS (SELECT * FROM types WHERE name='hamster');
|
||||||
|
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=1);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=2);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=3);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=4);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=5);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=6);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=7);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=8);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=9);
|
||||||
|
INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=10);
|
||||||
|
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Leo', '2000-09-07', 1, 1 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=1);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Basil', '2002-08-06', 6, 2 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=2);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Rosy', '2001-04-17', 2, 3 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=3);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Jewel', '2000-03-07', 2, 3 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=4);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Iggy', '2000-11-30', 3, 4 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=5);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'George', '2000-01-20', 4, 5 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=6);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Samantha', '1995-09-04', 1, 6 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=7);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Max', '1995-09-04', 1, 6 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=8);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Lucky', '1999-08-06', 5, 7 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=9);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Mulligan', '1997-02-24', 2, 8 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=10);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Freddy', '2000-03-09', 5, 9 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=11);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Lucky', '2000-06-24', 2, 10 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=12);
|
||||||
|
INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Sly', '2002-06-08', 1, 10 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=13);
|
||||||
|
|
||||||
|
INSERT INTO visits (pet_id, visit_date, description) SELECT 7, '2010-03-04', 'rabies shot' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=1);
|
||||||
|
INSERT INTO visits (pet_id, visit_date, description) SELECT 8, '2011-03-04', 'rabies shot' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=2);
|
||||||
|
INSERT INTO visits (pet_id, visit_date, description) SELECT 8, '2009-06-04', 'neutered' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=3);
|
||||||
|
INSERT INTO visits (pet_id, visit_date, description) SELECT 7, '2008-09-04', 'spayed' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=4);
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
===============================================================================
|
||||||
|
=== Spring PetClinic sample application - PostgreSQL Configuration ===
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
1) Run the "docker-compose.yml" from the root of the project:
|
||||||
|
|
||||||
|
$ docker-compose up
|
||||||
|
...
|
||||||
|
spring-petclinic-postgres-1 | The files belonging to this database system will be owned by user "postgres".
|
||||||
|
...
|
||||||
|
|
||||||
|
2) Run the app with `spring.profiles.active=postgres` (e.g. as a System property via the command
|
||||||
|
line, but any way that sets that property in a Spring Boot app should work). For example use
|
||||||
|
|
||||||
|
mvn spring-boot:run -Dspring-boot.run.profiles=postgres
|
||||||
|
|
||||||
|
To activate the profile on the command line.
|
||||||
53
src/main/resources/db/postgres/schema.sql
Normal file
53
src/main/resources/db/postgres/schema.sql
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS vets (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
first_name TEXT,
|
||||||
|
last_name TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_vets_last_name ON vets (last_name);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS specialties (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_specialties_name ON specialties (name);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS vet_specialties (
|
||||||
|
vet_id INT NOT NULL REFERENCES vets (id),
|
||||||
|
specialty_id INT NOT NULL REFERENCES specialties (id),
|
||||||
|
UNIQUE (vet_id, specialty_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS types (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_types_name ON types (name);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS owners (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
first_name TEXT,
|
||||||
|
last_name TEXT,
|
||||||
|
address TEXT,
|
||||||
|
city TEXT,
|
||||||
|
telephone TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_owners_last_name ON owners (last_name);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS pets (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
name TEXT,
|
||||||
|
birth_date DATE,
|
||||||
|
type_id INT NOT NULL REFERENCES types (id),
|
||||||
|
owner_id INT REFERENCES owners (id)
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_pets_name ON pets (name);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_pets_owner_id ON pets (owner_id);
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS unique_owner_pet_name ON pets (owner_id, LOWER(name));
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS visits (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||||
|
pet_id INT REFERENCES pets (id),
|
||||||
|
visit_date DATE,
|
||||||
|
description TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_visits_pet_id ON visits (pet_id);
|
||||||
52
src/main/resources/messages/messages.properties
Normal file
52
src/main/resources/messages/messages.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=Welcome
|
||||||
|
required=is required
|
||||||
|
notFound=has not been found
|
||||||
|
duplicate=is already in use
|
||||||
|
nonNumeric=must be all numeric
|
||||||
|
duplicateFormSubmission=Duplicate form submission is not allowed
|
||||||
|
typeMismatch.date=invalid date
|
||||||
|
typeMismatch.birthDate=invalid date
|
||||||
|
typeMismatch.visitDate=Visit date must be in the future
|
||||||
|
owner=Owner
|
||||||
|
firstName=First Name
|
||||||
|
lastName=Last Name
|
||||||
|
address=Address
|
||||||
|
city=City
|
||||||
|
telephone=Telephone
|
||||||
|
owners=Owners
|
||||||
|
addOwner=Add Owner
|
||||||
|
findOwner=Find Owner
|
||||||
|
findOwners=Find Owners
|
||||||
|
updateOwner=Update Owner
|
||||||
|
vets=Veterinarians
|
||||||
|
name=Name
|
||||||
|
specialties=Specialties
|
||||||
|
none=none
|
||||||
|
pages=pages
|
||||||
|
first=First
|
||||||
|
next=Next
|
||||||
|
previous=Previous
|
||||||
|
last=Last
|
||||||
|
somethingHappened=Something happened...
|
||||||
|
pets=Pets
|
||||||
|
home=Home
|
||||||
|
error=Error
|
||||||
|
telephone.invalid=Telephone must be a 10-digit number
|
||||||
|
layoutTitle=PetClinic :: a Spring Framework demonstration
|
||||||
|
pet=Pet
|
||||||
|
birthDate=Birth Date
|
||||||
|
type=Type
|
||||||
|
previousVisits=Previous Visits
|
||||||
|
date=Date
|
||||||
|
description=Description
|
||||||
|
new=New
|
||||||
|
addVisit=Add Visit
|
||||||
|
editPet=Edit Pet
|
||||||
|
ownerInformation=Owner Information
|
||||||
|
visitDate=Visit Date
|
||||||
|
editOwner=Edit Owner
|
||||||
|
addNewPet=Add New Pet
|
||||||
|
petsAndVisits=Pets and Visits
|
||||||
|
error.404=The requested page was not found.
|
||||||
|
error.500=An internal server error occurred.
|
||||||
|
error.general=An unexpected error occurred.
|
||||||
52
src/main/resources/messages/messages_de.properties
Normal file
52
src/main/resources/messages/messages_de.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=Willkommen
|
||||||
|
required=muss angegeben werden
|
||||||
|
notFound=wurde nicht gefunden
|
||||||
|
duplicate=ist bereits vergeben
|
||||||
|
nonNumeric=darf nur numerisch sein
|
||||||
|
duplicateFormSubmission=Wiederholtes Absenden des Formulars ist nicht erlaubt
|
||||||
|
typeMismatch.date=ung<EFBFBD>ltiges Datum
|
||||||
|
typeMismatch.birthDate=ung<EFBFBD>ltiges Datum
|
||||||
|
typeMismatch.visitDate=Das Besuchsdatum muss in der Zukunft liegen
|
||||||
|
owner=Besitzer
|
||||||
|
firstName=Vorname
|
||||||
|
lastName=Nachname
|
||||||
|
address=Adresse
|
||||||
|
city=Stadt
|
||||||
|
telephone=Telefon
|
||||||
|
owners=Besitzer
|
||||||
|
addOwner=Besitzer hinzufügen
|
||||||
|
findOwner=Besitzer finden
|
||||||
|
findOwners=Besitzer suchen
|
||||||
|
updateOwner=Besitzer aktualisieren
|
||||||
|
vets=Tierärzte
|
||||||
|
name=Name
|
||||||
|
specialties=Fachgebiete
|
||||||
|
none=keine
|
||||||
|
pages=Seiten
|
||||||
|
first=Erste
|
||||||
|
next=Nächste
|
||||||
|
previous=Vorherige
|
||||||
|
last=Letzte
|
||||||
|
somethingHappened=Etwas ist passiert...
|
||||||
|
pets=Haustiere
|
||||||
|
home=Startseite
|
||||||
|
error=Fehler
|
||||||
|
telephone.invalid=Telefonnummer muss aus 10 Ziffern bestehen
|
||||||
|
layoutTitle=PetClinic :: eine Demonstration des Spring Frameworks
|
||||||
|
pet=Haustier
|
||||||
|
birthDate=Geburtsdatum
|
||||||
|
type=Typ
|
||||||
|
previousVisits=Frühere Besuche
|
||||||
|
date=Datum
|
||||||
|
description=Beschreibung
|
||||||
|
new=Neu
|
||||||
|
addVisit=Besuch hinzufügen
|
||||||
|
editPet=Haustier bearbeiten
|
||||||
|
ownerInformation=Besitzerinformationen
|
||||||
|
visitDate=Besuchsdatum
|
||||||
|
editOwner=Besitzer bearbeiten
|
||||||
|
addNewPet=Neues Haustier hinzufügen
|
||||||
|
petsAndVisits=Haustiere und Besuche
|
||||||
|
error.404=Die angeforderte Seite wurde nicht gefunden.
|
||||||
|
error.500=Ein interner Serverfehler ist aufgetreten.
|
||||||
|
error.general=Ein unerwarteter Fehler ist aufgetreten.
|
||||||
1
src/main/resources/messages/messages_en.properties
Normal file
1
src/main/resources/messages/messages_en.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# This file is intentionally empty. Message look-ups will fall back to the default "messages.properties" file.
|
||||||
52
src/main/resources/messages/messages_es.properties
Normal file
52
src/main/resources/messages/messages_es.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=Bienvenido
|
||||||
|
required=Es requerido
|
||||||
|
notFound=No ha sido encontrado
|
||||||
|
duplicate=Ya se encuentra en uso
|
||||||
|
nonNumeric=Sólo debe contener numeros
|
||||||
|
duplicateFormSubmission=No se permite el envío de formularios duplicados
|
||||||
|
typeMismatch.date=Fecha invalida
|
||||||
|
typeMismatch.birthDate=Fecha invalida
|
||||||
|
typeMismatch.visitDate=La fecha de la visita debe ser futura
|
||||||
|
owner=Propietario
|
||||||
|
firstName=Nombre
|
||||||
|
lastName=Apellido
|
||||||
|
address=Dirección
|
||||||
|
city=Ciudad
|
||||||
|
telephone=Teléfono
|
||||||
|
owners=Propietarios
|
||||||
|
addOwner=Añadir propietario
|
||||||
|
findOwner=Buscar propietario
|
||||||
|
findOwners=Buscar propietarios
|
||||||
|
updateOwner=Actualizar propietario
|
||||||
|
vets=Veterinarios
|
||||||
|
name=Nombre
|
||||||
|
specialties=Especialidades
|
||||||
|
none=ninguno
|
||||||
|
pages=páginas
|
||||||
|
first=Primero
|
||||||
|
next=Siguiente
|
||||||
|
previous=Anterior
|
||||||
|
last=Último
|
||||||
|
somethingHappened=Algo pasó...
|
||||||
|
pets=Mascotas
|
||||||
|
home=Inicio
|
||||||
|
error=Error
|
||||||
|
telephone.invalid=El número de teléfono debe tener 10 dígitos
|
||||||
|
layoutTitle=PetClinic :: una demostración de Spring Framework
|
||||||
|
pet=Mascota
|
||||||
|
birthDate=Fecha de nacimiento
|
||||||
|
type=Tipo
|
||||||
|
previousVisits=Visitas anteriores
|
||||||
|
date=Fecha
|
||||||
|
description=Descripción
|
||||||
|
new=Nuevo
|
||||||
|
addVisit=Agregar visita
|
||||||
|
editPet=Editar mascota
|
||||||
|
ownerInformation=Información del propietario
|
||||||
|
visitDate=Fecha de visita
|
||||||
|
editOwner=Editar propietario
|
||||||
|
addNewPet=Agregar nueva mascota
|
||||||
|
petsAndVisits=Mascotas y visitas
|
||||||
|
error.404=La página solicitada no fue encontrada.
|
||||||
|
error.500=Ocurrió un error interno del servidor.
|
||||||
|
error.general=Ocurrió un error inesperado.
|
||||||
52
src/main/resources/messages/messages_fa.properties
Normal file
52
src/main/resources/messages/messages_fa.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=خوش آمدید
|
||||||
|
required=الزامی
|
||||||
|
notFound=یافت نشد
|
||||||
|
duplicate=قبلا استفاده شده
|
||||||
|
nonNumeric=باید عددی باشد
|
||||||
|
duplicateFormSubmission=ارسال تکراری فرم مجاز نیست
|
||||||
|
typeMismatch.date=تاریخ نامعتبر
|
||||||
|
typeMismatch.birthDate=تاریخ تولد نامعتبر
|
||||||
|
typeMismatch.visitDate=تاریخ ویزیت باید در آینده باشد
|
||||||
|
owner=مالک
|
||||||
|
firstName=نام
|
||||||
|
lastName=نام خانوادگی
|
||||||
|
address=آدرس
|
||||||
|
city=شهر
|
||||||
|
telephone=تلفن
|
||||||
|
owners=مالکان
|
||||||
|
addOwner=افزودن مالک
|
||||||
|
findOwner=یافتن مالک
|
||||||
|
findOwners=یافتن مالکان
|
||||||
|
updateOwner=ویرایش مالک
|
||||||
|
vets=دامپزشکان
|
||||||
|
name=نام
|
||||||
|
specialties=تخصصها
|
||||||
|
none=هیچکدام
|
||||||
|
pages=صفحات
|
||||||
|
first=اول
|
||||||
|
next=بعدی
|
||||||
|
previous=قبلی
|
||||||
|
last=آخر
|
||||||
|
somethingHappened=مشکلی پیش آمد...
|
||||||
|
pets=حیوانات خانگی
|
||||||
|
home=خانه
|
||||||
|
error=خطا
|
||||||
|
telephone.invalid=شماره تلفن باید ۱۰ رقمی باشد
|
||||||
|
layoutTitle=PetClinic :: یک نمایش از Spring Framework
|
||||||
|
pet=حیوان خانگی
|
||||||
|
birthDate=تاریخ تولد
|
||||||
|
type=نوع
|
||||||
|
previousVisits=ویزیتهای قبلی
|
||||||
|
date=تاریخ
|
||||||
|
description=توضیحات
|
||||||
|
new=جدید
|
||||||
|
addVisit=افزودن ویزیت
|
||||||
|
editPet=ویرایش حیوان خانگی
|
||||||
|
ownerInformation=اطلاعات مالک
|
||||||
|
visitDate=تاریخ ویزیت
|
||||||
|
editOwner=ویرایش مالک
|
||||||
|
addNewPet=افزودن حیوان خانگی جدید
|
||||||
|
petsAndVisits=حیوانات و ویزیتها
|
||||||
|
error.404=صفحه درخواستی پیدا نشد.
|
||||||
|
error.500=خطای داخلی سرور رخ داد.
|
||||||
|
error.general=خطای غیرمنتظرهای رخ داد.
|
||||||
54
src/main/resources/messages/messages_hi.properties
Normal file
54
src/main/resources/messages/messages_hi.properties
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# Hindi properties for PetClinic
|
||||||
|
|
||||||
|
welcome=\u0938\u094D\u0935\u093E\u0917\u0924 \u0939\u0948
|
||||||
|
required=\u0906\u0935\u0936\u094D\u092F\u0915 \u0939\u0948
|
||||||
|
notFound=\u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E
|
||||||
|
duplicate=\u092A\u0939\u0932\u0947 \u0938\u0947 \u092E\u094C\u091C\u0942\u0926 \u0939\u0948
|
||||||
|
nonNumeric=\u0938\u092D\u0940 \u0938\u0902\u0916\u094D\u092F\u093E\u0924\u094D\u092E\u0915 \u0939\u094B\u0928\u093E \u091A\u093E\u0939\u093F\u090F
|
||||||
|
duplicateFormSubmission=\u0921\u0941\u092A\u094D\u0932\u093F\u0915\u0947\u091F \u092B\u093E\u0930\u094D\u092E \u0938\u092C\u092E\u093F\u0936\u0928 \u0915\u0940 \u0905\u0928\u0941\u092E\u0924\u093F \u0928\u0939\u0940\u0902 \u0939\u0948
|
||||||
|
typeMismatch.date=\u0905\u092E\u093E\u0928\u094D\u092F \u0924\u093F\u0925\u093F
|
||||||
|
typeMismatch.birthDate=\u0905\u092E\u093E\u0928\u094D\u092F \u0924\u093F\u0925\u093F
|
||||||
|
typeMismatch.visitDate=\u092D\u0947\u091F\u0940 \u0915\u0940 \u0924\u093E\u0930\u0940\u0916 \u092D\u0935\u093F\u0937\u094D\u092F \u092E\u0947\u0902 \u0939\u094B\u0928\u0940 \u091A\u093E\u0939\u093F\u090F
|
||||||
|
owner=\u092E\u093E\u0932\u093F\u0915
|
||||||
|
firstName=\u092A\u0939\u0932\u093E \u0928\u093E\u092E
|
||||||
|
lastName=\u0905\u0902\u0924\u093F\u092E \u0928\u093E\u092E
|
||||||
|
address=\u092A\u0924\u093E
|
||||||
|
city=\u0936\u0939\u0930
|
||||||
|
telephone=\u091F\u0947\u0932\u0940\u092B\u094B\u0928
|
||||||
|
owners=\u092E\u093E\u0932\u093F\u0915
|
||||||
|
addOwner=\u092E\u093E\u0932\u093F\u0915 \u091C\u094B\u0921\u093C\u0947\u0902
|
||||||
|
findOwner=\u092E\u093E\u0932\u093F\u0915 \u0916\u094B\u091C\u0947\u0902
|
||||||
|
findOwners=\u092E\u093E\u0932\u093F\u0915 \u0916\u094B\u091C\u0947\u0902
|
||||||
|
updateOwner=\u092E\u093E\u0932\u093F\u0915 \u0905\u092A\u0921\u0947\u091F \u0915\u0930\u0947\u0902
|
||||||
|
vets=\u092A\u0936\u0941 \u091A\u093F\u0915\u093F\u0924\u094D\u0938\u0915
|
||||||
|
name=\u0928\u093E\u092E
|
||||||
|
specialties=\u0935\u093F\u0936\u0947\u0937\u0924\u093E\u090F\u0902
|
||||||
|
none=\u0915\u094B\u0908 \u0928\u0939\u0940\u0902
|
||||||
|
pages=\u092A\u0947\u091C
|
||||||
|
first=\u092A\u0939\u0932\u093E
|
||||||
|
next=\u0905\u0917\u0932\u093E
|
||||||
|
previous=\u092A\u093F\u091B\u0932\u093E
|
||||||
|
last=\u0905\u0902\u0924\u093F\u092E
|
||||||
|
somethingHappened=\u0915\u0941\u091B \u0939\u0941\u0906...
|
||||||
|
pets=\u092A\u093E\u0932\u0924\u0942 \u091C\u093E\u0928\u0935\u0930
|
||||||
|
home=\u0918\u0930
|
||||||
|
error=\u0924\u094D\u0930\u0941\u091F\u093F
|
||||||
|
telephone.invalid=\u091F\u0947\u0932\u0940\u092B\u094B\u0928 \u090F\u0915 10-\u0905\u0902\u0915\u094B\u0902 \u0915\u0940 \u0938\u0902\u0916\u094D\u092F\u093E \u0939\u094B\u0928\u0940 \u091A\u093E\u0939\u093F\u090F
|
||||||
|
layoutTitle=PetClinic :: \u090F\u0915 \u0938\u094D\u092A\u094D\u0930\u093F\u0902\u0917 \u092B\u094D\u0930\u0947\u092E\u0935\u0930\u094D\u0915 \u092A\u094D\u0930\u0926\u0930\u094D\u0936\u0928
|
||||||
|
pet=\u092A\u093E\u0932\u0924\u0942 \u091C\u093E\u0928\u0935\u0930
|
||||||
|
birthDate=\u091C\u0928\u094D\u092E \u0924\u093F\u0925\u093F
|
||||||
|
type=\u092A\u094D\u0930\u0915\u093E\u0930
|
||||||
|
previousVisits=\u092A\u093F\u091B\u0932\u0940 \u092F\u093E\u0924\u094D\u0930\u093E\u090F\u0902
|
||||||
|
date=\u0924\u093E\u0930\u0940\u0916
|
||||||
|
description=\u0935\u093F\u0935\u0930\u0923
|
||||||
|
new=\u0928\u092F\u093E
|
||||||
|
addVisit=\u092F\u093E\u0924\u094D\u0930\u093E \u091C\u094B\u0921\u093C\u0947\u0902
|
||||||
|
editPet=\u092A\u093E\u0932\u0924\u0942 \u0938\u0902\u092A\u093E\u0926\u093F\u0924 \u0915\u0930\u0947\u0902
|
||||||
|
ownerInformation=\u092E\u093E\u0932\u093F\u0915 \u0915\u0940 \u091C\u093E\u0928\u0915\u093E\u0930\u0940
|
||||||
|
visitDate=\u092F\u093E\u0924\u094D\u0930\u093E \u0915\u0940 \u0924\u093E\u0930\u0940\u0916
|
||||||
|
editOwner=\u092E\u093E\u0932\u093F\u0915 \u0938\u0902\u092A\u093E\u0926\u093F\u0924 \u0915\u0930\u0947\u0902
|
||||||
|
addNewPet=\u090F\u0915 \u0928\u092F\u093E \u092A\u093E\u0932\u0924\u0942 \u091C\u094B\u0921\u093C\u0947\u0902
|
||||||
|
petsAndVisits=\u092A\u093E\u0932\u0924\u0942 \u0914\u0930 \u092F\u093E\u0924\u094D\u0930\u093E\u090F\u0902
|
||||||
|
error.404=\u0905\u0928\u0941\u0930\u094B\u0927\u093F\u0924 \u092A\u0943\u0937\u094D\u0920 \u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E\u0964
|
||||||
|
error.500=\u090F\u0915 \u0906\u0902\u0924\u0930\u093F\u0915 \u0938\u0930\u094D\u0935\u0930 \u0924\u094D\u0930\u0941\u091F\u093F \u0939\u0941\u0906\u0964
|
||||||
|
error.general=\u090F\u0915 \u0905\u092A\u094D\u0930\u0924\u094D\u092F\u093E\u0936\u093F\u0924 \u0924\u094D\u0930\u0941\u091F\u093F \u0939\u0941\u0906\u0964
|
||||||
54
src/main/resources/messages/messages_ja.properties
Normal file
54
src/main/resources/messages/messages_ja.properties
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# Japanese properties for PetClinic
|
||||||
|
|
||||||
|
welcome=ようこそ
|
||||||
|
required=必須です
|
||||||
|
notFound=見つかりません
|
||||||
|
duplicate=既に使用されています
|
||||||
|
nonNumeric=数字のみで入力してください
|
||||||
|
duplicateFormSubmission=重複したフォーム送信は許可されていません
|
||||||
|
typeMismatch.date=無効な日付です
|
||||||
|
typeMismatch.birthDate=無効な日付です
|
||||||
|
typeMismatch.visitDate=診察日は未来の日付である必要があります
|
||||||
|
owner=オーナー
|
||||||
|
firstName=名
|
||||||
|
lastName=姓
|
||||||
|
address=住所
|
||||||
|
city=市区町村
|
||||||
|
telephone=電話番号
|
||||||
|
owners=オーナー一覧
|
||||||
|
addOwner=オーナーを追加
|
||||||
|
findOwner=オーナーを検索
|
||||||
|
findOwners=オーナーを検索
|
||||||
|
updateOwner=オーナーを更新
|
||||||
|
vets=獣医師
|
||||||
|
name=名前
|
||||||
|
specialties=専門分野
|
||||||
|
none=なし
|
||||||
|
pages=ページ
|
||||||
|
first=最初
|
||||||
|
next=次へ
|
||||||
|
previous=前へ
|
||||||
|
last=最後
|
||||||
|
somethingHappened=問題が発生しました...
|
||||||
|
pets=ペット
|
||||||
|
home=ホーム
|
||||||
|
error=エラー
|
||||||
|
telephone.invalid=電話番号は10桁の数字で入力してください
|
||||||
|
layoutTitle=PetClinic :: Spring Framework デモ
|
||||||
|
pet=ペット
|
||||||
|
birthDate=生年月日
|
||||||
|
type=種類
|
||||||
|
previousVisits=以前の診察
|
||||||
|
date=日付
|
||||||
|
description=説明
|
||||||
|
new=新規
|
||||||
|
addVisit=診察を追加
|
||||||
|
editPet=ペットを編集
|
||||||
|
ownerInformation=オーナー情報
|
||||||
|
visitDate=診察日
|
||||||
|
editOwner=オーナーを編集
|
||||||
|
addNewPet=新しいペットを追加
|
||||||
|
petsAndVisits=ペットと診察
|
||||||
|
error.404=リクエストされたページが見つかりませんでした。
|
||||||
|
error.500=サーバー内部エラーが発生しました。
|
||||||
|
error.general=予期しないエラーが発生しました。
|
||||||
52
src/main/resources/messages/messages_ko.properties
Normal file
52
src/main/resources/messages/messages_ko.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=환영합니다
|
||||||
|
required=입력이 필요합니다
|
||||||
|
notFound=찾을 수 없습니다
|
||||||
|
duplicate=이미 존재합니다
|
||||||
|
nonNumeric=모두 숫자로 입력해야 합니다
|
||||||
|
duplicateFormSubmission=중복 제출은 허용되지 않습니다
|
||||||
|
typeMismatch.date=잘못된 날짜입니다
|
||||||
|
typeMismatch.birthDate=잘못된 날짜입니다
|
||||||
|
typeMismatch.visitDate=방문 날짜는 미래 날짜여야 합니다
|
||||||
|
owner=소유자
|
||||||
|
firstName=이름
|
||||||
|
lastName=성
|
||||||
|
address=주소
|
||||||
|
city=도시
|
||||||
|
telephone=전화번호
|
||||||
|
owners=소유자 목록
|
||||||
|
addOwner=소유자 추가
|
||||||
|
findOwner=소유자 찾기
|
||||||
|
findOwners=소유자들 찾기
|
||||||
|
updateOwner=소유자 수정
|
||||||
|
vets=수의사
|
||||||
|
name=이름
|
||||||
|
specialties=전문 분야
|
||||||
|
none=없음
|
||||||
|
pages=페이지
|
||||||
|
first=첫 번째
|
||||||
|
next=다음
|
||||||
|
previous=이전
|
||||||
|
last=마지막
|
||||||
|
somethingHappened=문제가 발생했습니다...
|
||||||
|
pets=반려동물
|
||||||
|
home=홈
|
||||||
|
error=오류
|
||||||
|
telephone.invalid=전화번호는 10자리 숫자여야 합니다
|
||||||
|
layoutTitle=PetClinic :: Spring Framework 데모
|
||||||
|
pet=반려동물
|
||||||
|
birthDate=생년월일
|
||||||
|
type=종류
|
||||||
|
previousVisits=이전 방문
|
||||||
|
date=날짜
|
||||||
|
description=설명
|
||||||
|
new=새로운
|
||||||
|
addVisit=방문 추가
|
||||||
|
editPet=반려동물 수정
|
||||||
|
ownerInformation=소유자 정보
|
||||||
|
visitDate=방문 날짜
|
||||||
|
editOwner=소유자 수정
|
||||||
|
addNewPet=새 반려동물 추가
|
||||||
|
petsAndVisits=반려동물 및 방문
|
||||||
|
error.404=요청하신 페이지를 찾을 수 없습니다.
|
||||||
|
error.500=서버 내부 오류가 발생했습니다.
|
||||||
|
error.general=알 수 없는 오류가 발생했습니다.
|
||||||
52
src/main/resources/messages/messages_pt.properties
Normal file
52
src/main/resources/messages/messages_pt.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=Bem-vindo
|
||||||
|
required=E necessario
|
||||||
|
notFound=Nao foi encontrado
|
||||||
|
duplicate=Ja esta em uso
|
||||||
|
nonNumeric=Deve ser tudo numerico
|
||||||
|
duplicateFormSubmission=O envio duplicado de formulario nao e permitido
|
||||||
|
typeMismatch.date=Data invalida
|
||||||
|
typeMismatch.birthDate=Data de nascimento invalida
|
||||||
|
typeMismatch.visitDate=A data da visita deve estar no futuro
|
||||||
|
owner=Proprietário
|
||||||
|
firstName=Primeiro Nome
|
||||||
|
lastName=Sobrenome
|
||||||
|
address=Endereço
|
||||||
|
city=Cidade
|
||||||
|
telephone=Telefone
|
||||||
|
owners=Proprietários
|
||||||
|
addOwner=Adicionar proprietário
|
||||||
|
findOwner=Encontrar proprietário
|
||||||
|
findOwners=Encontrar proprietários
|
||||||
|
updateOwner=Atualizar proprietário
|
||||||
|
vets=Veterinários
|
||||||
|
name=Nome
|
||||||
|
specialties=Especialidades
|
||||||
|
none=nenhum
|
||||||
|
pages=páginas
|
||||||
|
first=Primeiro
|
||||||
|
next=Próximo
|
||||||
|
previous=Anterior
|
||||||
|
last=Último
|
||||||
|
somethingHappened=Algo aconteceu...
|
||||||
|
pets=Animais de estimação
|
||||||
|
home=Início
|
||||||
|
error=Erro
|
||||||
|
telephone.invalid=O número de telefone deve conter 10 dígitos
|
||||||
|
layoutTitle=PetClinic :: uma demonstração do Spring Framework
|
||||||
|
pet=Animal de estimação
|
||||||
|
birthDate=Data de nascimento
|
||||||
|
type=Tipo
|
||||||
|
previousVisits=Visitas anteriores
|
||||||
|
date=Data
|
||||||
|
description=Descrição
|
||||||
|
new=Novo
|
||||||
|
addVisit=Adicionar visita
|
||||||
|
editPet=Editar animal
|
||||||
|
ownerInformation=Informações do proprietário
|
||||||
|
visitDate=Data da visita
|
||||||
|
editOwner=Editar proprietário
|
||||||
|
addNewPet=Adicionar novo animal
|
||||||
|
petsAndVisits=Animais e visitas
|
||||||
|
error.404=A página solicitada não foi encontrada.
|
||||||
|
error.500=Ocorreu um erro interno no servidor.
|
||||||
|
error.general=Ocorreu um erro inesperado.
|
||||||
52
src/main/resources/messages/messages_ru.properties
Normal file
52
src/main/resources/messages/messages_ru.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=Добро пожаловать
|
||||||
|
required=необходимо
|
||||||
|
notFound=не найдено
|
||||||
|
duplicate=уже используется
|
||||||
|
nonNumeric=должно быть все числовое значение
|
||||||
|
duplicateFormSubmission=Дублирование формы не допускается
|
||||||
|
typeMismatch.date=неправильная даные
|
||||||
|
typeMismatch.birthDate=неправильная дата
|
||||||
|
typeMismatch.visitDate=Дата визита должна быть в будущем
|
||||||
|
owner=Владелец
|
||||||
|
firstName=Имя
|
||||||
|
lastName=Фамилия
|
||||||
|
address=Адрес
|
||||||
|
city=Город
|
||||||
|
telephone=Телефон
|
||||||
|
owners=Владельцы
|
||||||
|
addOwner=Добавить владельца
|
||||||
|
findOwner=Найти владельца
|
||||||
|
findOwners=Найти владельцев
|
||||||
|
updateOwner=Обновить владельца
|
||||||
|
vets=Ветеринары
|
||||||
|
name=Имя
|
||||||
|
specialties=Специальности
|
||||||
|
none=нет
|
||||||
|
pages=страницы
|
||||||
|
first=Первый
|
||||||
|
next=Следующий
|
||||||
|
previous=Предыдущий
|
||||||
|
last=Последний
|
||||||
|
somethingHappened=Что-то пошло не так...
|
||||||
|
pets=Питомцы
|
||||||
|
home=Главная
|
||||||
|
error=Ошибка
|
||||||
|
telephone.invalid=Телефон должен содержать 10 цифр
|
||||||
|
layoutTitle=PetClinic :: демонстрация Spring Framework
|
||||||
|
pet=Питомец
|
||||||
|
birthDate=Дата рождения
|
||||||
|
type=Тип
|
||||||
|
previousVisits=Предыдущие визиты
|
||||||
|
date=Дата
|
||||||
|
description=Описание
|
||||||
|
new=Новый
|
||||||
|
addVisit=Добавить визит
|
||||||
|
editPet=Редактировать питомца
|
||||||
|
ownerInformation=Информация о владельце
|
||||||
|
visitDate=Дата визита
|
||||||
|
editOwner=Редактировать владельца
|
||||||
|
addNewPet=Добавить нового питомца
|
||||||
|
petsAndVisits=Питомцы и визиты
|
||||||
|
error.404=Запрашиваемая страница не найдена.
|
||||||
|
error.500=Произошла внутренняя ошибка сервера.
|
||||||
|
error.general=Произошла непредвиденная ошибка.
|
||||||
52
src/main/resources/messages/messages_tr.properties
Normal file
52
src/main/resources/messages/messages_tr.properties
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
welcome=hoş geldiniz
|
||||||
|
required=gerekli
|
||||||
|
notFound=bulunamadı
|
||||||
|
duplicate=zaten kullanılıyor
|
||||||
|
nonNumeric=sadece sayısal olmalıdır
|
||||||
|
duplicateFormSubmission=Formun tekrar gönderilmesine izin verilmez
|
||||||
|
typeMismatch.date=geçersiz tarih
|
||||||
|
typeMismatch.birthDate=geçersiz tarih
|
||||||
|
typeMismatch.visitDate=Ziyaret tarihi gelecekte olmalıdır
|
||||||
|
owner=Sahip
|
||||||
|
firstName=Ad
|
||||||
|
lastName=Soyad
|
||||||
|
address=Adres
|
||||||
|
city=Şehir
|
||||||
|
telephone=Telefon
|
||||||
|
owners=Sahipler
|
||||||
|
addOwner=Sahip Ekle
|
||||||
|
findOwner=Sahip Bul
|
||||||
|
findOwners=Sahipleri Bul
|
||||||
|
updateOwner=Sahip Güncelle
|
||||||
|
vets=Veterinerler
|
||||||
|
name=İsim
|
||||||
|
specialties=Uzmanlıklar
|
||||||
|
none=yok
|
||||||
|
pages=sayfalar
|
||||||
|
first=İlk
|
||||||
|
next=Sonraki
|
||||||
|
previous=Önceki
|
||||||
|
last=Son
|
||||||
|
somethingHappened=Bir şey oldu...
|
||||||
|
pets=Evcil Hayvanlar
|
||||||
|
home=Ana Sayfa
|
||||||
|
error=Hata
|
||||||
|
telephone.invalid=Telefon numarası 10 basamaklı olmalıdır
|
||||||
|
layoutTitle=PetClinic :: bir Spring Framework demosu
|
||||||
|
pet=Evcil Hayvan
|
||||||
|
birthDate=Doğum Tarihi
|
||||||
|
type=Tür
|
||||||
|
previousVisits=Önceki Ziyaretler
|
||||||
|
date=Tarih
|
||||||
|
description=Açıklama
|
||||||
|
new=Yeni
|
||||||
|
addVisit=Ziyaret Ekle
|
||||||
|
editPet=Evcil Hayvanı Düzenle
|
||||||
|
ownerInformation=Sahip Bilgileri
|
||||||
|
visitDate=Ziyaret Tarihi
|
||||||
|
editOwner=Sahibi Düzenle
|
||||||
|
addNewPet=Yeni Evcil Hayvan Ekle
|
||||||
|
petsAndVisits=Evcil Hayvanlar ve Ziyaretler
|
||||||
|
error.404=İstenen sayfa bulunamadı.
|
||||||
|
error.500=Sunucuda dahili bir hata oluştu.
|
||||||
|
error.general=Beklenmeyen bir hata oluştu.
|
||||||
9532
src/main/resources/static/resources/css/petclinic.css
Normal file
9532
src/main/resources/static/resources/css/petclinic.css
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/main/resources/static/resources/fonts/montserrat-webfont.eot
Normal file
BIN
src/main/resources/static/resources/fonts/montserrat-webfont.eot
Normal file
Binary file not shown.
1283
src/main/resources/static/resources/fonts/montserrat-webfont.svg
Normal file
1283
src/main/resources/static/resources/fonts/montserrat-webfont.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 83 KiB |
BIN
src/main/resources/static/resources/fonts/montserrat-webfont.ttf
Normal file
BIN
src/main/resources/static/resources/fonts/montserrat-webfont.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
7875
src/main/resources/static/resources/fonts/varela_round-webfont.svg
Normal file
7875
src/main/resources/static/resources/fonts/varela_round-webfont.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 362 KiB |
Binary file not shown.
Binary file not shown.
BIN
src/main/resources/static/resources/images/favicon.png
Normal file
BIN
src/main/resources/static/resources/images/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 528 B |
BIN
src/main/resources/static/resources/images/pets.png
Normal file
BIN
src/main/resources/static/resources/images/pets.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user