a2a3be0529
- Fix Quarkus BOM groupId (io.quarkus:quarkus-bom) and version (3.37.1)
- Fix artifact names: quarkus-resteasy, quarkus-resteasy-qute, quarkus-resteasy-client
- Add UserAgentFilter for MusicBrainz API compliance
- Fix @RestClient qualifier on MB client injection points
- Fix Qute template section names: {#insert}{/insert}, {#else} not {:else}
- Fix template injection with @Location annotation
- Remove unused imports
- Fix RSS feed builder to use Synd API
114 lines
3.7 KiB
Java
114 lines
3.7 KiB
Java
package com.discdrop.service;
|
|
|
|
import com.discdrop.client.MusicBrainzClient;
|
|
import com.discdrop.client.dto.ArtistDetailsResponse;
|
|
import com.discdrop.client.dto.ArtistSearchResponse;
|
|
import com.discdrop.db.DatabaseService;
|
|
import com.discdrop.db.Record.MonitoringFlags;
|
|
import com.discdrop.db.Record.TrackedArtist;
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
import jakarta.inject.Inject;
|
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
@ApplicationScoped
|
|
public class ArtistService {
|
|
|
|
@Inject
|
|
@RestClient
|
|
MusicBrainzClient mbClient;
|
|
|
|
@Inject
|
|
DatabaseService db;
|
|
|
|
public record SearchResult(String mbid, String name, String disambiguation,
|
|
String area, String type, String country,
|
|
boolean alreadyTracked) {}
|
|
|
|
public List<SearchResult> search(String query) {
|
|
var resp = mbClient.searchArtists(
|
|
"artist:" + query, 10, "json");
|
|
if (resp == null || resp.artists() == null) return List.of();
|
|
|
|
var results = new ArrayList<SearchResult>();
|
|
for (var a : resp.artists()) {
|
|
results.add(new SearchResult(
|
|
a.id(),
|
|
a.name(),
|
|
a.disambiguation() != null ? a.disambiguation() : "",
|
|
a.area() != null ? a.area().name() : (a.country() != null ? a.country() : ""),
|
|
a.type() != null ? a.type() : "",
|
|
a.country() != null ? a.country() : "",
|
|
db.exists(a.id())
|
|
));
|
|
}
|
|
return results;
|
|
}
|
|
|
|
public Optional<TrackedArtist> findByMbid(String mbid) {
|
|
return db.findByMbid(mbid);
|
|
}
|
|
|
|
public List<TrackedArtist> findAll() {
|
|
return db.findAllArtists();
|
|
}
|
|
|
|
public TrackedArtist addArtist(String mbid) {
|
|
ArtistDetailsResponse details = mbClient.getArtistDetails(mbid, "url-rels", "json");
|
|
if (details == null) {
|
|
throw new RuntimeException("Artist not found: " + mbid);
|
|
}
|
|
|
|
var defaultTypes = db.getSetting("default_types", "Album");
|
|
var flags = parseDefaultTypes(defaultTypes);
|
|
|
|
var artist = new TrackedArtist(
|
|
details.id(),
|
|
details.name(),
|
|
details.disambiguation() != null ? details.disambiguation() : "",
|
|
details.area() != null ? details.area().name() : "",
|
|
flags.album(),
|
|
flags.single(),
|
|
flags.ep(),
|
|
flags.broadcast(),
|
|
flags.other(),
|
|
Instant.now(),
|
|
Instant.now()
|
|
);
|
|
|
|
db.insertArtist(artist);
|
|
return artist;
|
|
}
|
|
|
|
public void removeArtist(String mbid) {
|
|
db.deleteReleaseGroupsForArtist(mbid);
|
|
db.deleteArtist(mbid);
|
|
}
|
|
|
|
public void updateMonitoring(String mbid, MonitoringFlags flags) {
|
|
db.updateMonitoring(mbid, flags);
|
|
}
|
|
|
|
private MonitoringFlags parseDefaultTypes(String types) {
|
|
boolean album = false, single = false, ep = false,
|
|
broadcast = false, other = false;
|
|
if (types == null || types.isBlank()) {
|
|
album = true;
|
|
return new MonitoringFlags(album, single, ep, broadcast, other);
|
|
}
|
|
for (var t : types.split(",")) {
|
|
switch (t.trim().toLowerCase()) {
|
|
case "album" -> album = true;
|
|
case "single" -> single = true;
|
|
case "ep" -> ep = true;
|
|
case "broadcast" -> broadcast = true;
|
|
case "other" -> other = true;
|
|
}
|
|
}
|
|
return new MonitoringFlags(album, single, ep, broadcast, other);
|
|
}
|
|
}
|