Go to file
Gustavo Henrique Santos Souza de Miranda a102b24ecd Implement AlbumHasGenre relationship management with CRUD operations
This commit introduces the AlbumHasGenre join table entity management,
  establishing the many-to-many relationship between Album and Genre
  entities. This implementation follows the established repository pattern
  used for other join table entities like AlbumHasArtist.

  Key components implemented:

  Model Layer:
  - AlbumHasGenre entity representing the join table
  - ManyToOne relationships to Album and Genre entities
  - JPA annotations with proper foreign key constraints (nullable = false)
  - Complete getters and setters
  - Custom toString method for debugging

  Repository Layer:
  - AlbumHasGenreRepository with EntityManager-based operations
  - Full transaction management with proper rollback handling
  - Methods: save, findAll, findById, deleteById
  - No update method (join tables typically only need create/delete)

  Service Layer:
  - AlbumHasGenreService with business logic and validation
  - Constructor injection of AlbumHasGenreRepository, AlbumRepository, GenreRepository
  - Relationship validation: ensures both Album and Genre exist before creating association
  - Input validation for null/invalid IDs
  - ID validation for all operations requiring entity lookup
  - Comprehensive logging using Log4j2

  Mapper Layer:
  - AlbumHasGenreMapper for bidirectional entity/protobuf conversion
  - Foreign key mapping for Album and Genre relationships
  - Null safety checks and validation
  - Proper handling of optional ID field

  Action Handlers:
  - CreateAlbumHasGenreHandler (albumhasgenre.create)
  - GetAlbumHasGenreHandler (albumhasgenre.getAll)
  - GetAlbumHasGenreByIdHandler (albumhasgenre.getById)
  - DeleteAlbumHasGenreHandler (albumhasgenre.delete)
  - HTTP status code handling: 200 (success), 400 (validation),
    404 (not found), 500 (server error)
  - No update handler as join tables typically only require create/delete operations

  Protocol Buffers:
  - Complete proto definition with AlbumHasGenreMessages
  - Messages support fk_album_id and fk_genre_id foreign keys
  - CRUD message definitions (Create, Get, GetById, Delete)
  - No Update messages as per join table requirements

  Service Registration:
  - AlbumHasGenreRepository initialized with EntityManagerFactory
  - AlbumHasGenreService registered with ServiceLocator with required dependencies
  - Ensures all AlbumHasGenre action handlers can resolve dependencies
  - Proper dependency injection of AlbumRepository and GenreRepository

  The implementation follows best practices with proper error handling,
  logging, validation, relationship integrity checks, and consistency with
  existing codebase patterns. This enables proper many-to-many relationship
  management between albums and genres, allowing albums to be associated
  with multiple genres and vice versa.

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

  Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 23:24:52 -03:00
src/main Implement AlbumHasGenre relationship management with CRUD operations 2025-12-07 23:24:52 -03:00
.gitignore Register AlbumArtService with service locator and update gitignore 2025-12-07 02:17:29 -03:00
COPYING Add GPLv3 license to project: included `COPYING` file with full license text. 2025-11-13 02:28:26 -03:00
README.md Replace `application.properties` with `config.properties`: 2025-11-13 03:25:33 -03:00
pom.xml Remove `Media` entity and integrate Hibernate ORM into `DatabaseManager`: 2025-11-27 18:40:08 -03:00

README.md

MediaManager Core

A Java-based media management system that uses IPC (Inter-Process Communication) with named pipes and PostgreSQL for data persistence.

Features

  • IPC communication using named pipes
  • PostgreSQL database integration
  • JPA/Hibernate for ORM
  • Log4j 2 for logging
  • HikariCP connection pooling
  • Sample Media entity model

Prerequisites

  • Java 17 or higher
  • Maven 3.6+
  • PostgreSQL 12 or higher

Project Structure

MediaManager-Core/
├── src/
│   └── main/
│       ├── java/
│       │   └── com/
│       │       └── mediamanager/
│       │           ├── config/          # Configuration classes
│       │           ├── model/           # JPA entities
│       │           ├── repository/      # Data access layer
│       │           ├── service/         # Business logic
│       │           ├── ipc/            # IPC implementation
│       │           ├── util/           # Utility classes
│       │           └── MediaManagerApplication.java
│       └── resources/
│           ├── config.properties       # App configuration
│           ├── log4j2.xml              # Logging configuration
│           └── META-INF/
│               └── persistence.xml     # JPA configuration
└── pom.xml

Setup

1. Database Setup

Create a PostgreSQL database and user:

CREATE DATABASE mediamanager;
CREATE USER mediamanager WITH PASSWORD 'changeme';
GRANT ALL PRIVILEGES ON DATABASE mediamanager TO mediamanager;

2. Configuration

Edit src/main/resources/config.properties and update the database credentials:

db.url=jdbc:postgresql://localhost:5432/mediamanager
db.username=mediamanager
db.password=your_password_here

3. Build the Project

mvn clean install

4. Run the Application

mvn exec:java -Dexec.mainClass="com.mediamanager.MediaManagerApplication"

Or build and run the JAR:

mvn clean package
java -jar target/MediaManager-Core-0.0.1-SNAPSHOT.jar

IPC Configuration

The application creates named pipes for inter-process communication. Default configuration:

  • Pipe path: /tmp/mediamanager
  • Pipe name: mediamanager-pipe
  • Buffer size: 8192 bytes

You can modify these settings in config.properties.

Logging

Logs are written to:

  • Console (STDOUT)
  • logs/mediamanager.log (rotating daily, max 10MB per file)

Log configuration can be modified in src/main/resources/log4j2.xml.

Development

Adding New Entities

  1. Create entity class in com.mediamanager.model
  2. Add the entity class to persistence.xml
  3. Create corresponding repository and service classes

Running Tests

mvn test

Dependencies

  • PostgreSQL Driver: 42.7.5
  • Hibernate ORM: 7.1.7.Final
  • HikariCP: 5.1.0
  • Log4j 2: 2.23.1
  • Jackson: 2.16.1
  • JUnit 5: 5.10.2

License

TBD

TODO

  • Implement IPC server with named pipes
  • Implement database connection manager
  • Create repository layer
  • Create service layer
  • Add comprehensive tests
  • Add API documentation