Compare commits

...
Author SHA1 Message Date
Gustavo Henrique Miranda dccbfcf546 Merge pull request #22 from gmbrax/feature/Implement-AlbumType-Management
Implement AlbumType management with full CRUD operations
2025-12-07 20:09:01 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 7446047b9d Implement AlbumType management with full CRUD operations
This commit introduces comprehensive AlbumType entity management following
the established repository pattern used for other entities like SamplingRate
and AlbumArt.

Key components implemented:

Model Layer:
- AlbumType entity with id and value fields
- JPA annotations for database persistence
- Complete getters and setters

Repository Layer:
- AlbumTypeRepository with EntityManager-based operations
- Full transaction management with proper rollback handling
- Methods: save, findAll, findById, update, deleteById

Service Layer:
- AlbumTypeService with business logic and validation
- Input validation for null/empty value fields
- ID validation for all operations requiring entity lookup
- Comprehensive logging using Log4j2

Mapper Layer:
- AlbumTypeMapper for bidirectional entity/protobuf conversion
- Null safety checks and validation
- Proper handling of optional ID field

Action Handlers:
- CreateAlbumTypeHandler (albumtype.create)
- GetAlbumTypeHandler (albumtype.getAll)
- GetAlbumTypeByIdHandler (albumtype.getById)
- UpdateAlbumTypeHandler (albumtype.update)
- DeleteAlbumTypeHandler (albumtype.delete)
- HTTP status code handling: 200 (success), 400 (validation),
  404 (not found), 500 (server error)

Protocol Buffers:
- Complete proto definition with AlbumTypeMessages
- All CRUD message definitions (Create, Get, GetById, Update, Delete)

Service Registration:
- AlbumTypeRepository initialized with EntityManagerFactory
- AlbumTypeService registered with ServiceLocator for dependency injection
- Ensures all AlbumType action handlers can resolve dependencies

The implementation follows best practices with proper error handling,
logging, validation, and consistency with existing codebase patterns.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 13:15:01 -03:00
Gustavo Henrique Miranda f43c609e04 Merge pull request #21 from gmbrax/feature/Implement-AlbumArt-Management
Feature/implement album art management
2025-12-07 02:34:38 -03:00
Gustavo Henrique Mirandaandcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> dc1f6dfbc8 Update src/main/java/com/mediamanager/model/AlbumArt.java
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-12-07 02:30:51 -03:00
Gustavo Henrique Mirandaandcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> 0aac0f2f14 Update src/main/proto/albumart.proto
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-12-07 02:21:47 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 2fb890a485 Register AlbumArtService with service locator and update gitignore
This commit completes the AlbumArt feature integration by registering
the service with the dependency injection system and updating repository
ignore rules.

Service Registration:
- Initialize AlbumArtRepository with EntityManagerFactory
- Create AlbumArtService instance with repository dependency
- Register AlbumArtService with ServiceLocator for handler injection
- Ensures all AlbumArt action handlers can resolve dependencies

The service follows the established initialization pattern used by other
entities (SamplingRate, BitDepth, BitRate, etc.) ensuring consistency
across the application architecture.

Repository Configuration:
- Add src/scripts/* to .gitignore for local script files
- Add local-repo/ to .gitignore for local Maven repository cache
- Prevents accidental commits of development artifacts and dependencies

These changes complete the AlbumArt feature, making it fully operational
and accessible through the action handler system.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 02:17:29 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 745ba7e5fc Implement AlbumArt management with full CRUD operations
This commit introduces comprehensive AlbumArt entity management following
the established repository pattern used for other entities like SamplingRate.

Key components implemented:

Model Layer:
- AlbumArt entity with id and filepath fields
- JPA annotations for database persistence

Repository Layer:
- AlbumArtRepository with EntityManager-based operations
- Full transaction management with proper rollback handling
- Methods: save, findAll, findById, update, deleteById

Service Layer:
- AlbumArtService with business logic and validation
- Input validation for null/empty filepath values
- ID validation for all operations requiring entity lookup
- Comprehensive logging using Log4j2

Mapper Layer:
- AlbumArtMapper for bidirectional entity/protobuf conversion
- Null safety checks and validation
- Proper handling of optional ID field

Action Handlers:
- CreateAlbumArtHandler (albumart.create)
- GetAlbumArtHandler (albumart.getAll)
- GetAlbumArtByIdHandler (albumart.getById)
- UpdateAlbumArtHandler (albumart.update)
- DeleteAlbumArtHandler (albumart.delete)
- HTTP status code handling: 200 (success), 400 (validation),
  404 (not found), 500 (server error)

Protocol Buffers:
- Fixed java_outer_classname from "BitDepthMessages" to "AlbumArtMessages"
- All CRUD message definitions (Create, Get, GetById, Update, Delete)

The implementation follows best practices with proper error handling,
logging, validation, and consistency with existing codebase patterns.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 02:15:57 -03:00
Gustavo Henrique Miranda ace73ae9c0 Merge pull request #20 from gmbrax/feature/Implement-SamplingRate-management
Feature/implement sampling rate management
2025-12-06 23:13:46 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 94297e75b9 Add id validation and improve code formatting in updateSamplingRate
Enhance input validation and code quality in the SamplingRate service:

- Add null check for id parameter in updateSamplingRate() method to prevent
  potential NullPointerException when calling repository.findById()
- Standardize indentation throughout the updateSamplingRate() method body,
  improving code readability and consistency with project style guidelines

This complements the previous validation improvements by ensuring all
method parameters are properly validated before use, creating a more
defensive and robust API surface.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-06 22:30:51 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 ff09d1b89a Fix null handling and validation in SamplingRate management
This commit addresses potential runtime exceptions and improves input validation:

- Replace Optional.of() with Optional.ofNullable() in SamplingRateRepository.findById()
  to properly handle cases where no sampling rate is found, preventing NullPointerException
- Add null validation for id parameter in SamplingRateService.deleteSamplingRate()
  to ensure proper error handling before repository operations
- Clean up code formatting in updateSamplingRate() validation block

These changes enhance the robustness of the sampling rate management feature
by preventing NPEs and providing clearer error messages for invalid inputs.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-06 22:18:57 -03:00
Gustavo Henrique Mirandaandcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> 4fa147282f Update src/main/java/com/mediamanager/service/samplingrate/SamplingRateService.java
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-12-06 22:07:39 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 5ff972ebcb Fix message name casing in SamplingRate proto definition
Standardize the naming convention by changing `GetSamplingRateByIDRequest`
to `GetSamplingRateByIdRequest`, using "Id" instead of "ID" for consistency
with other proto message names across the codebase. Updated the corresponding
handler to reference the corrected message name.

This aligns with the established naming pattern and improves code consistency
following the same convention applied in other proto definitions.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-06 02:55:36 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 5aeb54516c Implement sampling rate management with full CRUD operations
This commit introduces comprehensive sampling rate management functionality
to the MediaManager system, following the established patterns from BitDepth
and BitRate implementations.

Core Components Added:
- SamplingRate entity model with JPA annotations for database persistence
- SamplingRateRepository with full CRUD operations (save, findAll, findById, update, deleteById)
- SamplingRateService business logic layer with validation and error handling
- SamplingRateMapper for bidirectional entity-protobuf conversions

Protocol Buffers:
- Defined samplingrate.proto with complete message specifications
- SamplingRate message structure (id, value)
- Request/Response pairs for all CRUD operations (Create, GetAll, GetById, Update, Delete)
- Fixed typo in UpdateSamplingRateRequest (valeu -> value)

Action Handlers:
- CreateSamplingRateHandler: Validates and creates new sampling rate entries
- GetSamplingRateHandler: Retrieves all sampling rates from the database
- GetSamplingRateByIdHandler: Fetches individual sampling rates with 404 handling
- UpdateSamplingRateHandler: Updates existing sampling rates with validation
- DeleteSamplingRateHandler: Removes sampling rates with success confirmation

Integration:
- Registered SamplingRateService in DelegateActionManager
- All handlers follow the @Action annotation pattern for automatic discovery
- Consistent error handling with appropriate HTTP status codes (400, 404, 500)

This implementation provides a complete foundation for managing audio sampling
rates within the media management system, enabling clients to perform all
standard CRUD operations through the established protocol buffer interface.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-06 02:41:48 -03:00
Gustavo Henrique Miranda 1dd2542656 Merge pull request #19 from gmbrax/fix/Fix-artist-proto-mismatch
Feature/Implement-BitRate-Management
2025-12-05 21:55:31 -03:00
Gustavo Henrique Santos Souza de MirandaandClaude Sonnet 4.5 c787eba20e Fix field name casing in UpdateArtistResponse proto message
Change field name from 'Artist' to 'artist' to follow protobuf naming conventions, which require lowercase field names with underscores for word separation.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-05 21:48:46 -03:00
Gustavo Henrique Santos Souza de Miranda 2294a57ffd Implement bit-rate management feature
Add complete CRUD functionality for bit-rate management following the same pattern as bit-depth:
  - Create BitRate entity model with JPA annotations
  - Implement BitRateRepository with full CRUD operations
  - Add BitRateService with validation and business logic
  - Create BitRateMapper for protobuf/entity conversion
  - Implement action handlers: Create, GetAll, GetById, Update, Delete
  - Define bitrate.proto protobuf message definitions
  - Register BitRateService in DelegateActionManager

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

  Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 20:43:04 -03:00
Gustavo Henrique Miranda 8c8b8ec765 Merge pull request #17 from gmbrax/fix/Fix-Repeated-return-on-CreateBitDepthHandler
Remove duplicate `newBuilder` call in `CreateBitDepthHandler`
2025-12-05 18:12:32 -03:00
Gustavo Henrique Santos Souza de Miranda 92b4b21e60 Remove duplicate TransportProtocol.Response.newBuilder() call in CreateBitDepthHandler. 2025-12-05 17:02:02 -03:00
Gustavo Henrique Miranda 026a3aefa4 Merge pull request #15 from gmbrax/feature/implement-bitdepth-management
Implement BitDepth Management with CRUD Operations
2025-12-05 04:55:14 -03:00
44 changed files with 2307 additions and 3 deletions
+3 -1
View File
@@ -51,4 +51,6 @@ src/main/resources/config.properties
src/main/resources/application.properties src/main/resources/application.properties
# Allow example configuration files to be committed # Allow example configuration files to be committed
!src/main/resources/*.properties.example !src/main/resources/*.properties.example
src/scripts/*
local-repo/
@@ -0,0 +1,35 @@
package com.mediamanager.mapper;
import com.mediamanager.model.AlbumArt;
import com.mediamanager.protocol.messages.AlbumArtMessages;
public class AlbumArtMapper {
public static AlbumArtMessages.AlbumArt toProtobuf(AlbumArt entity) {
if (entity == null) {
return null;
}
String filepath = entity.getFilepath();
if (filepath == null || filepath.isEmpty()) {
throw new IllegalArgumentException("Filepath cannot be null or empty");
}
AlbumArtMessages.AlbumArt.Builder builder = AlbumArtMessages.AlbumArt.newBuilder()
.setFilepath(filepath);
Integer id = entity.getId();
if (id != null) {
builder.setId(id);
}
return builder.build();
}
public static AlbumArt toEntity(AlbumArtMessages.AlbumArt protobuf) {
if (protobuf == null) {
return null;
}
AlbumArt entity = new AlbumArt();
if (protobuf.getId() >0) {
entity.setId(protobuf.getId());
}
entity.setFilepath(protobuf.getFilepath());
return entity;
}
}
@@ -0,0 +1,35 @@
package com.mediamanager.mapper;
import com.mediamanager.model.AlbumType;
import com.mediamanager.protocol.messages.AlbumTypeMessages;
public class AlbumTypeMapper {
public static AlbumTypeMessages.AlbumType toProtobuf(AlbumType entity) {
if (entity == null) {
return null;
}
String value = entity.getValue();
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("Value cannot be null or empty");
}
AlbumTypeMessages.AlbumType.Builder builder = AlbumTypeMessages.AlbumType.newBuilder()
.setValue(value);
Integer id = entity.getId();
if (id != null) {
builder.setId(id);
}
return builder.build();
}
public static AlbumType toEntity(AlbumTypeMessages.AlbumType protobuf) {
if (protobuf == null) {
return null;
}
AlbumType entity = new AlbumType();
if (protobuf.getId() >0) {
entity.setId(protobuf.getId());
}
entity.setValue(protobuf.getValue());
return entity;
}
}
@@ -0,0 +1,39 @@
package com.mediamanager.mapper;
import com.mediamanager.model.BitRate;
import com.mediamanager.protocol.messages.BitRateMessages;
public class BitRateMapper {
public static BitRateMessages.BitRate toProtobuf(BitRate entity) {
if (entity == null) {
return null;
}
String value = entity.getValue();
if (value == null) {
throw new IllegalArgumentException("Bit rate value cannot be null");
}
BitRateMessages.BitRate.Builder builder = BitRateMessages.BitRate.newBuilder()
.setValue(value);
Integer id = entity.getId();
if (id != null && id > 0) {
builder.setId(id);
}
return builder.build();
}
public static BitRate toEntity(BitRateMessages.BitRate protobuf) {
if (protobuf == null) {
return null;
}
BitRate entity = new BitRate();
if (protobuf.getId() > 0) {
entity.setId(protobuf.getId());
}
entity.setValue(protobuf.getValue());
return entity;
}
}
@@ -0,0 +1,35 @@
package com.mediamanager.mapper;
import com.mediamanager.model.SamplingRate;
import com.mediamanager.protocol.messages.SamplingRateMessages;
public class SamplingRateMapper {
public static SamplingRateMessages.SamplingRate toProtobuf(SamplingRate entity) {
if (entity == null) {
return null;
}
String value = entity.getValue();
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("Value cannot be null or empty");
}
SamplingRateMessages.SamplingRate.Builder builder = SamplingRateMessages.SamplingRate.newBuilder()
.setValue(value);
Integer id = entity.getId();
if (id != null) {
builder.setId(id);
}
return builder.build();
}
public static SamplingRate toEntity(SamplingRateMessages.SamplingRate protobuf) {
if (protobuf == null) {
return null;
}
SamplingRate entity = new SamplingRate();
if (protobuf.getId() >0) {
entity.setId(protobuf.getId());
}
entity.setValue(protobuf.getValue());
return entity;
}
}
@@ -0,0 +1,33 @@
package com.mediamanager.model;
import jakarta.persistence.*;
@Entity
@Table(name = "albumArt")
public class AlbumArt {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String filepath;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFilepath() {
return filepath;
}
public void setFilepath(String filepath) {
this.filepath = filepath;
}
}
@@ -0,0 +1,31 @@
package com.mediamanager.model;
import jakarta.persistence.*;
@Entity
@Table(name = "albumtype")
public class AlbumType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String value;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
@@ -0,0 +1,31 @@
package com.mediamanager.model;
import jakarta.persistence.*;
@Entity
@Table(name = "bit_rate")
public class BitRate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String value;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
@@ -0,0 +1,30 @@
package com.mediamanager.model;
import jakarta.persistence.*;
@Entity
@Table(name = "sampling_rate")
public class SamplingRate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String value;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
@@ -0,0 +1,103 @@
package com.mediamanager.repository;
import com.mediamanager.model.AlbumArt;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class AlbumArtRepository {
private static final Logger logger = LogManager.getLogger(AlbumArtRepository.class);
private final EntityManagerFactory entityManagerFactory;
public AlbumArtRepository(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
public AlbumArt save(AlbumArt albumArt) {
logger.debug("Saving AlbumArt: {}", albumArt.getFilepath());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
em.persist(albumArt);
em.getTransaction().commit();
logger.debug("AlbumArt has been saved successfully");
return albumArt;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while saving AlbumArt: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public List<AlbumArt> findAll() {
logger.debug("Finding All AlbumArt");
EntityManager em = entityManagerFactory.createEntityManager();
try{
return em.createQuery("select a from AlbumArt a", AlbumArt.class).getResultList();
}finally {
if (em.isOpen()) em.close();
}
}
public Optional<AlbumArt> findById(Integer id) {
logger.debug("Finding AlbumArt with id: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
try{
AlbumArt albumArt = em.find(AlbumArt.class, id);
return Optional.ofNullable(albumArt);
}finally {
if (em.isOpen()) em.close();
}
}
public AlbumArt update(AlbumArt albumArt) {
logger.debug("Updating AlbumArt: {}", albumArt.getFilepath());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
AlbumArt updated = em.merge(albumArt);
em.getTransaction().commit();
logger.debug("AlbumArt has been updated successfully");
return updated;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while updating AlbumArt: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public boolean deleteById(Integer id){
logger.debug("Deleting AlbumArt with id: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try{
AlbumArt albumArt = em.find(AlbumArt.class, id);
if (albumArt == null) {
em.getTransaction().rollback();
return false;
}
em.remove(albumArt);
em.getTransaction().commit();
logger.debug("AlbumArt has been deleted successfully");
return true;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while deleting AlbumArt: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
}
@@ -0,0 +1,103 @@
package com.mediamanager.repository;
import com.mediamanager.model.AlbumType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class AlbumTypeRepository {
private static final Logger logger = LogManager.getLogger(AlbumTypeRepository.class);
private final EntityManagerFactory entityManagerFactory;
public AlbumTypeRepository(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
public AlbumType save(AlbumType albumType) {
logger.debug("Saving AlbumType: {}", albumType.getValue());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
em.persist(albumType);
em.getTransaction().commit();
logger.debug("AlbumType has been saved successfully");
return albumType;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while saving AlbumType: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public List<AlbumType> findAll() {
logger.debug("Finding All AlbumType");
EntityManager em = entityManagerFactory.createEntityManager();
try{
return em.createQuery("select a from AlbumType a", AlbumType.class).getResultList();
}finally {
if (em.isOpen()) em.close();
}
}
public Optional<AlbumType> findById(Integer id) {
logger.debug("Finding AlbumType with id: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
try{
AlbumType albumType = em.find(AlbumType.class, id);
return Optional.ofNullable(albumType);
}finally {
if (em.isOpen()) em.close();
}
}
public AlbumType update(AlbumType albumType) {
logger.debug("Updating AlbumType: {}", albumType.getValue());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
AlbumType updated = em.merge(albumType);
em.getTransaction().commit();
logger.debug("AlbumType has been updated successfully");
return updated;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while updating AlbumType: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public boolean deleteById(Integer id){
logger.debug("Deleting AlbumType with id: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try{
AlbumType albumType = em.find(AlbumType.class, id);
if (albumType == null) {
em.getTransaction().rollback();
return false;
}
em.remove(albumType);
em.getTransaction().commit();
logger.debug("AlbumType has been deleted successfully");
return true;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while deleting AlbumType: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
}
@@ -0,0 +1,101 @@
package com.mediamanager.repository;
import com.mediamanager.model.BitRate;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class BitRateRepository {
private static final Logger logger = LogManager.getLogger(BitRateRepository.class);
private final EntityManagerFactory entityManagerFactory;
public BitRateRepository(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
public BitRate save(BitRate bitRate) {
logger.debug("Saving BitRate: {}", bitRate.getValue());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
em.persist(bitRate);
em.getTransaction().commit();
logger.debug("BitRate saved with ID: {}", bitRate.getId());
return bitRate;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error saving BitRate", e);
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public List<BitRate> findAll(){
logger.debug("Finding all BitRates");
EntityManager em = entityManagerFactory.createEntityManager();
try{
return em.createQuery("SELECT b FROM BitRate b ORDER BY b.value", BitRate.class).getResultList();
}finally {
if (em.isOpen()) em.close();
}
}
public Optional<BitRate> findById(Integer id){
logger.debug("Finding BitRate by ID: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
try{
BitRate bitRate = em.find(BitRate.class, id);
return Optional.ofNullable(bitRate);
} finally {
if (em.isOpen()) em.close();
}
}
public BitRate update(BitRate bitRate){
logger.debug("Updating BitRate ID: {}", bitRate.getId());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try{
BitRate updated = em.merge(bitRate);
em.getTransaction().commit();
logger.debug("BitRate updated with ID: {}", bitRate.getId());
return updated;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error updating BitRate", e);
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public boolean deleteById(Integer id){
logger.debug("Deleting BitRate by ID: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try{
BitRate bitRate = em.find(BitRate.class, id);
if (bitRate == null) {
em.getTransaction().rollback();
return false;
}
em.remove(bitRate);
em.getTransaction().commit();
logger.debug("BitRate deleted successfully");
return true;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error deleting BitRate", e);
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
}
@@ -0,0 +1,103 @@
package com.mediamanager.repository;
import com.mediamanager.model.SamplingRate;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class SamplingRateRepository {
private static final Logger logger = LogManager.getLogger(SamplingRateRepository.class);
private final EntityManagerFactory entityManagerFactory;
public SamplingRateRepository(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
public SamplingRate save(SamplingRate samplingRate) {
logger.debug("Saving SamplingRate: {}", samplingRate.getValue());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
em.persist(samplingRate);
em.getTransaction().commit();
logger.debug("SamplingRate has been saved successfully");
return samplingRate;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while saving SamplingRate: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public List<SamplingRate> findAll() {
logger.debug("Finding All SamplingRate");
EntityManager em = entityManagerFactory.createEntityManager();
try{
return em.createQuery("select s from SamplingRate s", SamplingRate.class).getResultList();
}finally {
if (em.isOpen()) em.close();
}
}
public Optional<SamplingRate> findById(Integer id) {
logger.debug("Finding SamplingRate with id: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
try{
SamplingRate samplingRate = em.find(SamplingRate.class, id);
return Optional.ofNullable(samplingRate);
}finally {
if (em.isOpen()) em.close();
}
}
public SamplingRate update(SamplingRate samplingRate) {
logger.debug("Updating SamplingRate: {}", samplingRate.getValue());
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
SamplingRate updated = em.merge(samplingRate);
em.getTransaction().commit();
logger.debug("SamplingRate has been updated successfully");
return updated;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while updating SamplingRate: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
public boolean deleteById(Integer id){
logger.debug("Deleting SamplingRate with id: {}", id);
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try{
SamplingRate samplingRate = em.find(SamplingRate.class, id);
if (samplingRate == null) {
em.getTransaction().rollback();
return false;
}
em.remove(samplingRate);
em.getTransaction().commit();
logger.debug("SamplingRate has been deleted successfully");
return true;
} catch (Exception e) {
em.getTransaction().rollback();
logger.error("Error while deleting SamplingRate: {}", e.getMessage());
throw e;
} finally {
if (em.isOpen()) em.close();
}
}
}
@@ -0,0 +1,69 @@
package com.mediamanager.service.albumart;
import com.mediamanager.model.AlbumArt;
import com.mediamanager.repository.AlbumArtRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class AlbumArtService {
private static final Logger logger = LogManager.getLogger(AlbumArtService.class);
private final AlbumArtRepository repository;
public AlbumArtService(AlbumArtRepository repository) {
this.repository = repository;
}
public AlbumArt createAlbumArt(String filepath) {
logger.debug("Creating album art:{}", filepath);
if (filepath == null || filepath.trim().isEmpty()) {
throw new IllegalArgumentException("AlbumArt filepath cannot be null or empty");
}
AlbumArt albumArt = new AlbumArt();
albumArt.setFilepath(filepath);
return repository.save(albumArt);
}
public List<AlbumArt> getAllAlbumArts() {
logger.info("Getting all album arts");
return repository.findAll();
}
public Optional<AlbumArt> getAlbumArtById(Integer id) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Getting album art by id:{}", id);
return repository.findById(id);
}
public Optional<AlbumArt> updateAlbumArt(Integer id, String filepath) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Updating album art:{}", filepath);
if (filepath == null || filepath.trim().isEmpty()) {
throw new IllegalArgumentException("AlbumArt filepath cannot be null or empty");
}
Optional<AlbumArt> existingAlbumArt = repository.findById(id);
if(existingAlbumArt.isEmpty()) {
logger.warn("Album art not found with id:{}", id);
return Optional.empty();
}
AlbumArt albumArt = existingAlbumArt.get();
albumArt.setFilepath(filepath);
AlbumArt updatedAlbumArt = repository.update(albumArt);
return Optional.of(updatedAlbumArt);
}
public boolean deleteAlbumArt(Integer id) {
if (id == null) {
throw new IllegalArgumentException("Album art id cannot be null");
}
logger.info("Deleting album art:{}", id);
return repository.deleteById(id);
}
}
@@ -0,0 +1,69 @@
package com.mediamanager.service.albumtype;
import com.mediamanager.model.AlbumType;
import com.mediamanager.repository.AlbumTypeRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class AlbumTypeService {
private static final Logger logger = LogManager.getLogger(AlbumTypeService.class);
private final AlbumTypeRepository repository;
public AlbumTypeService(AlbumTypeRepository repository) {
this.repository = repository;
}
public AlbumType createAlbumType(String value) {
logger.debug("Creating album type:{}", value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("AlbumType value cannot be null or empty");
}
AlbumType albumType = new AlbumType();
albumType.setValue(value);
return repository.save(albumType);
}
public List<AlbumType> getAllAlbumTypes() {
logger.info("Getting all album types");
return repository.findAll();
}
public Optional<AlbumType> getAlbumTypeById(Integer id) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Getting album type by id:{}", id);
return repository.findById(id);
}
public Optional<AlbumType> updateAlbumType(Integer id, String value) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Updating album type:{}", value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("AlbumType value cannot be null or empty");
}
Optional<AlbumType> existingAlbumType = repository.findById(id);
if(existingAlbumType.isEmpty()) {
logger.warn("Album type not found with id:{}", id);
return Optional.empty();
}
AlbumType albumType = existingAlbumType.get();
albumType.setValue(value);
AlbumType updatedAlbumType = repository.update(albumType);
return Optional.of(updatedAlbumType);
}
public boolean deleteAlbumType(Integer id) {
if (id == null) {
throw new IllegalArgumentException("Album type id cannot be null");
}
logger.info("Deleting album type:{}", id);
return repository.deleteById(id);
}
}
@@ -0,0 +1,65 @@
package com.mediamanager.service.bitrate;
import com.mediamanager.model.BitRate;
import com.mediamanager.repository.BitRateRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class BitRateService {
private static final Logger logger = LogManager.getLogger(BitRateService.class);
private final BitRateRepository bitRateRepository;
public BitRateService(BitRateRepository bitRateRepository) {
this.bitRateRepository = bitRateRepository;
}
public BitRate createBitRate(String value){
logger.info("Creating bit-rate: {}",value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Bit-rate value cannot be empty");
}
BitRate bitRate = new BitRate();
bitRate.setValue(value.trim());
return bitRateRepository.save(bitRate);
}
public List<BitRate> getAllBitRates(){
logger.info("Getting all bit-rates");
return bitRateRepository.findAll();
}
public Optional<BitRate> getBitRateById(Integer id){
logger.info("Getting bit-rate by ID: {}", id);
return bitRateRepository.findById(id);
}
public Optional<BitRate> updateBitRate(Integer id, String value){
logger.info("Updating bit-rate ID {}: {}", id, value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Bit-rate value cannot be empty");
}
Optional<BitRate> existingBitRate = bitRateRepository.findById(id);
if(existingBitRate.isEmpty()) {
logger.warn("Bit-rate not found with ID: {}", id);
return Optional.empty();
}
BitRate bitRate = existingBitRate.get();
bitRate.setValue(value.trim());
BitRate updatedBitRate = bitRateRepository.update(bitRate);
return Optional.of(updatedBitRate);
}
public boolean deleteBitRate(Integer id){
logger.info("Deleting bit-rate ID: {}", id);
return bitRateRepository.deleteById(id);
}
}
@@ -3,13 +3,17 @@ package com.mediamanager.service.delegate;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.mediamanager.protocol.TransportProtocol; import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.repository.*; import com.mediamanager.repository.*;
import com.mediamanager.service.albumart.AlbumArtService;
import com.mediamanager.service.albumtype.AlbumTypeService;
import com.mediamanager.service.bitdepth.BitDepthService; import com.mediamanager.service.bitdepth.BitDepthService;
import com.mediamanager.service.bitrate.BitRateService;
import com.mediamanager.service.composer.ComposerService; import com.mediamanager.service.composer.ComposerService;
import com.mediamanager.repository.GenreRepository; import com.mediamanager.repository.GenreRepository;
import com.mediamanager.service.artist.ArtistService; import com.mediamanager.service.artist.ArtistService;
import com.mediamanager.service.delegate.annotation.Action; import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.genre.GenreService; import com.mediamanager.service.genre.GenreService;
import com.mediamanager.service.samplingrate.SamplingRateService;
import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -65,6 +69,22 @@ public class DelegateActionManager {
BitDepthService bitDepthService = new BitDepthService(bitDepthRepository); BitDepthService bitDepthService = new BitDepthService(bitDepthRepository);
serviceLocator.register(BitDepthService.class, bitDepthService); serviceLocator.register(BitDepthService.class, bitDepthService);
BitRateRepository bitRateRepository = new BitRateRepository(entityManagerFactory);
BitRateService bitRateService = new BitRateService(bitRateRepository);
serviceLocator.register(BitRateService.class, bitRateService);
SamplingRateRepository samplingRateRepository = new SamplingRateRepository(entityManagerFactory);
SamplingRateService samplingRateService = new SamplingRateService(samplingRateRepository);
serviceLocator.register(SamplingRateService.class, samplingRateService);
AlbumArtRepository albumArtRepository = new AlbumArtRepository(entityManagerFactory);
AlbumArtService albumArtService = new AlbumArtService(albumArtRepository);
serviceLocator.register(AlbumArtService.class, albumArtService);
AlbumTypeRepository albumTypeRepository = new AlbumTypeRepository(entityManagerFactory);
AlbumTypeService albumTypeService = new AlbumTypeService(albumTypeRepository);
serviceLocator.register(AlbumTypeService.class, albumTypeService);
serviceLocator.logRegisteredServices(); serviceLocator.logRegisteredServices();
logger.info("Services initialized successfully"); logger.info("Services initialized successfully");
@@ -0,0 +1,49 @@
package com.mediamanager.service.delegate.handler.albumart;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumArtMapper;
import com.mediamanager.model.AlbumArt;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumArtMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumart.AlbumArtService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("albumart.create")
public class CreateAlbumArtHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(CreateAlbumArtHandler.class);
private final AlbumArtService albumArtService;
public CreateAlbumArtHandler(AlbumArtService albumArtService) {
this.albumArtService = albumArtService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
AlbumArtMessages.CreateAlbumArtRequest createRequest =
AlbumArtMessages.CreateAlbumArtRequest.parseFrom(requestPayload);
AlbumArt albumArt = albumArtService.createAlbumArt(createRequest.getFilepath());
AlbumArtMessages.AlbumArt albumArtProto = AlbumArtMapper.toProtobuf(albumArt);
AlbumArtMessages.CreateAlbumArtResponse createAlbumArtResponse = AlbumArtMessages.CreateAlbumArtResponse.newBuilder()
.setAlbumart(albumArtProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(createAlbumArtResponse.toByteString());
} catch (IllegalArgumentException e) {
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error creating album art", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,62 @@
package com.mediamanager.service.delegate.handler.albumart;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumArtMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumart.AlbumArtService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("albumart.delete")
public class DeleteAlbumArtHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(DeleteAlbumArtHandler.class);
private final AlbumArtService albumArtService;
public DeleteAlbumArtHandler(AlbumArtService albumArtService) {
this.albumArtService = albumArtService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException {
try {
AlbumArtMessages.DeleteAlbumArtRequest deleteRequest =
AlbumArtMessages.DeleteAlbumArtRequest.parseFrom(requestPayload);
int id = deleteRequest.getId();
boolean success = albumArtService.deleteAlbumArt(id);
AlbumArtMessages.DeleteAlbumArtResponse deleteResponse;
if (success) {
deleteResponse = AlbumArtMessages.DeleteAlbumArtResponse.newBuilder()
.setSuccess(true)
.setMessage("Album art deleted successfully")
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(deleteResponse.toByteString());
} else {
deleteResponse = AlbumArtMessages.DeleteAlbumArtResponse.newBuilder()
.setSuccess(false)
.setMessage("Album art not found")
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(deleteResponse.toByteString());
}
} catch (Exception e) {
logger.error("Error deleting album art", e);
AlbumArtMessages.DeleteAlbumArtResponse deleteResponse =
AlbumArtMessages.DeleteAlbumArtResponse.newBuilder()
.setSuccess(false)
.setMessage("Error: " + e.getMessage())
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(deleteResponse.toByteString());
}
}
}
@@ -0,0 +1,56 @@
package com.mediamanager.service.delegate.handler.albumart;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumArtMapper;
import com.mediamanager.model.AlbumArt;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumArtMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumart.AlbumArtService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action(value = "albumart.getById")
public class GetAlbumArtByIdHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetAlbumArtByIdHandler.class);
private final AlbumArtService albumArtService;
public GetAlbumArtByIdHandler(AlbumArtService albumArtService) {
this.albumArtService = albumArtService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException{
try{
AlbumArtMessages.GetAlbumArtByIdRequest getByIdRequest =
AlbumArtMessages.GetAlbumArtByIdRequest.parseFrom(requestPayload);
int id = getByIdRequest.getId();
Optional<AlbumArt> albumArtOpt = albumArtService.getAlbumArtById(id);
if (albumArtOpt.isEmpty()){
logger.warn("AlbumArt not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("AlbumArt not found"));
}
AlbumArtMessages.AlbumArt albumArtProto = AlbumArtMapper.toProtobuf(albumArtOpt.get());
AlbumArtMessages.GetAlbumArtByIdResponse getByIdResponse = AlbumArtMessages.GetAlbumArtByIdResponse.newBuilder()
.setAlbumart(albumArtProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getByIdResponse.toByteString());
} catch (Exception e) {
logger.error("Error getting album art by ID", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
}
}
}
@@ -0,0 +1,48 @@
package com.mediamanager.service.delegate.handler.albumart;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumArtMapper;
import com.mediamanager.model.AlbumArt;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumArtMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumart.AlbumArtService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
@Action("albumart.getAll")
public class GetAlbumArtHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetAlbumArtHandler.class);
private final AlbumArtService albumArtService;
public GetAlbumArtHandler(AlbumArtService albumArtService){this.albumArtService = albumArtService;}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
List<AlbumArt> albumArts = albumArtService.getAllAlbumArts();
AlbumArtMessages.GetAlbumArtsResponse.Builder responseBuilder = AlbumArtMessages.GetAlbumArtsResponse.newBuilder();
for (AlbumArt albumArt : albumArts) {
AlbumArtMessages.AlbumArt albumArtProto = AlbumArtMapper.toProtobuf(albumArt);
responseBuilder.addAlbumarts(albumArtProto);
}
AlbumArtMessages.GetAlbumArtsResponse getAlbumArtsResponse = responseBuilder.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getAlbumArtsResponse.toByteString());
}catch (Exception e){
logger.error("Error getting album arts", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,65 @@
package com.mediamanager.service.delegate.handler.albumart;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumArtMapper;
import com.mediamanager.model.AlbumArt;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumArtMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumart.AlbumArtService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action("albumart.update")
public class UpdateAlbumArtHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(UpdateAlbumArtHandler.class);
private final AlbumArtService albumArtService;
public UpdateAlbumArtHandler(AlbumArtService albumArtService) {
this.albumArtService = albumArtService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
AlbumArtMessages.UpdateAlbumArtRequest updateRequest =
AlbumArtMessages.UpdateAlbumArtRequest.parseFrom(requestPayload);
int id = updateRequest.getId();
String newFilepath = updateRequest.getFilepath();
Optional<AlbumArt> albumArtOpt = albumArtService.updateAlbumArt(id, newFilepath);
if(albumArtOpt.isEmpty()){
logger.warn("AlbumArt not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("AlbumArt not found"));
}
AlbumArtMessages.AlbumArt albumArtProto = AlbumArtMapper.toProtobuf(albumArtOpt.get());
AlbumArtMessages.UpdateAlbumArtResponse updateResponse = AlbumArtMessages.UpdateAlbumArtResponse.newBuilder()
.setAlbumart(albumArtProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(updateResponse.toByteString());
} catch (IllegalArgumentException e){
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error updating album art", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,49 @@
package com.mediamanager.service.delegate.handler.albumtype;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumTypeMapper;
import com.mediamanager.model.AlbumType;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumTypeMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumtype.AlbumTypeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("albumtype.create")
public class CreateAlbumTypeHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(CreateAlbumTypeHandler.class);
private final AlbumTypeService albumTypeService;
public CreateAlbumTypeHandler(AlbumTypeService albumTypeService) {
this.albumTypeService = albumTypeService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
AlbumTypeMessages.CreateAlbumTypeRequest createRequest =
AlbumTypeMessages.CreateAlbumTypeRequest.parseFrom(requestPayload);
AlbumType albumType = albumTypeService.createAlbumType(createRequest.getValue());
AlbumTypeMessages.AlbumType albumTypeProto = AlbumTypeMapper.toProtobuf(albumType);
AlbumTypeMessages.CreateAlbumTypeResponse createAlbumTypeResponse = AlbumTypeMessages.CreateAlbumTypeResponse.newBuilder()
.setAlbumtype(albumTypeProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(createAlbumTypeResponse.toByteString());
} catch (IllegalArgumentException e) {
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error creating album type", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,62 @@
package com.mediamanager.service.delegate.handler.albumtype;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumTypeMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumtype.AlbumTypeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("albumtype.delete")
public class DeleteAlbumTypeHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(DeleteAlbumTypeHandler.class);
private final AlbumTypeService albumTypeService;
public DeleteAlbumTypeHandler(AlbumTypeService albumTypeService) {
this.albumTypeService = albumTypeService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException {
try {
AlbumTypeMessages.DeleteAlbumTypeRequest deleteRequest =
AlbumTypeMessages.DeleteAlbumTypeRequest.parseFrom(requestPayload);
int id = deleteRequest.getId();
boolean success = albumTypeService.deleteAlbumType(id);
AlbumTypeMessages.DeleteAlbumTypeResponse deleteResponse;
if (success) {
deleteResponse = AlbumTypeMessages.DeleteAlbumTypeResponse.newBuilder()
.setSuccess(true)
.setMessage("Album type deleted successfully")
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(deleteResponse.toByteString());
} else {
deleteResponse = AlbumTypeMessages.DeleteAlbumTypeResponse.newBuilder()
.setSuccess(false)
.setMessage("Album type not found")
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(deleteResponse.toByteString());
}
} catch (Exception e) {
logger.error("Error deleting album type", e);
AlbumTypeMessages.DeleteAlbumTypeResponse deleteResponse =
AlbumTypeMessages.DeleteAlbumTypeResponse.newBuilder()
.setSuccess(false)
.setMessage("Error: " + e.getMessage())
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(deleteResponse.toByteString());
}
}
}
@@ -0,0 +1,56 @@
package com.mediamanager.service.delegate.handler.albumtype;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumTypeMapper;
import com.mediamanager.model.AlbumType;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumTypeMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumtype.AlbumTypeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action(value = "albumtype.getById")
public class GetAlbumTypeByIdHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetAlbumTypeByIdHandler.class);
private final AlbumTypeService albumTypeService;
public GetAlbumTypeByIdHandler(AlbumTypeService albumTypeService) {
this.albumTypeService = albumTypeService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException{
try{
AlbumTypeMessages.GetAlbumTypeByIdRequest getByIdRequest =
AlbumTypeMessages.GetAlbumTypeByIdRequest.parseFrom(requestPayload);
int id = getByIdRequest.getId();
Optional<AlbumType> albumTypeOpt = albumTypeService.getAlbumTypeById(id);
if (albumTypeOpt.isEmpty()){
logger.warn("AlbumType not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("AlbumType not found"));
}
AlbumTypeMessages.AlbumType albumTypeProto = AlbumTypeMapper.toProtobuf(albumTypeOpt.get());
AlbumTypeMessages.GetAlbumTypeByIdResponse getByIdResponse = AlbumTypeMessages.GetAlbumTypeByIdResponse.newBuilder()
.setAlbumtype(albumTypeProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getByIdResponse.toByteString());
} catch (Exception e) {
logger.error("Error getting album type by ID", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
}
}
}
@@ -0,0 +1,48 @@
package com.mediamanager.service.delegate.handler.albumtype;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumTypeMapper;
import com.mediamanager.model.AlbumType;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumTypeMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumtype.AlbumTypeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
@Action("albumtype.getAll")
public class GetAlbumTypeHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetAlbumTypeHandler.class);
private final AlbumTypeService albumTypeService;
public GetAlbumTypeHandler(AlbumTypeService albumTypeService){this.albumTypeService = albumTypeService;}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
List<AlbumType> albumTypes = albumTypeService.getAllAlbumTypes();
AlbumTypeMessages.GetAlbumTypesResponse.Builder responseBuilder = AlbumTypeMessages.GetAlbumTypesResponse.newBuilder();
for (AlbumType albumType : albumTypes) {
AlbumTypeMessages.AlbumType albumTypeProto = AlbumTypeMapper.toProtobuf(albumType);
responseBuilder.addAlbumtypes(albumTypeProto);
}
AlbumTypeMessages.GetAlbumTypesResponse getAlbumTypesResponse = responseBuilder.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getAlbumTypesResponse.toByteString());
}catch (Exception e){
logger.error("Error getting album types", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,65 @@
package com.mediamanager.service.delegate.handler.albumtype;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.AlbumTypeMapper;
import com.mediamanager.model.AlbumType;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.AlbumTypeMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.albumtype.AlbumTypeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action("albumtype.update")
public class UpdateAlbumTypeHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(UpdateAlbumTypeHandler.class);
private final AlbumTypeService albumTypeService;
public UpdateAlbumTypeHandler(AlbumTypeService albumTypeService) {
this.albumTypeService = albumTypeService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
AlbumTypeMessages.UpdateAlbumTypeRequest updateRequest =
AlbumTypeMessages.UpdateAlbumTypeRequest.parseFrom(requestPayload);
int id = updateRequest.getId();
String newValue = updateRequest.getValue();
Optional<AlbumType> albumTypeOpt = albumTypeService.updateAlbumType(id, newValue);
if(albumTypeOpt.isEmpty()){
logger.warn("AlbumType not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("AlbumType not found"));
}
AlbumTypeMessages.AlbumType albumTypeProto = AlbumTypeMapper.toProtobuf(albumTypeOpt.get());
AlbumTypeMessages.UpdateAlbumTypeResponse updateResponse = AlbumTypeMessages.UpdateAlbumTypeResponse.newBuilder()
.setAlbumtype(albumTypeProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(updateResponse.toByteString());
} catch (IllegalArgumentException e){
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error updating album type", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -42,7 +42,6 @@ public class CreateBitDepthHandler implements ActionHandler {
} catch (Exception e) { } catch (Exception e) {
logger.error("Error creating bit-depth", e); logger.error("Error creating bit-depth", e);
return TransportProtocol.Response.newBuilder()
return TransportProtocol.Response.newBuilder() return TransportProtocol.Response.newBuilder()
.setStatusCode(500) .setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage())); .setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
@@ -0,0 +1,50 @@
package com.mediamanager.service.delegate.handler.bitrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.BitRateMapper;
import com.mediamanager.model.BitRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.BitRateMessages;
import com.mediamanager.service.bitrate.BitRateService;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("bitrate.create")
public class CreateBitRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(CreateBitRateHandler.class);
private final BitRateService bitRateService;
public CreateBitRateHandler(BitRateService bitRateService) {
this.bitRateService = bitRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
BitRateMessages.CreateBitRateRequest createRequest =
BitRateMessages.CreateBitRateRequest.parseFrom(requestPayload);
BitRate bitRate = bitRateService.createBitRate(createRequest.getValue());
BitRateMessages.BitRate BitRateProto = BitRateMapper.toProtobuf(bitRate);
BitRateMessages.CreateBitRateResponse createBitRateResponse = BitRateMessages.CreateBitRateResponse.newBuilder()
.setBitrate(BitRateProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(createBitRateResponse.toByteString());
} catch (IllegalArgumentException e) {
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error creating bit-rate", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,62 @@
package com.mediamanager.service.delegate.handler.bitrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.BitRateMessages;
import com.mediamanager.service.bitrate.BitRateService;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("bitrate.delete")
public class DeleteBitRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(DeleteBitRateHandler.class);
private final BitRateService bitRateService;
public DeleteBitRateHandler(BitRateService bitRateService) {
this.bitRateService = bitRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException {
try {
BitRateMessages.DeleteBitRateRequest deleteRequest =
BitRateMessages.DeleteBitRateRequest.parseFrom(requestPayload);
int id = deleteRequest.getId();
boolean success = bitRateService.deleteBitRate(id);
BitRateMessages.DeleteBitRateResponse deleteResponse;
if (success) {
deleteResponse = BitRateMessages.DeleteBitRateResponse.newBuilder()
.setSuccess(true)
.setMessage("Bit-Rate deleted successfully")
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(deleteResponse.toByteString());
} else {
deleteResponse = BitRateMessages.DeleteBitRateResponse.newBuilder()
.setSuccess(false)
.setMessage("Bit-Rate not found")
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(deleteResponse.toByteString());
}
} catch (Exception e) {
logger.error("Error deleting bit-rate", e);
BitRateMessages.DeleteBitRateResponse deleteResponse =
BitRateMessages.DeleteBitRateResponse.newBuilder()
.setSuccess(false)
.setMessage("Error: " + e.getMessage())
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(deleteResponse.toByteString());
}
}
}
@@ -0,0 +1,56 @@
package com.mediamanager.service.delegate.handler.bitrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.BitRateMapper;
import com.mediamanager.model.BitRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.BitRateMessages;
import com.mediamanager.service.bitrate.BitRateService;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action(value = "bitrate.getById")
public class GetBitRateByIdHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetBitRateByIdHandler.class);
private final BitRateService bitRateService;
public GetBitRateByIdHandler(BitRateService bitRateService) {
this.bitRateService = bitRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException{
try{
BitRateMessages.GetBitRateByIdRequest getByIdRequest =
BitRateMessages.GetBitRateByIdRequest.parseFrom(requestPayload);
int id = getByIdRequest.getId();
Optional<BitRate> bitRateOpt = bitRateService.getBitRateById(id);
if (bitRateOpt.isEmpty()){
logger.warn("BitRate not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("BitRate not found"));
}
BitRateMessages.BitRate bitRateProto = BitRateMapper.toProtobuf(bitRateOpt.get());
BitRateMessages.GetBitRateByIdResponse getByIdResponse = BitRateMessages.GetBitRateByIdResponse.newBuilder()
.setBitrate(bitRateProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getByIdResponse.toByteString());
} catch (Exception e) {
logger.error("Error getting bit-rate by ID", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
}
}
}
@@ -0,0 +1,48 @@
package com.mediamanager.service.delegate.handler.bitrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.BitRateMapper;
import com.mediamanager.model.BitRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.BitRateMessages;
import com.mediamanager.service.bitrate.BitRateService;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
@Action("bitrate.getAll")
public class GetBitRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetBitRateHandler.class);
private final BitRateService bitRateService;
public GetBitRateHandler(BitRateService bitRateService){this.bitRateService = bitRateService;}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
List<BitRate> bitRates = bitRateService.getAllBitRates();
BitRateMessages.GetBitRatesResponse.Builder responseBuilder = BitRateMessages.GetBitRatesResponse.newBuilder();
for (BitRate bitRate : bitRates) {
BitRateMessages.BitRate bitRateProto = BitRateMapper.toProtobuf(bitRate);
responseBuilder.addBitrates(bitRateProto);
}
BitRateMessages.GetBitRatesResponse getBitRatesResponse = responseBuilder.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getBitRatesResponse.toByteString());
}catch (Exception e){
logger.error("Error getting bit-rates", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,65 @@
package com.mediamanager.service.delegate.handler.bitrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.BitRateMapper;
import com.mediamanager.model.BitRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.BitRateMessages;
import com.mediamanager.service.bitrate.BitRateService;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action("bitrate.update")
public class UpdateBitRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(UpdateBitRateHandler.class);
private final BitRateService bitRateService;
public UpdateBitRateHandler(BitRateService bitRateService) {
this.bitRateService = bitRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
BitRateMessages.UpdateBitRateRequest updateRequest =
BitRateMessages.UpdateBitRateRequest.parseFrom(requestPayload);
int id = updateRequest.getId();
String newValue = updateRequest.getValue();
Optional<BitRate> bitRateOpt = bitRateService.updateBitRate(id, newValue);
if(bitRateOpt.isEmpty()){
logger.warn("BitRate not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("BitRate not found"));
}
BitRateMessages.BitRate bitRateProto = BitRateMapper.toProtobuf(bitRateOpt.get());
BitRateMessages.UpdateBitRateResponse updateResponse = BitRateMessages.UpdateBitRateResponse.newBuilder()
.setBitrate(bitRateProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(updateResponse.toByteString());
} catch (IllegalArgumentException e){
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error updating bit-rate", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,50 @@
package com.mediamanager.service.delegate.handler.samplingrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.SamplingRateMapper;
import com.mediamanager.model.SamplingRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.SamplingRateMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.samplingrate.SamplingRateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("samplingrate.create")
public class CreateSamplingRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(CreateSamplingRateHandler.class);
private final SamplingRateService samplingRateService;
public CreateSamplingRateHandler(SamplingRateService samplingRateService) {
this.samplingRateService = samplingRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
SamplingRateMessages.CreateSamplingRateRequest createRequest =
SamplingRateMessages.CreateSamplingRateRequest.parseFrom(requestPayload);
SamplingRate samplingRate = samplingRateService.createSamplingRate(createRequest.getValue());
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRate);
SamplingRateMessages.CreateSamplingRateResponse createSamplingRateResponse = SamplingRateMessages.CreateSamplingRateResponse.newBuilder()
.setSamplingrate(samplingRateProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(createSamplingRateResponse.toByteString());
} catch (IllegalArgumentException e) {
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error creating sampling rate", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,62 @@
package com.mediamanager.service.delegate.handler.samplingrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.SamplingRateMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.samplingrate.SamplingRateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Action("samplingrate.delete")
public class DeleteSamplingRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(DeleteSamplingRateHandler.class);
private final SamplingRateService samplingRateService;
public DeleteSamplingRateHandler(SamplingRateService samplingRateService) {
this.samplingRateService = samplingRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException {
try {
SamplingRateMessages.DeleteSamplingRateRequest deleteRequest =
SamplingRateMessages.DeleteSamplingRateRequest.parseFrom(requestPayload);
int id = deleteRequest.getId();
boolean success = samplingRateService.deleteSamplingRate(id);
SamplingRateMessages.DeleteSamplingRateResponse deleteResponse;
if (success) {
deleteResponse = SamplingRateMessages.DeleteSamplingRateResponse.newBuilder()
.setSuccess(true)
.setMessage("Sampling rate deleted successfully")
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(deleteResponse.toByteString());
} else {
deleteResponse = SamplingRateMessages.DeleteSamplingRateResponse.newBuilder()
.setSuccess(false)
.setMessage("Sampling rate not found")
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(deleteResponse.toByteString());
}
} catch (Exception e) {
logger.error("Error deleting sampling rate", e);
SamplingRateMessages.DeleteSamplingRateResponse deleteResponse =
SamplingRateMessages.DeleteSamplingRateResponse.newBuilder()
.setSuccess(false)
.setMessage("Error: " + e.getMessage())
.build();
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(deleteResponse.toByteString());
}
}
}
@@ -0,0 +1,56 @@
package com.mediamanager.service.delegate.handler.samplingrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.SamplingRateMapper;
import com.mediamanager.model.SamplingRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.SamplingRateMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.samplingrate.SamplingRateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action(value = "samplingrate.getById")
public class GetSamplingRateByIdHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetSamplingRateByIdHandler.class);
private final SamplingRateService samplingRateService;
public GetSamplingRateByIdHandler(SamplingRateService samplingRateService) {
this.samplingRateService = samplingRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
throws InvalidProtocolBufferException{
try{
SamplingRateMessages.GetSamplingRateByIdRequest getByIdRequest =
SamplingRateMessages.GetSamplingRateByIdRequest.parseFrom(requestPayload);
int id = getByIdRequest.getId();
Optional<SamplingRate> samplingRateOpt = samplingRateService.getSamplingRateById(id);
if (samplingRateOpt.isEmpty()){
logger.warn("SamplingRate not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("SamplingRate not found"));
}
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRateOpt.get());
SamplingRateMessages.GetSamplingRateByIdResponse getByIdResponse = SamplingRateMessages.GetSamplingRateByIdResponse.newBuilder()
.setSamplingrate(samplingRateProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getByIdResponse.toByteString());
} catch (Exception e) {
logger.error("Error getting sampling rate by ID", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
}
}
}
@@ -0,0 +1,48 @@
package com.mediamanager.service.delegate.handler.samplingrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.SamplingRateMapper;
import com.mediamanager.model.SamplingRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.SamplingRateMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.samplingrate.SamplingRateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
@Action("samplingrate.getAll")
public class GetSamplingRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(GetSamplingRateHandler.class);
private final SamplingRateService samplingRateService;
public GetSamplingRateHandler(SamplingRateService samplingRateService){this.samplingRateService = samplingRateService;}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
List<SamplingRate> samplingRates = samplingRateService.getAllSamplingRates();
SamplingRateMessages.GetSamplingRatesResponse.Builder responseBuilder = SamplingRateMessages.GetSamplingRatesResponse.newBuilder();
for (SamplingRate samplingRate : samplingRates) {
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRate);
responseBuilder.addSamplingrates(samplingRateProto);
}
SamplingRateMessages.GetSamplingRatesResponse getSamplingRatesResponse = responseBuilder.build();
return TransportProtocol.Response.newBuilder()
.setPayload(getSamplingRatesResponse.toByteString());
}catch (Exception e){
logger.error("Error getting sampling rates", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,65 @@
package com.mediamanager.service.delegate.handler.samplingrate;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mediamanager.mapper.SamplingRateMapper;
import com.mediamanager.model.SamplingRate;
import com.mediamanager.protocol.TransportProtocol;
import com.mediamanager.protocol.messages.SamplingRateMessages;
import com.mediamanager.service.delegate.ActionHandler;
import com.mediamanager.service.delegate.annotation.Action;
import com.mediamanager.service.samplingrate.SamplingRateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Optional;
@Action("samplingrate.update")
public class UpdateSamplingRateHandler implements ActionHandler {
private static final Logger logger = LogManager.getLogger(UpdateSamplingRateHandler.class);
private final SamplingRateService samplingRateService;
public UpdateSamplingRateHandler(SamplingRateService samplingRateService) {
this.samplingRateService = samplingRateService;
}
@Override
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
try{
SamplingRateMessages.UpdateSamplingRateRequest updateRequest =
SamplingRateMessages.UpdateSamplingRateRequest.parseFrom(requestPayload);
int id = updateRequest.getId();
String newValue = updateRequest.getValue();
Optional<SamplingRate> samplingRateOpt = samplingRateService.updateSamplingRate(id, newValue);
if(samplingRateOpt.isEmpty()){
logger.warn("SamplingRate not found with ID: {}", id);
return TransportProtocol.Response.newBuilder()
.setStatusCode(404)
.setPayload(ByteString.copyFromUtf8("SamplingRate not found"));
}
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRateOpt.get());
SamplingRateMessages.UpdateSamplingRateResponse updateResponse = SamplingRateMessages.UpdateSamplingRateResponse.newBuilder()
.setSamplingrate(samplingRateProto)
.build();
return TransportProtocol.Response.newBuilder()
.setPayload(updateResponse.toByteString());
} catch (IllegalArgumentException e){
logger.error("Validation error", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(400)
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
} catch (Exception e) {
logger.error("Error updating sampling rate", e);
return TransportProtocol.Response.newBuilder()
.setStatusCode(500)
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
}
}
}
@@ -0,0 +1,69 @@
package com.mediamanager.service.samplingrate;
import com.mediamanager.model.SamplingRate;
import com.mediamanager.repository.SamplingRateRepository;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Optional;
public class SamplingRateService {
private static final Logger logger = LogManager.getLogger(SamplingRateService.class);
private final SamplingRateRepository repository;
public SamplingRateService(SamplingRateRepository repository) {
this.repository = repository;
}
public SamplingRate createSamplingRate(String value) {
logger.debug("Creating sampling rate:{}", value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
}
SamplingRate samplingRate = new SamplingRate();
samplingRate.setValue(value);
return repository.save(samplingRate);
}
public List<SamplingRate> getAllSamplingRates() {
logger.info("Getting all sampling rates");
return repository.findAll();
}
public Optional<SamplingRate> getSamplingRateById(Integer id) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Getting sampling rate by id:{}", id);
return repository.findById(id);
}
public Optional<SamplingRate> updateSamplingRate(Integer id, String value) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
logger.info("Updating sampling rate:{}", value);
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
}
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
if(existingSamplingRate.isEmpty()) {
logger.warn("Sampling rate not found with id:{}", id);
return Optional.empty();
}
SamplingRate samplingRate = existingSamplingRate.get();
samplingRate.setValue(value);
SamplingRate updatedSamplingRate = repository.update(samplingRate);
return Optional.of(updatedSamplingRate);
}
public boolean deleteSamplingRate(Integer id) {
if (id == null) {
throw new IllegalArgumentException("Sampling rate id cannot be null");
}
logger.info("Deleting sampling rate:{}", id);
return repository.deleteById(id);
}
}
+53
View File
@@ -0,0 +1,53 @@
syntax = "proto3";
option java_package = "com.mediamanager.protocol.messages";
option java_outer_classname = "AlbumArtMessages";
package mediamanager.messages;
message AlbumArt {
int32 id = 1;
string filepath = 2;
}
message CreateAlbumArtRequest {
string filepath = 1;
}
message CreateAlbumArtResponse {
AlbumArt albumart = 1;
}
message GetAlbumArtsRequest {
}
message GetAlbumArtsResponse {
repeated AlbumArt albumarts = 1;
}
message GetAlbumArtByIdRequest {
int32 id = 1;
}
message GetAlbumArtByIdResponse {
AlbumArt albumart = 1;
}
message UpdateAlbumArtRequest {
int32 id = 1;
string filepath = 2;
}
message UpdateAlbumArtResponse {
AlbumArt albumart = 1;
}
message DeleteAlbumArtRequest {
int32 id = 1;
}
message DeleteAlbumArtResponse {
bool success = 1;
string message = 2;
}
+53
View File
@@ -0,0 +1,53 @@
syntax = "proto3";
option java_package = "com.mediamanager.protocol.messages";
option java_outer_classname = "AlbumTypeMessages";
package mediamanager.messages;
message AlbumType {
int32 id = 1;
string value = 2;
}
message CreateAlbumTypeRequest {
string value = 1;
}
message CreateAlbumTypeResponse {
AlbumType albumtype = 1;
}
message GetAlbumTypesRequest {
}
message GetAlbumTypesResponse {
repeated AlbumType albumtypes = 1;
}
message GetAlbumTypeByIdRequest {
int32 id = 1;
}
message GetAlbumTypeByIdResponse {
AlbumType albumtype = 1;
}
message UpdateAlbumTypeRequest {
int32 id = 1;
string value = 2; // Novo nome
}
message UpdateAlbumTypeResponse {
AlbumType albumtype = 1;
}
message DeleteAlbumTypeRequest {
int32 id = 1;
}
message DeleteAlbumTypeResponse {
bool success = 1;
string message = 2;
}
+1 -1
View File
@@ -40,7 +40,7 @@ message UpdateArtistRequest {
} }
message UpdateArtistResponse { message UpdateArtistResponse {
Artist Artist = 1; Artist artist = 1;
} }
message DeleteArtistRequest { message DeleteArtistRequest {
+53
View File
@@ -0,0 +1,53 @@
syntax = "proto3";
option java_package = "com.mediamanager.protocol.messages";
option java_outer_classname = "BitRateMessages";
package mediamanager.messages;
message BitRate{
int32 id =1;
string value = 2;
}
message CreateBitRateRequest{
string value = 1;
}
message CreateBitRateResponse{
BitRate bitrate = 1;
}
message GetBitRatesRequest{
}
message GetBitRatesResponse{
repeated BitRate bitrates = 1;
}
message GetBitRateByIdRequest{
int32 id = 1;
}
message GetBitRateByIdResponse{
BitRate bitrate = 1;
}
message UpdateBitRateRequest{
int32 id = 1;
string value = 2;
}
message UpdateBitRateResponse{
BitRate bitrate = 1;
}
message DeleteBitRateRequest{
int32 id =1;
}
message DeleteBitRateResponse{
bool success = 1;
string message = 2;
}
+51
View File
@@ -0,0 +1,51 @@
syntax = "proto3";
option java_package = "com.mediamanager.protocol.messages";
option java_outer_classname = "SamplingRateMessages";
package mediamanager.messages;
message SamplingRate{
int32 id=1;
string value=2;
}
message CreateSamplingRateRequest{
string value= 1;
}
message CreateSamplingRateResponse{
SamplingRate samplingrate =1;
}
message GetSamplingRatesRequest{}
message GetSamplingRatesResponse{
repeated SamplingRate samplingrates = 1;
}
message GetSamplingRateByIdRequest{
int32 id =1;
}
message GetSamplingRateByIdResponse{
SamplingRate samplingrate = 1;
}
message UpdateSamplingRateRequest{
int32 id = 1;
string value = 2;
}
message UpdateSamplingRateResponse{
SamplingRate samplingrate = 1;
}
message DeleteSamplingRateRequest{
int32 id =1;
}
message DeleteSamplingRateResponse{
bool success = 1;
string message =2;
}