mirror of
https://github.com/gmbrax/MediaManager-core.git
synced 2026-11-09 14:00:17 +00:00
Compare commits
@@ -52,3 +52,5 @@ 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,47 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumHasArtist;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasArtistMessages;
|
||||||
|
|
||||||
|
public class AlbumHasArtistMapper {
|
||||||
|
public static AlbumHasArtistMessages.AlbumHasArtist toProtobuf(AlbumHasArtist entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumHasArtistMessages.AlbumHasArtist.Builder builder = AlbumHasArtistMessages.AlbumHasArtist.newBuilder();
|
||||||
|
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map Album foreign key
|
||||||
|
if (entity.getAlbum() != null && entity.getAlbum().getId() != null) {
|
||||||
|
builder.setFkAlbumId(entity.getAlbum().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map Artist foreign key
|
||||||
|
if (entity.getArtist() != null && entity.getArtist().getId() != null) {
|
||||||
|
builder.setFkArtistId(entity.getArtist().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AlbumHasArtist toEntity(AlbumHasArtistMessages.AlbumHasArtist protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumHasArtist entity = new AlbumHasArtist();
|
||||||
|
|
||||||
|
if (protobuf.getId() > 0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Foreign key relationships (Album, Artist) are handled in the service layer
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumHasGenre;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasGenreMessages;
|
||||||
|
|
||||||
|
public class AlbumHasGenreMapper {
|
||||||
|
public static AlbumHasGenreMessages.AlbumHasGenre toProtobuf(AlbumHasGenre entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumHasGenreMessages.AlbumHasGenre.Builder builder = AlbumHasGenreMessages.AlbumHasGenre.newBuilder();
|
||||||
|
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map Album foreign key
|
||||||
|
if (entity.getAlbum() != null && entity.getAlbum().getId() != null) {
|
||||||
|
builder.setFkAlbumId(entity.getAlbum().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map Genre foreign key
|
||||||
|
if (entity.getGenre() != null && entity.getGenre().getId() != null) {
|
||||||
|
builder.setFkGenreId(entity.getGenre().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AlbumHasGenre toEntity(AlbumHasGenreMessages.AlbumHasGenre protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumHasGenre entity = new AlbumHasGenre();
|
||||||
|
|
||||||
|
if (protobuf.getId() > 0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Foreign key relationships (Album, Genre) are handled in the service layer
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumMessages;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
|
||||||
|
public class AlbumMapper {
|
||||||
|
public static AlbumMessages.Album toProtobuf(Album entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = entity.getName();
|
||||||
|
if (name == null || name.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Name cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumMessages.Album.Builder builder = AlbumMessages.Album.newBuilder()
|
||||||
|
.setName(name);
|
||||||
|
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer year = entity.getYear();
|
||||||
|
if (year != null) {
|
||||||
|
builder.setYear(year);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer numberOfDiscs = entity.getNumberOfDiscs();
|
||||||
|
if (numberOfDiscs != null) {
|
||||||
|
builder.setNumberOfDiscs(numberOfDiscs);
|
||||||
|
}
|
||||||
|
|
||||||
|
String code = entity.getCode();
|
||||||
|
if (code != null) {
|
||||||
|
builder.setCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean isCompilation = entity.getIsCompilation();
|
||||||
|
if (isCompilation != null) {
|
||||||
|
builder.setIsCompilation(isCompilation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map AlbumType foreign key
|
||||||
|
if (entity.getAlbumType() != null && entity.getAlbumType().getId() != null) {
|
||||||
|
builder.setFkAlbumtypeId(entity.getAlbumType().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map AlbumArt foreign key
|
||||||
|
if (entity.getAlbumArt() != null && entity.getAlbumArt().getId() != null) {
|
||||||
|
builder.setFkAlbumartId(entity.getAlbumArt().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map timestamps
|
||||||
|
if (entity.getCreatedAt() != null) {
|
||||||
|
long createdAtEpoch = entity.getCreatedAt()
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toInstant()
|
||||||
|
.toEpochMilli();
|
||||||
|
builder.setCreatedAt(createdAtEpoch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.getUpdatedAt() != null) {
|
||||||
|
long updatedAtEpoch = entity.getUpdatedAt()
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toInstant()
|
||||||
|
.toEpochMilli();
|
||||||
|
builder.setUpdatedAt(updatedAtEpoch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Album toEntity(AlbumMessages.Album protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Album entity = new Album();
|
||||||
|
|
||||||
|
if (protobuf.getId() > 0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setName(protobuf.getName());
|
||||||
|
|
||||||
|
if (protobuf.getYear() > 0) {
|
||||||
|
entity.setYear(protobuf.getYear());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protobuf.getNumberOfDiscs() > 0) {
|
||||||
|
entity.setNumberOfDiscs(protobuf.getNumberOfDiscs());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!protobuf.getCode().isEmpty()) {
|
||||||
|
entity.setCode(protobuf.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setIsCompilation(protobuf.getIsCompilation());
|
||||||
|
|
||||||
|
// Note: Foreign key relationships (AlbumType, AlbumArt) are handled in the service layer
|
||||||
|
// Timestamps are managed by JPA @PrePersist and @PreUpdate
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumType;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumTypeMessages;
|
||||||
|
|
||||||
|
public class AlbumTypeMapper {
|
||||||
|
public static AlbumTypeMessages.AlbumType toProtobuf(AlbumType entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String value = entity.getValue();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Value cannot be null or empty");
|
||||||
|
}
|
||||||
|
AlbumTypeMessages.AlbumType.Builder builder = AlbumTypeMessages.AlbumType.newBuilder()
|
||||||
|
.setValue(value);
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AlbumType toEntity(AlbumTypeMessages.AlbumType protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
AlbumType entity = new AlbumType();
|
||||||
|
if (protobuf.getId() >0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
entity.setValue(protobuf.getValue());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import com.mediamanager.protocol.messages.BitRateMessages;
|
||||||
|
|
||||||
|
public class BitRateMapper {
|
||||||
|
public static BitRateMessages.BitRate toProtobuf(BitRate entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = entity.getValue();
|
||||||
|
if (value == null) {
|
||||||
|
throw new IllegalArgumentException("Bit rate value cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
BitRateMessages.BitRate.Builder builder = BitRateMessages.BitRate.newBuilder()
|
||||||
|
.setValue(value);
|
||||||
|
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null && id > 0) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BitRate toEntity(BitRateMessages.BitRate protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BitRate entity = new BitRate();
|
||||||
|
|
||||||
|
if (protobuf.getId() > 0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
entity.setValue(protobuf.getValue());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
import com.mediamanager.protocol.messages.DiscMessages;
|
||||||
|
|
||||||
|
public class DiscMapper {
|
||||||
|
public static DiscMessages.Disc toProtobuf(Disc entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer discNumber = entity.getDiscNumber();
|
||||||
|
if (discNumber == null) {
|
||||||
|
throw new IllegalArgumentException("Disc number cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscMessages.Disc.Builder builder = DiscMessages.Disc.newBuilder()
|
||||||
|
.setDiscNumber(discNumber);
|
||||||
|
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map Album foreign key
|
||||||
|
if (entity.getAlbum() != null && entity.getAlbum().getId() != null) {
|
||||||
|
builder.setFkAlbumId(entity.getAlbum().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Disc toEntity(DiscMessages.Disc protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Disc entity = new Disc();
|
||||||
|
|
||||||
|
if (protobuf.getId() > 0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setDiscNumber(protobuf.getDiscNumber());
|
||||||
|
|
||||||
|
// Note: Foreign key relationship (Album) is handled in the service layer
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import com.mediamanager.protocol.messages.SamplingRateMessages;
|
||||||
|
|
||||||
|
public class SamplingRateMapper {
|
||||||
|
public static SamplingRateMessages.SamplingRate toProtobuf(SamplingRate entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String value = entity.getValue();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Value cannot be null or empty");
|
||||||
|
}
|
||||||
|
SamplingRateMessages.SamplingRate.Builder builder = SamplingRateMessages.SamplingRate.newBuilder()
|
||||||
|
.setValue(value);
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SamplingRate toEntity(SamplingRateMessages.SamplingRate protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SamplingRate entity = new SamplingRate();
|
||||||
|
if (protobuf.getId() >0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
entity.setValue(protobuf.getValue());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "album")
|
||||||
|
public class Album {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private Integer year;
|
||||||
|
|
||||||
|
@Column(name = "number_of_discs")
|
||||||
|
private Integer numberOfDiscs;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Column(name = "is_compilation")
|
||||||
|
private Boolean isCompilation;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_albumtype_id")
|
||||||
|
private AlbumType albumType;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_albumart_id")
|
||||||
|
private AlbumArt albumArt;
|
||||||
|
|
||||||
|
// Relacionamento ManyToMany com Artist através da tabela de junção
|
||||||
|
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<AlbumHasArtist> albumArtists = new ArrayList<>();
|
||||||
|
|
||||||
|
// Relacionamento ManyToMany com Genre através da tabela de junção
|
||||||
|
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<AlbumHasGenre> albumGenres = new ArrayList<>(); // ← ADICIONE ESSA LINHA
|
||||||
|
|
||||||
|
@Column(name = "created_at", nullable = false, updatable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Column(name = "updated_at")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
protected void onCreate() {
|
||||||
|
this.createdAt = LocalDateTime.now();
|
||||||
|
this.updatedAt = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
protected void onUpdate() {
|
||||||
|
this.updatedAt = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album() {}
|
||||||
|
|
||||||
|
// Métodos helper para Artist (ManyToMany)
|
||||||
|
public void addArtist(Artist artist) {
|
||||||
|
AlbumHasArtist albumHasArtist = new AlbumHasArtist();
|
||||||
|
albumHasArtist.setAlbum(this);
|
||||||
|
albumHasArtist.setArtist(artist);
|
||||||
|
albumArtists.add(albumHasArtist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeArtist(Artist artist) {
|
||||||
|
albumArtists.removeIf(aa ->
|
||||||
|
aa.getArtist() != null &&
|
||||||
|
aa.getArtist().getId() != null &&
|
||||||
|
aa.getArtist().getId().equals(artist.getId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método conveniente para pegar só os artistas
|
||||||
|
public List<Artist> getArtists() {
|
||||||
|
return albumArtists.stream()
|
||||||
|
.map(AlbumHasArtist::getArtist)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== ADICIONE ESSES MÉTODOS PARA GENRE ==========
|
||||||
|
|
||||||
|
// Métodos helper para Genre (ManyToMany)
|
||||||
|
public void addGenre(Genre genre) {
|
||||||
|
AlbumHasGenre albumHasGenre = new AlbumHasGenre();
|
||||||
|
albumHasGenre.setAlbum(this);
|
||||||
|
albumHasGenre.setGenre(genre);
|
||||||
|
albumGenres.add(albumHasGenre);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeGenre(Genre genre) {
|
||||||
|
if (genre == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
albumGenres.removeIf(ag ->
|
||||||
|
ag.getGenre() != null &&
|
||||||
|
ag.getGenre().getId() != null &&
|
||||||
|
ag.getGenre().getId().equals(genre.getId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método conveniente para pegar só os gêneros
|
||||||
|
public List<Genre> getGenres() {
|
||||||
|
return albumGenres.stream()
|
||||||
|
.map(AlbumHasGenre::getGenre)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== FIM DOS MÉTODOS DE GENRE ==========
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(Integer year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNumberOfDiscs() {
|
||||||
|
return numberOfDiscs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumberOfDiscs(Integer numberOfDiscs) {
|
||||||
|
this.numberOfDiscs = numberOfDiscs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsCompilation() {
|
||||||
|
return isCompilation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsCompilation(Boolean isCompilation) {
|
||||||
|
this.isCompilation = isCompilation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumType getAlbumType() {
|
||||||
|
return albumType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumType(AlbumType albumType) {
|
||||||
|
this.albumType = albumType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumArt getAlbumArt() {
|
||||||
|
return albumArt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumArt(AlbumArt albumArt) {
|
||||||
|
this.albumArt = albumArt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumHasArtist> getAlbumArtists() {
|
||||||
|
return albumArtists;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumArtists(List<AlbumHasArtist> albumArtists) {
|
||||||
|
this.albumArtists = albumArtists;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== ADICIONE ESSES GETTERS/SETTERS ==========
|
||||||
|
|
||||||
|
public List<AlbumHasGenre> getAlbumGenres() {
|
||||||
|
return albumGenres;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumGenres(List<AlbumHasGenre> albumGenres) {
|
||||||
|
this.albumGenres = albumGenres;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== FIM DOS GETTERS/SETTERS DE GENRE ==========
|
||||||
|
|
||||||
|
public LocalDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(LocalDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getUpdatedAt() {
|
||||||
|
return updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Album{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", year=" + year +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,56 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "albumshasartist")
|
||||||
|
public class AlbumHasArtist {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_album_id", nullable = false)
|
||||||
|
private Album album;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_artist_id", nullable = false)
|
||||||
|
private Artist artist;
|
||||||
|
|
||||||
|
public AlbumHasArtist() {}
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album getAlbum() {
|
||||||
|
return album;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbum(Album album) {
|
||||||
|
this.album = album;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artist getArtist() {
|
||||||
|
return artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtist(Artist artist) {
|
||||||
|
this.artist = artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AlbumHasArtist{" +
|
||||||
|
"id=" + id +
|
||||||
|
", albumId=" + (album != null ? album.getId() : null) +
|
||||||
|
", artistId=" + (artist != null ? artist.getId() : null) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "albumshasgenre")
|
||||||
|
public class AlbumHasGenre {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_album_id", nullable = false)
|
||||||
|
private Album album;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_genre_id", nullable = false)
|
||||||
|
private Genre genre;
|
||||||
|
|
||||||
|
public AlbumHasGenre() {}
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album getAlbum() {
|
||||||
|
return album;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbum(Album album) {
|
||||||
|
this.album = album;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Genre getGenre() {
|
||||||
|
return genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenre(Genre genre) {
|
||||||
|
this.genre = genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AlbumHasGenre{" +
|
||||||
|
"id=" + id +
|
||||||
|
", albumId=" + (album != null ? album.getId() : null) +
|
||||||
|
", genreId=" + (genre != null ? genre.getId() : null) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "albumtype")
|
||||||
|
public class AlbumType {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "bit_rate")
|
||||||
|
public class BitRate {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "disc")
|
||||||
|
public class Disc {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "disc_number", nullable = false)
|
||||||
|
private Integer discNumber;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "fk_album_id",nullable = false)
|
||||||
|
private Album album;
|
||||||
|
|
||||||
|
public Disc() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDiscNumber() {
|
||||||
|
return discNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDiscNumber(Integer discNumber) {
|
||||||
|
this.discNumber = discNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album getAlbum() {
|
||||||
|
return album;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbum(Album album) {
|
||||||
|
this.album = album;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sampling_rate")
|
||||||
|
public class SamplingRate {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumArt;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AlbumArtRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumArtRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public AlbumArtRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumArt save(AlbumArt albumArt) {
|
||||||
|
logger.debug("Saving AlbumArt: {}", albumArt.getFilepath());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(albumArt);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumArt has been saved successfully");
|
||||||
|
return albumArt;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving AlbumArt: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumArt> findAll() {
|
||||||
|
logger.debug("Finding All AlbumArt");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select a from AlbumArt a", AlbumArt.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumArt> findById(Integer id) {
|
||||||
|
logger.debug("Finding AlbumArt with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
AlbumArt albumArt = em.find(AlbumArt.class, id);
|
||||||
|
return Optional.ofNullable(albumArt);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumArt update(AlbumArt albumArt) {
|
||||||
|
logger.debug("Updating AlbumArt: {}", albumArt.getFilepath());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
AlbumArt updated = em.merge(albumArt);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumArt has been updated successfully");
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while updating AlbumArt: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting AlbumArt with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
AlbumArt albumArt = em.find(AlbumArt.class, id);
|
||||||
|
if (albumArt == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(albumArt);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumArt has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting AlbumArt: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumHasArtist;
|
||||||
|
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 AlbumHasArtistRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumHasArtistRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public AlbumHasArtistRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumHasArtist save(AlbumHasArtist albumHasArtist) {
|
||||||
|
logger.debug("Saving AlbumHasArtist: {}", albumHasArtist);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(albumHasArtist);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumHasArtist has been saved successfully");
|
||||||
|
return albumHasArtist;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving AlbumHasArtist: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumHasArtist> findAll() {
|
||||||
|
logger.debug("Finding All AlbumHasArtist");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select a from AlbumHasArtist a", AlbumHasArtist.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumHasArtist> findById(Integer id) {
|
||||||
|
logger.debug("Finding AlbumHasArtist with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
AlbumHasArtist albumHasArtist = em.find(AlbumHasArtist.class, id);
|
||||||
|
return Optional.ofNullable(albumHasArtist);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting AlbumHasArtist with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
AlbumHasArtist albumHasArtist = em.find(AlbumHasArtist.class, id);
|
||||||
|
if (albumHasArtist == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(albumHasArtist);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumHasArtist has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting AlbumHasArtist: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumHasGenre;
|
||||||
|
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 AlbumHasGenreRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumHasGenreRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public AlbumHasGenreRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumHasGenre save(AlbumHasGenre albumHasGenre) {
|
||||||
|
logger.debug("Saving AlbumHasGenre: {}", albumHasGenre);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(albumHasGenre);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumHasGenre has been saved successfully");
|
||||||
|
return albumHasGenre;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving AlbumHasGenre: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumHasGenre> findAll() {
|
||||||
|
logger.debug("Finding All AlbumHasGenre");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select a from AlbumHasGenre a", AlbumHasGenre.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumHasGenre> findById(Integer id) {
|
||||||
|
logger.debug("Finding AlbumHasGenre with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
AlbumHasGenre albumHasGenre = em.find(AlbumHasGenre.class, id);
|
||||||
|
return Optional.ofNullable(albumHasGenre);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting AlbumHasGenre with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
AlbumHasGenre albumHasGenre = em.find(AlbumHasGenre.class, id);
|
||||||
|
if (albumHasGenre == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(albumHasGenre);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumHasGenre has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting AlbumHasGenre: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
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 AlbumRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public AlbumRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album save(Album album) {
|
||||||
|
logger.debug("Saving Album: {}", album.getName());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(album);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Album has been saved successfully");
|
||||||
|
return album;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving Album: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Album> findAll() {
|
||||||
|
logger.debug("Finding All Album");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select a from Album a", Album.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Album> findById(Integer id) {
|
||||||
|
logger.debug("Finding Album with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
Album album = em.find(Album.class, id);
|
||||||
|
return Optional.ofNullable(album);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album update(Album album) {
|
||||||
|
logger.debug("Updating Album: {}", album.getName());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
Album updated = em.merge(album);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Album has been updated successfully");
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while updating Album: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting Album with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
Album album = em.find(Album.class, id);
|
||||||
|
if (album == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(album);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Album has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting Album: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumType;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AlbumTypeRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumTypeRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public AlbumTypeRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumType save(AlbumType albumType) {
|
||||||
|
logger.debug("Saving AlbumType: {}", albumType.getValue());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(albumType);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumType has been saved successfully");
|
||||||
|
return albumType;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving AlbumType: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumType> findAll() {
|
||||||
|
logger.debug("Finding All AlbumType");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select a from AlbumType a", AlbumType.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumType> findById(Integer id) {
|
||||||
|
logger.debug("Finding AlbumType with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
AlbumType albumType = em.find(AlbumType.class, id);
|
||||||
|
return Optional.ofNullable(albumType);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumType update(AlbumType albumType) {
|
||||||
|
logger.debug("Updating AlbumType: {}", albumType.getValue());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
AlbumType updated = em.merge(albumType);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumType has been updated successfully");
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while updating AlbumType: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting AlbumType with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
AlbumType albumType = em.find(AlbumType.class, id);
|
||||||
|
if (albumType == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(albumType);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("AlbumType has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting AlbumType: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class BitRateRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(BitRateRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public BitRateRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BitRate save(BitRate bitRate) {
|
||||||
|
logger.debug("Saving BitRate: {}", bitRate.getValue());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(bitRate);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("BitRate saved with ID: {}", bitRate.getId());
|
||||||
|
return bitRate;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error saving BitRate", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BitRate> findAll(){
|
||||||
|
logger.debug("Finding all BitRates");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("SELECT b FROM BitRate b ORDER BY b.value", BitRate.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<BitRate> findById(Integer id){
|
||||||
|
logger.debug("Finding BitRate by ID: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
BitRate bitRate = em.find(BitRate.class, id);
|
||||||
|
return Optional.ofNullable(bitRate);
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BitRate update(BitRate bitRate){
|
||||||
|
logger.debug("Updating BitRate ID: {}", bitRate.getId());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
BitRate updated = em.merge(bitRate);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("BitRate updated with ID: {}", bitRate.getId());
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error updating BitRate", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting BitRate by ID: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
BitRate bitRate = em.find(BitRate.class, id);
|
||||||
|
if (bitRate == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(bitRate);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("BitRate deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error deleting BitRate", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
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 DiscRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DiscRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public DiscRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Disc save(Disc disc) {
|
||||||
|
logger.debug("Saving Disc: {}", disc.getDiscNumber());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(disc);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Disc has been saved successfully");
|
||||||
|
return disc;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving Disc: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Disc> findAll() {
|
||||||
|
logger.debug("Finding All Disc");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select d from Disc d", Disc.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Disc> findById(Integer id) {
|
||||||
|
logger.debug("Finding Disc with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
Disc disc = em.find(Disc.class, id);
|
||||||
|
return Optional.ofNullable(disc);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Disc update(Disc disc) {
|
||||||
|
logger.debug("Updating Disc: {}", disc.getDiscNumber());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
Disc updated = em.merge(disc);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Disc has been updated successfully");
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while updating Disc: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting Disc with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
Disc disc = em.find(Disc.class, id);
|
||||||
|
if (disc == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(disc);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Disc has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting Disc: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SamplingRateRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(SamplingRateRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public SamplingRateRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SamplingRate save(SamplingRate samplingRate) {
|
||||||
|
logger.debug("Saving SamplingRate: {}", samplingRate.getValue());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(samplingRate);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("SamplingRate has been saved successfully");
|
||||||
|
return samplingRate;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while saving SamplingRate: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SamplingRate> findAll() {
|
||||||
|
logger.debug("Finding All SamplingRate");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
return em.createQuery("select s from SamplingRate s", SamplingRate.class).getResultList();
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<SamplingRate> findById(Integer id) {
|
||||||
|
logger.debug("Finding SamplingRate with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try{
|
||||||
|
SamplingRate samplingRate = em.find(SamplingRate.class, id);
|
||||||
|
return Optional.ofNullable(samplingRate);
|
||||||
|
}finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SamplingRate update(SamplingRate samplingRate) {
|
||||||
|
logger.debug("Updating SamplingRate: {}", samplingRate.getValue());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
SamplingRate updated = em.merge(samplingRate);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("SamplingRate has been updated successfully");
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while updating SamplingRate: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Integer id){
|
||||||
|
logger.debug("Deleting SamplingRate with id: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try{
|
||||||
|
SamplingRate samplingRate = em.find(SamplingRate.class, id);
|
||||||
|
if (samplingRate == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(samplingRate);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("SamplingRate has been deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error while deleting SamplingRate: {}", e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
package com.mediamanager.service.album;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.model.AlbumArt;
|
||||||
|
import com.mediamanager.model.AlbumType;
|
||||||
|
import com.mediamanager.repository.AlbumRepository;
|
||||||
|
import com.mediamanager.repository.AlbumArtRepository;
|
||||||
|
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 AlbumService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumService.class);
|
||||||
|
private final AlbumRepository repository;
|
||||||
|
private final AlbumTypeRepository albumTypeRepository;
|
||||||
|
private final AlbumArtRepository albumArtRepository;
|
||||||
|
|
||||||
|
public AlbumService(AlbumRepository repository, AlbumTypeRepository albumTypeRepository, AlbumArtRepository albumArtRepository) {
|
||||||
|
this.repository = repository;
|
||||||
|
this.albumTypeRepository = albumTypeRepository;
|
||||||
|
this.albumArtRepository = albumArtRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album createAlbum(String name, Integer year, Integer numberOfDiscs, String code, Boolean isCompilation, Integer albumTypeId, Integer albumArtId) {
|
||||||
|
logger.debug("Creating album:{}", name);
|
||||||
|
if (name == null || name.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Album name cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Album album = new Album();
|
||||||
|
album.setName(name);
|
||||||
|
album.setYear(year);
|
||||||
|
album.setNumberOfDiscs(numberOfDiscs);
|
||||||
|
album.setCode(code);
|
||||||
|
album.setIsCompilation(isCompilation);
|
||||||
|
|
||||||
|
// Set AlbumType if provided
|
||||||
|
if (albumTypeId != null && albumTypeId > 0) {
|
||||||
|
Optional<AlbumType> albumType = albumTypeRepository.findById(albumTypeId);
|
||||||
|
if (albumType.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("AlbumType not found with id: " + albumTypeId);
|
||||||
|
}
|
||||||
|
album.setAlbumType(albumType.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set AlbumArt if provided
|
||||||
|
if (albumArtId != null && albumArtId > 0) {
|
||||||
|
Optional<AlbumArt> albumArt = albumArtRepository.findById(albumArtId);
|
||||||
|
if (albumArt.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("AlbumArt not found with id: " + albumArtId);
|
||||||
|
}
|
||||||
|
album.setAlbumArt(albumArt.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
return repository.save(album);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Album> getAllAlbums() {
|
||||||
|
logger.info("Getting all albums");
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Album> getAlbumById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Getting album by id:{}", id);
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Album> updateAlbum(Integer id, String name, Integer year,
|
||||||
|
Integer numberOfDiscs, String code,
|
||||||
|
Boolean isCompilation, Integer albumTypeId,
|
||||||
|
Integer albumArtId,
|
||||||
|
boolean updateYear, // ← Novo!
|
||||||
|
boolean updateNumberOfDiscs, // ← Novo!
|
||||||
|
boolean updateAlbumType, // ← Novo!
|
||||||
|
boolean updateAlbumArt) { // ← Novo!
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Updating album: {}", name);
|
||||||
|
if (name == null || name.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Album name cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Album> existingAlbum = repository.findById(id);
|
||||||
|
if (existingAlbum.isEmpty()) {
|
||||||
|
logger.warn("Album not found with id: {}", id);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Album album = existingAlbum.get();
|
||||||
|
album.setName(name);
|
||||||
|
album.setCode(code);
|
||||||
|
album.setIsCompilation(isCompilation);
|
||||||
|
|
||||||
|
// Atualiza year SOMENTE se o campo foi fornecido
|
||||||
|
if (updateYear) {
|
||||||
|
album.setYear(year);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Atualiza numberOfDiscs SOMENTE se o campo foi fornecido
|
||||||
|
if (updateNumberOfDiscs) {
|
||||||
|
album.setNumberOfDiscs(numberOfDiscs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update AlbumType SOMENTE se o campo foi fornecido
|
||||||
|
if (updateAlbumType) {
|
||||||
|
if (albumTypeId != null && albumTypeId > 0) {
|
||||||
|
Optional<AlbumType> albumType = albumTypeRepository.findById(albumTypeId);
|
||||||
|
if (albumType.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("AlbumType not found with id: " + albumTypeId);
|
||||||
|
}
|
||||||
|
album.setAlbumType(albumType.get());
|
||||||
|
} else {
|
||||||
|
// Explicitamente passado como 0 ou null = remover a relação
|
||||||
|
album.setAlbumType(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Se não foi fornecido, mantém o existente
|
||||||
|
|
||||||
|
// Update AlbumArt SOMENTE se o campo foi fornecido
|
||||||
|
if (updateAlbumArt) {
|
||||||
|
if (albumArtId != null && albumArtId > 0) {
|
||||||
|
Optional<AlbumArt> albumArt = albumArtRepository.findById(albumArtId);
|
||||||
|
if (albumArt.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("AlbumArt not found with id: " + albumArtId);
|
||||||
|
}
|
||||||
|
album.setAlbumArt(albumArt.get());
|
||||||
|
} else {
|
||||||
|
// Explicitamente passado como 0 ou null = remover a relação
|
||||||
|
album.setAlbumArt(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Se não foi fornecido, mantém o existente
|
||||||
|
|
||||||
|
Album updatedAlbum = repository.update(album);
|
||||||
|
return Optional.of(updatedAlbum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteAlbum(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("Album id cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Deleting album:{}", id);
|
||||||
|
return repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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,77 @@
|
|||||||
|
package com.mediamanager.service.albumhasartist;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.model.AlbumHasArtist;
|
||||||
|
import com.mediamanager.model.Artist;
|
||||||
|
import com.mediamanager.repository.AlbumHasArtistRepository;
|
||||||
|
import com.mediamanager.repository.AlbumRepository;
|
||||||
|
import com.mediamanager.repository.ArtistRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AlbumHasArtistService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumHasArtistService.class);
|
||||||
|
private final AlbumHasArtistRepository repository;
|
||||||
|
private final AlbumRepository albumRepository;
|
||||||
|
private final ArtistRepository artistRepository;
|
||||||
|
|
||||||
|
public AlbumHasArtistService(AlbumHasArtistRepository repository, AlbumRepository albumRepository, ArtistRepository artistRepository) {
|
||||||
|
this.repository = repository;
|
||||||
|
this.albumRepository = albumRepository;
|
||||||
|
this.artistRepository = artistRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumHasArtist createAlbumHasArtist(Integer albumId, Integer artistId) {
|
||||||
|
logger.debug("Creating album has artist relationship - albumId:{}, artistId:{}", albumId, artistId);
|
||||||
|
|
||||||
|
if (albumId == null || albumId <= 0) {
|
||||||
|
throw new IllegalArgumentException("Album ID cannot be null or invalid");
|
||||||
|
}
|
||||||
|
if (artistId == null || artistId <= 0) {
|
||||||
|
throw new IllegalArgumentException("Artist ID cannot be null or invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify Album exists
|
||||||
|
Optional<Album> album = albumRepository.findById(albumId);
|
||||||
|
if (album.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Album not found with id: " + albumId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify Artist exists
|
||||||
|
Optional<Artist> artist = artistRepository.findById(artistId);
|
||||||
|
if (artist.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Artist not found with id: " + artistId);
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumHasArtist albumHasArtist = new AlbumHasArtist();
|
||||||
|
albumHasArtist.setAlbum(album.get());
|
||||||
|
albumHasArtist.setArtist(artist.get());
|
||||||
|
|
||||||
|
return repository.save(albumHasArtist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumHasArtist> getAllAlbumHasArtists() {
|
||||||
|
logger.info("Getting all album has artist relationships");
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumHasArtist> getAlbumHasArtistById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Getting album has artist by id:{}", id);
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteAlbumHasArtist(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("Album has artist id cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Deleting album has artist:{}", id);
|
||||||
|
return repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.mediamanager.service.albumhasgenre;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.model.AlbumHasGenre;
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.repository.AlbumHasGenreRepository;
|
||||||
|
import com.mediamanager.repository.AlbumRepository;
|
||||||
|
import com.mediamanager.repository.GenreRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AlbumHasGenreService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumHasGenreService.class);
|
||||||
|
private final AlbumHasGenreRepository repository;
|
||||||
|
private final AlbumRepository albumRepository;
|
||||||
|
private final GenreRepository genreRepository;
|
||||||
|
|
||||||
|
public AlbumHasGenreService(AlbumHasGenreRepository repository, AlbumRepository albumRepository, GenreRepository genreRepository) {
|
||||||
|
this.repository = repository;
|
||||||
|
this.albumRepository = albumRepository;
|
||||||
|
this.genreRepository = genreRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumHasGenre createAlbumHasGenre(Integer albumId, Integer genreId) {
|
||||||
|
logger.debug("Creating album has genre relationship - albumId:{}, genreId:{}", albumId, genreId);
|
||||||
|
|
||||||
|
if (albumId == null || albumId <= 0) {
|
||||||
|
throw new IllegalArgumentException("Album ID cannot be null or invalid");
|
||||||
|
}
|
||||||
|
if (genreId == null || genreId <= 0) {
|
||||||
|
throw new IllegalArgumentException("Genre ID cannot be null or invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify Album exists
|
||||||
|
Optional<Album> album = albumRepository.findById(albumId);
|
||||||
|
if (album.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Album not found with id: " + albumId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify Genre exists
|
||||||
|
Optional<Genre> genre = genreRepository.findById(genreId);
|
||||||
|
if (genre.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Genre not found with id: " + genreId);
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumHasGenre albumHasGenre = new AlbumHasGenre();
|
||||||
|
albumHasGenre.setAlbum(album.get());
|
||||||
|
albumHasGenre.setGenre(genre.get());
|
||||||
|
|
||||||
|
return repository.save(albumHasGenre);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumHasGenre> getAllAlbumHasGenres() {
|
||||||
|
logger.info("Getting all album has genre relationships");
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumHasGenre> getAlbumHasGenreById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Getting album has genre by id:{}", id);
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteAlbumHasGenre(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("Album has genre id cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Deleting album has genre:{}", id);
|
||||||
|
return repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.mediamanager.service.albumtype;
|
||||||
|
|
||||||
|
import com.mediamanager.model.AlbumType;
|
||||||
|
import com.mediamanager.repository.AlbumTypeRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AlbumTypeService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(AlbumTypeService.class);
|
||||||
|
private final AlbumTypeRepository repository;
|
||||||
|
|
||||||
|
public AlbumTypeService(AlbumTypeRepository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlbumType createAlbumType(String value) {
|
||||||
|
logger.debug("Creating album type:{}", value);
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("AlbumType value cannot be null or empty");
|
||||||
|
}
|
||||||
|
AlbumType albumType = new AlbumType();
|
||||||
|
albumType.setValue(value);
|
||||||
|
return repository.save(albumType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlbumType> getAllAlbumTypes() {
|
||||||
|
logger.info("Getting all album types");
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumType> getAlbumTypeById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Getting album type by id:{}", id);
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<AlbumType> updateAlbumType(Integer id, String value) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Updating album type:{}", value);
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("AlbumType value cannot be null or empty");
|
||||||
|
}
|
||||||
|
Optional<AlbumType> existingAlbumType = repository.findById(id);
|
||||||
|
if(existingAlbumType.isEmpty()) {
|
||||||
|
logger.warn("Album type not found with id:{}", id);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
AlbumType albumType = existingAlbumType.get();
|
||||||
|
albumType.setValue(value);
|
||||||
|
AlbumType updatedAlbumType = repository.update(albumType);
|
||||||
|
return Optional.of(updatedAlbumType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteAlbumType(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("Album type id cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Deleting album type:{}", id);
|
||||||
|
return repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.mediamanager.service.bitrate;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import com.mediamanager.repository.BitRateRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class BitRateService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(BitRateService.class);
|
||||||
|
private final BitRateRepository bitRateRepository;
|
||||||
|
|
||||||
|
public BitRateService(BitRateRepository bitRateRepository) {
|
||||||
|
this.bitRateRepository = bitRateRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BitRate createBitRate(String value){
|
||||||
|
logger.info("Creating bit-rate: {}",value);
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Bit-rate value cannot be empty");
|
||||||
|
}
|
||||||
|
BitRate bitRate = new BitRate();
|
||||||
|
bitRate.setValue(value.trim());
|
||||||
|
return bitRateRepository.save(bitRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BitRate> getAllBitRates(){
|
||||||
|
logger.info("Getting all bit-rates");
|
||||||
|
return bitRateRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<BitRate> getBitRateById(Integer id){
|
||||||
|
logger.info("Getting bit-rate by ID: {}", id);
|
||||||
|
return bitRateRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<BitRate> updateBitRate(Integer id, String value){
|
||||||
|
logger.info("Updating bit-rate ID {}: {}", id, value);
|
||||||
|
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Bit-rate value cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<BitRate> existingBitRate = bitRateRepository.findById(id);
|
||||||
|
|
||||||
|
if(existingBitRate.isEmpty()) {
|
||||||
|
logger.warn("Bit-rate not found with ID: {}", id);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
BitRate bitRate = existingBitRate.get();
|
||||||
|
bitRate.setValue(value.trim());
|
||||||
|
|
||||||
|
BitRate updatedBitRate = bitRateRepository.update(bitRate);
|
||||||
|
return Optional.of(updatedBitRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteBitRate(Integer id){
|
||||||
|
logger.info("Deleting bit-rate ID: {}", id);
|
||||||
|
return bitRateRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,13 +3,22 @@ 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.repository.DiscRepository;
|
||||||
|
import com.mediamanager.service.album.AlbumService;
|
||||||
|
import com.mediamanager.service.albumart.AlbumArtService;
|
||||||
|
import com.mediamanager.service.albumhasartist.AlbumHasArtistService;
|
||||||
|
import com.mediamanager.service.albumhasgenre.AlbumHasGenreService;
|
||||||
|
import com.mediamanager.service.albumtype.AlbumTypeService;
|
||||||
import com.mediamanager.service.bitdepth.BitDepthService;
|
import com.mediamanager.service.bitdepth.BitDepthService;
|
||||||
|
import com.mediamanager.service.bitrate.BitRateService;
|
||||||
import com.mediamanager.service.composer.ComposerService;
|
import com.mediamanager.service.composer.ComposerService;
|
||||||
import com.mediamanager.repository.GenreRepository;
|
import com.mediamanager.repository.GenreRepository;
|
||||||
import com.mediamanager.service.artist.ArtistService;
|
import com.mediamanager.service.artist.ArtistService;
|
||||||
import com.mediamanager.service.delegate.annotation.Action;
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
|
||||||
|
import com.mediamanager.service.disc.DiscService;
|
||||||
import com.mediamanager.service.genre.GenreService;
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import com.mediamanager.service.samplingrate.SamplingRateService;
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -65,6 +74,38 @@ public class DelegateActionManager {
|
|||||||
BitDepthService bitDepthService = new BitDepthService(bitDepthRepository);
|
BitDepthService bitDepthService = new BitDepthService(bitDepthRepository);
|
||||||
serviceLocator.register(BitDepthService.class, bitDepthService);
|
serviceLocator.register(BitDepthService.class, bitDepthService);
|
||||||
|
|
||||||
|
BitRateRepository bitRateRepository = new BitRateRepository(entityManagerFactory);
|
||||||
|
BitRateService bitRateService = new BitRateService(bitRateRepository);
|
||||||
|
serviceLocator.register(BitRateService.class, bitRateService);
|
||||||
|
|
||||||
|
SamplingRateRepository samplingRateRepository = new SamplingRateRepository(entityManagerFactory);
|
||||||
|
SamplingRateService samplingRateService = new SamplingRateService(samplingRateRepository);
|
||||||
|
serviceLocator.register(SamplingRateService.class, samplingRateService);
|
||||||
|
|
||||||
|
AlbumArtRepository albumArtRepository = new AlbumArtRepository(entityManagerFactory);
|
||||||
|
AlbumArtService albumArtService = new AlbumArtService(albumArtRepository);
|
||||||
|
serviceLocator.register(AlbumArtService.class, albumArtService);
|
||||||
|
|
||||||
|
AlbumTypeRepository albumTypeRepository = new AlbumTypeRepository(entityManagerFactory);
|
||||||
|
AlbumTypeService albumTypeService = new AlbumTypeService(albumTypeRepository);
|
||||||
|
serviceLocator.register(AlbumTypeService.class, albumTypeService);
|
||||||
|
|
||||||
|
AlbumRepository albumRepository = new AlbumRepository(entityManagerFactory);
|
||||||
|
AlbumService albumService = new AlbumService(albumRepository, albumTypeRepository, albumArtRepository);
|
||||||
|
serviceLocator.register(AlbumService.class, albumService);
|
||||||
|
|
||||||
|
AlbumHasArtistRepository albumHasArtistRepository = new AlbumHasArtistRepository(entityManagerFactory);
|
||||||
|
AlbumHasArtistService albumHasArtistService = new AlbumHasArtistService(albumHasArtistRepository, albumRepository, artistRepository);
|
||||||
|
serviceLocator.register(AlbumHasArtistService.class, albumHasArtistService);
|
||||||
|
|
||||||
|
AlbumHasGenreRepository albumHasGenreRepository = new AlbumHasGenreRepository(entityManagerFactory);
|
||||||
|
AlbumHasGenreService albumHasGenreService = new AlbumHasGenreService(albumHasGenreRepository, albumRepository, genreRepository);
|
||||||
|
serviceLocator.register(AlbumHasGenreService.class, albumHasGenreService);
|
||||||
|
|
||||||
|
DiscRepository discRepository = new DiscRepository(entityManagerFactory);
|
||||||
|
DiscService discService = new DiscService(discRepository, albumRepository);
|
||||||
|
serviceLocator.register(DiscService.class, discService);
|
||||||
|
|
||||||
serviceLocator.logRegisteredServices();
|
serviceLocator.logRegisteredServices();
|
||||||
|
|
||||||
logger.info("Services initialized successfully");
|
logger.info("Services initialized successfully");
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.album;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumMapper;
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.album.AlbumService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("album.create")
|
||||||
|
public class CreateAlbumHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateAlbumHandler.class);
|
||||||
|
private final AlbumService albumService;
|
||||||
|
|
||||||
|
public CreateAlbumHandler(AlbumService albumService) {
|
||||||
|
this.albumService = albumService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
AlbumMessages.CreateAlbumRequest createRequest =
|
||||||
|
AlbumMessages.CreateAlbumRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
Album album = albumService.createAlbum(
|
||||||
|
createRequest.getName(),
|
||||||
|
createRequest.getYear() > 0 ? createRequest.getYear() : null,
|
||||||
|
createRequest.getNumberOfDiscs() > 0 ? createRequest.getNumberOfDiscs() : null,
|
||||||
|
createRequest.getCode().isEmpty() ? null : createRequest.getCode(),
|
||||||
|
createRequest.getIsCompilation(),
|
||||||
|
createRequest.getFkAlbumtypeId() > 0 ? createRequest.getFkAlbumtypeId() : null,
|
||||||
|
createRequest.getFkAlbumartId() > 0 ? createRequest.getFkAlbumartId() : null
|
||||||
|
);
|
||||||
|
|
||||||
|
AlbumMessages.Album albumProto = AlbumMapper.toProtobuf(album);
|
||||||
|
AlbumMessages.CreateAlbumResponse createAlbumResponse = AlbumMessages.CreateAlbumResponse.newBuilder()
|
||||||
|
.setAlbum(albumProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createAlbumResponse.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", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.album;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.album.AlbumService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("album.delete")
|
||||||
|
public class DeleteAlbumHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteAlbumHandler.class);
|
||||||
|
|
||||||
|
private final AlbumService albumService;
|
||||||
|
|
||||||
|
public DeleteAlbumHandler(AlbumService albumService) {
|
||||||
|
this.albumService = albumService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
AlbumMessages.DeleteAlbumRequest deleteRequest =
|
||||||
|
AlbumMessages.DeleteAlbumRequest.parseFrom(requestPayload);
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
boolean success = albumService.deleteAlbum(id);
|
||||||
|
AlbumMessages.DeleteAlbumResponse deleteResponse;
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = AlbumMessages.DeleteAlbumResponse.newBuilder()
|
||||||
|
.setSuccess(true)
|
||||||
|
.setMessage("Album deleted successfully")
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = AlbumMessages.DeleteAlbumResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Album not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting album", e);
|
||||||
|
AlbumMessages.DeleteAlbumResponse deleteResponse =
|
||||||
|
AlbumMessages.DeleteAlbumResponse.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.album;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumMapper;
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.album.AlbumService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action(value = "album.getById")
|
||||||
|
public class GetAlbumByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetAlbumByIdHandler.class);
|
||||||
|
private final AlbumService albumService;
|
||||||
|
|
||||||
|
public GetAlbumByIdHandler(AlbumService albumService) {
|
||||||
|
this.albumService = albumService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException{
|
||||||
|
|
||||||
|
try{
|
||||||
|
AlbumMessages.GetAlbumByIdRequest getByIdRequest =
|
||||||
|
AlbumMessages.GetAlbumByIdRequest.parseFrom(requestPayload);
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
Optional<Album> albumOpt = albumService.getAlbumById(id);
|
||||||
|
|
||||||
|
if (albumOpt.isEmpty()){
|
||||||
|
logger.warn("Album not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Album not found"));
|
||||||
|
}
|
||||||
|
AlbumMessages.Album albumProto = AlbumMapper.toProtobuf(albumOpt.get());
|
||||||
|
AlbumMessages.GetAlbumByIdResponse getByIdResponse = AlbumMessages.GetAlbumByIdResponse.newBuilder()
|
||||||
|
.setAlbum(albumProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting album by ID", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.album;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumMapper;
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.album.AlbumService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Action("album.getAll")
|
||||||
|
public class GetAlbumHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetAlbumHandler.class);
|
||||||
|
|
||||||
|
private final AlbumService albumService;
|
||||||
|
|
||||||
|
public GetAlbumHandler(AlbumService albumService){this.albumService = albumService;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
List<Album> albums = albumService.getAllAlbums();
|
||||||
|
AlbumMessages.GetAlbumsResponse.Builder responseBuilder = AlbumMessages.GetAlbumsResponse.newBuilder();
|
||||||
|
|
||||||
|
for (Album album : albums) {
|
||||||
|
AlbumMessages.Album albumProto = AlbumMapper.toProtobuf(album);
|
||||||
|
responseBuilder.addAlbums(albumProto);
|
||||||
|
}
|
||||||
|
AlbumMessages.GetAlbumsResponse getAlbumsResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getAlbumsResponse.toByteString());
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("Error getting albums", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.album;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumMapper;
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.album.AlbumService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action("album.update")
|
||||||
|
public class UpdateAlbumHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(UpdateAlbumHandler.class);
|
||||||
|
private final AlbumService albumService;
|
||||||
|
|
||||||
|
public UpdateAlbumHandler(AlbumService albumService) {
|
||||||
|
this.albumService = albumService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
AlbumMessages.UpdateAlbumRequest updateRequest =
|
||||||
|
AlbumMessages.UpdateAlbumRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = updateRequest.getId();
|
||||||
|
|
||||||
|
// Extrai valores dos wrappers - null se não foi fornecido
|
||||||
|
Integer year = updateRequest.hasYear()
|
||||||
|
? updateRequest.getYear().getValue()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
Integer numberOfDiscs = updateRequest.hasNumberOfDiscs()
|
||||||
|
? updateRequest.getNumberOfDiscs().getValue()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
Integer albumTypeId = updateRequest.hasFkAlbumtypeId()
|
||||||
|
? updateRequest.getFkAlbumtypeId().getValue()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
Integer albumArtId = updateRequest.hasFkAlbumartId()
|
||||||
|
? updateRequest.getFkAlbumartId().getValue()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
Optional<Album> albumOpt = albumService.updateAlbum(
|
||||||
|
id,
|
||||||
|
updateRequest.getName(),
|
||||||
|
year,
|
||||||
|
numberOfDiscs,
|
||||||
|
updateRequest.getCode().isEmpty() ? null : updateRequest.getCode(),
|
||||||
|
updateRequest.getIsCompilation(),
|
||||||
|
albumTypeId,
|
||||||
|
albumArtId,
|
||||||
|
updateRequest.hasYear(), // ← Novo!
|
||||||
|
updateRequest.hasNumberOfDiscs(), // ← Novo!
|
||||||
|
updateRequest.hasFkAlbumtypeId(), // ← Novo!
|
||||||
|
updateRequest.hasFkAlbumartId() // ← Novo!
|
||||||
|
);
|
||||||
|
|
||||||
|
if (albumOpt.isEmpty()) {
|
||||||
|
logger.warn("Album not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Album not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
AlbumMessages.Album albumProto = AlbumMapper.toProtobuf(albumOpt.get());
|
||||||
|
|
||||||
|
AlbumMessages.UpdateAlbumResponse updateResponse =
|
||||||
|
AlbumMessages.UpdateAlbumResponse.newBuilder()
|
||||||
|
.setAlbum(albumProto)
|
||||||
|
.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", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.albumhasartist;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumHasArtistMapper;
|
||||||
|
import com.mediamanager.model.AlbumHasArtist;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasArtistMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasartist.AlbumHasArtistService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("albumhasartist.create")
|
||||||
|
public class CreateAlbumHasArtistHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateAlbumHasArtistHandler.class);
|
||||||
|
private final AlbumHasArtistService albumHasArtistService;
|
||||||
|
|
||||||
|
public CreateAlbumHasArtistHandler(AlbumHasArtistService albumHasArtistService) {
|
||||||
|
this.albumHasArtistService = albumHasArtistService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
AlbumHasArtistMessages.CreateAlbumHasArtistRequest createRequest =
|
||||||
|
AlbumHasArtistMessages.CreateAlbumHasArtistRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
AlbumHasArtist albumHasArtist = albumHasArtistService.createAlbumHasArtist(
|
||||||
|
createRequest.getFkAlbumId() > 0 ? createRequest.getFkAlbumId() : null,
|
||||||
|
createRequest.getFkArtistId() > 0 ? createRequest.getFkArtistId() : null
|
||||||
|
);
|
||||||
|
|
||||||
|
AlbumHasArtistMessages.AlbumHasArtist albumHasArtistProto = AlbumHasArtistMapper.toProtobuf(albumHasArtist);
|
||||||
|
AlbumHasArtistMessages.CreateAlbumHasArtistResponse createAlbumHasArtistResponse = AlbumHasArtistMessages.CreateAlbumHasArtistResponse.newBuilder()
|
||||||
|
.setAlbumhasartist(albumHasArtistProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createAlbumHasArtistResponse.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 has artist", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.albumhasartist;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasArtistMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasartist.AlbumHasArtistService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("albumhasartist.delete")
|
||||||
|
public class DeleteAlbumHasArtistHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteAlbumHasArtistHandler.class);
|
||||||
|
|
||||||
|
private final AlbumHasArtistService albumHasArtistService;
|
||||||
|
|
||||||
|
public DeleteAlbumHasArtistHandler(AlbumHasArtistService albumHasArtistService) {
|
||||||
|
this.albumHasArtistService = albumHasArtistService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
AlbumHasArtistMessages.DeleteAlbumHasArtistRequest deleteRequest =
|
||||||
|
AlbumHasArtistMessages.DeleteAlbumHasArtistRequest.parseFrom(requestPayload);
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
boolean success = albumHasArtistService.deleteAlbumHasArtist(id);
|
||||||
|
AlbumHasArtistMessages.DeleteAlbumHasArtistResponse deleteResponse;
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = AlbumHasArtistMessages.DeleteAlbumHasArtistResponse.newBuilder()
|
||||||
|
.setSuccess(true)
|
||||||
|
.setMessage("Album has artist deleted successfully")
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = AlbumHasArtistMessages.DeleteAlbumHasArtistResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Album has artist not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting album has artist", e);
|
||||||
|
AlbumHasArtistMessages.DeleteAlbumHasArtistResponse deleteResponse =
|
||||||
|
AlbumHasArtistMessages.DeleteAlbumHasArtistResponse.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.albumhasartist;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumHasArtistMapper;
|
||||||
|
import com.mediamanager.model.AlbumHasArtist;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasArtistMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasartist.AlbumHasArtistService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action(value = "albumhasartist.getById")
|
||||||
|
public class GetAlbumHasArtistByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetAlbumHasArtistByIdHandler.class);
|
||||||
|
private final AlbumHasArtistService albumHasArtistService;
|
||||||
|
|
||||||
|
public GetAlbumHasArtistByIdHandler(AlbumHasArtistService albumHasArtistService) {
|
||||||
|
this.albumHasArtistService = albumHasArtistService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException{
|
||||||
|
|
||||||
|
try{
|
||||||
|
AlbumHasArtistMessages.GetAlbumHasArtistByIdRequest getByIdRequest =
|
||||||
|
AlbumHasArtistMessages.GetAlbumHasArtistByIdRequest.parseFrom(requestPayload);
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
Optional<AlbumHasArtist> albumHasArtistOpt = albumHasArtistService.getAlbumHasArtistById(id);
|
||||||
|
|
||||||
|
if (albumHasArtistOpt.isEmpty()){
|
||||||
|
logger.warn("AlbumHasArtist not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("AlbumHasArtist not found"));
|
||||||
|
}
|
||||||
|
AlbumHasArtistMessages.AlbumHasArtist albumHasArtistProto = AlbumHasArtistMapper.toProtobuf(albumHasArtistOpt.get());
|
||||||
|
AlbumHasArtistMessages.GetAlbumHasArtistByIdResponse getByIdResponse = AlbumHasArtistMessages.GetAlbumHasArtistByIdResponse.newBuilder()
|
||||||
|
.setAlbumhasartist(albumHasArtistProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting album has artist 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.albumhasartist;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumHasArtistMapper;
|
||||||
|
import com.mediamanager.model.AlbumHasArtist;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasArtistMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasartist.AlbumHasArtistService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Action("albumhasartist.getAll")
|
||||||
|
public class GetAlbumHasArtistHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetAlbumHasArtistHandler.class);
|
||||||
|
|
||||||
|
private final AlbumHasArtistService albumHasArtistService;
|
||||||
|
|
||||||
|
public GetAlbumHasArtistHandler(AlbumHasArtistService albumHasArtistService){this.albumHasArtistService = albumHasArtistService;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
List<AlbumHasArtist> albumHasArtists = albumHasArtistService.getAllAlbumHasArtists();
|
||||||
|
AlbumHasArtistMessages.GetAlbumHasArtistsResponse.Builder responseBuilder = AlbumHasArtistMessages.GetAlbumHasArtistsResponse.newBuilder();
|
||||||
|
|
||||||
|
for (AlbumHasArtist albumHasArtist : albumHasArtists) {
|
||||||
|
AlbumHasArtistMessages.AlbumHasArtist albumHasArtistProto = AlbumHasArtistMapper.toProtobuf(albumHasArtist);
|
||||||
|
responseBuilder.addAlbumhasartist(albumHasArtistProto);
|
||||||
|
}
|
||||||
|
AlbumHasArtistMessages.GetAlbumHasArtistsResponse getAlbumHasArtistsResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getAlbumHasArtistsResponse.toByteString());
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("Error getting album has artists", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.albumhasgenre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumHasGenreMapper;
|
||||||
|
import com.mediamanager.model.AlbumHasGenre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasGenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasgenre.AlbumHasGenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("albumhasgenre.create")
|
||||||
|
public class CreateAlbumHasGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateAlbumHasGenreHandler.class);
|
||||||
|
private final AlbumHasGenreService albumHasGenreService;
|
||||||
|
|
||||||
|
public CreateAlbumHasGenreHandler(AlbumHasGenreService albumHasGenreService) {
|
||||||
|
this.albumHasGenreService = albumHasGenreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
AlbumHasGenreMessages.CreateAlbumHasGenreRequest createRequest =
|
||||||
|
AlbumHasGenreMessages.CreateAlbumHasGenreRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
AlbumHasGenre albumHasGenre = albumHasGenreService.createAlbumHasGenre(
|
||||||
|
createRequest.getFkAlbumId() > 0 ? createRequest.getFkAlbumId() : null,
|
||||||
|
createRequest.getFkGenreId() > 0 ? createRequest.getFkGenreId() : null
|
||||||
|
);
|
||||||
|
|
||||||
|
AlbumHasGenreMessages.AlbumHasGenre albumHasGenreProto = AlbumHasGenreMapper.toProtobuf(albumHasGenre);
|
||||||
|
AlbumHasGenreMessages.CreateAlbumHasGenreResponse createAlbumHasGenreResponse = AlbumHasGenreMessages.CreateAlbumHasGenreResponse.newBuilder()
|
||||||
|
.setAlbumhasgenre(albumHasGenreProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createAlbumHasGenreResponse.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 has genre", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.albumhasgenre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasGenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasgenre.AlbumHasGenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("albumhasgenre.delete")
|
||||||
|
public class DeleteAlbumHasGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteAlbumHasGenreHandler.class);
|
||||||
|
|
||||||
|
private final AlbumHasGenreService albumHasGenreService;
|
||||||
|
|
||||||
|
public DeleteAlbumHasGenreHandler(AlbumHasGenreService albumHasGenreService) {
|
||||||
|
this.albumHasGenreService = albumHasGenreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
AlbumHasGenreMessages.DeleteAlbumHasGenreRequest deleteRequest =
|
||||||
|
AlbumHasGenreMessages.DeleteAlbumHasGenreRequest.parseFrom(requestPayload);
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
boolean success = albumHasGenreService.deleteAlbumHasGenre(id);
|
||||||
|
AlbumHasGenreMessages.DeleteAlbumHasGenreResponse deleteResponse;
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = AlbumHasGenreMessages.DeleteAlbumHasGenreResponse.newBuilder()
|
||||||
|
.setSuccess(true)
|
||||||
|
.setMessage("Album has genre deleted successfully")
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = AlbumHasGenreMessages.DeleteAlbumHasGenreResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Album has genre not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting album has genre", e);
|
||||||
|
AlbumHasGenreMessages.DeleteAlbumHasGenreResponse deleteResponse =
|
||||||
|
AlbumHasGenreMessages.DeleteAlbumHasGenreResponse.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.albumhasgenre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumHasGenreMapper;
|
||||||
|
import com.mediamanager.model.AlbumHasGenre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasGenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasgenre.AlbumHasGenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action(value = "albumhasgenre.getById")
|
||||||
|
public class GetAlbumHasGenreByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetAlbumHasGenreByIdHandler.class);
|
||||||
|
private final AlbumHasGenreService albumHasGenreService;
|
||||||
|
|
||||||
|
public GetAlbumHasGenreByIdHandler(AlbumHasGenreService albumHasGenreService) {
|
||||||
|
this.albumHasGenreService = albumHasGenreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException{
|
||||||
|
|
||||||
|
try{
|
||||||
|
AlbumHasGenreMessages.GetAlbumHasGenreByIdRequest getByIdRequest =
|
||||||
|
AlbumHasGenreMessages.GetAlbumHasGenreByIdRequest.parseFrom(requestPayload);
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
Optional<AlbumHasGenre> albumHasGenreOpt = albumHasGenreService.getAlbumHasGenreById(id);
|
||||||
|
|
||||||
|
if (albumHasGenreOpt.isEmpty()){
|
||||||
|
logger.warn("AlbumHasGenre not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("AlbumHasGenre not found"));
|
||||||
|
}
|
||||||
|
AlbumHasGenreMessages.AlbumHasGenre albumHasGenreProto = AlbumHasGenreMapper.toProtobuf(albumHasGenreOpt.get());
|
||||||
|
AlbumHasGenreMessages.GetAlbumHasGenreByIdResponse getByIdResponse = AlbumHasGenreMessages.GetAlbumHasGenreByIdResponse.newBuilder()
|
||||||
|
.setAlbumhasgenre(albumHasGenreProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting album has genre 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.albumhasgenre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.AlbumHasGenreMapper;
|
||||||
|
import com.mediamanager.model.AlbumHasGenre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.AlbumHasGenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.albumhasgenre.AlbumHasGenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Action("albumhasgenre.getAll")
|
||||||
|
public class GetAlbumHasGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetAlbumHasGenreHandler.class);
|
||||||
|
|
||||||
|
private final AlbumHasGenreService albumHasGenreService;
|
||||||
|
|
||||||
|
public GetAlbumHasGenreHandler(AlbumHasGenreService albumHasGenreService){this.albumHasGenreService = albumHasGenreService;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
List<AlbumHasGenre> albumHasGenres = albumHasGenreService.getAllAlbumHasGenres();
|
||||||
|
AlbumHasGenreMessages.GetAlbumHasGenresResponse.Builder responseBuilder = AlbumHasGenreMessages.GetAlbumHasGenresResponse.newBuilder();
|
||||||
|
|
||||||
|
for (AlbumHasGenre albumHasGenre : albumHasGenres) {
|
||||||
|
AlbumHasGenreMessages.AlbumHasGenre albumHasGenreProto = AlbumHasGenreMapper.toProtobuf(albumHasGenre);
|
||||||
|
responseBuilder.addAlbumhasgenre(albumHasGenreProto);
|
||||||
|
}
|
||||||
|
AlbumHasGenreMessages.GetAlbumHasGenresResponse getAlbumHasGenresResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getAlbumHasGenresResponse.toByteString());
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("Error getting album has genres", 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-1
@@ -42,7 +42,6 @@ public class CreateBitDepthHandler implements ActionHandler {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error creating bit-depth", e);
|
logger.error("Error creating bit-depth", e);
|
||||||
return TransportProtocol.Response.newBuilder()
|
|
||||||
return TransportProtocol.Response.newBuilder()
|
return TransportProtocol.Response.newBuilder()
|
||||||
.setStatusCode(500)
|
.setStatusCode(500)
|
||||||
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
|||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.bitrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.BitRateMapper;
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.BitRateMessages;
|
||||||
|
import com.mediamanager.service.bitrate.BitRateService;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("bitrate.create")
|
||||||
|
public class CreateBitRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateBitRateHandler.class);
|
||||||
|
private final BitRateService bitRateService;
|
||||||
|
|
||||||
|
public CreateBitRateHandler(BitRateService bitRateService) {
|
||||||
|
this.bitRateService = bitRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
BitRateMessages.CreateBitRateRequest createRequest =
|
||||||
|
BitRateMessages.CreateBitRateRequest.parseFrom(requestPayload);
|
||||||
|
BitRate bitRate = bitRateService.createBitRate(createRequest.getValue());
|
||||||
|
BitRateMessages.BitRate BitRateProto = BitRateMapper.toProtobuf(bitRate);
|
||||||
|
BitRateMessages.CreateBitRateResponse createBitRateResponse = BitRateMessages.CreateBitRateResponse.newBuilder()
|
||||||
|
.setBitrate(BitRateProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createBitRateResponse.toByteString());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating bit-rate", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.bitrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.BitRateMessages;
|
||||||
|
import com.mediamanager.service.bitrate.BitRateService;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("bitrate.delete")
|
||||||
|
public class DeleteBitRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteBitRateHandler.class);
|
||||||
|
|
||||||
|
private final BitRateService bitRateService;
|
||||||
|
|
||||||
|
public DeleteBitRateHandler(BitRateService bitRateService) {
|
||||||
|
this.bitRateService = bitRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
BitRateMessages.DeleteBitRateRequest deleteRequest =
|
||||||
|
BitRateMessages.DeleteBitRateRequest.parseFrom(requestPayload);
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
boolean success = bitRateService.deleteBitRate(id);
|
||||||
|
BitRateMessages.DeleteBitRateResponse deleteResponse;
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = BitRateMessages.DeleteBitRateResponse.newBuilder()
|
||||||
|
.setSuccess(true)
|
||||||
|
.setMessage("Bit-Rate deleted successfully")
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = BitRateMessages.DeleteBitRateResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Bit-Rate not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting bit-rate", e);
|
||||||
|
BitRateMessages.DeleteBitRateResponse deleteResponse =
|
||||||
|
BitRateMessages.DeleteBitRateResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Error: " + e.getMessage())
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.bitrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.BitRateMapper;
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.BitRateMessages;
|
||||||
|
import com.mediamanager.service.bitrate.BitRateService;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action(value = "bitrate.getById")
|
||||||
|
public class GetBitRateByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetBitRateByIdHandler.class);
|
||||||
|
private final BitRateService bitRateService;
|
||||||
|
|
||||||
|
public GetBitRateByIdHandler(BitRateService bitRateService) {
|
||||||
|
this.bitRateService = bitRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException{
|
||||||
|
|
||||||
|
try{
|
||||||
|
BitRateMessages.GetBitRateByIdRequest getByIdRequest =
|
||||||
|
BitRateMessages.GetBitRateByIdRequest.parseFrom(requestPayload);
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
Optional<BitRate> bitRateOpt = bitRateService.getBitRateById(id);
|
||||||
|
|
||||||
|
if (bitRateOpt.isEmpty()){
|
||||||
|
logger.warn("BitRate not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("BitRate not found"));
|
||||||
|
}
|
||||||
|
BitRateMessages.BitRate bitRateProto = BitRateMapper.toProtobuf(bitRateOpt.get());
|
||||||
|
BitRateMessages.GetBitRateByIdResponse getByIdResponse = BitRateMessages.GetBitRateByIdResponse.newBuilder()
|
||||||
|
.setBitrate(bitRateProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting bit-rate by ID", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.bitrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.BitRateMapper;
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.BitRateMessages;
|
||||||
|
import com.mediamanager.service.bitrate.BitRateService;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Action("bitrate.getAll")
|
||||||
|
public class GetBitRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetBitRateHandler.class);
|
||||||
|
|
||||||
|
private final BitRateService bitRateService;
|
||||||
|
|
||||||
|
public GetBitRateHandler(BitRateService bitRateService){this.bitRateService = bitRateService;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
List<BitRate> bitRates = bitRateService.getAllBitRates();
|
||||||
|
BitRateMessages.GetBitRatesResponse.Builder responseBuilder = BitRateMessages.GetBitRatesResponse.newBuilder();
|
||||||
|
|
||||||
|
for (BitRate bitRate : bitRates) {
|
||||||
|
BitRateMessages.BitRate bitRateProto = BitRateMapper.toProtobuf(bitRate);
|
||||||
|
responseBuilder.addBitrates(bitRateProto);
|
||||||
|
}
|
||||||
|
BitRateMessages.GetBitRatesResponse getBitRatesResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getBitRatesResponse.toByteString());
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("Error getting bit-rates", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.bitrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.BitRateMapper;
|
||||||
|
import com.mediamanager.model.BitRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.BitRateMessages;
|
||||||
|
import com.mediamanager.service.bitrate.BitRateService;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action("bitrate.update")
|
||||||
|
public class UpdateBitRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(UpdateBitRateHandler.class);
|
||||||
|
private final BitRateService bitRateService;
|
||||||
|
|
||||||
|
public UpdateBitRateHandler(BitRateService bitRateService) {
|
||||||
|
this.bitRateService = bitRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
BitRateMessages.UpdateBitRateRequest updateRequest =
|
||||||
|
BitRateMessages.UpdateBitRateRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = updateRequest.getId();
|
||||||
|
String newValue = updateRequest.getValue();
|
||||||
|
|
||||||
|
Optional<BitRate> bitRateOpt = bitRateService.updateBitRate(id, newValue);
|
||||||
|
|
||||||
|
if(bitRateOpt.isEmpty()){
|
||||||
|
logger.warn("BitRate not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("BitRate not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
BitRateMessages.BitRate bitRateProto = BitRateMapper.toProtobuf(bitRateOpt.get());
|
||||||
|
|
||||||
|
BitRateMessages.UpdateBitRateResponse updateResponse = BitRateMessages.UpdateBitRateResponse.newBuilder()
|
||||||
|
.setBitrate(bitRateProto)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(updateResponse.toByteString());
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e){
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error updating bit-rate", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.disc;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.DiscMapper;
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.DiscMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.disc.DiscService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("disc.create")
|
||||||
|
public class CreateDiscHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateDiscHandler.class);
|
||||||
|
private final DiscService discService;
|
||||||
|
|
||||||
|
public CreateDiscHandler(DiscService discService) {
|
||||||
|
this.discService = discService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
DiscMessages.CreateDiscRequest createRequest =
|
||||||
|
DiscMessages.CreateDiscRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
Disc disc = discService.createDisc(
|
||||||
|
createRequest.getDiscNumber(),
|
||||||
|
createRequest.getFkAlbumId() > 0 ? createRequest.getFkAlbumId() : null
|
||||||
|
);
|
||||||
|
|
||||||
|
DiscMessages.Disc discProto = DiscMapper.toProtobuf(disc);
|
||||||
|
DiscMessages.CreateDiscResponse createDiscResponse = DiscMessages.CreateDiscResponse.newBuilder()
|
||||||
|
.setDisc(discProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createDiscResponse.toByteString());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Invalid request"));
|
||||||
|
|
||||||
|
} catch (InvalidProtocolBufferException e) {
|
||||||
|
logger.error("Invalid CreateDiscRequest payload", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Invalid request payload"));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating disc", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Internal server error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.disc;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.DiscMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.disc.DiscService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("disc.delete")
|
||||||
|
public class DeleteDiscHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteDiscHandler.class);
|
||||||
|
|
||||||
|
private final DiscService discService;
|
||||||
|
|
||||||
|
public DeleteDiscHandler(DiscService discService) {
|
||||||
|
this.discService = discService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
DiscMessages.DeleteDiscRequest deleteRequest =
|
||||||
|
DiscMessages.DeleteDiscRequest.parseFrom(requestPayload);
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
boolean success = discService.deleteDisc(id);
|
||||||
|
DiscMessages.DeleteDiscResponse deleteResponse;
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = DiscMessages.DeleteDiscResponse.newBuilder()
|
||||||
|
.setMessage("Disc deleted successfully")
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = DiscMessages.DeleteDiscResponse.newBuilder()
|
||||||
|
.setMessage("Disc not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting disc", e);
|
||||||
|
DiscMessages.DeleteDiscResponse deleteResponse =
|
||||||
|
DiscMessages.DeleteDiscResponse.newBuilder()
|
||||||
|
.setMessage("Error: " + e.getMessage())
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.disc;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.DiscMapper;
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.DiscMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.disc.DiscService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action(value = "disc.getById")
|
||||||
|
public class GetDiscByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetDiscByIdHandler.class);
|
||||||
|
private final DiscService discService;
|
||||||
|
|
||||||
|
public GetDiscByIdHandler(DiscService discService) {
|
||||||
|
this.discService = discService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException{
|
||||||
|
|
||||||
|
try{
|
||||||
|
DiscMessages.GetDiscByIdRequest getByIdRequest =
|
||||||
|
DiscMessages.GetDiscByIdRequest.parseFrom(requestPayload);
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
Optional<Disc> discOpt = discService.getDiscById(id);
|
||||||
|
|
||||||
|
if (discOpt.isEmpty()){
|
||||||
|
logger.warn("Disc not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Disc not found"));
|
||||||
|
}
|
||||||
|
DiscMessages.Disc discProto = DiscMapper.toProtobuf(discOpt.get());
|
||||||
|
DiscMessages.GetDiscByIdResponse getByIdResponse = DiscMessages.GetDiscByIdResponse.newBuilder()
|
||||||
|
.setDisc(discProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting disc by ID", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.disc;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.DiscMapper;
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.DiscMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.disc.DiscService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Action("disc.getAll")
|
||||||
|
public class GetDiscHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetDiscHandler.class);
|
||||||
|
|
||||||
|
private final DiscService discService;
|
||||||
|
|
||||||
|
public GetDiscHandler(DiscService discService){this.discService = discService;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
List<Disc> discs = discService.getAllDiscs();
|
||||||
|
DiscMessages.GetDiscsResponse.Builder responseBuilder = DiscMessages.GetDiscsResponse.newBuilder();
|
||||||
|
|
||||||
|
for (Disc disc : discs) {
|
||||||
|
DiscMessages.Disc discProto = DiscMapper.toProtobuf(disc);
|
||||||
|
responseBuilder.addDiscs(discProto);
|
||||||
|
}
|
||||||
|
DiscMessages.GetDiscsResponse getDiscsResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getDiscsResponse.toByteString());
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("Error getting discs", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.disc;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.DiscMapper;
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.DiscMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.disc.DiscService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action("disc.update")
|
||||||
|
public class UpdateDiscHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(UpdateDiscHandler.class);
|
||||||
|
private final DiscService discService;
|
||||||
|
|
||||||
|
public UpdateDiscHandler(DiscService discService) {
|
||||||
|
this.discService = discService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
DiscMessages.UpdateDiscRequest updateRequest =
|
||||||
|
DiscMessages.UpdateDiscRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = updateRequest.getId();
|
||||||
|
Integer discNumber = updateRequest.getDiscNumber();
|
||||||
|
Integer albumId = updateRequest.getFkAlbumId() > 0 ? updateRequest.getFkAlbumId() : null;
|
||||||
|
|
||||||
|
Optional<Disc> discOpt = discService.updateDisc(
|
||||||
|
id,
|
||||||
|
discNumber,
|
||||||
|
albumId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (discOpt.isEmpty()) {
|
||||||
|
logger.warn("Disc not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Disc not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscMessages.Disc discProto = DiscMapper.toProtobuf(discOpt.get());
|
||||||
|
|
||||||
|
DiscMessages.UpdateDiscResponse updateResponse =
|
||||||
|
DiscMessages.UpdateDiscResponse.newBuilder()
|
||||||
|
.setDisc(discProto)
|
||||||
|
.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 disc", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.samplingrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.SamplingRateMapper;
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.SamplingRateMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.samplingrate.SamplingRateService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("samplingrate.create")
|
||||||
|
public class CreateSamplingRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateSamplingRateHandler.class);
|
||||||
|
private final SamplingRateService samplingRateService;
|
||||||
|
|
||||||
|
public CreateSamplingRateHandler(SamplingRateService samplingRateService) {
|
||||||
|
this.samplingRateService = samplingRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
SamplingRateMessages.CreateSamplingRateRequest createRequest =
|
||||||
|
SamplingRateMessages.CreateSamplingRateRequest.parseFrom(requestPayload);
|
||||||
|
SamplingRate samplingRate = samplingRateService.createSamplingRate(createRequest.getValue());
|
||||||
|
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRate);
|
||||||
|
SamplingRateMessages.CreateSamplingRateResponse createSamplingRateResponse = SamplingRateMessages.CreateSamplingRateResponse.newBuilder()
|
||||||
|
.setSamplingrate(samplingRateProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createSamplingRateResponse.toByteString());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating sampling rate", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.samplingrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.SamplingRateMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.samplingrate.SamplingRateService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@Action("samplingrate.delete")
|
||||||
|
public class DeleteSamplingRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteSamplingRateHandler.class);
|
||||||
|
|
||||||
|
private final SamplingRateService samplingRateService;
|
||||||
|
|
||||||
|
public DeleteSamplingRateHandler(SamplingRateService samplingRateService) {
|
||||||
|
this.samplingRateService = samplingRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
SamplingRateMessages.DeleteSamplingRateRequest deleteRequest =
|
||||||
|
SamplingRateMessages.DeleteSamplingRateRequest.parseFrom(requestPayload);
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
boolean success = samplingRateService.deleteSamplingRate(id);
|
||||||
|
SamplingRateMessages.DeleteSamplingRateResponse deleteResponse;
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = SamplingRateMessages.DeleteSamplingRateResponse.newBuilder()
|
||||||
|
.setSuccess(true)
|
||||||
|
.setMessage("Sampling rate deleted successfully")
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = SamplingRateMessages.DeleteSamplingRateResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Sampling rate not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting sampling rate", e);
|
||||||
|
SamplingRateMessages.DeleteSamplingRateResponse deleteResponse =
|
||||||
|
SamplingRateMessages.DeleteSamplingRateResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Error: " + e.getMessage())
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.samplingrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.SamplingRateMapper;
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.SamplingRateMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.samplingrate.SamplingRateService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action(value = "samplingrate.getById")
|
||||||
|
public class GetSamplingRateByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetSamplingRateByIdHandler.class);
|
||||||
|
private final SamplingRateService samplingRateService;
|
||||||
|
|
||||||
|
public GetSamplingRateByIdHandler(SamplingRateService samplingRateService) {
|
||||||
|
this.samplingRateService = samplingRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException{
|
||||||
|
|
||||||
|
try{
|
||||||
|
SamplingRateMessages.GetSamplingRateByIdRequest getByIdRequest =
|
||||||
|
SamplingRateMessages.GetSamplingRateByIdRequest.parseFrom(requestPayload);
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
Optional<SamplingRate> samplingRateOpt = samplingRateService.getSamplingRateById(id);
|
||||||
|
|
||||||
|
if (samplingRateOpt.isEmpty()){
|
||||||
|
logger.warn("SamplingRate not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("SamplingRate not found"));
|
||||||
|
}
|
||||||
|
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRateOpt.get());
|
||||||
|
SamplingRateMessages.GetSamplingRateByIdResponse getByIdResponse = SamplingRateMessages.GetSamplingRateByIdResponse.newBuilder()
|
||||||
|
.setSamplingrate(samplingRateProto)
|
||||||
|
.build();
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting sampling rate by ID", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: "+ e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.samplingrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.SamplingRateMapper;
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.SamplingRateMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.samplingrate.SamplingRateService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Action("samplingrate.getAll")
|
||||||
|
public class GetSamplingRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetSamplingRateHandler.class);
|
||||||
|
|
||||||
|
private final SamplingRateService samplingRateService;
|
||||||
|
|
||||||
|
public GetSamplingRateHandler(SamplingRateService samplingRateService){this.samplingRateService = samplingRateService;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
List<SamplingRate> samplingRates = samplingRateService.getAllSamplingRates();
|
||||||
|
SamplingRateMessages.GetSamplingRatesResponse.Builder responseBuilder = SamplingRateMessages.GetSamplingRatesResponse.newBuilder();
|
||||||
|
|
||||||
|
for (SamplingRate samplingRate : samplingRates) {
|
||||||
|
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRate);
|
||||||
|
responseBuilder.addSamplingrates(samplingRateProto);
|
||||||
|
}
|
||||||
|
SamplingRateMessages.GetSamplingRatesResponse getSamplingRatesResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getSamplingRatesResponse.toByteString());
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("Error getting sampling rates", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.samplingrate;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.SamplingRateMapper;
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.SamplingRateMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.delegate.annotation.Action;
|
||||||
|
import com.mediamanager.service.samplingrate.SamplingRateService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Action("samplingrate.update")
|
||||||
|
public class UpdateSamplingRateHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(UpdateSamplingRateHandler.class);
|
||||||
|
private final SamplingRateService samplingRateService;
|
||||||
|
|
||||||
|
public UpdateSamplingRateHandler(SamplingRateService samplingRateService) {
|
||||||
|
this.samplingRateService = samplingRateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload) throws InvalidProtocolBufferException {
|
||||||
|
try{
|
||||||
|
SamplingRateMessages.UpdateSamplingRateRequest updateRequest =
|
||||||
|
SamplingRateMessages.UpdateSamplingRateRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = updateRequest.getId();
|
||||||
|
String newValue = updateRequest.getValue();
|
||||||
|
|
||||||
|
Optional<SamplingRate> samplingRateOpt = samplingRateService.updateSamplingRate(id, newValue);
|
||||||
|
|
||||||
|
if(samplingRateOpt.isEmpty()){
|
||||||
|
logger.warn("SamplingRate not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("SamplingRate not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
SamplingRateMessages.SamplingRate samplingRateProto = SamplingRateMapper.toProtobuf(samplingRateOpt.get());
|
||||||
|
|
||||||
|
SamplingRateMessages.UpdateSamplingRateResponse updateResponse = SamplingRateMessages.UpdateSamplingRateResponse.newBuilder()
|
||||||
|
.setSamplingrate(samplingRateProto)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(updateResponse.toByteString());
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e){
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error updating sampling rate", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.mediamanager.service.disc;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Album;
|
||||||
|
import com.mediamanager.model.Disc;
|
||||||
|
import com.mediamanager.repository.AlbumRepository;
|
||||||
|
import com.mediamanager.repository.DiscRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class DiscService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DiscService.class);
|
||||||
|
private final DiscRepository repository;
|
||||||
|
private final AlbumRepository albumRepository;
|
||||||
|
|
||||||
|
public DiscService(DiscRepository repository, AlbumRepository albumRepository) {
|
||||||
|
this.repository = repository;
|
||||||
|
this.albumRepository = albumRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Disc createDisc(Integer discNumber, Integer albumId) {
|
||||||
|
logger.debug("Creating disc with number: {}", discNumber);
|
||||||
|
if (discNumber == null) {
|
||||||
|
throw new IllegalArgumentException("Disc number cannot be null");
|
||||||
|
}
|
||||||
|
if (albumId == null) {
|
||||||
|
throw new IllegalArgumentException("Album ID cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
Disc disc = new Disc();
|
||||||
|
disc.setDiscNumber(discNumber);
|
||||||
|
|
||||||
|
// Set Album (required)
|
||||||
|
Optional<Album> album = albumRepository.findById(albumId);
|
||||||
|
if (album.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Album not found with id: " + albumId);
|
||||||
|
}
|
||||||
|
disc.setAlbum(album.get());
|
||||||
|
|
||||||
|
return repository.save(disc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Disc> getAllDiscs() {
|
||||||
|
logger.info("Getting all discs");
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Disc> getDiscById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Getting disc by id: {}", id);
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Disc> updateDisc(Integer id, Integer discNumber, Integer albumId) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
if (discNumber == null) {
|
||||||
|
throw new IllegalArgumentException("Disc number cannot be null");
|
||||||
|
}
|
||||||
|
if (albumId == null) {
|
||||||
|
throw new IllegalArgumentException("Album ID cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Updating disc with id: {}", id);
|
||||||
|
|
||||||
|
Optional<Disc> existingDisc = repository.findById(id);
|
||||||
|
if (existingDisc.isEmpty()) {
|
||||||
|
logger.warn("Disc not found with id: {}", id);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Disc disc = existingDisc.get();
|
||||||
|
disc.setDiscNumber(discNumber);
|
||||||
|
|
||||||
|
// Update Album
|
||||||
|
Optional<Album> album = albumRepository.findById(albumId);
|
||||||
|
if (album.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Album not found with id: " + albumId);
|
||||||
|
}
|
||||||
|
disc.setAlbum(album.get());
|
||||||
|
|
||||||
|
Disc updatedDisc = repository.update(disc);
|
||||||
|
return Optional.of(updatedDisc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteDisc(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("Disc id cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Deleting disc: {}", id);
|
||||||
|
return repository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.mediamanager.service.samplingrate;
|
||||||
|
|
||||||
|
import com.mediamanager.model.SamplingRate;
|
||||||
|
import com.mediamanager.repository.SamplingRateRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SamplingRateService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(SamplingRateService.class);
|
||||||
|
private final SamplingRateRepository repository;
|
||||||
|
|
||||||
|
public SamplingRateService(SamplingRateRepository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SamplingRate createSamplingRate(String value) {
|
||||||
|
logger.debug("Creating sampling rate:{}", value);
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
|
||||||
|
}
|
||||||
|
SamplingRate samplingRate = new SamplingRate();
|
||||||
|
samplingRate.setValue(value);
|
||||||
|
return repository.save(samplingRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SamplingRate> getAllSamplingRates() {
|
||||||
|
logger.info("Getting all sampling rates");
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<SamplingRate> getSamplingRateById(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Getting sampling rate by id:{}", id);
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<SamplingRate> updateSamplingRate(Integer id, String value) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("ID cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Updating sampling rate:{}", value);
|
||||||
|
if (value == null || value.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty");
|
||||||
|
}
|
||||||
|
Optional<SamplingRate> existingSamplingRate = repository.findById(id);
|
||||||
|
if(existingSamplingRate.isEmpty()) {
|
||||||
|
logger.warn("Sampling rate not found with id:{}", id);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
SamplingRate samplingRate = existingSamplingRate.get();
|
||||||
|
samplingRate.setValue(value);
|
||||||
|
SamplingRate updatedSamplingRate = repository.update(samplingRate);
|
||||||
|
return Optional.of(updatedSamplingRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteSamplingRate(Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new IllegalArgumentException("Sampling rate id cannot be null");
|
||||||
|
}
|
||||||
|
logger.info("Deleting sampling rate:{}", id);
|
||||||
|
return repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
import "google/protobuf/wrappers.proto"; // ← Adicione esse import!
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "AlbumMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message Album {
|
||||||
|
int32 id = 1;
|
||||||
|
string name = 2;
|
||||||
|
int32 year = 3;
|
||||||
|
int32 number_of_discs = 4;
|
||||||
|
string code = 5;
|
||||||
|
bool is_compilation = 6;
|
||||||
|
|
||||||
|
int32 fk_albumtype_id = 7;
|
||||||
|
int32 fk_albumart_id = 8;
|
||||||
|
|
||||||
|
int64 created_at = 9;
|
||||||
|
int64 updated_at = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateAlbumRequest {
|
||||||
|
string name = 1;
|
||||||
|
int32 year = 2;
|
||||||
|
int32 number_of_discs = 3;
|
||||||
|
string code = 4;
|
||||||
|
bool is_compilation = 5;
|
||||||
|
int32 fk_albumtype_id = 6;
|
||||||
|
int32 fk_albumart_id = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateAlbumResponse {
|
||||||
|
Album album = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumsRequest {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumsResponse {
|
||||||
|
repeated Album albums = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumByIdRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumByIdResponse {
|
||||||
|
Album album = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateAlbumRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
string name = 2;
|
||||||
|
google.protobuf.Int32Value year = 3; // ← Mudou!
|
||||||
|
google.protobuf.Int32Value number_of_discs = 4; // ← Mudou!
|
||||||
|
string code = 5;
|
||||||
|
bool is_compilation = 6;
|
||||||
|
google.protobuf.Int32Value fk_albumtype_id = 7; // ← Mudou!
|
||||||
|
google.protobuf.Int32Value fk_albumart_id = 8; // ← Mudou!
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateAlbumResponse {
|
||||||
|
Album album = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAlbumRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAlbumResponse {
|
||||||
|
bool success = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
@@ -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,46 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "AlbumHasArtistMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message AlbumHasArtist {
|
||||||
|
int32 id = 1;
|
||||||
|
int32 fk_album_id = 2;
|
||||||
|
int32 fk_artist_id = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateAlbumHasArtistRequest {
|
||||||
|
int32 fk_album_id = 1;
|
||||||
|
int32 fk_artist_id = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateAlbumHasArtistResponse {
|
||||||
|
AlbumHasArtist albumhasartist = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasArtistsRequest {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasArtistsResponse {
|
||||||
|
repeated AlbumHasArtist albumhasartist = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasArtistByIdRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasArtistByIdResponse {
|
||||||
|
AlbumHasArtist albumhasartist = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAlbumHasArtistRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAlbumHasArtistResponse {
|
||||||
|
bool success = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "AlbumHasGenreMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message AlbumHasGenre {
|
||||||
|
int32 id = 1;
|
||||||
|
int32 fk_album_id = 2;
|
||||||
|
int32 fk_genre_id = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateAlbumHasGenreRequest {
|
||||||
|
int32 fk_album_id = 1;
|
||||||
|
int32 fk_genre_id = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateAlbumHasGenreResponse {
|
||||||
|
AlbumHasGenre albumhasgenre = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasGenresRequest {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasGenresResponse {
|
||||||
|
repeated AlbumHasGenre albumhasgenre = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasGenreByIdRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetAlbumHasGenreByIdResponse {
|
||||||
|
AlbumHasGenre albumhasgenre = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAlbumHasGenreRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteAlbumHasGenreResponse {
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ message UpdateArtistRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message UpdateArtistResponse {
|
message UpdateArtistResponse {
|
||||||
Artist Artist = 1;
|
Artist artist = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteArtistRequest {
|
message DeleteArtistRequest {
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "BitRateMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message BitRate{
|
||||||
|
int32 id =1;
|
||||||
|
string value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateBitRateRequest{
|
||||||
|
string value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateBitRateResponse{
|
||||||
|
BitRate bitrate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetBitRatesRequest{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetBitRatesResponse{
|
||||||
|
repeated BitRate bitrates = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetBitRateByIdRequest{
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetBitRateByIdResponse{
|
||||||
|
BitRate bitrate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateBitRateRequest{
|
||||||
|
int32 id = 1;
|
||||||
|
string value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateBitRateResponse{
|
||||||
|
BitRate bitrate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteBitRateRequest{
|
||||||
|
int32 id =1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteBitRateResponse{
|
||||||
|
bool success = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "DiscMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message Disc{
|
||||||
|
int32 id = 1;
|
||||||
|
int32 disc_number = 2;
|
||||||
|
int32 fk_album_id = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateDiscRequest {
|
||||||
|
int32 disc_number = 1;
|
||||||
|
int32 fk_album_id = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateDiscResponse {
|
||||||
|
Disc disc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetDiscsRequest {
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetDiscsResponse {
|
||||||
|
repeated Disc discs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetDiscByIdRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetDiscByIdResponse {
|
||||||
|
Disc disc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateDiscRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
int32 disc_number = 2;
|
||||||
|
int32 fk_album_id = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateDiscResponse {
|
||||||
|
Disc disc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteDiscRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteDiscResponse {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "SamplingRateMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message SamplingRate{
|
||||||
|
int32 id=1;
|
||||||
|
string value=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateSamplingRateRequest{
|
||||||
|
string value= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateSamplingRateResponse{
|
||||||
|
SamplingRate samplingrate =1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSamplingRatesRequest{}
|
||||||
|
|
||||||
|
message GetSamplingRatesResponse{
|
||||||
|
repeated SamplingRate samplingrates = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSamplingRateByIdRequest{
|
||||||
|
int32 id =1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSamplingRateByIdResponse{
|
||||||
|
SamplingRate samplingrate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateSamplingRateRequest{
|
||||||
|
int32 id = 1;
|
||||||
|
string value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateSamplingRateResponse{
|
||||||
|
SamplingRate samplingrate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteSamplingRateRequest{
|
||||||
|
int32 id =1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteSamplingRateResponse{
|
||||||
|
bool success = 1;
|
||||||
|
string message =2;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user