mirror of
https://github.com/gmbrax/MediaManager-core.git
synced 2026-11-09 14:00:17 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
463d87ec5a | ||
|
|
dccbfcf546 | ||
|
|
7446047b9d | ||
|
|
f43c609e04 | ||
|
|
dc1f6dfbc8 | ||
|
|
0aac0f2f14 | ||
|
|
2fb890a485 | ||
|
|
745ba7e5fc | ||
|
|
ace73ae9c0 | ||
|
|
1dd2542656 |
+3
-1
@@ -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,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,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,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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ 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.bitrate.BitRateService;
|
||||||
import com.mediamanager.service.composer.ComposerService;
|
import com.mediamanager.service.composer.ComposerService;
|
||||||
@@ -75,6 +77,14 @@ public class DelegateActionManager {
|
|||||||
SamplingRateService samplingRateService = new SamplingRateService(samplingRateRepository);
|
SamplingRateService samplingRateService = new SamplingRateService(samplingRateRepository);
|
||||||
serviceLocator.register(SamplingRateService.class, samplingRateService);
|
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");
|
||||||
|
|||||||
+49
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+49
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user