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.
This commit is contained in:
commit
f66cfa6ea4
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
<?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>org.example</groupId>
|
||||
<artifactId>MediaManager-Core</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<hibernate.version>7.1.7.Final</hibernate.version>
|
||||
<postgresql.version>42.7.5</postgresql.version>
|
||||
<hikaricp.version>5.1.0</hikaricp.version>
|
||||
<log4j.version>2.23.1</log4j.version>
|
||||
<junit.version>5.10.2</junit.version>
|
||||
<jackson.version>2.16.1</jackson.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- PostgreSQL Driver -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${postgresql.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate ORM -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HikariCP for connection pooling -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>${hikaricp.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Log4j 2 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Jackson for JSON processing (useful for IPC messages) -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JUnit 5 for testing -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.12.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?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="MediaManagerPU" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<!-- Add entity classes here as they are created -->
|
||||
<!-- <class>com.mediamanager.model.Media</class> -->
|
||||
|
||||
<properties>
|
||||
<!-- Database connection properties will be set programmatically -->
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||
<property name="hibernate.show_sql" value="false"/>
|
||||
<property name="hibernate.format_sql" value="true"/>
|
||||
|
||||
<!-- Connection pool settings -->
|
||||
<property name="hibernate.hikari.maximumPoolSize" value="10"/>
|
||||
<property name="hibernate.hikari.minimumIdle" value="2"/>
|
||||
<property name="hibernate.hikari.connectionTimeout" value="30000"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
|
||||
<RollingFile name="FileAppender" fileName="logs/mediamanager.log"
|
||||
filePattern="logs/mediamanager-%d{yyyy-MM-dd}-%i.log">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1"/>
|
||||
<SizeBasedTriggeringPolicy size="10MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="10"/>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Logger name="com.mediamanager" level="debug" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="FileAppender"/>
|
||||
</Logger>
|
||||
|
||||
<Logger name="org.hibernate" level="info" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="FileAppender"/>
|
||||
</Logger>
|
||||
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="FileAppender"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Loading…
Reference in New Issue