commit f66cfa6ea4cc4072d0f9130f21f2078c1e4086ad Author: Gustavo Henrique Santos Souza de Miranda Date: Thu Nov 13 02:24:11 2025 -0300 Initialize MediaManager-Core project with essential setup: - Added `.gitignore` for common IDE and build artifacts. - Configured `pom.xml` with dependencies: PostgreSQL, Hibernate, HikariCP, Log4j 2, Jackson, JUnit 5. - Created `Media` entity with JPA annotations. - Added `application.properties` for database and IPC configuration. - Configured Log4j 2 with console and rolling file appenders. - Provided `README.md` with setup instructions. - Included `MediaManagerApplication` class as a starting point. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac22162 --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +.kotlin + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +### Application Specific ### +application-local.properties +*.db +pipes/ +*.log \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..df00c07 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..baf75eb --- /dev/null +++ b/README.md @@ -0,0 +1,137 @@ +# 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/ +│ ├── application.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: + +```sql +CREATE DATABASE mediamanager; +CREATE USER mediamanager WITH PASSWORD 'changeme'; +GRANT ALL PRIVILEGES ON DATABASE mediamanager TO mediamanager; +``` + +### 2. Configuration + +Edit `src/main/resources/application.properties` and update the database credentials: + +```properties +db.url=jdbc:postgresql://localhost:5432/mediamanager +db.username=mediamanager +db.password=your_password_here +``` + +### 3. Build the Project + +```bash +mvn clean install +``` + +### 4. Run the Application + +```bash +mvn exec:java -Dexec.mainClass="com.mediamanager.MediaManagerApplication" +``` + +Or build and run the JAR: + +```bash +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 `application.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 + +```bash +mvn test +``` + +## Dependencies + +- PostgreSQL Driver: 42.7.3 +- Hibernate ORM: 6.4.4.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 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9a87f4d --- /dev/null +++ b/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + org.example + MediaManager-Core + 0.0.1-SNAPSHOT + + + 17 + 17 + UTF-8 + 7.1.7.Final + 42.7.5 + 5.1.0 + 2.23.1 + 5.10.2 + 2.16.1 + + + + + + org.postgresql + postgresql + ${postgresql.version} + + + + + org.hibernate.orm + hibernate-core + ${hibernate.version} + + + + + com.zaxxer + HikariCP + ${hikaricp.version} + + + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-slf4j2-impl + ${log4j.version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.12.1 + + 17 + 17 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + + \ No newline at end of file diff --git a/src/main/java/com/mediamanager/MediaManagerApplication.java b/src/main/java/com/mediamanager/MediaManagerApplication.java new file mode 100644 index 0000000..d3030da --- /dev/null +++ b/src/main/java/com/mediamanager/MediaManagerApplication.java @@ -0,0 +1,55 @@ +package com.mediamanager; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class MediaManagerApplication { + private static final Logger logger = LogManager.getLogger(MediaManagerApplication.class); + private static Properties config; + + public static void main(String[] args) { + logger.info("Starting MediaManager Core Application..."); + + try { + // Load configuration + loadConfiguration(); + + // TODO: Initialize database connection + // TODO: Initialize IPC server with named pipes + // TODO: Start application services + + logger.info("MediaManager Core started successfully"); + logger.info("IPC Pipe: {}", config.getProperty("ipc.pipe.path") + "/" + config.getProperty("ipc.pipe.name")); + + // Keep application running + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + logger.info("Shutting down MediaManager Core..."); + // TODO: Cleanup resources + })); + + } catch (Exception e) { + logger.error("Failed to start MediaManager Core", e); + System.exit(1); + } + } + + private static void loadConfiguration() throws IOException { + config = new Properties(); + try (InputStream input = MediaManagerApplication.class.getClassLoader() + .getResourceAsStream("application.properties")) { + if (input == null) { + throw new IOException("Unable to find application.properties"); + } + config.load(input); + logger.info("Configuration loaded successfully"); + } + } + + public static Properties getConfig() { + return config; + } +} diff --git a/src/main/java/com/mediamanager/model/Media.java b/src/main/java/com/mediamanager/model/Media.java new file mode 100644 index 0000000..99a455d --- /dev/null +++ b/src/main/java/com/mediamanager/model/Media.java @@ -0,0 +1,128 @@ +package com.mediamanager.model; + +import jakarta.persistence.*; +import java.time.LocalDateTime; + +@Entity +@Table(name = "media") +public class Media { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String title; + + @Column(nullable = false, unique = true) + private String filePath; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private MediaType type; + + @Column + private Long fileSize; + + @Column + private String mimeType; + + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + @PrePersist + protected void onCreate() { + createdAt = LocalDateTime.now(); + updatedAt = LocalDateTime.now(); + } + + @PreUpdate + protected void onUpdate() { + updatedAt = LocalDateTime.now(); + } + + // Constructors + public Media() {} + + public Media(String title, String filePath, MediaType type) { + this.title = title; + this.filePath = filePath; + this.type = type; + } + + // Getters and Setters + 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 getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public MediaType getType() { + return type; + } + + public void setType(MediaType type) { + this.type = type; + } + + public Long getFileSize() { + return fileSize; + } + + public void setFileSize(Long fileSize) { + this.fileSize = fileSize; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + public enum MediaType { + VIDEO, + AUDIO, + IMAGE, + DOCUMENT, + OTHER + } +} diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..afbc2ee --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,28 @@ + + + + + org.hibernate.jpa.HibernatePersistenceProvider + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..fbef11a --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,23 @@ +# Database Configuration +db.url=jdbc:postgresql://localhost:5432/mediamanager +db.username=mediamanager +db.password=changeme +db.driver=org.postgresql.Driver + +# HikariCP Connection Pool Settings +db.pool.maximum-pool-size=10 +db.pool.minimum-idle=2 +db.pool.connection-timeout=30000 +db.pool.idle-timeout=600000 +db.pool.max-lifetime=1800000 + +# Hibernate Settings +hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +hibernate.hbm2ddl.auto=update +hibernate.show_sql=false +hibernate.format_sql=true + +# IPC Configuration +ipc.pipe.name=mediamanager-pipe +ipc.pipe.path=/tmp/mediamanager +ipc.buffer.size=8192 diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..29d32dc --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +