35 lines
1.3 KiB
Java
35 lines
1.3 KiB
Java
package com.backend.unifier.title.service;
|
|
|
|
import java.util.Optional;
|
|
import java.util.UUID;
|
|
|
|
import com.backend.unifier.title.model.ContentDetailEntry;
|
|
import com.backend.unifier.title.model.ContentIdentifier;
|
|
import com.backend.unifier.title.model.ContentProviderSource;
|
|
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
import jakarta.enterprise.inject.Instance;
|
|
|
|
@ApplicationScoped
|
|
public class GeneralDetailService {
|
|
private final IdentifierMaskService maskService;
|
|
private final Instance<DetailService> detailServices;
|
|
|
|
public GeneralDetailService(IdentifierMaskService maskService, Instance<DetailService> detailServices) {
|
|
this.maskService = maskService;
|
|
this.detailServices = detailServices;
|
|
}
|
|
|
|
public Optional<ContentDetailEntry> details(UUID id) {
|
|
ContentIdentifier realIdentifier = maskService.realIdentifier(id);
|
|
if (realIdentifier == null)
|
|
throw new IllegalStateException("content identifier not found for id '" + id + "'");
|
|
ContentProviderSource source = ContentProviderSource.valueOf(realIdentifier.source());
|
|
for (DetailService detailService : detailServices) {
|
|
if (detailService.source() == source)
|
|
return detailService.details(realIdentifier.id());
|
|
}
|
|
return Optional.empty();
|
|
}
|
|
}
|