mirror of
https://github.com/gmbrax/MediaManager-core.git
synced 2026-11-09 22:10:17 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32ca465c38 |
@@ -1,39 +0,0 @@
|
|||||||
package com.mediamanager.mapper;
|
|
||||||
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
import com.mediamanager.protocol.messages.BitDepthMessages;
|
|
||||||
|
|
||||||
public class BitDepthMapper {
|
|
||||||
public static BitDepthMessages.BitDepth toProtobuf(BitDepth entity) {
|
|
||||||
if (entity == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String value = entity.getValue();
|
|
||||||
if (value == null) {
|
|
||||||
throw new IllegalArgumentException("Bit depth value cannot be null");
|
|
||||||
}
|
|
||||||
BitDepthMessages.BitDepth.Builder builder = BitDepthMessages.BitDepth.newBuilder()
|
|
||||||
.setValue(value);
|
|
||||||
|
|
||||||
Integer id = entity.getId();
|
|
||||||
if (id != null && id > 0) {
|
|
||||||
builder.setId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BitDepth toEntity(BitDepthMessages.BitDepth protobuf) {
|
|
||||||
if (protobuf == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
BitDepth entity = new BitDepth();
|
|
||||||
|
|
||||||
if (protobuf.getId() > 0) {
|
|
||||||
entity.setId(protobuf.getId());
|
|
||||||
}
|
|
||||||
entity.setValue(protobuf.getValue());
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.mediamanager.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "bit_depth")
|
|
||||||
public class BitDepth {
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
package com.mediamanager.repository;
|
|
||||||
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
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 BitDepthRepository {
|
|
||||||
private static final Logger logger = LogManager.getLogger(BitDepthRepository.class);
|
|
||||||
|
|
||||||
private final EntityManagerFactory entityManagerFactory;
|
|
||||||
|
|
||||||
public BitDepthRepository(EntityManagerFactory entityManagerFactory) {
|
|
||||||
this.entityManagerFactory = entityManagerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BitDepth save(BitDepth bitDepth) {
|
|
||||||
logger.debug("Saving BitDepth: {}", bitDepth.getValue());
|
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
|
||||||
em.getTransaction().begin();
|
|
||||||
try {
|
|
||||||
em.persist(bitDepth);
|
|
||||||
em.getTransaction().commit();
|
|
||||||
logger.debug("BitDepth saved with ID: {}", bitDepth.getId());
|
|
||||||
return bitDepth;
|
|
||||||
} catch (Exception e) {
|
|
||||||
em.getTransaction().rollback();
|
|
||||||
logger.error("Error saving BitDepth", e);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
if (em.isOpen()) em.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BitDepth> findAll(){
|
|
||||||
logger.debug("Finding all BitDepths");
|
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
|
||||||
try{
|
|
||||||
return em.createQuery("SELECT b FROM BitDepth b ORDER BY b.value", BitDepth.class).getResultList();
|
|
||||||
}finally {
|
|
||||||
if (em.isOpen()) em.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<BitDepth> findById(Integer id){
|
|
||||||
logger.debug("Finding BitDepth by ID: {}", id);
|
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
|
||||||
try{
|
|
||||||
BitDepth bitDepth = em.find(BitDepth.class, id);
|
|
||||||
return Optional.ofNullable(bitDepth);
|
|
||||||
}finally {
|
|
||||||
if (em.isOpen()) em.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BitDepth update(BitDepth bitDepth){
|
|
||||||
logger.debug("Updating BitDepth ID: {}", bitDepth.getId());
|
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
|
||||||
em.getTransaction().begin();
|
|
||||||
try{
|
|
||||||
BitDepth updated = em.merge(bitDepth);
|
|
||||||
em.getTransaction().commit();
|
|
||||||
logger.debug("BitDepth updated successfully");
|
|
||||||
return updated;
|
|
||||||
}catch (Exception e){
|
|
||||||
em.getTransaction().rollback();
|
|
||||||
logger.error("Error updating BitDepth", e);
|
|
||||||
throw e;
|
|
||||||
}finally {
|
|
||||||
if (em.isOpen()) em.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteById(Integer id){
|
|
||||||
logger.debug("Deleting BitDepth by ID: {}", id);
|
|
||||||
EntityManager em = entityManagerFactory.createEntityManager();
|
|
||||||
em.getTransaction().begin();
|
|
||||||
try{
|
|
||||||
BitDepth bitDepth = em.find(BitDepth.class, id);
|
|
||||||
if (bitDepth == null) {
|
|
||||||
em.getTransaction().rollback();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
em.remove(bitDepth);
|
|
||||||
em.getTransaction().commit();
|
|
||||||
logger.debug("BitDepth deleted successfully");
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
em.getTransaction().rollback();
|
|
||||||
logger.error("Error deleting BitDepth", e);
|
|
||||||
throw e;
|
|
||||||
}finally {
|
|
||||||
if (em.isOpen()) em.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.mediamanager.service.bitdepth;
|
|
||||||
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
import com.mediamanager.repository.BitDepthRepository;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class BitDepthService {
|
|
||||||
private static final Logger logger = LogManager.getLogger(BitDepthService.class);
|
|
||||||
private final BitDepthRepository bitDepthRepository;
|
|
||||||
|
|
||||||
public BitDepthService(BitDepthRepository bitDepthRepository) {
|
|
||||||
this.bitDepthRepository = bitDepthRepository;
|
|
||||||
}
|
|
||||||
public BitDepth createBitDepth(String value){
|
|
||||||
logger.info("Creating bit-depth: {}", value);
|
|
||||||
if (value == null || value.trim().isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Bit-depth value cannot be empty");
|
|
||||||
}
|
|
||||||
BitDepth bitDepth = new BitDepth();
|
|
||||||
bitDepth.setValue(value.trim());
|
|
||||||
return bitDepthRepository.save(bitDepth);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BitDepth> getAllBitDepths(){
|
|
||||||
logger.info("Getting all bit-depths");
|
|
||||||
return bitDepthRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<BitDepth> getBitDepthById(Integer id){
|
|
||||||
logger.info("Getting bit-depth by ID: {}", id);
|
|
||||||
return bitDepthRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<BitDepth> updateBitDepth(Integer id, String value){
|
|
||||||
logger.info("Updating bit-depth ID {}: {}", id, value);
|
|
||||||
|
|
||||||
if (value == null || value.trim().isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Bit-depth value cannot be empty");
|
|
||||||
}
|
|
||||||
Optional<BitDepth> existingBitDepth = bitDepthRepository.findById(id);
|
|
||||||
if(existingBitDepth.isEmpty()){
|
|
||||||
logger.warn("Bit-depth not found with ID: {}", id);
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
BitDepth bitDepth = existingBitDepth.get();
|
|
||||||
bitDepth.setValue(value.trim());
|
|
||||||
BitDepth updatedBitDepth = bitDepthRepository.update(bitDepth);
|
|
||||||
return Optional.of(updatedBitDepth);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteBitDepth(Integer id){
|
|
||||||
logger.info("Deleting bit-depth ID: {}", id);
|
|
||||||
return bitDepthRepository.deleteById(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,15 @@ 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.ComposerRepository;
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
import com.mediamanager.repository.GenreRepository;
|
||||||
import com.mediamanager.service.bitrate.BitRateService;
|
|
||||||
import com.mediamanager.service.composer.ComposerService;
|
import com.mediamanager.service.composer.ComposerService;
|
||||||
|
import com.mediamanager.repository.ArtistRepository;
|
||||||
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;
|
||||||
@@ -59,21 +58,14 @@ public class DelegateActionManager {
|
|||||||
|
|
||||||
serviceLocator.register(ArtistService.class, artistService);
|
serviceLocator.register(ArtistService.class, artistService);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ComposerRepository composerRepository = new ComposerRepository(entityManagerFactory);
|
ComposerRepository composerRepository = new ComposerRepository(entityManagerFactory);
|
||||||
ComposerService composerService = new ComposerService(composerRepository);
|
ComposerService composerService = new ComposerService(composerRepository);
|
||||||
serviceLocator.register(ComposerService.class, composerService);
|
serviceLocator.register(ComposerService.class, composerService);
|
||||||
|
|
||||||
BitDepthRepository bitDepthRepository = new BitDepthRepository(entityManagerFactory);
|
|
||||||
BitDepthService bitDepthService = new BitDepthService(bitDepthRepository);
|
|
||||||
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);
|
|
||||||
|
|
||||||
serviceLocator.logRegisteredServices();
|
serviceLocator.logRegisteredServices();
|
||||||
|
|
||||||
|
|||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
package com.mediamanager.service.delegate.handler.bitdepth;
|
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.mediamanager.mapper.BitDepthMapper;
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
|
||||||
import com.mediamanager.protocol.messages.ArtistMessages;
|
|
||||||
import com.mediamanager.protocol.messages.BitDepthMessages;
|
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
|
||||||
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("bitdepth.create")
|
|
||||||
public class CreateBitDepthHandler implements ActionHandler {
|
|
||||||
private static final Logger logger = LogManager.getLogger(CreateBitDepthHandler.class);
|
|
||||||
private final BitDepthService bitDepthService;
|
|
||||||
|
|
||||||
public CreateBitDepthHandler(BitDepthService bitDepthService) {
|
|
||||||
this.bitDepthService = bitDepthService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
|
||||||
try{
|
|
||||||
BitDepthMessages.CreateBitDepthRequest createRequest =
|
|
||||||
BitDepthMessages.CreateBitDepthRequest.parseFrom(requestPayload);
|
|
||||||
BitDepth bitDepth = bitDepthService.createBitDepth(createRequest.getValue());
|
|
||||||
BitDepthMessages.BitDepth BitDepthProto = BitDepthMapper.toProtobuf(bitDepth);
|
|
||||||
BitDepthMessages.CreateBitDepthResponse createBitDepthResponse = BitDepthMessages.CreateBitDepthResponse.newBuilder()
|
|
||||||
.setBitdepth(BitDepthProto)
|
|
||||||
.build();
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setPayload(createBitDepthResponse.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-depth", e);
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(500)
|
|
||||||
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
package com.mediamanager.service.delegate.handler.bitdepth;
|
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
|
||||||
import com.mediamanager.protocol.messages.BitDepthMessages;
|
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
|
||||||
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("bitdepth.delete")
|
|
||||||
public class DeleteBitDepthHandler implements ActionHandler {
|
|
||||||
private static final Logger logger = LogManager.getLogger(DeleteBitDepthHandler.class);
|
|
||||||
|
|
||||||
private final BitDepthService bitDepthService;
|
|
||||||
|
|
||||||
public DeleteBitDepthHandler(BitDepthService bitDepthService) {
|
|
||||||
this.bitDepthService = bitDepthService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
|
||||||
throws InvalidProtocolBufferException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
BitDepthMessages.DeleteBitDepthRequest deleteRequest =
|
|
||||||
BitDepthMessages.DeleteBitDepthRequest.parseFrom(requestPayload);
|
|
||||||
int id = deleteRequest.getId();
|
|
||||||
boolean success = bitDepthService.deleteBitDepth(id);
|
|
||||||
BitDepthMessages.DeleteBitDepthResponse deleteResponse;
|
|
||||||
if (success) {
|
|
||||||
deleteResponse = BitDepthMessages.DeleteBitDepthResponse.newBuilder()
|
|
||||||
.setSuccess(true)
|
|
||||||
.setMessage("Bit-Depth deleted successfully")
|
|
||||||
.build();
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setPayload(deleteResponse.toByteString());
|
|
||||||
} else {
|
|
||||||
deleteResponse = BitDepthMessages.DeleteBitDepthResponse.newBuilder()
|
|
||||||
.setSuccess(false)
|
|
||||||
.setMessage("Bit-Depth not found")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(404)
|
|
||||||
.setPayload(deleteResponse.toByteString());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error deleting bit-depth", e);
|
|
||||||
BitDepthMessages.DeleteBitDepthResponse deleteResponse =
|
|
||||||
BitDepthMessages.DeleteBitDepthResponse.newBuilder()
|
|
||||||
.setSuccess(false)
|
|
||||||
.setMessage("Error: " + e.getMessage())
|
|
||||||
.build();
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(500)
|
|
||||||
.setPayload(deleteResponse.toByteString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
package com.mediamanager.service.delegate.handler.bitdepth;
|
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.mediamanager.mapper.BitDepthMapper;
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
|
||||||
import com.mediamanager.protocol.messages.BitDepthMessages;
|
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
|
||||||
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 = "bitdepth.getById")
|
|
||||||
public class GetBitDepthByIdHandler implements ActionHandler {
|
|
||||||
private static final Logger logger = LogManager.getLogger(GetBitDepthByIdHandler.class);
|
|
||||||
private final BitDepthService bitDepthServicee;
|
|
||||||
|
|
||||||
public GetBitDepthByIdHandler(BitDepthService bitDepthServicee) {
|
|
||||||
this.bitDepthServicee = bitDepthServicee;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
|
||||||
throws InvalidProtocolBufferException{
|
|
||||||
|
|
||||||
try{
|
|
||||||
BitDepthMessages.GetBitDepthByIdRequest getByIdRequest =
|
|
||||||
BitDepthMessages.GetBitDepthByIdRequest.parseFrom(requestPayload);
|
|
||||||
int id = getByIdRequest.getId();
|
|
||||||
|
|
||||||
Optional<BitDepth> bitDepthOpt = bitDepthServicee.getBitDepthById(id);
|
|
||||||
|
|
||||||
if (bitDepthOpt.isEmpty()){
|
|
||||||
logger.warn("BitDepth not found with ID: {}", id);
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(404)
|
|
||||||
.setPayload(ByteString.copyFromUtf8("BitDepth not found"));
|
|
||||||
}
|
|
||||||
BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepthOpt.get());
|
|
||||||
BitDepthMessages.GetBitDepthByIdResponse getByIdResponse = BitDepthMessages.GetBitDepthByIdResponse.newBuilder()
|
|
||||||
.setBitdepth(bitDepthProto)
|
|
||||||
.build();
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setPayload(getByIdResponse.toByteString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error getting bit-depth by ID", e);
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(500)
|
|
||||||
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package com.mediamanager.service.delegate.handler.bitdepth;
|
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.mediamanager.mapper.BitDepthMapper;
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
|
||||||
import com.mediamanager.protocol.messages.BitDepthMessages;
|
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
|
||||||
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("bitdepth.getAll")
|
|
||||||
public class GetBitDepthHandler implements ActionHandler {
|
|
||||||
private static final Logger logger = LogManager.getLogger(GetBitDepthHandler.class);
|
|
||||||
|
|
||||||
private final BitDepthService bitDepthService;
|
|
||||||
|
|
||||||
public GetBitDepthHandler(BitDepthService bitDepthService){this.bitDepthService = bitDepthService;}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
|
||||||
try{
|
|
||||||
List<BitDepth> bitDepths = bitDepthService.getAllBitDepths();
|
|
||||||
BitDepthMessages.GetBitDepthsResponse.Builder responseBuilder = BitDepthMessages.GetBitDepthsResponse.newBuilder();
|
|
||||||
|
|
||||||
for (BitDepth bitDepth : bitDepths) {
|
|
||||||
BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepth);
|
|
||||||
responseBuilder.addBitdepths(bitDepthProto);
|
|
||||||
}
|
|
||||||
BitDepthMessages.GetBitDepthsResponse getBitDepthsResponse = responseBuilder.build();
|
|
||||||
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setPayload(getBitDepthsResponse.toByteString());
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
logger.error("Error getting bit-depths", e);
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(500)
|
|
||||||
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
package com.mediamanager.service.delegate.handler.bitdepth;
|
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.mediamanager.mapper.BitDepthMapper;
|
|
||||||
import com.mediamanager.model.BitDepth;
|
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
|
||||||
import com.mediamanager.protocol.messages.BitDepthMessages;
|
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
|
||||||
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("bitdepth.update")
|
|
||||||
public class UpdateBitDepthHandler implements ActionHandler {
|
|
||||||
private static final Logger logger = LogManager.getLogger(UpdateBitDepthHandler.class);
|
|
||||||
private final BitDepthService bitDepthService;
|
|
||||||
|
|
||||||
public UpdateBitDepthHandler(BitDepthService bitDepthService) {
|
|
||||||
this.bitDepthService = bitDepthService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
|
||||||
try{
|
|
||||||
BitDepthMessages.UpdateBitDepthRequest updateRequest =
|
|
||||||
BitDepthMessages.UpdateBitDepthRequest.parseFrom(requestPayload);
|
|
||||||
|
|
||||||
int id = updateRequest.getId();
|
|
||||||
String newValue = updateRequest.getValue();
|
|
||||||
|
|
||||||
Optional<BitDepth> bitDepthOpt = bitDepthService.updateBitDepth(id, newValue);
|
|
||||||
|
|
||||||
if(bitDepthOpt.isEmpty()){
|
|
||||||
logger.warn("BitDepth not found with ID: {}", id);
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(404)
|
|
||||||
.setPayload(ByteString.copyFromUtf8("BitDepth not found"));
|
|
||||||
}
|
|
||||||
|
|
||||||
BitDepthMessages.BitDepth bitDepthProto = BitDepthMapper.toProtobuf(bitDepthOpt.get());
|
|
||||||
|
|
||||||
BitDepthMessages.UpdateBitDepthResponse updateResponse = BitDepthMessages.UpdateBitDepthResponse.newBuilder()
|
|
||||||
.setBitdepth(bitDepthProto)
|
|
||||||
.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-depth", e);
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
.setStatusCode(500)
|
|
||||||
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,7 @@ message UpdateArtistRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message UpdateArtistResponse {
|
message UpdateArtistResponse {
|
||||||
Artist artist = 1;
|
Artist Artist = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteArtistRequest {
|
message DeleteArtistRequest {
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option java_package = "com.mediamanager.protocol.messages";
|
|
||||||
option java_outer_classname = "BitDepthMessages";
|
|
||||||
|
|
||||||
package mediamanager.messages;
|
|
||||||
|
|
||||||
message BitDepth {
|
|
||||||
int32 id = 1;
|
|
||||||
string value = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CreateBitDepthRequest {
|
|
||||||
string value = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CreateBitDepthResponse {
|
|
||||||
BitDepth bitdepth = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetBitDepthsRequest {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetBitDepthsResponse {
|
|
||||||
repeated BitDepth bitdepths = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetBitDepthByIdRequest {
|
|
||||||
int32 id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetBitDepthByIdResponse {
|
|
||||||
BitDepth bitdepth = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UpdateBitDepthRequest {
|
|
||||||
int32 id = 1;
|
|
||||||
string value = 2; // Novo nome
|
|
||||||
}
|
|
||||||
|
|
||||||
message UpdateBitDepthResponse {
|
|
||||||
BitDepth bitdepth = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message DeleteBitDepthRequest {
|
|
||||||
int32 id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message DeleteBitDepthResponse {
|
|
||||||
bool success = 1;
|
|
||||||
string message = 2;
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user