Compare commits
53 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90e307a35b | |||
|
|
3082aef1e8 | ||
| 0bc0695d37 | |||
|
|
719ae05a3a | ||
| 8196feb632 | |||
| c83a5b989f | |||
| c332d80080 | |||
| c702dcb009 | |||
| df331da696 | |||
|
|
851e863d85 | ||
|
|
2c09fd84b1 | ||
|
|
822c137eab | ||
| 7ad848f5ce | |||
| 891e9235e4 | |||
| f170c89ebc | |||
| 7ad5a283a8 | |||
| eb89238297 | |||
| 7c43235120 | |||
| ef0098ab65 | |||
| 3a83ffa914 | |||
| 663268d469 | |||
| 0e373833dd | |||
| de0223a298 | |||
|
|
914914cd2f | ||
|
|
bd2abab88e | ||
|
|
6415097740 | ||
|
|
0ab7c7aa3f | ||
|
|
dad67158a6 | ||
|
|
100e2b28de | ||
|
|
23de1e244d | ||
|
|
7a45eb3c92 | ||
|
|
6632fca48c | ||
| 77c9cd42cb | |||
| 3c9ad0758b | |||
|
|
f37f01308e | ||
|
|
01fdb7e1e3 | ||
| ff5337c7e7 | |||
|
|
f445c77301 | ||
| 75b0e7912a | |||
| a41a262640 | |||
|
|
42cfaed2f9 | ||
|
|
ff0e2b9890 | ||
| 8e48aa6a09 | |||
| 3abd4a985a | |||
| 83ffeb107f | |||
| d605c3bd7d | |||
| b75d5b2d11 | |||
| a03f180e43 | |||
| d851c1b628 | |||
| 111756ffe5 | |||
| 5ac9e64eb5 | |||
| 3a32b39f3d | |||
| acf4e95e08 |
121 changed files with 6014 additions and 1275 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
.settings/
|
||||||
|
MacOSX11.3.sdk
|
||||||
|
MacOSX11.3.sdk.tar.xz
|
||||||
|
packages
|
||||||
BIN
Icon.png
BIN
Icon.png
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 259 KiB |
202
README.md
202
README.md
|
|
@ -1,103 +1,177 @@
|
||||||
# JakartaEE & Spring Boot Starter
|
# Java Web Starter (JWS) - University Project Environment Initializer
|
||||||
|
|
||||||
This application is a GUI tool developed in Go using the Fyne framework (v2.5.4). It helps users set up a development environment for JakartaEE and Spring Boot projects by checking and installing necessary dependencies, and then allowing users to deploy starter projects.
|
[](https://opensource.org/licenses/MIT) **Dieses Projekt entstand im Rahmen einer wissenschaftlichen Hausarbeit im Modul "Programmieren von Webanwendungen" an der IU Internationale Hochschule.**
|
||||||
|
|
||||||
## Features
|
## Inhaltsverzeichnis
|
||||||
|
|
||||||
- _Dependency Check_: Verifies the installation of required tools (Visual Studio Code and Docker).
|
- [Motivation / Problemstellung](#motivation--problemstellung)
|
||||||
|
- [Lösungsansatz](#lösungsansatz)
|
||||||
|
- [Kernfunktionen](#kernfunktionen)
|
||||||
|
- [Technologie-Stack](#technologie-stack)
|
||||||
|
- [Zielgruppe](#zielgruppe)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Voraussetzungen](#voraussetzungen)
|
||||||
|
- [Über Releases (Empfohlen)](#über-releases-empfohlen)
|
||||||
|
- [Aus dem Quellcode bauen](#aus-dem-quellcode-bauen)
|
||||||
|
- [Benutzung](#benutzung)
|
||||||
|
- [Enthaltene Projekt-Templates](#enthaltene-projekt-templates)
|
||||||
|
- [Funktionsweise (Dev Container)](#funktionsweise-dev-container)
|
||||||
|
- [Bekannte Probleme / Limitationen](#bekannte-probleme--limitationen)
|
||||||
|
- [Zukünftige Arbeit / Ausblick](#zukünftige-arbeit--ausblick)
|
||||||
|
- [Beitragen](#beitragen)
|
||||||
|
- [Lizenz](#lizenz)
|
||||||
|
- [Danksagung](#danksagung)
|
||||||
|
|
||||||
- _Automatic Installation_: Offers to install missing dependencies on supported platforms.
|
## Motivation / Problemstellung
|
||||||
|
|
||||||
- _Project Selection_: Provides a list of starter projects for JakartaEE and Spring Boot.
|
Die Einrichtung adäquater Entwicklungsumgebungen stellt besonders in der Lehre eine signifikante Hürde dar. Studierende nutzen oft heterogene Systeme (Betriebssysteme, installierte Software, Konfigurationen), was häufig zu Kompatibilitätsproblemen, zeitaufwendiger Fehlersuche und dem bekannten „Works on my machine“-Problem führt. Dies verursacht Frustration, erhöht den Betreuungsaufwand und lenkt vom eigentlichen Lerninhalt ab. Besonders bei komplexen Technologie-Stacks, wie sie in der Webentwicklung mit Java (z.B. Jakarta EE, Spring Boot, Datenbanken) üblich sind, ist die manuelle Konfiguration fehleranfällig.
|
||||||
|
|
||||||
- _Project Deployment_: Allows users to deploy selected projects and open them in Visual Studio Code with dev containers.
|
## Lösungsansatz
|
||||||
|
|
||||||
## Prerequisites
|
Dieses Projekt bietet eine plattformübergreifende Desktop-Anwendung (`jws`), die den Prozess der Bereitstellung standardisierter Entwicklungsumgebungen für universitäre Java-Webprojekte radikal vereinfacht. Unter Nutzung von **Docker** für die Containerisierung und dem **Dev Container Standard** ermöglicht das Tool Studierenden, mit wenigen Klicks eine vorkonfigurierte, lauffähige und konsistente Umgebung für spezifische Projektvorlagen zu initialisieren.
|
||||||
|
|
||||||
- Go 1.23 or later
|
Das Tool wurde in **Go** mit dem **Fyne** GUI-Toolkit entwickelt, um native Ausführbarkeit unter Windows, macOS und Linux zu gewährleisten
|
||||||
|
|
||||||
- Fyne v2.5.4
|
## Kernfunktionen
|
||||||
|
|
||||||
|
- **Plattformübergreifend:** Läuft nativ unter Windows, macOS und Linux.
|
||||||
|
- **Abhängigkeitsprüfung:** Überprüft automatisch, ob Docker Desktop und Visual Studio Code installiert sind.
|
||||||
|
- **Automatisierte Installation:** Bietet an, fehlende Abhängigkeiten (Docker Desktop, VS Code) systemabhängig zu installieren:
|
||||||
|
- **Windows:** Nutzt Winget (prüft auch auf WSL).
|
||||||
|
- **macOS:** Nutzt Homebrew (installiert Homebrew bei Bedarf).
|
||||||
|
- **Linux:** Nutzt distributionsspezifische Methoden (dpkg/dnf für VS Code, Docker-Installationsskripte).
|
||||||
|
- **Template-Auswahl:** Bietet eine Auswahl vordefinierter Starter-Projektvorlagen.
|
||||||
|
- **Lokales Deployment:** Kopiert die ausgewählten Template-Dateien in ein vom Benutzer gewähltes Verzeichnis.
|
||||||
|
- **VS Code Integration:** Öffnet das erstellte Projektverzeichnis automatisch in Visual Studio Code.
|
||||||
|
- **Vorkonfigurierte Umgebungen:** Jedes Template enthält:
|
||||||
|
- `Dockerfile(s)`: Definiert das Basis-Image mit JDK, Build-Tools etc..
|
||||||
|
- `docker-compose.yml`: Definiert die Dienste (App-Container, PostgreSQL-Datenbank, ggf. Runtime-Container wie Open Liberty) und Netzwerke.
|
||||||
|
- `devcontainer.json`: Konfiguriert VS Code für die Nutzung des Containers, installiert notwendige Extensions (z.B. Java Extension Pack) und richtet Port-Weiterleitungen ein.
|
||||||
|
- Projekt-Grundgerüst mit vorkonfigurierter Hibernate-Datenbankanbindung.
|
||||||
|
|
||||||
|
## Technologie-Stack
|
||||||
|
|
||||||
|
- **Kernanwendung:** Go, Fyne Toolkit
|
||||||
|
- **Containerisierung:** Docker, Docker Compose
|
||||||
|
- **Standardisierung:** Dev Container Standard (`devcontainer.json`)
|
||||||
|
- **Ziel-IDE:** Visual Studio Code
|
||||||
|
- **Abhängigkeitsinstallation (Helfer):** Winget (Windows), Homebrew (macOS), Shell-Befehle (Linux)
|
||||||
|
- **Projekt-Templates:**
|
||||||
|
- Java Frameworks: Jakarta EE (Servlet/JSP, JSF, REST), Spring Boot (REST)
|
||||||
|
- Persistenz: Hibernate (JPA)
|
||||||
|
- Datenbank: PostgreSQL
|
||||||
|
- Build-Tools: Maven / Gradle (implizit)
|
||||||
|
|
||||||
|
## Zielgruppe
|
||||||
|
|
||||||
|
- **Studierende:** Insbesondere in Informatik- und Wirtschaftsinformatik-Studiengängen, die Java-Webanwendungen programmieren und eine einfache, fehlerfreie Setup-Erfahrung wünschen.
|
||||||
|
- **Lehrende:** Die ihren Studierenden standardisierte Umgebungen zur Verfügung stellen möchten, um den Support-Aufwand zu reduzieren und die Konzentration auf Lerninhalte zu fördern.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Option 1: Download Pre-built Binary
|
### Voraussetzungen
|
||||||
|
|
||||||
Go to the Releases page of this repository.
|
- Ein unterstütztes Betriebssystem: Windows 10/11, macOS, gängige Linux-Distributionen (getestet unter Mint, Ubuntu, Fedora).
|
||||||
|
- Administratorrechte (werden ggf. für die Installation von Docker/VS Code benötigt).
|
||||||
|
- Unter Windows: Eine funktionierende Winget-Installation wird empfohlen/benötigt für die automatische Installation. WSL wird ggf. benötigt und aktiviert.
|
||||||
|
- Unter macOS: Homebrew wird empfohlen/benötigt (kann vom Tool installiert werden).
|
||||||
|
- Für das Bauen aus dem Quellcode: Eine aktuelle Go-Installation.
|
||||||
|
|
||||||
Download the appropriate binary for your operating system.
|
### Über Releases (Empfohlen)
|
||||||
|
|
||||||
### Option 2: Build from Source
|
Die einfachste Methode ist das Herunterladen einer vorkompilierten Version für Ihr Betriebssystem von der [**Releases-Seite**](https://codeberg.org/Pata1704/jws_gui/releases) . Laden Sie die passende Datei herunter, entpacken Sie sie ggf. und führen Sie die `jws` aus.
|
||||||
|
|
||||||
- Clone the repository:
|
### Aus dem Quellcode bauen
|
||||||
|
|
||||||
```bash
|
1. Klonen Sie das Repository:
|
||||||
git clone https://github.com/yourusername/jws_gui.git
|
```bash
|
||||||
```
|
git clone https://codeberg.org/Pata1704/jws_gui.git
|
||||||
|
cd jws_gui
|
||||||
|
```
|
||||||
|
2. Installieren Sie die von [Fyne](https://docs.fyne.io/started/) definierten Abhängigkeiten für ihr Betriebssytem
|
||||||
|
3. Bauen Sie die Anwendung:
|
||||||
|
```bash
|
||||||
|
go build .
|
||||||
|
```
|
||||||
|
Dies erstellt die ausführbare Datei `jws` (oder `jws.exe` unter Windows) im aktuellen Verzeichnis.
|
||||||
|
|
||||||
Navigate to the project directory:
|
## Benutzung
|
||||||
|
|
||||||
```bash
|
1. **Starten Sie die Anwendung** (`jws`). Ein Info-Fenster weist auf wichtige Punkte hin.
|
||||||
cd jws_gui
|
2. **Abhängigkeits-Check:** Die Anwendung prüft, ob Docker Desktop und Visual Studio Code installiert sind ("Dependency Screen").
|
||||||
```
|
- Falls etwas fehlt, klicken Sie auf die entsprechenden Buttons, um die Installation anzustoßen. Folgen Sie den Anweisungen (ggf. sind Admin-Rechte nötig). Ein Fortschrittsbalken wird angezeigt.
|
||||||
|
3. **Template-Auswahl:** Sobald alle Abhängigkeiten erfüllt sind, gelangen Sie zum "Project Screen". Wählen Sie hier das gewünschte Projekt-Template aus (z.B. "JakartaEE Todo-App mit JSP").
|
||||||
|
4. **Deployment:** Klicken Sie auf "Deploy". Wählen Sie im Dialog einen Zielordner auf Ihrem Rechner aus und bestätigen Sie. Die Template-Dateien werden dorthin kopiert.
|
||||||
|
5. **Öffnen in VS Code:** Die Anwendung öffnet das erstellte Projektverzeichnis automatisch in Visual Studio Code.
|
||||||
|
6. **In Container öffnen:**
|
||||||
|
- Stellen Sie sicher, dass Docker Desktop läuft.
|
||||||
|
- VS Code sollte eine Benachrichtigung anzeigen: "Folder contains a Dev Container configuration file. Reopen folder to develop in a container?". Klicken Sie auf "**Reopen in Container**".
|
||||||
|
- (Falls die Benachrichtigung nicht erscheint: Klicken Sie auf das blaue Icon `><` unten links in der VS Code Statusleiste oder nutzen Sie die Befehlspalette (Ctrl+Shift+P) und suchen Sie nach "Dev Containers: Reopen in Container".
|
||||||
|
7. **Build & Run:** Docker/VS Code bauen nun das Image und starten die Container (dies kann beim ersten Mal etwas dauern). Sobald die Umgebung bereit ist, können Sie im integrierten Terminal von VS Code arbeiten, als wären Sie direkt im Container.
|
||||||
|
- **Beispiel (für JakartaEE JSP Template):** Führen Sie im VS Code Terminal aus:
|
||||||
|
```bash
|
||||||
|
mvn clean package && sudo cp target/*.war /app/
|
||||||
|
```
|
||||||
|
Dieser Befehl kompiliert das Projekt und kopiert die `.war`-Datei in das Deployment-Verzeichnis des laufenden OpenLiberty-Servers.
|
||||||
|
8. **Zugriff:** Nach kurzer Zeit ist die Beispielanwendung im Browser unter `http://localhost:9080/todo-app` (oder einem ähnlichen Port/Pfad je nach Template) erreichbar.
|
||||||
|
|
||||||
Install dependencies:
|
Sie haben nun eine funktionierende, containerisierte Entwicklungsumgebung, ohne sich manuell um Installationen oder Konfigurationen kümmern zu müssen!
|
||||||
|
|
||||||
The list of dependencies required for the development of Fyne Apps can be found at “https://docs.fyne.io/started/”.
|
## Enthaltene Projekt-Templates
|
||||||
|
|
||||||
```bash
|
Aktuell sind folgende Templates enthalten:
|
||||||
go mod tidy
|
|
||||||
```
|
|
||||||
|
|
||||||
Build the application:
|
1. Jakarta EE mit Servlet/JSP
|
||||||
|
2. Jakarta EE mit JSF
|
||||||
|
3. Jakarta EE mit REST (JAX-RS)
|
||||||
|
4. Spring Boot mit REST
|
||||||
|
|
||||||
```bash
|
Alle Templates beinhalten eine PostgreSQL-Datenbankanbindung via Hibernate/JPA.
|
||||||
go build
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
## Funktionsweise (Dev Container)
|
||||||
|
|
||||||
Run the application:
|
Der Kern der Standardisierung basiert auf dem **Dev Container Standard**:
|
||||||
|
|
||||||
If you downloaded a pre-built binary:
|
1. Die `devcontainer.json`-Datei im Projektwurzelverzeichnis teilt VS Code mit, wie die Entwicklungsumgebung konfiguriert ist.
|
||||||
|
2. Sie verweist meist auf eine `docker-compose.yml`-Datei, die die notwendigen Dienste (Applikationscontainer, Datenbank etc.) definiert.
|
||||||
|
3. Die `Dockerfile(s)` definieren, wie die einzelnen Container-Images gebaut werden (Basis-Image, JDK, Tools, Abhängigkeiten).
|
||||||
|
4. Wenn Sie das Projekt in VS Code "im Container öffnen", startet VS Code die definierten Docker-Container und verbindet sich mit dem spezifizierten Entwicklungscontainer.
|
||||||
|
5. VS Code installiert automatisch die in der `devcontainer.json` festgelegten Extensions _innerhalb_ des Containers.
|
||||||
|
6. Sie arbeiten in VS Code (Terminal, Debugger, Code-Editor) nahtlos innerhalb dieser isolierten, vorkonfigurierten Umgebung.
|
||||||
|
|
||||||
```bash
|
Dies stellt sicher, dass alle Nutzer exakt die gleiche Umgebung mit den richtigen Werkzeugversionen und Abhängigkeiten haben, unabhängig von ihrem lokalen System.
|
||||||
./jakartaee-springboot-starter
|
|
||||||
```
|
|
||||||
|
|
||||||
or by double-clicking the excutable.
|
## Bekannte Probleme / Limitationen
|
||||||
|
|
||||||
If you built from source:
|
- **SELinux (Fedora):** Unter Fedora mit aktiviertem SELinux kann es zu Problemen beim Mounten von Host-Verzeichnissen in Docker-Containern kommen. Ein Workaround ist `sudo setenforce 0` (nicht empfohlen), eine korrekte SELinux-Konfiguration für Docker ist komplexer.
|
||||||
|
- **Abhängigkeit von Paketmanagern:** Die automatische Installation hängt vom Funktionieren externer Tools wie Winget und Homebrew ab. Fehler in diesen Tools können die Installation behindern.
|
||||||
|
- **Manuelle Schritte:** Docker Desktop muss manuell gestartet werden, bevor "Reopen in Container" funktioniert
|
||||||
|
- **Installation Robustheit:** Obwohl auf mehreren Systemen getestet, kann es auf spezifischen Konfigurationen zu Problemen kommen
|
||||||
|
- **Evaluation:** Bisher hauptsächlich technisch und durch Experten-Feedback evaluiert. Eine breite Evaluation mit Studierenden (Usability, Zeitersparnis) steht noch aus
|
||||||
|
|
||||||
```bash
|
## Zukünftige Arbeit / Ausblick
|
||||||
./jakartaee-springboot-starter
|
|
||||||
```
|
|
||||||
|
|
||||||
The application will launch a GUI window where you can:
|
- Verbesserung der Robustheit der Installationsprozesse
|
||||||
|
- UI-Verbesserungen und automatische Sprachanpassung
|
||||||
|
- Erweiterung um zusätzliche Templates (z.B. andere Java-Versionen, Microservices, spezifische Bibliotheken)
|
||||||
|
- Plugin-System für Lehrende zur einfachen Erstellung eigener Templates
|
||||||
|
- Unterstützung für Git-Repositories als Template-Quelle
|
||||||
|
- Einführung einer Wahl der IDE (IntelliJ IDEA, Eclipse, NeoVim, Zed, Fleet)
|
||||||
|
- Umfassende quantitative Evaluation
|
||||||
|
|
||||||
1. Check and install dependencies (Visual Studio Code and Docker).
|
## Beitragen
|
||||||
2. Select a starter project from the available options.
|
|
||||||
3. Deploy the selected project and open it in Visual Studio Code.
|
|
||||||
|
|
||||||
## Project Structure
|
Beiträge sind willkommen!
|
||||||
|
|
||||||
_TODO_
|
## Software Bill of Materials (SBOM)
|
||||||
|
Das SBOM dieses Projekts finden Sie unter [sbom.json](sbom.json).
|
||||||
|
|
||||||
## Customization
|
## Lizenz
|
||||||
|
|
||||||
To add new starter projects:
|
Dieses Projekt ist lizenziert unter der MIT Lizenz
|
||||||
|
|
||||||
1. Create a new project template in the projects/ directory.
|
## Danksagung
|
||||||
2. Add the project details to the projects.json file.
|
|
||||||
|
|
||||||
## Contributing
|
- Danke an meinem Dozenten im Modul "Programmieren von Webanwendungen" für die Betreuung der ursprünglichen Hausarbeit.
|
||||||
|
- Danke an die Teilnehmer der Umfrage für ihr wertvolles Feedback.
|
||||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
- Inspiration durch die Konzepte von Docker, Dev Containers und die Arbeiten von Malan et al. und Valstar et al. .
|
||||||
|
|
||||||
License
|
|
||||||
[Insert your chosen license here]
|
|
||||||
|
|
||||||
## Acknowledgments
|
|
||||||
|
|
||||||
- Fyne: https://fyne.io/
|
|
||||||
- JakartaEE: https://jakarta.ee/
|
|
||||||
- Spring Boot: https://spring.io/projects/spring-boot
|
|
||||||
|
|
|
||||||
5
build.sh
5
build.sh
|
|
@ -57,6 +57,7 @@ fyne-cross windows \
|
||||||
-name "$NAME.exe" \
|
-name "$NAME.exe" \
|
||||||
-ldflags "-s" \
|
-ldflags "-s" \
|
||||||
-ldflags "-w" \
|
-ldflags "-w" \
|
||||||
|
-ldflags "-H=windowsgui" \
|
||||||
./cmd/jws
|
./cmd/jws
|
||||||
|
|
||||||
mv fyne-cross/dist/windows-amd64/jws.exe.zip packages/jws_windows.zip
|
mv fyne-cross/dist/windows-amd64/jws.exe.zip packages/jws_windows.zip
|
||||||
|
|
@ -72,5 +73,9 @@ fyne build ./cmd/jws
|
||||||
tar -cJf packages/jws_linux_exe.tar.xz ./jws
|
tar -cJf packages/jws_linux_exe.tar.xz ./jws
|
||||||
tar -cJf packages/jws_linux_bundle.tar.xz ./jws.tar.xz
|
tar -cJf packages/jws_linux_bundle.tar.xz ./jws.tar.xz
|
||||||
|
|
||||||
|
echo "Performing Clean Up"
|
||||||
|
rm -rf fyne-cross
|
||||||
|
rm jws jws.tar.xz
|
||||||
|
|
||||||
echo "Build abgeschlossen! Dateien finden sich im packages-Ordner:"
|
echo "Build abgeschlossen! Dateien finden sich im packages-Ordner:"
|
||||||
ls -lh packages/
|
ls -lh packages/
|
||||||
|
|
|
||||||
64
changelog.md
64
changelog.md
|
|
@ -2,6 +2,69 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.6.0] - 2025-03-30
|
||||||
|
|
||||||
|
### 📚 Documentation
|
||||||
|
|
||||||
|
- Update README
|
||||||
|
|
||||||
|
## [0.5.0] - 2025-03-23
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- Add jakarta rest todo implementation with devcontainer setup
|
||||||
|
- Added complete example for spring boot rest service with devcontainer
|
||||||
|
|
||||||
|
### 📚 Documentation
|
||||||
|
|
||||||
|
- Update changelog.md
|
||||||
|
|
||||||
|
## [0.4.0] - 2025-03-21
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- Optimize software installation on windows and add information splash screen on startup
|
||||||
|
- Add complete example for Jakarta Faces and a devcontainer setup
|
||||||
|
|
||||||
|
### 💼 Other
|
||||||
|
|
||||||
|
- Add clean up step to build.sh
|
||||||
|
|
||||||
|
### 📚 Documentation
|
||||||
|
|
||||||
|
- Update changelog
|
||||||
|
|
||||||
|
## [0.3.0] - 2025-03-21
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- Finalize jakarta-jsp devcontainer setup
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
- Reorder wsl checks on windows docker installation to reduce executation if elevated privileges
|
||||||
|
|
||||||
|
### 📚 Documentation
|
||||||
|
|
||||||
|
- Update changelog
|
||||||
|
|
||||||
|
## [0.2.0] - 2025-03-20
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- Add jakarta-todo-jsp implementation
|
||||||
|
- Improve usability by including a progressbar while installing packages on windows and mac
|
||||||
|
- Improve docker installation process by adding wsl feature activation
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
- Reanble window resize to better support multi monitor setups with different resolutions
|
||||||
|
- Disable password dialog on windows
|
||||||
|
|
||||||
|
### ⚙️ Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Add .devcontainer directory to jakarta jsp project directory
|
||||||
|
|
||||||
## [0.1.0] - 2025-03-19
|
## [0.1.0] - 2025-03-19
|
||||||
|
|
||||||
### 🚀 Features
|
### 🚀 Features
|
||||||
|
|
@ -12,6 +75,7 @@ All notable changes to this project will be documented in this file.
|
||||||
### 📚 Documentation
|
### 📚 Documentation
|
||||||
|
|
||||||
- Add changelog.md
|
- Add changelog.md
|
||||||
|
- Fix missing version info in changelog.md
|
||||||
|
|
||||||
## [0.0.2] - 2025-03-17
|
## [0.0.2] - 2025-03-17
|
||||||
|
|
||||||
|
|
|
||||||
BIN
cmd/jws/Icon.png
BIN
cmd/jws/Icon.png
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 259 KiB |
|
|
@ -1,4 +1,3 @@
|
||||||
// cmd/jws/main.go
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -16,8 +15,10 @@ import (
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed all:projects
|
//go:embed all:projects
|
||||||
|
|
@ -47,24 +48,61 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Logger.Info("Applikation started")
|
logger.Logger.Info("Application started")
|
||||||
a := app.New()
|
a := app.New()
|
||||||
|
|
||||||
|
showSplashScreen(a, func() {
|
||||||
|
createMainWindow(a, config)
|
||||||
|
})
|
||||||
|
|
||||||
|
a.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func showSplashScreen(a fyne.App, onComplete func()) {
|
||||||
|
splash := a.NewWindow("Important Information")
|
||||||
|
splash.SetFixedSize(true)
|
||||||
|
splash.CenterOnScreen()
|
||||||
|
splash.SetPadded(true)
|
||||||
|
|
||||||
|
title := widget.NewLabel("JakartaEE & Spring Boot Starter")
|
||||||
|
title.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
title.Alignment = fyne.TextAlignCenter
|
||||||
|
|
||||||
|
infoText := widget.NewLabel("Please note:\n\n" +
|
||||||
|
"• On Windows, a functional Winget installation is required.\n" +
|
||||||
|
"• Administrator rights may be needed at some points.\n\n" +
|
||||||
|
"Click 'Continue' when you're ready to proceed.")
|
||||||
|
infoText.Wrapping = fyne.TextWrapWord
|
||||||
|
|
||||||
|
continueButton := widget.NewButton("Continue", func() {
|
||||||
|
splash.Close()
|
||||||
|
onComplete()
|
||||||
|
})
|
||||||
|
|
||||||
|
content := container.NewVBox(
|
||||||
|
title,
|
||||||
|
infoText,
|
||||||
|
continueButton,
|
||||||
|
)
|
||||||
|
|
||||||
|
splash.SetContent(content)
|
||||||
|
splash.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func createMainWindow(a fyne.App, config *config.Config) {
|
||||||
mainWindow = a.NewWindow("JakartaEE & Spring Boot Starter")
|
mainWindow = a.NewWindow("JakartaEE & Spring Boot Starter")
|
||||||
mainWindow.Resize(fyne.NewSize(600, 600))
|
mainWindow.Resize(fyne.NewSize(600, 600))
|
||||||
// mainWindow.SetFixedSize(true)
|
|
||||||
|
|
||||||
// Initialize dependencies
|
|
||||||
dependencies = []dependency.Dependency{
|
dependencies = []dependency.Dependency{
|
||||||
{Name: "Visual Studio Code", Installed: false, Icon: theme.DocumentIcon()},
|
{Name: "Visual Studio Code", Installed: false, Icon: theme.DocumentIcon()},
|
||||||
{Name: "Docker", Installed: false, Icon: theme.MediaPlayIcon()},
|
{Name: "Docker", Installed: false, Icon: theme.MediaPlayIcon()},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard projects
|
|
||||||
standartProjects := []project.Project{
|
standartProjects := []project.Project{
|
||||||
{
|
{
|
||||||
Name: "JakartaEE Todo-App mit Servlet",
|
Name: "JakartaEE Todo-App mit Server Faces",
|
||||||
Description: "Eine Todo-Anwendung mit Jakarta Servlet und\nPostgreSQL-Datenbank.",
|
Description: "Eine Todo-Anwendung mit Jakarta Faces und\nPostgreSQL-Datenbank.",
|
||||||
FolderName: "jakarta-servlet-todo",
|
FolderName: "jakarta-faces-todo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "JakartaEE Todo-App mit JSP",
|
Name: "JakartaEE Todo-App mit JSP",
|
||||||
|
|
@ -83,7 +121,6 @@ func main() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load additional projects from projects.json
|
|
||||||
pluginProjects, err := loadProjects(filepath.Join(config.ProjectsPath, "projects.json"))
|
pluginProjects, err := loadProjects(filepath.Join(config.ProjectsPath, "projects.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dialog.ShowError(fmt.Errorf("error loading projects: %v", err), mainWindow)
|
dialog.ShowError(fmt.Errorf("error loading projects: %v", err), mainWindow)
|
||||||
|
|
@ -92,11 +129,9 @@ func main() {
|
||||||
|
|
||||||
projects = append(standartProjects, pluginProjects...)
|
projects = append(standartProjects, pluginProjects...)
|
||||||
|
|
||||||
// Initialize packages
|
|
||||||
gui.Init(mainWindow, dependencies, projects, projectsFS)
|
gui.Init(mainWindow, dependencies, projects, projectsFS)
|
||||||
project.Init(projects, config)
|
project.Init(projects, config)
|
||||||
|
|
||||||
// Check dependencies
|
|
||||||
dependency.CheckDependencies(dependencies)
|
dependency.CheckDependencies(dependencies)
|
||||||
allInstalled := true
|
allInstalled := true
|
||||||
for _, dep := range dependencies {
|
for _, dep := range dependencies {
|
||||||
|
|
@ -106,14 +141,13 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show appropriate screen
|
|
||||||
if allInstalled {
|
if allInstalled {
|
||||||
gui.ShowProjectScreen()
|
gui.ShowProjectScreen()
|
||||||
} else {
|
} else {
|
||||||
gui.ShowDependencyScreen()
|
gui.ShowDependencyScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.ShowAndRun()
|
mainWindow.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadProjects(filePath string) ([]project.Project, error) {
|
func loadProjects(filePath string) ([]project.Project, error) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.settings
|
||||||
|
target
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
node_modules
|
||||||
27
cmd/jws/projects/jakarta-faces-todo/.devcontainer/.gitignore
vendored
Normal file
27
cmd/jws/projects/jakarta-faces-todo/.devcontainer/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
# IDE-spezifische Dateien
|
||||||
|
.idea/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
.vscode/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
# Temporäre Dateien
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# Lokale Konfigurationsdateien
|
||||||
|
src/main/resources/application-local.properties
|
||||||
|
|
||||||
|
# Devcontainer Volumen
|
||||||
|
.devcontainer/postgres-data/
|
||||||
12
cmd/jws/projects/jakarta-faces-todo/.devcontainer/Dockerfile
Normal file
12
cmd/jws/projects/jakarta-faces-todo/.devcontainer/Dockerfile
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
FROM icr.io/appcafe/open-liberty:25.0.0.5-kernel-slim-java17-openj9-ubi
|
||||||
|
|
||||||
|
COPY --chown=1001:0 src/main/liberty/config /config
|
||||||
|
# # Verzeichnis erstellen und PostgreSQL JDBC-Treiber herunterladen
|
||||||
|
RUN mkdir -p /config/lib && \
|
||||||
|
curl -o /config/lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
||||||
|
|
||||||
|
RUN features.sh
|
||||||
|
|
||||||
|
#COPY --chown=1001:0 target/*.war /config/apps
|
||||||
|
|
||||||
|
RUN configure.sh
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
|
||||||
|
|
||||||
|
#ARG INSTALL_MAVEN="true"
|
||||||
|
#ARG MAVEN_VERSION=""
|
||||||
|
|
||||||
|
#ARG INSTALL_GRADLE="false"
|
||||||
|
#ARG GRADLE_VERSION=""
|
||||||
|
|
||||||
|
#RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
|
||||||
|
# && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
|
||||||
|
|
||||||
|
# Hier kannst du zusätzliche Tools oder Bibliotheken installieren, die du für die Entwicklung benötigst.
|
||||||
|
# Zum Beispiel den PostgreSQL JDBC-Treiber, wenn du ihn für die Entwicklung benötigst:
|
||||||
|
RUN apt-get update && apt-get install -y curl && curl -o /tmp/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar && mkdir -p /usr/local/lib/ && mv /tmp/postgresql.jar /usr/local/lib/postgresql.jar
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "Java & PostgreSQL",
|
||||||
|
"dockerComposeFile": "docker-compose.yml",
|
||||||
|
"service": "app",
|
||||||
|
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||||
|
"forwardPorts": [9080, 5432, 9433],
|
||||||
|
"postCreateCommand": "mvn clean install -DskipTests",
|
||||||
|
"remoteUser": "vscode",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/docker-in-docker:2": {"version": "latest"},
|
||||||
|
"ghcr.io/devcontainers-extra/features/maven-sdkman:2": {"version": "latest"},
|
||||||
|
"ghcr.io/devcontainers/features/git:1": {"version": "latest"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
container_name: javadev
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: .devcontainer/Dockerfile.dev
|
||||||
|
volumes:
|
||||||
|
- ../..:/workspaces:cached
|
||||||
|
- ./app:/app
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
command: sleep infinity
|
||||||
|
|
||||||
|
openliberty:
|
||||||
|
container_name: openliberty_app
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: .devcontainer/Dockerfile
|
||||||
|
ports:
|
||||||
|
- "9080:9080"
|
||||||
|
- "9443:9443"
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: todo_db
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
volumes:
|
||||||
|
- ./app:/config/dropins
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
|
db:
|
||||||
|
container_name: postgresdb
|
||||||
|
image: postgres:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_DB: todo_db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
my_network:
|
||||||
|
driver: bridge
|
||||||
87
cmd/jws/projects/jakarta-faces-todo/pom.xml
Normal file
87
cmd/jws/projects/jakarta-faces-todo/pom.xml
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.todoapp</groupId>
|
||||||
|
<artifactId>todo-app</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<jakartaee.version>10.0.0</jakartaee.version>
|
||||||
|
<hibernate.version>6.6.22.Final</hibernate.version>
|
||||||
|
<postgresql.version>42.7.6</postgresql.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Jakarta EE 10 API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.platform</groupId>
|
||||||
|
<artifactId>jakarta.jakartaee-api</artifactId>
|
||||||
|
<version>${jakartaee.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Hibernate Core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<version>${hibernate.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- PostgreSQL JDBC Driver -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>${postgresql.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.websocket</groupId>
|
||||||
|
<artifactId>jakarta.websocket-api</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<version>7.0.0.Final</version> <!-- Stelle sicher, dass du eine aktuelle Version benutzt -->
|
||||||
|
</dependency>
|
||||||
|
<!-- Mindestens zum Passwort-Hashing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>at.favre.lib</groupId>
|
||||||
|
<artifactId>bcrypt</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>todo-app</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.14.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.openliberty.tools</groupId>
|
||||||
|
<artifactId>liberty-maven-plugin</artifactId>
|
||||||
|
<version>3.11.4</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
34
cmd/jws/projects/jakarta-faces-todo/server.xml
Normal file
34
cmd/jws/projects/jakarta-faces-todo/server.xml
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<server description="OpenLiberty Todo App Server">
|
||||||
|
|
||||||
|
<featureManager>
|
||||||
|
<feature>servlet-6.0</feature>
|
||||||
|
<feature>pages-3.1</feature>
|
||||||
|
<feature>jdbc-4.2</feature>
|
||||||
|
<feature>jndi-1.0</feature>
|
||||||
|
<feature>monitor-1.0</feature>
|
||||||
|
<feature>faces-4.0</feature>
|
||||||
|
</featureManager>
|
||||||
|
|
||||||
|
<httpEndpoint id="defaultHttpEndpoint"
|
||||||
|
httpPort="9080"
|
||||||
|
httpsPort="9443" />
|
||||||
|
|
||||||
|
<applicationManager autoExpand="true" />
|
||||||
|
|
||||||
|
<dataSource id="PostgresDataSource">
|
||||||
|
<jdbcDriver libraryRef="PostgresLib" />
|
||||||
|
<properties.postgresql serverName="postgres"
|
||||||
|
portNumber="5432"
|
||||||
|
databaseName="todo_db"
|
||||||
|
user="postgres"
|
||||||
|
password="postgres" />
|
||||||
|
</dataSource>
|
||||||
|
|
||||||
|
<library id="PostgresLib">
|
||||||
|
<fileset dir="${server.config.dir}/lib" includes="postgresql-*.jar" />
|
||||||
|
</library>
|
||||||
|
|
||||||
|
<webApplication location="todo-app.war" contextRoot="/todo-app" />
|
||||||
|
|
||||||
|
</server>
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
package com.todoapp.bean;
|
||||||
|
|
||||||
|
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||||
|
import com.todoapp.dao.UserDAO;
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import jakarta.enterprise.context.SessionScoped;
|
||||||
|
import jakarta.faces.application.FacesMessage;
|
||||||
|
import jakarta.faces.context.FacesContext;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.inject.Named;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Named
|
||||||
|
@SessionScoped
|
||||||
|
public class AuthBean implements Serializable {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private UserDAO userDAO;
|
||||||
|
|
||||||
|
private User user = new User();
|
||||||
|
private String confirmPassword;
|
||||||
|
|
||||||
|
public String login() {
|
||||||
|
User foundUser = userDAO
|
||||||
|
.getUserByUsername(user.getUsername())
|
||||||
|
.orElse(null);
|
||||||
|
if (
|
||||||
|
foundUser != null &&
|
||||||
|
BCrypt.verifyer()
|
||||||
|
.verify(
|
||||||
|
user.getPassword().toCharArray(),
|
||||||
|
foundUser.getPassword()
|
||||||
|
)
|
||||||
|
.verified
|
||||||
|
) {
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.getExternalContext()
|
||||||
|
.getSessionMap()
|
||||||
|
.put("user", foundUser);
|
||||||
|
return "todo-list?faces-redirect=true";
|
||||||
|
} else {
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.addMessage(
|
||||||
|
null,
|
||||||
|
new FacesMessage(
|
||||||
|
FacesMessage.SEVERITY_ERROR,
|
||||||
|
"Invalid username or password",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String register() {
|
||||||
|
if (!user.getPassword().equals(confirmPassword)) {
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.addMessage(
|
||||||
|
null,
|
||||||
|
new FacesMessage(
|
||||||
|
FacesMessage.SEVERITY_ERROR,
|
||||||
|
"Passwords do not match",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (userDAO.usernameExists(user.getUsername())) {
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.addMessage(
|
||||||
|
null,
|
||||||
|
new FacesMessage(
|
||||||
|
FacesMessage.SEVERITY_ERROR,
|
||||||
|
"Username already exists",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (userDAO.emailExists(user.getEmail())) {
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.addMessage(
|
||||||
|
null,
|
||||||
|
new FacesMessage(
|
||||||
|
FacesMessage.SEVERITY_ERROR,
|
||||||
|
"Email already registered",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String hashedPassword = BCrypt.withDefaults()
|
||||||
|
.hashToString(12, user.getPassword().toCharArray());
|
||||||
|
user.setPassword(hashedPassword);
|
||||||
|
userDAO.saveUser(user);
|
||||||
|
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.addMessage(
|
||||||
|
null,
|
||||||
|
new FacesMessage(
|
||||||
|
FacesMessage.SEVERITY_INFO,
|
||||||
|
"Registration successful. Please log in.",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return "login?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String logout() {
|
||||||
|
FacesContext.getCurrentInstance()
|
||||||
|
.getExternalContext()
|
||||||
|
.invalidateSession();
|
||||||
|
return "login?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConfirmPassword() {
|
||||||
|
return confirmPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfirmPassword(String confirmPassword) {
|
||||||
|
this.confirmPassword = confirmPassword;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
package com.todoapp.bean;
|
||||||
|
|
||||||
|
import com.todoapp.dao.TodoDAO;
|
||||||
|
import com.todoapp.model.Todo;
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import jakarta.enterprise.context.SessionScoped;
|
||||||
|
import jakarta.faces.context.FacesContext;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.inject.Named;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Named
|
||||||
|
@SessionScoped
|
||||||
|
public class TodoBean implements Serializable {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private TodoDAO todoDAO;
|
||||||
|
|
||||||
|
private Todo todo = new Todo();
|
||||||
|
private List<Todo> todos;
|
||||||
|
|
||||||
|
public String saveOrUpdateTodo() {
|
||||||
|
if (todo.getId() == null) {
|
||||||
|
return saveTodo();
|
||||||
|
} else {
|
||||||
|
return updateTodo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getTodosByUser(Long userId) {
|
||||||
|
if (todos == null) {
|
||||||
|
todos = todoDAO.getTodosByUser(userId);
|
||||||
|
}
|
||||||
|
return todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getTodosByUser() {
|
||||||
|
User user = (User) FacesContext.getCurrentInstance()
|
||||||
|
.getExternalContext()
|
||||||
|
.getSessionMap()
|
||||||
|
.get("user");
|
||||||
|
System.out.println("Fetching todos for user ID: " + user.getId());
|
||||||
|
List<Todo> todos = todoDAO.getTodosByUser(user.getId());
|
||||||
|
System.out.println("Fetched todos: " + todos);
|
||||||
|
return todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadTodo() {
|
||||||
|
String idParam = FacesContext.getCurrentInstance()
|
||||||
|
.getExternalContext()
|
||||||
|
.getRequestParameterMap()
|
||||||
|
.get("id");
|
||||||
|
if (idParam != null && !idParam.isEmpty()) {
|
||||||
|
Long id = Long.parseLong(idParam);
|
||||||
|
todo = todoDAO.getTodoById(id);
|
||||||
|
} else {
|
||||||
|
todo = new Todo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String saveTodo(User user) {
|
||||||
|
todo.setUser(user);
|
||||||
|
todoDAO.saveTodo(todo);
|
||||||
|
todo = new Todo();
|
||||||
|
todos = null;
|
||||||
|
return "todo-list?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String saveTodo() {
|
||||||
|
User user = (User) FacesContext.getCurrentInstance()
|
||||||
|
.getExternalContext()
|
||||||
|
.getSessionMap()
|
||||||
|
.get("user");
|
||||||
|
System.out.println(user);
|
||||||
|
todo.setUser(user);
|
||||||
|
todoDAO.saveTodo(todo);
|
||||||
|
todo = new Todo();
|
||||||
|
todos = null;
|
||||||
|
return "todo-list?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String updateTodo() {
|
||||||
|
todoDAO.updateTodo(todo);
|
||||||
|
todo = new Todo();
|
||||||
|
todos = null;
|
||||||
|
return "todo-list?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String deleteTodo(Long id) {
|
||||||
|
todoDAO.deleteTodo(id);
|
||||||
|
todos = null;
|
||||||
|
return "todo-list?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String completeTodo(Long id) {
|
||||||
|
Todo todoToComplete = todoDAO.getTodoById(id);
|
||||||
|
todoToComplete.setCompleted(!todoToComplete.isCompleted());
|
||||||
|
todoDAO.updateTodo(todoToComplete);
|
||||||
|
todos = null;
|
||||||
|
return "todo-list?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter für 'todo'
|
||||||
|
public Todo getTodo() {
|
||||||
|
return todo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTodo(Todo todo) {
|
||||||
|
this.todo = todo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.todoapp.bean;
|
||||||
|
|
||||||
|
import com.todoapp.dao.UserDAO;
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import jakarta.enterprise.context.SessionScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.inject.Named;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Named
|
||||||
|
@SessionScoped
|
||||||
|
public class UserBean implements Serializable {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private UserDAO userDAO;
|
||||||
|
|
||||||
|
private User user = new User();
|
||||||
|
private List<User> users;
|
||||||
|
|
||||||
|
public List<User> getAllUsers() {
|
||||||
|
if (users == null) {
|
||||||
|
users = userDAO.getAllUsers();
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String saveUser() {
|
||||||
|
userDAO.saveUser(user);
|
||||||
|
user = new User();
|
||||||
|
users = null; // Reset the list to force a refresh
|
||||||
|
return "user-list?faces-redirect=true";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter für 'user'
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
package com.todoapp.dao;
|
||||||
|
|
||||||
|
import com.todoapp.model.Todo;
|
||||||
|
import com.todoapp.util.HibernateUtil;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import java.util.List;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.Query;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class TodoDAO {
|
||||||
|
|
||||||
|
public void saveTodo(Todo todo) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
session.persist(todo);
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTodo(Todo todo) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
session.merge(todo);
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteTodo(Long id) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
Todo todo = session.get(Todo.class, id);
|
||||||
|
if (todo != null) {
|
||||||
|
session.remove(todo);
|
||||||
|
}
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Todo getTodoById(Long id) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
return session.get(Todo.class, id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getAllTodos() {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
return session.createQuery("FROM Todo", Todo.class).list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getTodosByUser(Long userId) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
Query<Todo> query = session.createQuery(
|
||||||
|
"FROM Todo t WHERE t.user.id = :userId ORDER BY t.completed, t.targetDate",
|
||||||
|
Todo.class
|
||||||
|
);
|
||||||
|
query.setParameter("userId", userId);
|
||||||
|
return query.list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getCompletedTodosByUser(Long userId) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
Query<Todo> query = session.createQuery(
|
||||||
|
"FROM Todo t WHERE t.user.id = :userId AND t.completed = true",
|
||||||
|
Todo.class
|
||||||
|
);
|
||||||
|
query.setParameter("userId", userId);
|
||||||
|
return query.list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getIncompleteTodosByUser(Long userId) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
Query<Todo> query = session.createQuery(
|
||||||
|
"FROM Todo t WHERE t.user.id = :userId AND t.completed = false ORDER BY t.targetDate",
|
||||||
|
Todo.class
|
||||||
|
);
|
||||||
|
query.setParameter("userId", userId);
|
||||||
|
return query.list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,136 @@
|
||||||
|
package com.todoapp.dao;
|
||||||
|
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import com.todoapp.util.HibernateUtil;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.Query;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class UserDAO {
|
||||||
|
|
||||||
|
public void saveUser(User user) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
session.persist(user);
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUser(User user) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
session.merge(user);
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteUser(Long id) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
User user = session.get(User.class, id);
|
||||||
|
if (user != null) {
|
||||||
|
session.remove(user);
|
||||||
|
}
|
||||||
|
transaction.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUserById(Long id) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
return session.get(User.class, id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<User> getUserByUsername(String username) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
Query<User> query = session.createQuery(
|
||||||
|
"FROM User WHERE username = :username",
|
||||||
|
User.class
|
||||||
|
);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
User user = query.uniqueResult();
|
||||||
|
return Optional.ofNullable(user);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> getAllUsers() {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
return session.createQuery("FROM User", User.class).list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean usernameExists(String username) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
Query<Long> query = session.createQuery(
|
||||||
|
"SELECT COUNT(u) FROM User u WHERE u.username = :username",
|
||||||
|
Long.class
|
||||||
|
);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return query.uniqueResult() > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean emailExists(String email) {
|
||||||
|
try (
|
||||||
|
Session session = HibernateUtil.getSessionFactory().openSession()
|
||||||
|
) {
|
||||||
|
Query<Long> query = session.createQuery(
|
||||||
|
"SELECT COUNT(u) FROM User u WHERE u.email = :email",
|
||||||
|
Long.class
|
||||||
|
);
|
||||||
|
query.setParameter("email", email);
|
||||||
|
return query.uniqueResult() > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
package com.todoapp.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "todos")
|
||||||
|
public class Todo implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(length = 1000)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "target_date")
|
||||||
|
private LocalDate targetDate;
|
||||||
|
|
||||||
|
private boolean completed;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "user_id", nullable = false)
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
// Konstruktoren
|
||||||
|
public Todo() {}
|
||||||
|
|
||||||
|
public Todo(
|
||||||
|
String title,
|
||||||
|
String description,
|
||||||
|
LocalDate targetDate,
|
||||||
|
boolean completed
|
||||||
|
) {
|
||||||
|
this.title = title;
|
||||||
|
this.description = description;
|
||||||
|
this.targetDate = targetDate;
|
||||||
|
this.completed = completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getTargetDate() {
|
||||||
|
return targetDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetDate(LocalDate targetDate) {
|
||||||
|
this.targetDate = targetDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCompleted() {
|
||||||
|
return completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompleted(boolean completed) {
|
||||||
|
this.completed = completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return (
|
||||||
|
"Todo{" +
|
||||||
|
"id=" +
|
||||||
|
id +
|
||||||
|
", title='" +
|
||||||
|
title +
|
||||||
|
'\'' +
|
||||||
|
", targetDate=" +
|
||||||
|
targetDate +
|
||||||
|
", completed=" +
|
||||||
|
completed +
|
||||||
|
'}'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
package com.todoapp.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "users")
|
||||||
|
public class User implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, unique = true)
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<Todo> todos = new ArrayList<>();
|
||||||
|
|
||||||
|
// Konstruktoren
|
||||||
|
public User() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(String username, String password, String email) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getTodos() {
|
||||||
|
return todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTodos(List<Todo> todos) {
|
||||||
|
this.todos = todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hilfsmethoden
|
||||||
|
public void addTodo(Todo todo) {
|
||||||
|
todos.add(todo);
|
||||||
|
todo.setUser(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeTodo(Todo todo) {
|
||||||
|
todos.remove(todo);
|
||||||
|
todo.setUser(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", username='" + username + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.todoapp.util;
|
||||||
|
|
||||||
|
import jakarta.servlet.*;
|
||||||
|
import jakarta.servlet.annotation.WebFilter;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebFilter(urlPatterns = { "/todos/*", "/users/*" })
|
||||||
|
public class AuthFilter implements Filter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
// Initialisierung
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||||
|
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||||
|
|
||||||
|
HttpSession session = httpRequest.getSession(false);
|
||||||
|
|
||||||
|
boolean isLoggedIn = (session != null && session.getAttribute("userId") != null);
|
||||||
|
boolean isLoginRequest = httpRequest.getRequestURI().contains("/auth/login");
|
||||||
|
boolean isRegisterRequest = httpRequest.getRequestURI().contains("/auth/register");
|
||||||
|
boolean isResourceRequest = httpRequest.getRequestURI().contains("/css/") ||
|
||||||
|
httpRequest.getRequestURI().contains("/js/");
|
||||||
|
|
||||||
|
if (isLoggedIn || isLoginRequest || isRegisterRequest || isResourceRequest) {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
} else {
|
||||||
|
httpResponse.sendRedirect(httpRequest.getContextPath() + "/auth/login");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
// Aufräumen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
//package com.todoapp.util;
|
||||||
|
//
|
||||||
|
//import org.hibernate.SessionFactory;
|
||||||
|
//import org.hibernate.boot.Metadata;
|
||||||
|
//import org.hibernate.boot.MetadataSources;
|
||||||
|
//import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
//import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
//import org.hibernate.cfg.Configuration;
|
||||||
|
//
|
||||||
|
//public class HibernateUtil {
|
||||||
|
// private static StandardServiceRegistry registry;
|
||||||
|
// private static SessionFactory sessionFactory;
|
||||||
|
//
|
||||||
|
// public static SessionFactory getSessionFactory() {
|
||||||
|
// if (sessionFactory == null) {
|
||||||
|
// try {
|
||||||
|
// // Create registry
|
||||||
|
// registry = new StandardServiceRegistryBuilder()
|
||||||
|
// .configure()
|
||||||
|
// .build();
|
||||||
|
//
|
||||||
|
// // Create MetadataSources
|
||||||
|
// MetadataSources sources = new MetadataSources(registry);
|
||||||
|
//
|
||||||
|
// // Create Metadata
|
||||||
|
// Metadata metadata = sources.getMetadataBuilder().build();
|
||||||
|
//
|
||||||
|
// // Create SessionFactory
|
||||||
|
// sessionFactory = metadata.getSessionFactoryBuilder().build();
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// if (registry != null) {
|
||||||
|
// StandardServiceRegistryBuilder.destroy(registry);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return sessionFactory;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static void shutdown() {
|
||||||
|
// if (registry != null) {
|
||||||
|
// StandardServiceRegistryBuilder.destroy(registry);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
package com.todoapp.util;
|
||||||
|
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
public class HibernateUtil {
|
||||||
|
private static SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
public static SessionFactory getSessionFactory() {
|
||||||
|
if (sessionFactory == null) {
|
||||||
|
try {
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
|
||||||
|
configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://postgresdb:5432/todo_db");
|
||||||
|
configuration.setProperty("hibernate.connection.username", "postgres");
|
||||||
|
configuration.setProperty("hibernate.connection.password", "postgres");
|
||||||
|
|
||||||
|
// Entity-Klassen registrieren
|
||||||
|
configuration.addAnnotatedClass(com.todoapp.model.User.class);
|
||||||
|
configuration.addAnnotatedClass(com.todoapp.model.Todo.class);
|
||||||
|
sessionFactory = configuration.buildSessionFactory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sessionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static SessionFactory getSessionFactory() {
|
||||||
|
// if (sessionFactory == null) {
|
||||||
|
// try {
|
||||||
|
// // Create Configuration
|
||||||
|
// Configuration configuration = new Configuration();
|
||||||
|
//
|
||||||
|
// // Set JNDI DataSource
|
||||||
|
// Context ctx = new InitialContext();
|
||||||
|
// DataSource ds = (DataSource) ctx.lookup("jdbc/PostgresDataSource");
|
||||||
|
// configuration.setProperty("hibernate.connection.datasource",
|
||||||
|
// "jdbc/PostgresDataSource");
|
||||||
|
//
|
||||||
|
// //// Load hibernate.cfg.xml
|
||||||
|
// // configuration.configure("hibernate.cfg.xml");
|
||||||
|
//
|
||||||
|
// // Build SessionFactory
|
||||||
|
// sessionFactory = configuration.buildSessionFactory();
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return sessionFactory;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static void shutdown() {
|
||||||
|
if (sessionFactory != null) {
|
||||||
|
sessionFactory.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<server description="OpenLiberty Todo App Server">
|
||||||
|
|
||||||
|
<featureManager>
|
||||||
|
<feature>servlet-6.0</feature>
|
||||||
|
<feature>pages-3.1</feature>
|
||||||
|
<feature>jdbc-4.2</feature>
|
||||||
|
<feature>jndi-1.0</feature>
|
||||||
|
<feature>monitor-1.0</feature>
|
||||||
|
<feature>faces-4.0</feature>
|
||||||
|
<feature>websocket-2.1</feature>
|
||||||
|
</featureManager>
|
||||||
|
|
||||||
|
<httpEndpoint id="defaultHttpEndpoint"
|
||||||
|
httpPort="9080"
|
||||||
|
httpsPort="9443" />
|
||||||
|
|
||||||
|
<applicationManager autoExpand="true" />
|
||||||
|
|
||||||
|
<dataSource id="PostgresDataSource" jndiName="jdbc/PostgresDataSource">
|
||||||
|
<jdbcDriver libraryRef="PostgresLib" />
|
||||||
|
<properties.postgresql serverName="${POSTGRES_HOST}"
|
||||||
|
portNumber="${POSTGRES_PORT}"
|
||||||
|
databaseName="${POSTGRES_DB}"
|
||||||
|
user="${POSTGRES_USER}"
|
||||||
|
password="${POSTGRES_PASSWORD}" />
|
||||||
|
</dataSource>
|
||||||
|
|
||||||
|
|
||||||
|
<library id="PostgresLib">
|
||||||
|
<fileset dir="${server.config.dir}/lib" includes="postgresql-*.jar" />
|
||||||
|
</library>
|
||||||
|
|
||||||
|
</server>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
||||||
|
version="3.0">
|
||||||
|
<persistence-unit name="todoPU" transaction-type="RESOURCE_LOCAL">
|
||||||
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
<class>com.todoapp.model.User</class>
|
||||||
|
<class>com.todoapp.model.Todo</class>
|
||||||
|
<properties>
|
||||||
|
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://postgresdb:5432/todo_db"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.user" value="postgres"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.password" value="postgres"/>
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||||
|
<property name="hibernate.show_sql" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
|
</persistence>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE hibernate-configuration PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||||
|
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
|
<hibernate-configuration>
|
||||||
|
<session-factory>
|
||||||
|
<!-- JNDI connection settings -->
|
||||||
|
<property name="hibernate.connection.datasource">jdbc/PostgresDataSource</property>
|
||||||
|
|
||||||
|
<!-- Select our SQL dialect -->
|
||||||
|
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
|
||||||
|
|
||||||
|
<!-- Echo the SQL to stdout -->
|
||||||
|
<property name="hibernate.show_sql">true</property>
|
||||||
|
|
||||||
|
<!-- Set the current session context -->
|
||||||
|
<property name="hibernate.current_session_context_class">thread</property>
|
||||||
|
|
||||||
|
<!-- Drop and re-create the database schema on startup -->
|
||||||
|
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||||
|
|
||||||
|
<!-- Entity mapping -->
|
||||||
|
<mapping class="com.todoapp.model.User"/>
|
||||||
|
<mapping class="com.todoapp.model.Todo"/>
|
||||||
|
</session-factory>
|
||||||
|
</hibernate-configuration>
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<faces-config
|
||||||
|
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_0.xsd"
|
||||||
|
version="4.0">
|
||||||
|
</faces-config>
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
|
||||||
|
version="6.0">
|
||||||
|
|
||||||
|
<display-name>Todo Application</display-name>
|
||||||
|
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>login.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Faces Servlet</servlet-name>
|
||||||
|
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Faces Servlet</servlet-name>
|
||||||
|
<url-pattern>*.xhtml</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>jakarta.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<error-page>
|
||||||
|
<error-code>404</error-code>
|
||||||
|
<location>/error.xhtml</location>
|
||||||
|
</error-page>
|
||||||
|
|
||||||
|
<error-page>
|
||||||
|
<error-code>500</error-code>
|
||||||
|
<location>/error.xhtml</location>
|
||||||
|
</error-page>
|
||||||
|
|
||||||
|
<session-config>
|
||||||
|
<session-timeout>30</session-timeout>
|
||||||
|
</session-config>
|
||||||
|
|
||||||
|
</web-app>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:h="jakarta.faces.html"
|
||||||
|
xmlns:f="jakarta.faces.core">
|
||||||
|
<h:head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<title>Fehler</title>
|
||||||
|
<h:outputStylesheet name="./css/style.css"/>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Oops! Es ist ein Fehler aufgetreten</h1>
|
||||||
|
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<p>Etwas ist schiefgelaufen. Bitte versuchen Sie es später erneut.</p>
|
||||||
|
<p>Fehlercode: #{facesContext.externalContext.responseStatusCode}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:link outcome="/todos" value="Zurück zur Startseite" styleClass="btn"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:h="jakarta.faces.html"
|
||||||
|
xmlns:f="jakarta.faces.core">
|
||||||
|
<h:head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<title>Login</title>
|
||||||
|
<h:outputStylesheet name="./css/style.css"/>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Login</h1>
|
||||||
|
|
||||||
|
<h:messages globalOnly="true" styleClass="alert alert-danger"/>
|
||||||
|
|
||||||
|
<h:form>
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="username" value="Benutzername:"/>
|
||||||
|
<h:inputText id="username" value="#{authBean.user.username}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="password" value="Passwort:"/>
|
||||||
|
<h:inputSecret id="password" value="#{authBean.user.password}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:commandButton value="Anmelden" action="#{authBean.login}" styleClass="btn"/>
|
||||||
|
</div>
|
||||||
|
</h:form>
|
||||||
|
|
||||||
|
<p>Noch keinen Account? <h:link outcome="register" value="Registrieren"/></p>
|
||||||
|
</div>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:h="jakarta.faces.html"
|
||||||
|
xmlns:f="jakarta.faces.core">
|
||||||
|
<h:head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<title>Registrierung</title>
|
||||||
|
<h:outputStylesheet name="./css/style.css"/>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Registrierung</h1>
|
||||||
|
|
||||||
|
<h:messages globalOnly="true" styleClass="alert alert-danger"/>
|
||||||
|
|
||||||
|
<h:form>
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="username" value="Benutzername:"/>
|
||||||
|
<h:inputText id="username" value="#{authBean.user.username}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="email" value="E-Mail:"/>
|
||||||
|
<h:inputText id="email" value="#{authBean.user.email}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="password" value="Passwort:"/>
|
||||||
|
<h:inputSecret id="password" value="#{authBean.user.password}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="confirmPassword" value="Passwort bestätigen:"/>
|
||||||
|
<h:inputSecret id="confirmPassword" value="#{authBean.confirmPassword}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:commandButton value="Registrieren" action="#{authBean.register}" styleClass="btn"/>
|
||||||
|
</div>
|
||||||
|
</h:form>
|
||||||
|
|
||||||
|
<p>Bereits registriert? <h:link outcome="login" value="Anmelden"/></p>
|
||||||
|
</div>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,246 @@
|
||||||
|
/* Allgemeine Stile */
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
line-height: 1.6;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-align: center;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Header und Navigation */
|
||||||
|
header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-btn {
|
||||||
|
background-color: #f44336;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-btn:hover {
|
||||||
|
background-color: #d32f2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Formulare */
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input,
|
||||||
|
.form-group textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group button {
|
||||||
|
background-color: #4caf50;
|
||||||
|
color: white;
|
||||||
|
padding: 10px 15px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group button:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Alerts */
|
||||||
|
.alert {
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-danger {
|
||||||
|
background-color: #f8d7da;
|
||||||
|
color: #721c24;
|
||||||
|
border: 1px solid #f5c6cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-success {
|
||||||
|
background-color: #d4edda;
|
||||||
|
color: #155724;
|
||||||
|
border: 1px solid #c3e6cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Links */
|
||||||
|
a {
|
||||||
|
color: #007bff;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Buttons */
|
||||||
|
.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 6px 12px;
|
||||||
|
margin-bottom: 0;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 1.42857143;
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
vertical-align: middle;
|
||||||
|
cursor: pointer;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-btn {
|
||||||
|
background-color: #4caf50;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-btn:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-btn {
|
||||||
|
background-color: #2196f3;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-btn:hover {
|
||||||
|
background-color: #0b7dda;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
background-color: #f44336;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn:hover {
|
||||||
|
background-color: #d32f2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.complete-btn {
|
||||||
|
background-color: #ff9800;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.complete-btn:hover {
|
||||||
|
background-color: #e68a00;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-btn {
|
||||||
|
background-color: #9e9e9e;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-btn:hover {
|
||||||
|
background-color: #7e7e7e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-btn {
|
||||||
|
background-color: #4caf50;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-btn:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Todo-Liste */
|
||||||
|
.todo-actions {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo-table th,
|
||||||
|
.todo-table td {
|
||||||
|
padding: 10px;
|
||||||
|
text-align: left;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo-table th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo-table tr:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.todo-table tr.completed {
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
padding: 3px 8px;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.completed {
|
||||||
|
background-color: #4caf50;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status.pending {
|
||||||
|
background-color: #ff9800;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-todos {
|
||||||
|
text-align: center;
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:h="jakarta.faces.html"
|
||||||
|
xmlns:f="jakarta.faces.core">
|
||||||
|
<f:metadata>
|
||||||
|
<f:viewAction action="#{todoBean.loadTodo}" />
|
||||||
|
</f:metadata>
|
||||||
|
<h:head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<title>#{todoBean.todo.id == null ? 'Neue Aufgabe' : 'Aufgabe bearbeiten'}</title>
|
||||||
|
<h:outputStylesheet name="./css/style.css"/>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>#{todoBean.todo.id == null ? 'Neue Aufgabe' : 'Aufgabe bearbeiten'}</h1>
|
||||||
|
|
||||||
|
<h:form>
|
||||||
|
<h:inputHidden value="#{todoBean.todo.id}"/>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="title" value="Titel:"/>
|
||||||
|
<h:inputText id="title" value="#{todoBean.todo.title}" required="true"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="description" value="Beschreibung:"/>
|
||||||
|
<h:inputTextarea id="description" value="#{todoBean.todo.description}" rows="5"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:outputLabel for="targetDate" value="Fälligkeitsdatum:"/>
|
||||||
|
<h:inputText id="targetDate" value="#{todoBean.todo.targetDate}" required="false">
|
||||||
|
<f:convertDateTime type="localDate" pattern="yyyy-MM-dd"/>
|
||||||
|
</h:inputText>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<h:commandButton value="Speichern"
|
||||||
|
action="#{todoBean.saveOrUpdateTodo}"
|
||||||
|
styleClass="btn save-btn"/>
|
||||||
|
<h:link outcome="todo-list" value="Abbrechen" styleClass="btn cancel-btn"/>
|
||||||
|
</div>
|
||||||
|
</h:form>
|
||||||
|
</div>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:h="jakarta.faces.html"
|
||||||
|
xmlns:f="jakarta.faces.core"
|
||||||
|
xmlns:ui="jakarta.faces.facelets">
|
||||||
|
<h:head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<title>Meine Aufgaben</title>
|
||||||
|
<h:outputStylesheet name="./css/style.css"/>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<h1>Meine Aufgaben</h1>
|
||||||
|
<div class="user-info">
|
||||||
|
<span>Hallo, #{sessionScope.username}!</span>
|
||||||
|
<h:form>
|
||||||
|
<h:commandLink action="#{authBean.logout}" value="Abmelden" styleClass="logout-btn"/>
|
||||||
|
</h:form>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="todo-actions">
|
||||||
|
<h:link outcome="todo-form" value="Neue Aufgabe" styleClass="btn add-btn"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h:panelGroup rendered="#{empty todoBean.todosByUser}">
|
||||||
|
<div class="no-todos">
|
||||||
|
<p>Keine Aufgaben vorhanden. Erstellen Sie eine neue Aufgabe!</p>
|
||||||
|
</div>
|
||||||
|
</h:panelGroup>
|
||||||
|
|
||||||
|
<h:dataTable value="#{todoBean.todosByUser}" var="todo" styleClass="todo-table"
|
||||||
|
rendered="#{not empty todoBean.todosByUser}">
|
||||||
|
<h:column>
|
||||||
|
<f:facet name="header">Titel</f:facet>
|
||||||
|
#{todo.title}
|
||||||
|
</h:column>
|
||||||
|
<h:column>
|
||||||
|
<f:facet name="header">Beschreibung</f:facet>
|
||||||
|
#{todo.description}
|
||||||
|
</h:column>
|
||||||
|
<h:column>
|
||||||
|
<f:facet name="header">Fälligkeitsdatum</f:facet>
|
||||||
|
<h:outputText value="#{todo.targetDate}">
|
||||||
|
<f:convertDateTime type="localDate" pattern="yyyy-MM-dd"/>
|
||||||
|
</h:outputText>
|
||||||
|
</h:column>
|
||||||
|
<h:column>
|
||||||
|
<f:facet name="header">Status</f:facet>
|
||||||
|
<h:outputText value="Erledigt" rendered="#{todo.completed}" styleClass="status completed"/>
|
||||||
|
<h:outputText value="Offen" rendered="#{not todo.completed}" styleClass="status pending"/>
|
||||||
|
</h:column>
|
||||||
|
<h:column>
|
||||||
|
<f:facet name="header">Aktionen</f:facet>
|
||||||
|
<h:link outcome="todo-form" value="Bearbeiten" styleClass="btn edit-btn">
|
||||||
|
<f:param name="id" value="#{todo.id}"/>
|
||||||
|
</h:link>
|
||||||
|
<h:form>
|
||||||
|
<h:commandLink action="#{todoBean.deleteTodo(todo.id)}" value="Löschen"
|
||||||
|
styleClass="btn delete-btn"
|
||||||
|
onclick="return confirm('Möchten Sie diese Aufgabe wirklich löschen?')"/>
|
||||||
|
<h:commandLink action="#{todoBean.completeTodo(todo.id)}" value="#{todo.completed ? 'Als offen markieren' : 'Als erledigt markieren'}"
|
||||||
|
styleClass="btn complete-btn"/>
|
||||||
|
</h:form>
|
||||||
|
</h:column>
|
||||||
|
</h:dataTable>
|
||||||
|
</div>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
||||||
|
|
@ -1,17 +1,12 @@
|
||||||
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
|
FROM icr.io/appcafe/open-liberty:25.0.0.5-kernel-slim-java17-openj9-ubi
|
||||||
|
|
||||||
ARG INSTALL_MAVEN="true"
|
COPY --chown=1001:0 src/main/liberty/config /config
|
||||||
ARG MAVEN_VERSION=""
|
# # Verzeichnis erstellen und PostgreSQL JDBC-Treiber herunterladen
|
||||||
|
RUN mkdir -p /config/lib && \
|
||||||
|
curl -o /config/lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
||||||
|
|
||||||
ARG INSTALL_GRADLE="false"
|
RUN features.sh
|
||||||
ARG GRADLE_VERSION=""
|
|
||||||
|
|
||||||
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
|
#COPY --chown=1001:0 target/*.war /config/apps
|
||||||
&& if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
|
|
||||||
|
|
||||||
# [Optional] Uncomment this section to install additional OS packages.
|
RUN configure.sh
|
||||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|
||||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
|
||||||
|
|
||||||
# [Optional] Uncomment this line to install global node packages.
|
|
||||||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
|
||||||
|
|
||||||
|
#ARG INSTALL_MAVEN="true"
|
||||||
|
#ARG MAVEN_VERSION=""
|
||||||
|
|
||||||
|
#ARG INSTALL_GRADLE="false"
|
||||||
|
#ARG GRADLE_VERSION=""
|
||||||
|
|
||||||
|
#RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
|
||||||
|
# && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
|
||||||
|
|
||||||
|
# Hier kannst du zusätzliche Tools oder Bibliotheken installieren, die du für die Entwicklung benötigst.
|
||||||
|
# Zum Beispiel den PostgreSQL JDBC-Treiber, wenn du ihn für die Entwicklung benötigst:
|
||||||
|
RUN apt-get update && apt-get install -y curl && curl -o /tmp/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar && mkdir -p /usr/local/lib/ && mv /tmp/postgresql.jar /usr/local/lib/postgresql.jar
|
||||||
|
|
@ -3,7 +3,12 @@
|
||||||
"dockerComposeFile": "docker-compose.yml",
|
"dockerComposeFile": "docker-compose.yml",
|
||||||
"service": "app",
|
"service": "app",
|
||||||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||||
"forwardPorts": [9080, 5432],
|
"forwardPorts": [9080, 5432, 9433],
|
||||||
"postCreateCommand": "mvn clean install -DskipTests",
|
"postCreateCommand": "mvn clean install -DskipTests",
|
||||||
"remoteUser": "vscode"
|
"remoteUser": "vscode",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/docker-in-docker:2": {"version": "latest"},
|
||||||
|
"ghcr.io/devcontainers-extra/features/maven-sdkman:2": {"version": "latest"},
|
||||||
|
"ghcr.io/devcontainers/features/git:1": {"version": "latest"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,42 @@
|
||||||
version: "3.8"
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
postgres-data:
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
container_name: javadev
|
container_name: javadev
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ../
|
||||||
dockerfile: Dockerfile
|
dockerfile: .devcontainer/Dockerfile.dev
|
||||||
environment:
|
|
||||||
# NOTE: POSTGRES_DB/USER/PASSWORD should match values in db container
|
|
||||||
POSTGRES_PASSWORD: postgres
|
|
||||||
POSTGRES_USER: postgres
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
POSTGRES_HOSTNAME: postgresdb
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- ../..:/workspaces:cached
|
- ../..:/workspaces:cached
|
||||||
|
- ./app:/app
|
||||||
# Overrides default command so things don't shut down after the process ends.
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
command: sleep infinity
|
command: sleep infinity
|
||||||
|
|
||||||
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
|
openliberty:
|
||||||
network_mode: service:db
|
container_name: openliberty_app
|
||||||
|
build:
|
||||||
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
|
context: ../
|
||||||
# (Adding the "ports" property to this file will not forward from a Codespace.)
|
dockerfile: .devcontainer/Dockerfile
|
||||||
|
ports:
|
||||||
|
- "9080:9080"
|
||||||
|
- "9443:9443"
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: todo_db
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
volumes:
|
||||||
|
- ./app:/config/dropins
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
db:
|
db:
|
||||||
container_name: postgresdb
|
container_name: postgresdb
|
||||||
|
|
@ -34,11 +44,17 @@ services:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- postgres-data:/var/lib/postgresql/data
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
environment:
|
environment:
|
||||||
# NOTE: POSTGRES_DB/USER/PASSWORD should match values in app container
|
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_DB: postgres
|
POSTGRES_DB: todo_db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
|
volumes:
|
||||||
# (Adding the "ports" property to this file will not forward from a Codespace.)
|
postgres-data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
my_network:
|
||||||
|
driver: bridge
|
||||||
|
|
|
||||||
17
cmd/jws/projects/jakarta-jsp-todo/.devcontainer/init.sql
Normal file
17
cmd/jws/projects/jakarta-jsp-todo/.devcontainer/init.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
CREATE TABLE users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE todos (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
description VARCHAR(1000),
|
||||||
|
target_date DATE,
|
||||||
|
completed BOOLEAN,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
# # Dockerfile für OpenLiberty
|
|
||||||
# FROM icr.io/appcafe/open-liberty:23.0.0.4-kernel-slim-java17-openj9-ubi
|
|
||||||
# COPY --chown=1001:0 /src/main/liberty/config /config
|
|
||||||
#
|
|
||||||
# # PostgreSQL JDBC-Treiber laden
|
|
||||||
# # RUN mkdir -p ./lib && \
|
|
||||||
# # curl -o ./lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
|
||||||
#
|
|
||||||
# RUN curl -o /config/lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
|
||||||
#
|
|
||||||
# RUN features.sh
|
|
||||||
#
|
|
||||||
# COPY --chown=1001:0 target/*.war /config/apps
|
|
||||||
#
|
|
||||||
# RUN configure.sh
|
|
||||||
#
|
|
||||||
# # # Arbeitsverzeichnis setzen
|
|
||||||
# # WORKDIR /opt/ol/wlp/usr/servers/defaultServer
|
|
||||||
# #
|
|
||||||
# # # Notwendige Dateien kopieren
|
|
||||||
# # COPY target/todo-app.war ./apps/
|
|
||||||
# # # COPY server.xml ./
|
|
||||||
# #
|
|
||||||
# # # PostgreSQL JDBC-Treiber laden
|
|
||||||
# # RUN mkdir -p ./lib && \
|
|
||||||
# # curl -o ./lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
|
||||||
# #
|
|
||||||
# # # OpenLiberty starten
|
|
||||||
# # CMD ["/opt/ol/wlp/bin/server", "run", "defaultServer"]
|
|
||||||
|
|
||||||
# FROM icr.io/appcafe/open-liberty:23.0.0.4-kernel-slim-java17-openj9-ubi
|
|
||||||
#
|
|
||||||
# # COPY --chown=1001:0 /src/main/liberty/config /config
|
|
||||||
# #
|
|
||||||
# # COPY --chown=1001:0 /src/main/liberty/config/server.xml /opt/ol/wlp/usr/servers/defaultServer/
|
|
||||||
#
|
|
||||||
# RUN chmod 644 /opt/ol/wlp/usr/servers/defaultServer/server.xml
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# # Verzeichnis erstellen und PostgreSQL JDBC-Treiber herunterladen
|
|
||||||
# RUN mkdir -p /config/lib && \
|
|
||||||
# curl -o /config/lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
|
||||||
#
|
|
||||||
# RUN features.sh
|
|
||||||
#
|
|
||||||
# COPY --chown=1001:0 target/*.war /config/apps
|
|
||||||
#
|
|
||||||
# RUN configure.sh
|
|
||||||
|
|
||||||
FROM icr.io/appcafe/open-liberty:23.0.0.4-kernel-slim-java17-openj9-ubi
|
|
||||||
|
|
||||||
COPY --chown=1001:0 /src/main/liberty/config /config
|
|
||||||
# # Verzeichnis erstellen und PostgreSQL JDBC-Treiber herunterladen
|
|
||||||
RUN mkdir -p /config/lib && \
|
|
||||||
curl -o /config/lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
|
||||||
|
|
||||||
RUN features.sh
|
|
||||||
|
|
||||||
COPY --chown=1001:0 target/*.war /config/apps
|
|
||||||
|
|
||||||
RUN configure.sh
|
|
||||||
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
version: "3.8"
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:15
|
|
||||||
networks:
|
|
||||||
- my_network
|
|
||||||
container_name: postgres_db
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: todo_db
|
|
||||||
POSTGRES_USER: postgres
|
|
||||||
POSTGRES_PASSWORD: postgres
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
volumes:
|
|
||||||
- postgres_data:/var/lib/postgresql/data
|
|
||||||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
||||||
interval: 5s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
openliberty:
|
|
||||||
build: .
|
|
||||||
container_name: openliberty_app
|
|
||||||
networks:
|
|
||||||
- my_network
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- "9080:9080"
|
|
||||||
- "9443:9443"
|
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
environment:
|
|
||||||
- POSTGRES_HOST=postgres
|
|
||||||
- POSTGRES_PORT=5432
|
|
||||||
- POSTGRES_DB=todo_db
|
|
||||||
- POSTGRES_USER=postgres
|
|
||||||
- POSTGRES_PASSWORD=postgres
|
|
||||||
volumes:
|
|
||||||
- ./src/main/liberty/config/server.xml:/config/server.xml
|
|
||||||
# - ./src/main/liberty/config/server.xml:/opt/ol/wlp/usr/servers/defaultServer/server.xml
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
postgres_data:
|
|
||||||
networks:
|
|
||||||
my_network:
|
|
||||||
driver: bridge
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<jakartaee.version>10.0.0</jakartaee.version>
|
<jakartaee.version>10.0.0</jakartaee.version>
|
||||||
<hibernate.version>6.2.5.Final</hibernate.version>
|
<hibernate.version>6.6.22.Final</hibernate.version>
|
||||||
<postgresql.version>42.6.0</postgresql.version>
|
<postgresql.version>42.7.6</postgresql.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet.jsp.jstl</groupId>
|
<groupId>jakarta.servlet.jsp.jstl</groupId>
|
||||||
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
|
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.web</groupId>
|
<groupId>org.glassfish.web</groupId>
|
||||||
|
|
@ -54,9 +54,9 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>6.3.1.Final</version> <!-- Stelle sicher, dass du eine aktuelle Version benutzt -->
|
<version>7.0.0.Final</version> <!-- Stelle sicher, dass du eine aktuelle Version benutzt -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Mindestens zum Passwort-Hashing -->
|
<!-- Mindestens zum Passwort-Hashing -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
@ -72,17 +72,17 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.10.1</version>
|
<version>3.14.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.4.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>io.openliberty.tools</groupId>
|
<groupId>io.openliberty.tools</groupId>
|
||||||
<artifactId>liberty-maven-plugin</artifactId>
|
<artifactId>liberty-maven-plugin</artifactId>
|
||||||
<version>3.7.1</version>
|
<version>3.11.4</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class HibernateUtil {
|
||||||
try {
|
try {
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
|
configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
|
||||||
configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://postgres:5432/todo_db");
|
configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://postgresdb:5432/todo_db");
|
||||||
configuration.setProperty("hibernate.connection.username", "postgres");
|
configuration.setProperty("hibernate.connection.username", "postgres");
|
||||||
configuration.setProperty("hibernate.connection.password", "postgres");
|
configuration.setProperty("hibernate.connection.password", "postgres");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<class>com.todoapp.model.Todo</class>
|
<class>com.todoapp.model.Todo</class>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
||||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://postgres:5432/todo_db"/>
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://postgresdb:5432/todo_db"/>
|
||||||
<property name="jakarta.persistence.jdbc.user" value="postgres"/>
|
<property name="jakarta.persistence.jdbc.user" value="postgres"/>
|
||||||
<property name="jakarta.persistence.jdbc.password" value="postgres"/>
|
<property name="jakarta.persistence.jdbc.password" value="postgres"/>
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.settings
|
||||||
|
target
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
node_modules
|
||||||
27
cmd/jws/projects/jakarta-rest-todo/.devcontainer/.gitignore
vendored
Normal file
27
cmd/jws/projects/jakarta-rest-todo/.devcontainer/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
# IDE-spezifische Dateien
|
||||||
|
.idea/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
.vscode/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
# Temporäre Dateien
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# Lokale Konfigurationsdateien
|
||||||
|
src/main/resources/application-local.properties
|
||||||
|
|
||||||
|
# Devcontainer Volumen
|
||||||
|
.devcontainer/postgres-data/
|
||||||
12
cmd/jws/projects/jakarta-rest-todo/.devcontainer/Dockerfile
Normal file
12
cmd/jws/projects/jakarta-rest-todo/.devcontainer/Dockerfile
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
FROM icr.io/appcafe/open-liberty:25.0.0.5-kernel-slim-java17-openj9-ubi
|
||||||
|
|
||||||
|
COPY --chown=1001:0 src/main/liberty/config /config
|
||||||
|
# # Verzeichnis erstellen und PostgreSQL JDBC-Treiber herunterladen
|
||||||
|
RUN mkdir -p /config/lib && \
|
||||||
|
curl -o /config/lib/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar
|
||||||
|
|
||||||
|
RUN features.sh
|
||||||
|
|
||||||
|
#COPY --chown=1001:0 target/*.war /config/apps
|
||||||
|
|
||||||
|
RUN configure.sh
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
|
||||||
|
|
||||||
|
#ARG INSTALL_MAVEN="true"
|
||||||
|
#ARG MAVEN_VERSION=""
|
||||||
|
|
||||||
|
#ARG INSTALL_GRADLE="false"
|
||||||
|
#ARG GRADLE_VERSION=""
|
||||||
|
|
||||||
|
#RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
|
||||||
|
# && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
|
||||||
|
|
||||||
|
# Hier kannst du zusätzliche Tools oder Bibliotheken installieren, die du für die Entwicklung benötigst.
|
||||||
|
# Zum Beispiel den PostgreSQL JDBC-Treiber, wenn du ihn für die Entwicklung benötigst:
|
||||||
|
RUN apt-get update && apt-get install -y curl && curl -o /tmp/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar && mkdir -p /usr/local/lib/ && mv /tmp/postgresql.jar /usr/local/lib/postgresql.jar
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "Java & PostgreSQL",
|
||||||
|
"dockerComposeFile": "docker-compose.yml",
|
||||||
|
"service": "app",
|
||||||
|
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||||
|
"forwardPorts": [9080, 5432, 9433],
|
||||||
|
"postCreateCommand": "mvn clean install -DskipTests",
|
||||||
|
"remoteUser": "vscode",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/docker-in-docker:2": {"version": "latest"},
|
||||||
|
"ghcr.io/devcontainers-extra/features/maven-sdkman:2": {"version": "latest"},
|
||||||
|
"ghcr.io/devcontainers/features/git:1": {"version": "latest"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
container_name: javadev
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: .devcontainer/Dockerfile.dev
|
||||||
|
volumes:
|
||||||
|
- ../..:/workspaces:cached
|
||||||
|
- ./app:/app
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
command: sleep infinity
|
||||||
|
|
||||||
|
openliberty:
|
||||||
|
container_name: openliberty_app
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: .devcontainer/Dockerfile
|
||||||
|
ports:
|
||||||
|
- "9080:9080"
|
||||||
|
- "9443:9443"
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: todo_db
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
volumes:
|
||||||
|
- ./app:/config/dropins
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
|
db:
|
||||||
|
container_name: postgresdb
|
||||||
|
image: postgres:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_DB: todo_db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
my_network:
|
||||||
|
driver: bridge
|
||||||
19
cmd/jws/projects/jakarta-rest-todo/.devcontainer/init.sql
Normal file
19
cmd/jws/projects/jakarta-rest-todo/.devcontainer/init.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
CREATE TABLE users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE todos (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
description VARCHAR(1000),
|
||||||
|
target_date DATE,
|
||||||
|
completed BOOLEAN,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO users (username, password, email) VALUES
|
||||||
|
('test', '$2a$12$nt7xQKNDKZhxQFZGD5Wy0.Uh0wdPtWDgwfnWnPLgBWnQDGGkNLKBi', 'test@example.com');
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.todoapp</groupId>
|
||||||
|
<artifactId>todo-app</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<jakartaee.version>10.0.0</jakartaee.version>
|
||||||
|
<hibernate.version>6.6.22.Final</hibernate.version>
|
||||||
|
<postgresql.version>42.7.6</postgresql.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Jakarta EE 10 API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.platform</groupId>
|
||||||
|
<artifactId>jakarta.jakartaee-api</artifactId>
|
||||||
|
<version>${jakartaee.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Hibernate Core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<version>${hibernate.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- PostgreSQL JDBC Driver -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>${postgresql.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSTL -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.servlet.jsp.jstl</groupId>
|
||||||
|
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.web</groupId>
|
||||||
|
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JAX-RS -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.ws.rs</groupId>
|
||||||
|
<artifactId>jakarta.ws.rs-api</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSON-Binding -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.json.bind</groupId>
|
||||||
|
<artifactId>jakarta.json.bind-api</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSON-Processing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.json</groupId>
|
||||||
|
<artifactId>jakarta.json-api</artifactId>
|
||||||
|
<version>2.1.3</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<version>7.0.0.Final</version> <!-- Stelle sicher, dass du eine aktuelle Version benutzt -->
|
||||||
|
</dependency>
|
||||||
|
<!-- Mindestens zum Passwort-Hashing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>at.favre.lib</groupId>
|
||||||
|
<artifactId>bcrypt</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>todo-app</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.14.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.openliberty.tools</groupId>
|
||||||
|
<artifactId>liberty-maven-plugin</artifactId>
|
||||||
|
<version>3.11.4</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,135 @@
|
||||||
|
package com.todoapp.dao;
|
||||||
|
|
||||||
|
import com.todoapp.model.Todo;
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.Query;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class TodoDAO {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private UserDAO userDAO;
|
||||||
|
|
||||||
|
public Todo saveTodo(Todo todo, String username) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
|
||||||
|
// Benutzer aus der Datenbank holen
|
||||||
|
User user = userDAO.getUserByUsername(username);
|
||||||
|
if (user == null) {
|
||||||
|
throw new IllegalArgumentException("User not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
todo.setUser(user);
|
||||||
|
session.persist(todo);
|
||||||
|
transaction.commit();
|
||||||
|
return todo;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error saving todo", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Todo updateTodo(Todo todo) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
Todo updatedTodo = session.merge(todo);
|
||||||
|
transaction.commit();
|
||||||
|
return updatedTodo;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error updating todo", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteTodo(Long id) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
Todo todo = session.get(Todo.class, id);
|
||||||
|
if (todo != null) {
|
||||||
|
session.remove(todo);
|
||||||
|
transaction.commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error deleting todo", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Todo getTodoById(Long id) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
return session.get(Todo.class, id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting todo by ID", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getAllTodos() {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
return session.createQuery("FROM Todo", Todo.class).list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting all todos", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getTodosByUsername(String username) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
Query<Todo> query = session.createQuery(
|
||||||
|
"FROM Todo t WHERE t.user.username = :username ORDER BY t.completed, t.targetDate", Todo.class);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return query.list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting todos by username", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getCompletedTodosByUsername(String username) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
Query<Todo> query = session.createQuery(
|
||||||
|
"FROM Todo t WHERE t.user.username = :username AND t.completed = true", Todo.class);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return query.list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting completed todos", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getIncompleteTodosByUsername(String username) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
Query<Todo> query = session.createQuery(
|
||||||
|
"FROM Todo t WHERE t.user.username = :username AND t.completed = false ORDER BY t.targetDate", Todo.class);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return query.list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting incomplete todos", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,124 @@
|
||||||
|
package com.todoapp.dao;
|
||||||
|
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import com.todoapp.util.HibernateUtil;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.Query;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class UserDAO {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
public User saveUser(User user) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
session.persist(user);
|
||||||
|
transaction.commit();
|
||||||
|
return user;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error saving user", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User updateUser(User user) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
User updatedUser = session.merge(user);
|
||||||
|
transaction.commit();
|
||||||
|
return updatedUser;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error updating user", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteUser(Long id) {
|
||||||
|
Transaction transaction = null;
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
transaction = session.beginTransaction();
|
||||||
|
User user = session.get(User.class, id);
|
||||||
|
if (user != null) {
|
||||||
|
session.remove(user);
|
||||||
|
transaction.commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (transaction != null) {
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error deleting user", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUserById(Long id) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
return session.get(User.class, id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting user by ID", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUserByUsername(String username) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
Query<User> query = session.createQuery("FROM User WHERE username = :username", User.class);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return query.uniqueResult();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting user by username", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> getAllUsers() {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
return session.createQuery("FROM User", User.class).list();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error getting all users", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean usernameExists(String username) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
Query<Long> query = session.createQuery(
|
||||||
|
"SELECT COUNT(u) FROM User u WHERE u.username = :username", Long.class);
|
||||||
|
query.setParameter("username", username);
|
||||||
|
return query.uniqueResult() > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error checking if username exists", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean emailExists(String email) {
|
||||||
|
try (Session session = sessionFactory.openSession()) {
|
||||||
|
Query<Long> query = session.createQuery(
|
||||||
|
"SELECT COUNT(u) FROM User u WHERE u.email = :email", Long.class);
|
||||||
|
query.setParameter("email", email);
|
||||||
|
return query.uniqueResult() > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("Error checking if email exists", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.todoapp.dto;
|
||||||
|
|
||||||
|
public class LoginRequest {
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.todoapp.dto;
|
||||||
|
|
||||||
|
public class RegistrationRequest {
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
package com.todoapp.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.json.bind.annotation.JsonbTransient;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "todos")
|
||||||
|
public class Todo implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(length = 1000)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "target_date")
|
||||||
|
@Temporal(TemporalType.DATE)
|
||||||
|
private Date targetDate;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private boolean completed;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "user_id", nullable = false)
|
||||||
|
@JsonbTransient // Verhindert zirkuläre Referenzen
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
// Konstruktoren
|
||||||
|
public Todo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Todo(String title, String description, Date targetDate, boolean completed) {
|
||||||
|
this.title = title;
|
||||||
|
this.description = description;
|
||||||
|
this.targetDate = targetDate;
|
||||||
|
this.completed = completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getTargetDate() {
|
||||||
|
return targetDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetDate(Date targetDate) {
|
||||||
|
this.targetDate = targetDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCompleted() {
|
||||||
|
return completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompleted(boolean completed) {
|
||||||
|
this.completed = completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zusätzliche Methode für REST-Antworten
|
||||||
|
public Long getUserId() {
|
||||||
|
return user != null ? user.getId() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Todo{" +
|
||||||
|
"id=" + id +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", targetDate=" + targetDate +
|
||||||
|
", completed=" + completed +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.todoapp.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.json.bind.annotation.JsonbTransient;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "users")
|
||||||
|
public class User implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, unique = true)
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@JsonbTransient // Verhindert, dass das Passwort in JSON serialisiert wird
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
@JsonbTransient // Verhindert zirkuläre Referenzen bei der JSON-Serialisierung
|
||||||
|
private List<Todo> todos = new ArrayList<>();
|
||||||
|
|
||||||
|
// Konstruktoren
|
||||||
|
public User() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(String username, String password, String email) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter und Setter
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Todo> getTodos() {
|
||||||
|
return todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTodos(List<Todo> todos) {
|
||||||
|
this.todos = todos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hilfsmethoden
|
||||||
|
public void addTodo(Todo todo) {
|
||||||
|
todos.add(todo);
|
||||||
|
todo.setUser(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeTodo(Todo todo) {
|
||||||
|
todos.remove(todo);
|
||||||
|
todo.setUser(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", username='" + username + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.todoapp.rest;
|
||||||
|
|
||||||
|
import com.todoapp.dao.UserDAO;
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import com.todoapp.dto.LoginRequest;
|
||||||
|
import com.todoapp.dto.RegistrationRequest;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.ws.rs.*;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Path("/auth")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public class AuthResource {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private UserDAO userDAO;
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/register")
|
||||||
|
public Response register(RegistrationRequest request) {
|
||||||
|
if (request.getUsername() == null || request.getPassword() == null || request.getEmail() == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(Map.of("error", "Username, password, and email are required"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userDAO.usernameExists(request.getUsername())) {
|
||||||
|
System.out.println(userDAO.usernameExists(request.getUsername()));
|
||||||
|
return Response.status(Response.Status.CONFLICT)
|
||||||
|
.entity(Map.of("error", "Username already exists"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userDAO.emailExists(request.getEmail())) {
|
||||||
|
return Response.status(Response.Status.CONFLICT)
|
||||||
|
.entity(Map.of("error", "Email already exists"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername(request.getUsername());
|
||||||
|
user.setEmail(request.getEmail());
|
||||||
|
|
||||||
|
String hashedPassword = BCrypt.withDefaults()
|
||||||
|
.hashToString(12, request.getPassword().toCharArray());
|
||||||
|
user.setPassword(hashedPassword);
|
||||||
|
|
||||||
|
userDAO.saveUser(user);
|
||||||
|
|
||||||
|
return Response.status(Response.Status.CREATED)
|
||||||
|
.entity(Map.of("message", "User registered successfully"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@RolesAllowed("user")
|
||||||
|
@Path("/login")
|
||||||
|
public Response login(LoginRequest request) {
|
||||||
|
// Validierung
|
||||||
|
if (request.getUsername() == null || request.getPassword() == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(Map.of("error", "Username and password are required"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benutzer suchen
|
||||||
|
User user = userDAO.getUserByUsername(request.getUsername());
|
||||||
|
if (user == null) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED)
|
||||||
|
.entity(Map.of("error", "Invalid credentials"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passwort überprüfen
|
||||||
|
BCrypt.Result result = BCrypt.verifyer()
|
||||||
|
.verify(request.getPassword().toCharArray(), user.getPassword());
|
||||||
|
if (!result.verified) {
|
||||||
|
return Response.status(Response.Status.UNAUTHORIZED)
|
||||||
|
.entity(Map.of("error", "Invalid credentials"))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erfolgreiche Anmeldung
|
||||||
|
return Response.ok(Map.of(
|
||||||
|
"message", "Login successful",
|
||||||
|
"username", user.getUsername(),
|
||||||
|
"email", user.getEmail())).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.todoapp.rest;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.ApplicationPath;
|
||||||
|
import jakarta.ws.rs.core.Application;
|
||||||
|
|
||||||
|
@ApplicationPath("/api")
|
||||||
|
public class TodoApplication extends Application {
|
||||||
|
// Die leere Klasse ist ausreichend, um den REST-Endpunkt zu definieren
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
package com.todoapp.rest;
|
||||||
|
|
||||||
|
import com.todoapp.dao.TodoDAO;
|
||||||
|
import com.todoapp.model.Todo;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.ws.rs.*;
|
||||||
|
import jakarta.ws.rs.core.Context;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import jakarta.ws.rs.core.SecurityContext;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Path("/todos")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public class TodoResource {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private TodoDAO todoDAO;
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public Response getAllTodos(@Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
List<Todo> todos = todoDAO.getTodosByUsername(username);
|
||||||
|
return Response.ok(todos).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{id}")
|
||||||
|
public Response getTodoById(@PathParam("id") Long id, @Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
Todo todo = todoDAO.getTodoById(id);
|
||||||
|
|
||||||
|
if (todo == null) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sicherheitscheck: Nutzer darf nur eigene Todos sehen
|
||||||
|
if (!todo.getUser().getUsername().equals(username)) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.ok(todo).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/completed")
|
||||||
|
public Response getCompletedTodos(@Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
List<Todo> todos = todoDAO.getCompletedTodosByUsername(username);
|
||||||
|
return Response.ok(todos).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/incomplete")
|
||||||
|
public Response getIncompleteTodos(@Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
List<Todo> todos = todoDAO.getIncompleteTodosByUsername(username);
|
||||||
|
return Response.ok(todos).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public Response createTodo(Todo todo, @Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
todo = todoDAO.saveTodo(todo, username);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(todo).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/{id}")
|
||||||
|
public Response updateTodo(@PathParam("id") Long id, Todo updatedTodo, @Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
Todo existingTodo = todoDAO.getTodoById(id);
|
||||||
|
|
||||||
|
if (existingTodo == null) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sicherheitscheck: Nutzer darf nur eigene Todos aktualisieren
|
||||||
|
if (!existingTodo.getUser().getUsername().equals(username)) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID und Benutzer beibehalten
|
||||||
|
updatedTodo.setId(id);
|
||||||
|
updatedTodo.setUser(existingTodo.getUser());
|
||||||
|
|
||||||
|
todoDAO.updateTodo(updatedTodo);
|
||||||
|
return Response.ok(updatedTodo).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/{id}")
|
||||||
|
public Response deleteTodo(@PathParam("id") Long id, @Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
Todo todo = todoDAO.getTodoById(id);
|
||||||
|
|
||||||
|
if (todo == null) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sicherheitscheck: Nutzer darf nur eigene Todos löschen
|
||||||
|
if (!todo.getUser().getUsername().equals(username)) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean deleted = todoDAO.deleteTodo(id);
|
||||||
|
return deleted ? Response.noContent().build() : Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/{id}/complete")
|
||||||
|
public Response markTodoComplete(@PathParam("id") Long id, @Context SecurityContext securityContext) {
|
||||||
|
String username = securityContext.getUserPrincipal().getName();
|
||||||
|
Todo todo = todoDAO.getTodoById(id);
|
||||||
|
|
||||||
|
if (todo == null) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sicherheitscheck: Nutzer darf nur eigene Todos aktualisieren
|
||||||
|
if (!todo.getUser().getUsername().equals(username)) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
todo.setCompleted(true);
|
||||||
|
todoDAO.updateTodo(todo);
|
||||||
|
return Response.ok(todo).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.todoapp.security;
|
||||||
|
|
||||||
|
import com.todoapp.dao.UserDAO;
|
||||||
|
import com.todoapp.model.User;
|
||||||
|
import jakarta.annotation.Priority;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import jakarta.ws.rs.Priorities;
|
||||||
|
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||||
|
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||||
|
import jakarta.ws.rs.core.HttpHeaders;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import jakarta.ws.rs.core.SecurityContext;
|
||||||
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.util.Base64;
|
||||||
|
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
@Priority(Priorities.AUTHENTICATION)
|
||||||
|
@ApplicationScoped
|
||||||
|
public class BasicAuthenticationFilter implements ContainerRequestFilter {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private UserDAO userDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(ContainerRequestContext requestContext) throws IOException {
|
||||||
|
System.out.println("BasicAuthenticationFilter triggered for path: " + requestContext.getUriInfo().getPath());
|
||||||
|
String path = requestContext.getUriInfo().getPath();
|
||||||
|
if (path.endsWith("auth/register") || path.endsWith("auth/login")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String authHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
|
||||||
|
if (authHeader == null || !authHeader.startsWith("Basic ")) {
|
||||||
|
abortWithUnauthorized(requestContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] credentials = extractCredentials(authHeader);
|
||||||
|
if (credentials.length != 2) {
|
||||||
|
abortWithUnauthorized(requestContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String username = credentials[0];
|
||||||
|
String password = credentials[1];
|
||||||
|
|
||||||
|
User user = userDAO.getUserByUsername(username);
|
||||||
|
if (user == null) {
|
||||||
|
abortWithUnauthorized(requestContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BCrypt.Result result = BCrypt.verifyer()
|
||||||
|
.verify(password.toCharArray(), user.getPassword());
|
||||||
|
if (!result.verified) {
|
||||||
|
abortWithUnauthorized(requestContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final SecurityContext currentSecurityContext = requestContext.getSecurityContext();
|
||||||
|
requestContext.setSecurityContext(new SecurityContext() {
|
||||||
|
@Override
|
||||||
|
public Principal getUserPrincipal() {
|
||||||
|
return () -> username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUserInRole(String role) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSecure() {
|
||||||
|
return currentSecurityContext.isSecure();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAuthenticationScheme() {
|
||||||
|
return "BASIC";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
System.out.println("SecurityContext gesetzt für User: " + username);
|
||||||
|
System.out.println("User in Rolle user: " + requestContext.getSecurityContext().isUserInRole("user"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] extractCredentials(String authHeader) {
|
||||||
|
String base64Credentials = authHeader.substring("Basic ".length()).trim();
|
||||||
|
byte[] decoded = Base64.getDecoder().decode(base64Credentials);
|
||||||
|
String credentials = new String(decoded);
|
||||||
|
return credentials.split(":", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void abortWithUnauthorized(ContainerRequestContext requestContext) {
|
||||||
|
requestContext.abortWith(Response
|
||||||
|
.status(Response.Status.UNAUTHORIZED)
|
||||||
|
.header(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"TodoApp\"")
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.todoapp.security;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||||
|
import jakarta.ws.rs.container.ContainerResponseContext;
|
||||||
|
import jakarta.ws.rs.container.ContainerResponseFilter;
|
||||||
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Provider
|
||||||
|
public class CORSFilter implements ContainerResponseFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
|
||||||
|
throws IOException {
|
||||||
|
responseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
|
||||||
|
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||||
|
responseContext.getHeaders().add("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||||
|
responseContext.getHeaders().add("Access-Control-Max-Age", "86400");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.todoapp.util;
|
||||||
|
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.enterprise.inject.Produces;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class HibernateUtil {
|
||||||
|
|
||||||
|
private static SessionFactory sessionFactory;
|
||||||
|
|
||||||
|
@Produces
|
||||||
|
@ApplicationScoped
|
||||||
|
public SessionFactory getSessionFactory() {
|
||||||
|
if (sessionFactory == null) {
|
||||||
|
try {
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
|
||||||
|
configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://postgresdb:5432/todo_db");
|
||||||
|
configuration.setProperty("hibernate.connection.username", "postgres");
|
||||||
|
configuration.setProperty("hibernate.connection.password", "postgres");
|
||||||
|
|
||||||
|
// Entity-Klassen registrieren
|
||||||
|
configuration.addAnnotatedClass(com.todoapp.model.User.class);
|
||||||
|
configuration.addAnnotatedClass(com.todoapp.model.Todo.class);
|
||||||
|
|
||||||
|
sessionFactory = configuration.buildSessionFactory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sessionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shutdown() {
|
||||||
|
if (sessionFactory != null) {
|
||||||
|
sessionFactory.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<server description="OpenLiberty Todo App Server">
|
||||||
|
|
||||||
|
<featureManager>
|
||||||
|
<feature>servlet-6.0</feature>
|
||||||
|
<feature>pages-3.1</feature>
|
||||||
|
<feature>jdbc-4.2</feature>
|
||||||
|
<feature>jndi-1.0</feature>
|
||||||
|
<feature>monitor-1.0</feature>
|
||||||
|
<feature>restfulWS-3.1</feature>
|
||||||
|
<feature>jsonb-3.0</feature>
|
||||||
|
<feature>jsonp-2.1</feature>
|
||||||
|
<!-- <feature>appSecurity-5.0</feature> -->
|
||||||
|
<feature>transportSecurity-1.0</feature>
|
||||||
|
</featureManager>
|
||||||
|
|
||||||
|
<httpEndpoint id="defaultHttpEndpoint"
|
||||||
|
httpPort="9080"
|
||||||
|
httpsPort="9443" />
|
||||||
|
|
||||||
|
<applicationManager autoExpand="true" />
|
||||||
|
|
||||||
|
<dataSource id="PostgresDataSource" jndiName="jdbc/PostgresDataSource">
|
||||||
|
<jdbcDriver libraryRef="PostgresLib" />
|
||||||
|
<properties.postgresql serverName="${POSTGRES_HOST}"
|
||||||
|
portNumber="${POSTGRES_PORT}"
|
||||||
|
databaseName="${POSTGRES_DB}"
|
||||||
|
user="${POSTGRES_USER}"
|
||||||
|
password="${POSTGRES_PASSWORD}" />
|
||||||
|
</dataSource>
|
||||||
|
|
||||||
|
|
||||||
|
<library id="PostgresLib">
|
||||||
|
<fileset dir="${server.config.dir}/lib" includes="postgresql-*.jar" />
|
||||||
|
</library>
|
||||||
|
|
||||||
|
<webApplication location="todo-app.war" contextRoot="/todo-app" />
|
||||||
|
|
||||||
|
</server>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
||||||
|
version="3.0">
|
||||||
|
<persistence-unit name="todoPU" transaction-type="RESOURCE_LOCAL">
|
||||||
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
<class>com.todoapp.model.User</class>
|
||||||
|
<class>com.todoapp.model.Todo</class>
|
||||||
|
<properties>
|
||||||
|
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://postgresdb:5432/todo_db"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.user" value="postgres"/>
|
||||||
|
<property name="jakarta.persistence.jdbc.password" value="postgres"/>
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||||
|
<property name="hibernate.show_sql" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
|
</persistence>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE hibernate-configuration PUBLIC
|
||||||
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||||
|
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
|
<hibernate-configuration>
|
||||||
|
<session-factory>
|
||||||
|
<!-- JNDI connection settings -->
|
||||||
|
<property name="hibernate.connection.datasource">jdbc/PostgresDataSource</property>
|
||||||
|
|
||||||
|
<!-- Select our SQL dialect -->
|
||||||
|
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
|
||||||
|
|
||||||
|
<!-- Echo the SQL to stdout -->
|
||||||
|
<property name="hibernate.show_sql">true</property>
|
||||||
|
|
||||||
|
<!-- Set the current session context -->
|
||||||
|
<property name="hibernate.current_session_context_class">thread</property>
|
||||||
|
|
||||||
|
<!-- Drop and re-create the database schema on startup -->
|
||||||
|
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||||
|
|
||||||
|
<!-- Entity mapping -->
|
||||||
|
<mapping class="com.todoapp.model.User"/>
|
||||||
|
<mapping class="com.todoapp.model.Todo"/>
|
||||||
|
</session-factory>
|
||||||
|
</hibernate-configuration>
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
|
||||||
|
version="6.0">
|
||||||
|
|
||||||
|
<display-name>Todo Application</display-name>
|
||||||
|
|
||||||
|
<session-config>
|
||||||
|
<session-timeout>30</session-timeout>
|
||||||
|
</session-config>
|
||||||
|
</web-app>
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
|
|
||||||
|
|
||||||
ARG INSTALL_MAVEN="false"
|
|
||||||
ARG MAVEN_VERSION=""
|
|
||||||
|
|
||||||
ARG INSTALL_GRADLE="false"
|
|
||||||
ARG GRADLE_VERSION=""
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get upgrade -y && \
|
|
||||||
apt-get install -y \
|
|
||||||
git
|
|
||||||
|
|
||||||
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
|
|
||||||
&& if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi
|
|
||||||
|
|
||||||
RUN mkdir -p /workspaces/${localWorkspaceFolderBasename} && chown -R vscode:vscode /workspaces/${localWorkspaceFolderBasename}
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/bash"]
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Jakarta EE Todo App & PostgreSQL",
|
|
||||||
"dockerComposeFile": "docker-compose.yml",
|
|
||||||
"service": "app",
|
|
||||||
"workspaceFolder": "/workspaces",
|
|
||||||
"extensions": ["vscjava.vscode-java-pack", "redhat.vscode-xml"],
|
|
||||||
"forwardPorts": [9080],
|
|
||||||
"remoteUser": "vscode"
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>com.example</groupId>
|
|
||||||
<artifactId>jakarta-servlet-todo</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
<jakartaee.version>10.0.0</jakartaee.version>
|
|
||||||
<hibernate.version>6.0.0.Final</hibernate.version>
|
|
||||||
<postgresql.version>42.3.1</postgresql.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.platform</groupId>
|
|
||||||
<artifactId>jakarta.jakartaee-api</artifactId>
|
|
||||||
<version>${jakartaee.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hibernate.orm</groupId>
|
|
||||||
<artifactId>hibernate-core</artifactId>
|
|
||||||
<version>${hibernate.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
<version>${postgresql.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<finalName>${project.artifactId}</finalName>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
|
||||||
<version>3.3.2</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
||||||
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package com.example.dao;
|
|
||||||
|
|
||||||
import com.example.model.Todo;
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.PersistenceContext;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TodoDAO {
|
|
||||||
|
|
||||||
@PersistenceContext
|
|
||||||
private EntityManager em;
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void create(Todo todo) {
|
|
||||||
em.persist(todo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Todo> findAll() {
|
|
||||||
return em.createQuery("SELECT t FROM Todo t", Todo.class).getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void update(Todo todo) {
|
|
||||||
em.merge(todo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void delete(Long id) {
|
|
||||||
Todo todo = em.find(Todo.class, id);
|
|
||||||
if (todo != null) {
|
|
||||||
em.remove(todo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
package com.example.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "todos")
|
|
||||||
public class Todo {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
private boolean completed;
|
|
||||||
|
|
||||||
// Getter und Setter
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCompleted() {
|
|
||||||
return completed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCompleted(boolean completed) {
|
|
||||||
this.completed = completed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
package com.example.servlet;
|
|
||||||
|
|
||||||
import com.example.dao.TodoDAO;
|
|
||||||
import com.example.model.Todo;
|
|
||||||
import jakarta.inject.Inject;
|
|
||||||
import jakarta.servlet.ServletException;
|
|
||||||
import jakarta.servlet.annotation.WebServlet;
|
|
||||||
import jakarta.servlet.http.HttpServlet;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@WebServlet("/todos")
|
|
||||||
public class TodoServlet extends HttpServlet {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TodoDAO todoDAO;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
||||||
List<Todo> todos = todoDAO.findAll();
|
|
||||||
req.setAttribute("todos", todos);
|
|
||||||
req.getRequestDispatcher("/index.jsp").forward(req, resp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
||||||
String title = req.getParameter("title");
|
|
||||||
boolean completed = "on".equals(req.getParameter("completed"));
|
|
||||||
|
|
||||||
Todo todo = new Todo();
|
|
||||||
todo.setTitle(title);
|
|
||||||
todo.setCompleted(completed);
|
|
||||||
|
|
||||||
todoDAO.create(todo);
|
|
||||||
resp.sendRedirect(req.getContextPath() + "/todos");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
|
|
||||||
version="3.0">
|
|
||||||
|
|
||||||
<persistence-unit name="todoPU">
|
|
||||||
<class>com.example.model.Todo</class>
|
|
||||||
<properties>
|
|
||||||
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
|
||||||
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://db:5432/tododb"/>
|
|
||||||
<property name="jakarta.persistence.jdbc.user" value="todouser"/>
|
|
||||||
<property name="jakarta.persistence.jdbc.password" value="todopass"/>
|
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
|
||||||
</properties>
|
|
||||||
</persistence-unit>
|
|
||||||
|
|
||||||
</persistence>
|
|
||||||
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
|
||||||
version="4.0">
|
|
||||||
|
|
||||||
<display-name>JakartaEE Todo App</display-name>
|
|
||||||
|
|
||||||
</web-app>
|
|
||||||
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Todo App</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Todo App</h1>
|
|
||||||
|
|
||||||
<form method="post" action="todos">
|
|
||||||
<label for="title">Title:</label>
|
|
||||||
<input type="text" id="title" name="title" required />
|
|
||||||
|
|
||||||
<label for="completed">Completed:</label>
|
|
||||||
<input type="checkbox" id="completed" name="completed" />
|
|
||||||
|
|
||||||
<button type="submit">Add Todo</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<h2>Todos</h2>
|
|
||||||
<ul>
|
|
||||||
<%
|
|
||||||
List<com.example.model.Todo> todos = (List<com.example.model.Todo>) request.getAttribute("todos");
|
|
||||||
if (todos != null) {
|
|
||||||
for (com.example.model.Todo todo : todos) {
|
|
||||||
%>
|
|
||||||
<li><%= todo.getTitle() %> - <%= todo.isCompleted() ? "Completed" : "Pending" %></li>
|
|
||||||
<%
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,8 @@
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.settings
|
||||||
|
target
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
node_modules
|
||||||
27
cmd/jws/projects/spring-boot-todo/.devcontainer/.gitignore
vendored
Normal file
27
cmd/jws/projects/spring-boot-todo/.devcontainer/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
# IDE-spezifische Dateien
|
||||||
|
.idea/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
.vscode/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
# Temporäre Dateien
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# Lokale Konfigurationsdateien
|
||||||
|
src/main/resources/application-local.properties
|
||||||
|
|
||||||
|
# Devcontainer Volumen
|
||||||
|
.devcontainer/postgres-data/
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y curl maven
|
||||||
|
|
||||||
|
RUN curl -o /tmp/postgresql.jar https://jdbc.postgresql.org/download/postgresql-42.6.0.jar && \
|
||||||
|
mkdir -p /usr/local/lib/ && mv /tmp/postgresql.jar /usr/local/lib/postgresql.jar
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN mvn clean install -DskipTests
|
||||||
|
|
||||||
|
CMD ["mvn", "spring-boot:run"]
|
||||||
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"name": "Java & PostgreSQL",
|
||||||
|
"dockerComposeFile": "docker-compose.yml",
|
||||||
|
"service": "app",
|
||||||
|
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||||
|
"forwardPorts": [9080, 5432],
|
||||||
|
"postCreateCommand": "mvn clean install -DskipTests",
|
||||||
|
"remoteUser": "vscode",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers-extra/features/maven-sdkman:2": {
|
||||||
|
"version": "latest"
|
||||||
|
},
|
||||||
|
"ghcr.io/devcontainers/features/git:1": { "version": "latest" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,21 @@
|
||||||
version: "3.8"
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
postgres-data:
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
container_name: javadev
|
container_name: javadev
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ../
|
||||||
dockerfile: Dockerfile
|
dockerfile: .devcontainer/Dockerfile.dev
|
||||||
environment:
|
|
||||||
POSTGRES_PASSWORD: postgres
|
|
||||||
POSTGRES_USER: postgres
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
POSTGRES_HOSTNAME: postgresdb
|
|
||||||
volumes:
|
volumes:
|
||||||
- ..:/workspace
|
- ../..:/workspaces:cached
|
||||||
|
- ./app:/app
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: postgresdb
|
||||||
|
POSTGRES_PORT: 5432
|
||||||
|
POSTGRES_DB: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
command: sleep infinity
|
command: sleep infinity
|
||||||
network_mode: service:db
|
|
||||||
stdin_open: true
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
container_name: postgresdb
|
container_name: postgresdb
|
||||||
|
|
@ -26,7 +23,17 @@ services:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- postgres-data:/var/lib/postgresql/data
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_DB: postgres
|
POSTGRES_DB: todo_db
|
||||||
|
networks:
|
||||||
|
- my_network
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
my_network:
|
||||||
|
driver: bridge
|
||||||
19
cmd/jws/projects/spring-boot-todo/.devcontainer/init.sql
Normal file
19
cmd/jws/projects/spring-boot-todo/.devcontainer/init.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
CREATE TABLE users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE todos (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
description VARCHAR(1000),
|
||||||
|
target_date DATE,
|
||||||
|
completed BOOLEAN,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO users (username, password, email) VALUES
|
||||||
|
('test', '$2a$12$nt7xQKNDKZhxQFZGD5Wy0.Uh0wdPtWDgwfnWnPLgBWnQDGGkNLKBi', 'test@example.com');
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
FROM maven:3.9-eclipse-temurin-17 as builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
COPY . .
|
|
||||||
# RUN mvn clean package
|
|
||||||
|
|
||||||
# Baue die Anwendung mit Maven
|
|
||||||
RUN mvn clean install -DskipTests
|
|
||||||
|
|
||||||
# Verwende ein schlankes OpenJDK-Image für die Ausführung
|
|
||||||
FROM openjdk:17-jdk-slim
|
|
||||||
|
|
||||||
# Setze das Arbeitsverzeichnis im Container
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Kopiere die JAR-Datei aus dem Builder-Image
|
|
||||||
COPY --from=builder /app/target/*.jar app.jar
|
|
||||||
|
|
||||||
# Mache Port 8080 im Container verfügbar (oder den Port, den deine Anwendung verwendet)
|
|
||||||
EXPOSE 8090
|
|
||||||
|
|
||||||
# Definiere den Befehl zum Ausführen der Anwendung
|
|
||||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
|
||||||
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
version: "3.8"
|
|
||||||
services:
|
|
||||||
db:
|
|
||||||
image: postgres:latest
|
|
||||||
container_name: todolist-db
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: todolist
|
|
||||||
POSTGRES_USER: myuser
|
|
||||||
POSTGRES_PASSWORD: mypassword
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
volumes:
|
|
||||||
- db_data:/var/lib/postgresql/data
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U myuser -d todolist"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
app:
|
|
||||||
build: .
|
|
||||||
container_name: todo-spring-app
|
|
||||||
ports:
|
|
||||||
- "8090:8090"
|
|
||||||
depends_on:
|
|
||||||
db:
|
|
||||||
condition: service_healthy
|
|
||||||
environment:
|
|
||||||
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/todolist
|
|
||||||
SPRING_DATASOURCE_USERNAME: myuser
|
|
||||||
SPRING_DATASOURCE_PASSWORD: mypassword
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
db_data:
|
|
||||||
259
cmd/jws/projects/spring-boot-todo/mvnw
vendored
259
cmd/jws/projects/spring-boot-todo/mvnw
vendored
|
|
@ -1,259 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing,
|
|
||||||
# software distributed under the License is distributed on an
|
|
||||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
# KIND, either express or implied. See the License for the
|
|
||||||
# specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
|
||||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
|
||||||
#
|
|
||||||
# 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:]'
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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 <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
|
||||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.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${0##*/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
|
|
||||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
|
||||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
|
||||||
|
|
||||||
clean || :
|
|
||||||
exec_maven "$@"
|
|
||||||
149
cmd/jws/projects/spring-boot-todo/mvnw.cmd
vendored
149
cmd/jws/projects/spring-boot-todo/mvnw.cmd
vendored
|
|
@ -1,149 +0,0 @@
|
||||||
<# : batch portion
|
|
||||||
@REM ----------------------------------------------------------------------------
|
|
||||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
@REM or more contributor license agreements. See the NOTICE file
|
|
||||||
@REM distributed with this work for additional information
|
|
||||||
@REM regarding copyright ownership. The ASF licenses this file
|
|
||||||
@REM to you under the Apache License, Version 2.0 (the
|
|
||||||
@REM "License"); you may not use this file except in compliance
|
|
||||||
@REM with the License. You may obtain a copy of the License at
|
|
||||||
@REM
|
|
||||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@REM
|
|
||||||
@REM Unless required by applicable law or agreed to in writing,
|
|
||||||
@REM software distributed under the License is distributed on an
|
|
||||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
@REM KIND, either express or implied. See the License for the
|
|
||||||
@REM specific language governing permissions and limitations
|
|
||||||
@REM under the License.
|
|
||||||
@REM ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
@REM ----------------------------------------------------------------------------
|
|
||||||
@REM Apache Maven Wrapper startup batch script, version 3.3.2
|
|
||||||
@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) { "/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_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
|
||||||
if ($env:MAVEN_USER_HOME) {
|
|
||||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
|
||||||
}
|
|
||||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::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
|
|
||||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -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"
|
|
||||||
|
|
@ -5,50 +5,75 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.4.3</version>
|
<version>3.2.0</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.todoapp</groupId>
|
||||||
<artifactId>todo-spring</artifactId>
|
<artifactId>spring-todo-app</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>todo-spring</name>
|
<name>spring-todo-app</name>
|
||||||
<description>Demo Todo App for Spring Boot</description>
|
<description>Spring Boot Todo App</description>
|
||||||
<url/>
|
|
||||||
<licenses>
|
|
||||||
<license/>
|
|
||||||
</licenses>
|
|
||||||
<developers>
|
|
||||||
<developer/>
|
|
||||||
</developers>
|
|
||||||
<scm>
|
|
||||||
<connection/>
|
|
||||||
<developerConnection/>
|
|
||||||
<tag/>
|
|
||||||
<url/>
|
|
||||||
</scm>
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<!-- Spring Boot Starter Web für REST APIs -->
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Data JPA (ersetzt direkte Hibernate-Verwendung) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Security für Authentifizierung -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- PostgreSQL Treiber -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- BCrypt für Passwort-Hashing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>at.favre.lib</groupId>
|
||||||
|
<artifactId>bcrypt</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Jackson für JSON -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Validation API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Test Dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
@ -59,5 +84,4 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package com.example.todo_spring;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class TodoSpringApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(TodoSpringApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
package com.example.todo_spring.controllers;
|
|
||||||
|
|
||||||
import com.example.todo_spring.models.Task;
|
|
||||||
import com.example.todo_spring.services.TaskService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/api/v1/tasks")
|
|
||||||
public class TaskController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TaskService taskService;
|
|
||||||
|
|
||||||
@GetMapping("/")
|
|
||||||
public ResponseEntity<List<Task>> getAllTasks() {
|
|
||||||
return ResponseEntity.ok(taskService.getAllTask());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/completed")
|
|
||||||
public ResponseEntity<List<Task>> getAllCompletedTasks() {
|
|
||||||
return ResponseEntity.ok(taskService.findAllCompletedTask());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/incomplete")
|
|
||||||
public ResponseEntity<List<Task>> getAllIncompleteTasks() {
|
|
||||||
return ResponseEntity.ok(taskService.findAllInCompleteTask());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/")
|
|
||||||
public ResponseEntity<Task> createTask(@RequestBody Task task) {
|
|
||||||
return ResponseEntity.ok(taskService.createNewTask(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<Task> updateTask(@PathVariable Long id, @RequestBody Task task) {
|
|
||||||
task.setId(id);
|
|
||||||
return ResponseEntity.ok(taskService.updateTask(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Boolean> getAllTasks(@PathVariable Long id) {
|
|
||||||
taskService.deleteTaskById(id);
|
|
||||||
return ResponseEntity.ok(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
package com.example.todo_spring.models;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Task {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
private String task;
|
|
||||||
private boolean completed;
|
|
||||||
|
|
||||||
public Task(String task, boolean completed) {
|
|
||||||
this.task = task;
|
|
||||||
this.completed = completed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task() {
|
|
||||||
this.task = "";
|
|
||||||
this.completed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTask() {
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTask(String task) {
|
|
||||||
this.task = task;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCompleted() {
|
|
||||||
return completed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCompleted(boolean completed) {
|
|
||||||
this.completed = completed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package com.example.todo_spring.repositories;
|
|
||||||
|
|
||||||
import com.example.todo_spring.models.Task;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface TaskRepository extends JpaRepository<Task, Long> {
|
|
||||||
public Task findByTask(String task);
|
|
||||||
|
|
||||||
public List<Task> findByCompletedTrue();
|
|
||||||
|
|
||||||
public List<Task> findByCompletedFalse();
|
|
||||||
|
|
||||||
public List<Task> findAll();
|
|
||||||
|
|
||||||
public Task getById(Long id);
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
package com.example.todo_spring.services;
|
|
||||||
|
|
||||||
import com.example.todo_spring.models.Task;
|
|
||||||
import com.example.todo_spring.repositories.TaskRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class TaskService {
|
|
||||||
@Autowired
|
|
||||||
private TaskRepository taskRepository;
|
|
||||||
|
|
||||||
public Task createNewTask(Task task) {
|
|
||||||
return taskRepository.save(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Task> getAllTask() {
|
|
||||||
return taskRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task findTaskById(Long id) {
|
|
||||||
return taskRepository.getById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Task> findAllCompletedTask() {
|
|
||||||
return taskRepository.findByCompletedTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Task> findAllInCompleteTask() {
|
|
||||||
return taskRepository.findByCompletedFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteTask(Task task) {
|
|
||||||
taskRepository.delete(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteTaskById(Long id) {
|
|
||||||
Task task = taskRepository.getById(id);
|
|
||||||
taskRepository.delete(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task updateTask(Task task) {
|
|
||||||
return taskRepository.save(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.todoapp;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class TodoAppApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(TodoAppApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue