Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dmp
OpenAIRE-EUDAT-DMP-service-pilot
Commits
fc7c3908
Commit
fc7c3908
authored
Sep 28, 2021
by
George Kalampokis
Browse files
Improve configuration loader
parent
99e4d231
Changes
2
Hide whitespace changes
Inline
Side-by-side
dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/configloaders/De
vel
ConfigLoader.java
→
dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/configloaders/De
fault
ConfigLoader.java
View file @
fc7c3908
...
...
@@ -8,7 +8,6 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Profile
;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Service
;
import
org.w3c.dom.Document
;
...
...
@@ -26,16 +25,13 @@ import javax.xml.xpath.XPathConstants;
import
javax.xml.xpath.XPathExpressionException
;
import
javax.xml.xpath.XPathFactory
;
import
java.io.*
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
(
"configLoader"
)
@Profile
(
"devel"
)
public
class
De
vel
ConfigLoader
implements
ConfigLoader
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
De
vel
ConfigLoader
.
class
);
//
@Profile("devel")
public
class
De
fault
ConfigLoader
implements
ConfigLoader
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
De
fault
ConfigLoader
.
class
);
private
ExternalUrls
externalUrls
;
private
List
<
String
>
rdaProperties
;
...
...
@@ -53,10 +49,10 @@ public class DevelConfigLoader implements ConfigLoader {
try
{
JAXBContext
jaxbContext
=
JAXBContext
.
newInstance
(
ExternalUrls
.
class
);
Unmarshaller
jaxbUnmarshaller
=
jaxbContext
.
createUnmarshaller
();
is
=
get
Class
().
getClassLoader
().
getResource
(
fileUrl
).
openStream
(
);
is
=
get
StreamFromPath
(
fileUrl
);
externalUrls
=
(
ExternalUrls
)
jaxbUnmarshaller
.
unmarshal
(
is
);
}
catch
(
Exception
ex
)
{
logger
.
error
(
"Cannot find resource
in classpath
"
,
ex
);
logger
.
error
(
"Cannot find resource"
,
ex
);
}
finally
{
try
{
if
(
is
!=
null
)
is
.
close
();
...
...
@@ -89,7 +85,7 @@ public class DevelConfigLoader implements ConfigLoader {
String
filePath
=
environment
.
getProperty
(
"configuration.h2020template"
);
InputStream
is
=
null
;
try
{
is
=
get
Class
().
getClassLoader
().
getResource
(
filePath
).
openStream
(
);
is
=
get
StreamFromPath
(
filePath
);
this
.
document
=
new
XWPFDocument
(
is
);
}
catch
(
IOException
|
NullPointerException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
...
...
@@ -106,7 +102,7 @@ public class DevelConfigLoader implements ConfigLoader {
String
filePath
=
environment
.
getProperty
(
"configuration.configurable_login_providers"
);
InputStream
is
=
null
;
try
{
is
=
get
Class
().
getClassLoader
().
getResource
(
filePath
).
openStream
(
);
is
=
get
StreamFromPath
(
filePath
);
ObjectMapper
mapper
=
new
ObjectMapper
().
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
this
.
configurableProviders
=
mapper
.
readValue
(
is
,
ConfigurableProviders
.
class
);
}
catch
(
IOException
|
NullPointerException
e
)
{
...
...
@@ -145,12 +141,34 @@ public class DevelConfigLoader implements ConfigLoader {
public
ExternalUrls
getExternalUrls
()
{
this
.
setExternalUrls
();
if
(
externalUrls
==
null
)
{
externalUrls
=
new
ExternalUrls
();
this
.
setExternalUrls
();
}
else
{
while
(
externalUrls
.
getMaxresults
()
==
null
)
{
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
return
externalUrls
;
}
public
List
<
String
>
getRdaProperties
()
{
this
.
setRdaProperties
();
if
(
rdaProperties
==
null
)
{
rdaProperties
=
new
ArrayList
<>();
this
.
setRdaProperties
();
}
else
{
while
(
rdaProperties
.
size
()
==
0
)
{
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
return
rdaProperties
;
}
...
...
@@ -160,11 +178,34 @@ public class DevelConfigLoader implements ConfigLoader {
}
public
ConfigurableProviders
getConfigurableProviders
()
{
this
.
setConfigurableProviders
();
if
(
configurableProviders
==
null
)
{
configurableProviders
=
new
ConfigurableProviders
();
this
.
setConfigurableProviders
();
}
else
{
while
(
configurableProviders
.
getProviders
().
size
()
==
0
)
{
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
return
configurableProviders
;
}
public
Map
<
String
,
String
>
getKeyToSourceMap
()
{
if
(
keyToSourceMap
==
null
)
{
keyToSourceMap
=
new
HashMap
<>();
this
.
setKeyToSourceMap
();
}
else
{
while
(
keyToSourceMap
.
size
()
==
0
)
{
try
{
Thread
.
sleep
(
100L
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
this
.
setKeyToSourceMap
();
return
keyToSourceMap
;
}
...
...
@@ -173,7 +214,7 @@ public class DevelConfigLoader implements ConfigLoader {
InputStream
is
=
null
;
Document
doc
;
try
{
is
=
get
Class
().
getClassLoader
().
getResource
(
filePath
).
openStream
(
);
is
=
get
StreamFromPath
(
filePath
);
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
doc
=
documentBuilder
.
parse
(
is
);
...
...
@@ -211,4 +252,13 @@ public class DevelConfigLoader implements ConfigLoader {
}
return
values
;
}
private
InputStream
getStreamFromPath
(
String
filePath
)
{
try
{
return
new
FileInputStream
(
filePath
);
}
catch
(
FileNotFoundException
e
)
{
logger
.
info
(
"loading from classpath"
);
return
getClass
().
getClassLoader
().
getResourceAsStream
(
filePath
);
}
}
}
dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/configloaders/ProductionConfigLoader.java
View file @
fc7c3908
...
...
@@ -33,6 +33,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/*
@Service("configLoader")
@Profile({ "production", "staging" })
public class ProductionConfigLoader implements ConfigLoader {
...
...
@@ -236,4 +237,4 @@ public class ProductionConfigLoader implements ConfigLoader {
}
return values;
}
}
\ No newline at end of file
}*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment