Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 486b296

Browse files
committed
Added unset-methods to the Requirements-API. ConfigurationService ignores unset requirements now.
1 parent 0e3f9b4 commit 486b296

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/main/scala/org/codeoverflow/chatoverflow/configuration/ConfigurationService.scala

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
7373
}
7474
}
7575

76+
/**
77+
* Loads the config xml file and return its content.
78+
*/
79+
private def loadXML(): Node = {
80+
if (!new File(configFilePath).exists()) {
81+
logger debug s"Config file '$configFilePath' not found. Initialising with default values."
82+
saveXML(defaultContent)
83+
}
84+
85+
val xmlContent = xml.Utility.trim(xml.XML.loadFile(configFilePath))
86+
logger info "Loaded config file."
87+
xmlContent
88+
}
89+
7690
/**
7791
* Load all connector instances from the config xml and save them to the connector registry.
7892
*
@@ -103,20 +117,6 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
103117
}
104118
}
105119

106-
/**
107-
* Loads the config xml file and return its content.
108-
*/
109-
private def loadXML(): Node = {
110-
if (!new File(configFilePath).exists()) {
111-
logger debug s"Config file '$configFilePath' not found. Initialising with default values."
112-
saveXML(defaultContent)
113-
}
114-
115-
val xmlContent = xml.Utility.trim(xml.XML.loadFile(configFilePath))
116-
logger info "Loaded config file."
117-
xmlContent
118-
}
119-
120120
/**
121121
* Saves all connector and plugin instances.
122122
*
@@ -154,7 +154,7 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
154154
private def saveXML(xmlContent: Node): Unit = {
155155
// Create config folder, if not existent
156156
val dir = new File(configFilePath).getParentFile
157-
if(!dir.exists()) {
157+
if (!dir.exists()) {
158158
dir.mkdir()
159159
}
160160

@@ -195,7 +195,10 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
195195
val requirementMap = requirements.getRequirementMap
196196
val keys = requirementMap.keySet().toArray
197197

198-
for (key <- keys) yield {
198+
for {
199+
key <- keys
200+
if requirementMap.get(key).isSet
201+
} yield {
199202
<requirement>
200203
<uniqueRequirementId>
201204
{key}
@@ -204,7 +207,7 @@ class ConfigurationService(val configFilePath: String) extends WithLogger {
204207
{requirementMap.get(key).getTargetType.getName}
205208
</targetType>
206209
<content>
207-
{if (requirementMap.get(key).isSet) requirementMap.get(key).get().serialize()}
210+
{requirementMap.get(key).get().serialize()}
208211
</content>
209212
</requirement>
210213
}

0 commit comments

Comments
 (0)