1
0
Fork 0

unify getConfig for both commons and project specific

This commit is contained in:
xeviff 2022-10-12 12:44:53 +02:00
parent 4c39ba3e77
commit bd2a013283
5 changed files with 18 additions and 23 deletions

View File

@ -27,7 +27,6 @@ public abstract class CommonConfigFileLoader<P extends Enum<P>> {
private final Class<P> projectConfigEnumType;
private EnumMap<P, String> configurationsMap;
public CommonConfigFileLoader(Class<P> projectConfigEnumType) throws IncorrectWorkingReferencesException {
this.projectConfigEnumType = projectConfigEnumType;
loadAllConfigFromFile(false);
@ -37,12 +36,8 @@ public abstract class CommonConfigFileLoader<P extends Enum<P>> {
}
private CommonConfigFileLoader<P> loadAllConfigFromFile(boolean silently) throws IncorrectWorkingReferencesException {
commonConfigurationsMap = new EnumMap<>(CommonProjectConfiguration.class);
commonConfigurationsMap.putAll( loadFromFile(CommonProjectConfiguration.class, silently) );
configurationsMap = new EnumMap<>(projectConfigEnumType);
configurationsMap.putAll( loadFromFile(projectConfigEnumType, silently) );
commonConfigurationsMap = loadFromFile(CommonProjectConfiguration.class, silently);
configurationsMap = loadFromFile(projectConfigEnumType, silently);
return this;
}
@ -56,7 +51,7 @@ public abstract class CommonConfigFileLoader<P extends Enum<P>> {
public String getConfig(P key) {
return configurationsMap.get(key);
}
public String getCommonConfig(CommonProjectConfiguration key) {
public String getConfig(CommonProjectConfiguration key) {
return commonConfigurationsMap.get(key);
}

View File

@ -50,11 +50,11 @@ public class PlexCommandLauncher {
HttpUriRequest httpGET = RequestBuilder.get()
.setUri(new URI(plexRefreshURL))
.addParameter("path", plexPathToRefresh)
.addParameter("X-Plex-Token", config.getCommonConfig(PLEX_TOKEN))
.addParameter("X-Plex-Token", config.getConfig(PLEX_TOKEN))
.build();
httpclient.execute(httpGET);
@SuppressWarnings("unused")
String urlWithTokenHidden = httpGET.getURI().toString().replaceFirst(config.getCommonConfig(PLEX_TOKEN), "__plex_token__");
String urlWithTokenHidden = httpGET.getURI().toString().replaceFirst(config.getConfig(PLEX_TOKEN), "__plex_token__");
logger.nLog("Launched URL command: {0}", httpGET.getURI().toString());
} catch (Exception e) {
logger.nHLog("Some error has happened using the URL <{0}>", plexRefreshURL);
@ -63,10 +63,10 @@ public class PlexCommandLauncher {
}
public String getPlexUrlPath2Refresh(String fullDestinationPath) {
Pattern p = Pattern.compile(config.getCommonConfig(SONARR_PATHS_STARTER).concat("(.+/.+ \\(\\d{4}\\))"));
Pattern p = Pattern.compile(config.getConfig(SONARR_PATHS_STARTER).concat("(.+/.+ \\(\\d{4}\\))"));
Matcher m = p.matcher(fullDestinationPath);
if (m.find()) {
String pathInPlexDockerStart = config.getCommonConfig(PLEX_SERIES_PATHS_STARTER);
String pathInPlexDockerStart = config.getConfig(PLEX_SERIES_PATHS_STARTER);
return pathInPlexDockerStart.concat(m.group(1));
}
return null;
@ -76,7 +76,7 @@ public class PlexCommandLauncher {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpUriRequest httpGET = RequestBuilder.get()
.setUri(new URI(getPlexSectionsURL()))
.addParameter("X-Plex-Token", config.getCommonConfig(PLEX_TOKEN))
.addParameter("X-Plex-Token", config.getConfig(PLEX_TOKEN))
.build();
try (CloseableHttpResponse httpResponse = httpclient.execute(httpGET)) {
final HttpEntity entity = httpResponse.getEntity();
@ -90,7 +90,7 @@ public class PlexCommandLauncher {
}
}
}
log("launched url command: "+httpGET.getURI().toString().replaceFirst(config.getCommonConfig(PLEX_TOKEN), "__plex_token__"));
log("launched url command: "+httpGET.getURI().toString().replaceFirst(config.getConfig(PLEX_TOKEN), "__plex_token__"));
} catch (URISyntaxException | IOException e) {
log("could not refresh plex artist because of "+e.getMessage());
e.printStackTrace();
@ -101,15 +101,15 @@ public class PlexCommandLauncher {
private String getPlexRefreshURL(String fullDestinationPath) {
String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath);
if (sectionId==null) return null;
String host = config.getCommonConfig(PLEX_HOST);
String uriFormat = config.getCommonConfig(PLEX_SECTION_REFRESH_URI);
String host = config.getConfig(PLEX_HOST);
String uriFormat = config.getConfig(PLEX_SECTION_REFRESH_URI);
String uri = uriFormat.replaceFirst("\\{section_id}", sectionId);
return HTTPS.getMark() + host + uri;
}
private String getPlexSectionsURL() {
String host = HTTPS.getMark() + config.getCommonConfig(PLEX_HOST);
String uri = config.getCommonConfig(PLEX_SECTIONS_LIST_URI);
String host = HTTPS.getMark() + config.getConfig(PLEX_HOST);
String uri = config.getConfig(PLEX_SECTIONS_LIST_URI);
return host + uri;
}

View File

@ -26,7 +26,7 @@ public class PlexLibrarySectionsResolver {
}
public String resolveSectionByPath(String fullDestinationPath) {
final String plexPathStarter = config.getCommonConfig(PLEX_SERIES_PATHS_STARTER);
final String plexPathStarter = config.getConfig(PLEX_SERIES_PATHS_STARTER);
String keyFolder = fullDestinationPath.replaceFirst(plexPathStarter,"").split("/")[1];
Document xmlDocument = commandLauncher.retrieveSectionsInfo();
XPath xPath = XPathFactory.newInstance().newXPath();

View File

@ -16,8 +16,8 @@ public class RadarrApiGateway {
private final RadarrAPIInterface proxy;
public RadarrApiGateway(CommonConfigFileLoader<?> config) {
apiKey = config.getCommonConfig(RADARR_API_KEY);
proxy = APIProxyBuilderSingleton.getRadarrInterface(config.getCommonConfig(RADARR_API_HOST));
apiKey = config.getConfig(RADARR_API_KEY);
proxy = APIProxyBuilderSingleton.getRadarrInterface(config.getConfig(RADARR_API_HOST));
}
public QueueResourcePagingResource getQueue() {

View File

@ -19,8 +19,8 @@ public class SonarrApiGateway {
private final EasyLogger logger;
public SonarrApiGateway(CommonConfigFileLoader<?> config) {
apiKey = config.getCommonConfig(SONARR_API_KEY);
proxy = APIProxyBuilderSingleton.getSonarrInterface(config.getCommonConfig(SONARR_API_HOST));
apiKey = config.getConfig(SONARR_API_KEY);
proxy = APIProxyBuilderSingleton.getSonarrInterface(config.getConfig(SONARR_API_HOST));
logger = new EasyLogger();
}