adding test mode
This commit is contained in:
parent
896055015a
commit
f0223ed727
2
pom.xml
2
pom.xml
|
@ -28,7 +28,7 @@
|
|||
<dependency>
|
||||
<groupId>tv.mangrana</groupId>
|
||||
<artifactId>mangrana-commons</artifactId>
|
||||
<version>7.1.3</version>
|
||||
<version>7.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- needed for runtime -->
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package tv.mangrana.config;
|
||||
|
||||
import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
||||
|
||||
public class ConfigFileLoader extends CommonConfigFileLoader<ConfigFileLoader.ProjectConfiguration> {
|
||||
|
||||
private static final String CONFIG_FILE = "SonarrFixerConfig.yml";
|
||||
private static ConfigFileLoader service;
|
||||
|
||||
private ConfigFileLoader() throws IncorrectWorkingReferencesException {
|
||||
super(ProjectConfiguration.class);
|
||||
}
|
||||
|
||||
public static ConfigFileLoader getLoader() throws IncorrectWorkingReferencesException {
|
||||
if (service==null)
|
||||
service = new ConfigFileLoader();
|
||||
return service;
|
||||
}
|
||||
|
||||
public enum ProjectConfiguration {
|
||||
UPLOADS_PATHS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigFileName() {
|
||||
return CONFIG_FILE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package tv.mangrana.config;
|
||||
|
||||
import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
||||
|
||||
public class ConfigLoader extends CommonConfigFileLoader<ConfigLoader.ProjectConfiguration> {
|
||||
|
||||
private static final String CONFIG_FILE = "SonarrFixerConfig.yml";
|
||||
private static ConfigLoader service;
|
||||
|
||||
private ConfigLoader() throws IncorrectWorkingReferencesException {
|
||||
super(ProjectConfiguration.class);
|
||||
}
|
||||
|
||||
public static ConfigLoader getLoader() throws IncorrectWorkingReferencesException {
|
||||
if (service==null)
|
||||
service = new ConfigLoader();
|
||||
return service;
|
||||
}
|
||||
|
||||
public static String get(ProjectConfiguration configParam) throws IncorrectWorkingReferencesException {
|
||||
return getLoader().getConfig(configParam);
|
||||
}
|
||||
|
||||
public static boolean isDisabled(ProjectConfiguration configParam) {
|
||||
return !"true".equals(get(configParam));
|
||||
}
|
||||
|
||||
public enum ProjectConfiguration {
|
||||
UPLOADS_PATHS,
|
||||
TEST_MODE
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigFileName() {
|
||||
return CONFIG_FILE;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
package tv.mangrana.sonarr;
|
||||
|
||||
import tv.mangrana.config.ConfigFileLoader;
|
||||
import tv.mangrana.config.ConfigLoader;
|
||||
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
|
||||
|
||||
public class Sonarr {
|
||||
private static SonarrApiGateway service;
|
||||
|
||||
public static void initService(ConfigFileLoader configFileLoader) {
|
||||
service = new SonarrApiGateway(configFileLoader);
|
||||
public static void initService(ConfigLoader configLoader) {
|
||||
service = new SonarrApiGateway(configLoader);
|
||||
}
|
||||
|
||||
public static SonarrApiGateway api() {
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
package tv.mangrana.worker;
|
||||
|
||||
import tv.mangrana.config.ConfigLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static tv.mangrana.config.ConfigFileLoader.ProjectConfiguration.UPLOADS_PATHS;
|
||||
import static tv.mangrana.config.ConfigLoader.ProjectConfiguration.TEST_MODE;
|
||||
import static tv.mangrana.config.ConfigLoader.ProjectConfiguration.UPLOADS_PATHS;
|
||||
|
||||
class FileCopier {
|
||||
void hardLink(Path source, Path destination) {
|
||||
try {
|
||||
createDestinationFolderIfApply(destination);
|
||||
Files.createLink(destination, source);
|
||||
|
||||
if (ConfigLoader.isDisabled(TEST_MODE))
|
||||
Files.createLink(destination, source);
|
||||
} catch (IOException e) {
|
||||
System.out.printf("error when creating hardlink with destination %s, error: %s%n",
|
||||
destination, e.getMessage());
|
||||
|
@ -19,8 +24,11 @@ class FileCopier {
|
|||
}
|
||||
|
||||
private void createDestinationFolderIfApply(Path destination) throws IOException {
|
||||
if (isTemporaryDestination(destination) && !Files.exists(destination))
|
||||
Files.createDirectory(destination);
|
||||
if (isTemporaryDestination(destination) && !Files.exists(destination)) {
|
||||
System.out.printf("destination folder %s will be created", destination);
|
||||
if (ConfigLoader.isDisabled(TEST_MODE))
|
||||
Files.createDirectory(destination);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTemporaryDestination(Path destination) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package tv.mangrana.worker;
|
||||
|
||||
import tv.mangrana.config.ConfigFileLoader;
|
||||
import tv.mangrana.config.ConfigLoader;
|
||||
import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
||||
import tv.mangrana.sonarr.Sonarr;
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class MainWorker {
|
|||
}
|
||||
|
||||
private MainWorker() throws IncorrectWorkingReferencesException {
|
||||
var configLoader = ConfigFileLoader.getLoader();
|
||||
var configLoader = ConfigLoader.getLoader();
|
||||
Sonarr.initService(configLoader);
|
||||
queueFixer = new QueueFixer();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package tv.mangrana.worker;
|
||||
|
||||
import tv.mangrana.config.ConfigLoader;
|
||||
import tv.mangrana.sonarr.Sonarr;
|
||||
import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
|
||||
import tv.mangrana.sonarr.api.schema.queue.Record;
|
||||
|
@ -10,6 +11,8 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static tv.mangrana.config.ConfigLoader.ProjectConfiguration.TEST_MODE;
|
||||
|
||||
public class QueueFixer {
|
||||
final static String IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.";
|
||||
|
||||
|
@ -64,7 +67,8 @@ public class QueueFixer {
|
|||
private void cleanWorkedElementsFromQueue(List<Record> sonarQueue, List<Record> recordsToFix) {
|
||||
List<String> workedTitles = mapRecord2Title(recordsToFix);
|
||||
List<Integer> recordIds2Delete = filterPresentTitlesFromQueue(sonarQueue, workedTitles);
|
||||
sonarrApiGateway.deleteQueueElements(recordIds2Delete);
|
||||
if (ConfigLoader.isDisabled(TEST_MODE))
|
||||
sonarrApiGateway.deleteQueueElements(recordIds2Delete);
|
||||
}
|
||||
|
||||
private boolean recordsWithImportFailureBecauseIdMatching(Record record) {
|
||||
|
|
Loading…
Reference in New Issue