introduce queue fixer for all elements
This commit is contained in:
parent
8092b94b49
commit
a36e09ec98
2
pom.xml
2
pom.xml
|
@ -28,7 +28,7 @@
|
|||
<dependency>
|
||||
<groupId>tv.mangrana</groupId>
|
||||
<artifactId>mangrana-commons</artifactId>
|
||||
<version>6.0.0</version>
|
||||
<version>7.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- needed for runtime -->
|
||||
|
|
|
@ -2,19 +2,22 @@ package tv.mangrana.worker;
|
|||
|
||||
import tv.mangrana.config.ConfigFileLoader;
|
||||
import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
||||
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
|
||||
|
||||
public class MainWorker {
|
||||
private final SonarrApiGateway sonarrApiGateway;
|
||||
|
||||
private final QueueFixer queueFixer;
|
||||
|
||||
public MainWorker() throws IncorrectWorkingReferencesException {
|
||||
ConfigFileLoader configFileLoader = new ConfigFileLoader();
|
||||
sonarrApiGateway = new SonarrApiGateway(configFileLoader);
|
||||
queueFixer = new QueueFixer(configFileLoader);
|
||||
}
|
||||
|
||||
private void work() {
|
||||
queueFixer.fix();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IncorrectWorkingReferencesException {
|
||||
var worker = new MainWorker();
|
||||
var queue = worker.sonarrApiGateway.getQueue();
|
||||
System.out.println(queue);
|
||||
worker.work();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package tv.mangrana.worker;
|
||||
|
||||
import tv.mangrana.config.ConfigFileLoader;
|
||||
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
|
||||
import tv.mangrana.sonarr.api.schema.queue.Record;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QueueFixer {
|
||||
final static String ID_IMPORT_FAILURE = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.";
|
||||
private final SonarrApiGateway sonarrApiGateway;
|
||||
|
||||
QueueFixer(ConfigFileLoader configFileLoader) {
|
||||
sonarrApiGateway = new SonarrApiGateway(configFileLoader);
|
||||
}
|
||||
|
||||
void fix() {
|
||||
var queue = sonarrApiGateway.getFullQueue();
|
||||
List<Record> recordsWithImportFailure = queue.getRecords().stream()
|
||||
.filter(this::recordsWithImportFailure)
|
||||
.collect(Collectors.toList());
|
||||
fixFailedImports(recordsWithImportFailure);
|
||||
}
|
||||
|
||||
private boolean recordsWithImportFailure(Record record) {
|
||||
return record.getStatusMessages().stream()
|
||||
.flatMap(status -> status.getMessages().stream())
|
||||
.anyMatch(ID_IMPORT_FAILURE::equals);
|
||||
}
|
||||
|
||||
private void fixFailedImports(List<Record> recordsWithImportFailure) {
|
||||
Map<String, Record> recordsByTitle = new HashMap<>();
|
||||
for (var record : recordsWithImportFailure)
|
||||
recordsByTitle.putIfAbsent(record.getTitle(), record);
|
||||
System.out.println(recordsByTitle.keySet());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue