Load various resources from classpath instead of an actual path on Stagging and Production

This commit is contained in:
George Kalampokis 2020-06-16 11:19:27 +03:00
parent a8015064a8
commit ddd0b60d37
3 changed files with 43 additions and 24 deletions

View File

@ -74,17 +74,26 @@ public class ProductionConfigLoader implements ConfigLoader {
String filePath = environment.getProperty("configuration.rda");
BufferedReader reader;
List<String> rdaList = new LinkedList<>();
for (int i = 0; i < 2; i++) {
try {
if (i == 0) {
reader = new BufferedReader(new FileReader(filePath));
} else {
reader = new BufferedReader(new FileReader(getClass().getClassLoader().getResource(filePath).getFile()));
}
String line = reader.readLine();
while (line != null) {
rdaList.add(line);
line = reader.readLine();
}
reader.close();
break;
} catch (IOException e) {
if (i == 1) {
logger.error(e.getMessage(), e);
}
}
}
rdaProperties = rdaList;
}
@ -92,9 +101,17 @@ public class ProductionConfigLoader implements ConfigLoader {
private void setDocument() {
String filePath = environment.getProperty("configuration.h2020template");
InputStream is = null;
for (int i = 0; i < 2; i++) {
try {
if (i == 0) {
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
} else {
is = getClass().getClassLoader().getResource(filePath).openStream();
}
this.document = new XWPFDocument(is);
is.close();
is = null;
break;
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
@ -105,6 +122,7 @@ public class ProductionConfigLoader implements ConfigLoader {
}
}
}
}
private void setConfigurableProviders() {
String filePath = environment.getProperty("configuration.configurable_login_providers");
@ -113,11 +131,11 @@ public class ProductionConfigLoader implements ConfigLoader {
File tempFile = new File(filePath);
if (tempFile.exists()) {
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
} else {
is = getClass().getClassLoader().getResource(filePath).openStream();
}
ObjectMapper objectMapper = new ObjectMapper();
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class);
} else {
this.configurableProviders = new ConfigurableProviders();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
@ -179,6 +197,7 @@ public class ProductionConfigLoader implements ConfigLoader {
InputStream is = null;
Document doc;
try {
System.out.println(filePath);
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

View File

@ -16,9 +16,9 @@ pdf.converter.url=http://docsbox-web/
####################CONFIGURATION FILES OVERRIDES CONFIGURATIONS##########
configuration.externalUrls=externalUrls/ExternalUrls.xml
configuration.rda=/tmp/RDACommonStandards.txt
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.configurable_login_providers=/tmp/ConfigurableLoginProviders.json
configuration.configurable_login_providers=ConfigurableLoginProviders.json
####################SPRING MAIL CONFIGURATIONS#################
spring.mail.default-encoding=UTF-8

View File

@ -16,9 +16,9 @@ pdf.converter.url=http://docsbox-web/
####################CONFIGURATION FILES OVERRIDES CONFIGURATIONS##########
configuration.externalUrls=externalUrls/ExternalUrls.xml
configuration.rda=/tmp/RDACommonStandards.txt
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.configurable_login_providers=/tmp/ConfigurableLoginProviders.json
configuration.configurable_login_providers=ConfigurableLoginProviders.json
####################INVITATION MAIL CONFIGURATIONS##############
####################GENERIC MAIL CONFIGURATIONS#################