@@ -3,6 +3,7 @@ package com.swisscom.health.des.cdr.client.config
33import com.fasterxml.jackson.annotation.JsonIgnore
44import com.fasterxml.jackson.annotation.JsonIgnoreProperties
55import com.swisscom.health.des.cdr.client.common.Constants.EMPTY_STRING
6+ import com.swisscom.health.des.cdr.client.common.Constants.ERROR_DIR_NAME
67import com.swisscom.health.des.cdr.client.config.CdrClientConfig.Mode
78import com.swisscom.health.des.cdr.client.xml.DocumentType
89import io.github.oshai.kotlinlogging.KotlinLogging
@@ -17,7 +18,6 @@ import java.time.LocalDate
1718import java.time.format.DateTimeFormatter
1819import java.time.temporal.ChronoUnit
1920import kotlin.io.path.createDirectories
20- import kotlin.io.path.isDirectory
2121
2222
2323private val logger = KotlinLogging .logger {}
@@ -152,13 +152,8 @@ internal data class Connector(
152152 val sourceArchiveEnabled : Boolean = false ,
153153
154154 /* *
155- * Directory to archive uploaded files to. If you specify a relative path, it will be resolved relative to the source directory.
156- * If you specify an absolute path, the path will be used as is for all archive directories (see [docTypeFolders]).
157- *
158- * Beware: On Linux empty string, `.`, and `./` all resolve to the current working directory, while `./archive` (and just `archive`) resolve
159- * to `<source_dir>/archive`.
160- *
161- * Default is the system temp directory.
155+ * Directory to archive uploaded files to.
156+ * Needs to be an absolute path, the path will be used as is for all archive directories (see [docTypeFolders]).
162157 *
163158 * @see sourceArchiveEnabled
164159 * @see getEffectiveSourceArchiveFolder
@@ -167,13 +162,8 @@ internal data class Connector(
167162 val sourceArchiveFolder : Path ? = null ,
168163
169164 /* *
170- * Directory to move documents to for which the upload has failed. If you specify a relative path, it will be resolved relative
171- * to the source directory. If you specify an absolute path, the path will be used as is for all error directories, such as for all [docTypeFolders].
172- *
173- * Beware: On Linux empty string, `.`, and `./` all resolve to the current working directory, while `./archive` (and just `archive`) resolve
174- * to `<source_dir>/archive`.
175- *
176- * Default is the system temp directory.
165+ * Directory to move documents to for which the upload has failed.
166+ * Needs to be an absolute path, the path will be used as is for all error directories, such as for all [docTypeFolders].
177167 *
178168 * @see getEffectiveSourceErrorFolder
179169 * @see sourceFolder
@@ -199,46 +189,28 @@ internal data class Connector(
199189
200190 companion object {
201191 const val PROPERTY_NAME = " "
202-
203- @JvmStatic
204- val TEMP_DIR_PATH : Path = Path .of(System .getProperty(" java.io.tmpdir" ))
205192 }
206193
207194 /* *
208- * If [sourceArchiveEnabled] is set to `true` returns the archive directory resolved against the source directory with a subdirectory
209- * for the current date. The directories will be created if they do not exist. If [sourceArchiveEnabled] is `false` returns an
210- * empty path.
195+ * If [sourceArchiveEnabled] is set to `true` returns the archive directory with a subdirectory for the current date.
196+ * The directory will be created if it does not exist.
197+ * If [sourceArchiveEnabled] is `false` returns an empty path.
211198 *
212199 * @see sourceArchiveEnabled
213200 * @see sourceArchiveFolder
214- * @see sourceFolder
215201 */
216202 @JsonIgnore
217- fun getEffectiveSourceArchiveFolder (path : Path ): Path ? =
203+ fun getEffectiveSourceArchiveFolder (): Path ? =
218204 if (sourceArchiveEnabled) {
219- if (path.isDirectory()) {
220- path
221- } else {
222- path.parent
223- }.resolve((sourceArchiveFolder ? : TEMP_DIR_PATH ).resolve(getDateNow()))
224- .also { createDirectoryIfMissing(it) }
205+ createDirectoryIfMissing(when (sourceArchiveFolder) {
206+ null -> sourceFolder.resolve(" archive" )
207+ sourceFolder -> sourceFolder.resolve(" archive" )
208+ else -> sourceArchiveFolder
209+ }.resolve(getDateNow()))
225210 } else {
226211 null
227212 }
228213
229- /* *
230- * Convenience property to get the connector archive directory that is used in all cases where no message type related directories are defined.
231- * @see getEffectiveSourceArchiveFolder
232- */
233- val effectiveConnectorSourceArchiveFolder: Path ?
234- @JsonIgnore
235- get() =
236- if (sourceArchiveEnabled)
237- sourceFolder.resolve((sourceArchiveFolder ? : TEMP_DIR_PATH ).resolve(getDateNow()))
238- .also { createDirectoryIfMissing(it) }
239- else
240- null
241-
242214 /* *
243215 * Returns all source directories for all document types of this connector. If a [DocTypeFolders.sourceFolder] is not set, the entry is omitted.
244216 */
@@ -269,35 +241,20 @@ internal data class Connector(
269241
270242 private fun getDateNow (): String = LocalDate .now().format(DateTimeFormatter .BASIC_ISO_DATE )
271243
244+
272245 /* *
273- * Returns the error directory resolved against the source directory with a subdirectory for the current date. The directories will be
274- * created if they do not exist.
246+ * Returns the effective source error folder path. The directory will be created if it does not exist.
275247 *
276248 * @see sourceErrorFolder
277249 * @see sourceFolder
278250 */
279251 @JsonIgnore
280- fun getEffectiveSourceErrorFolder (path : Path ): Path =
281- (sourceErrorFolder ? : Path .of(EMPTY_STRING )).let { errorDir ->
282- if (path.isDirectory()) {
283- path
284- } else {
285- path.parent
286- }.resolve(errorDir.resolve(getDateNow()))
287- .also { createDirectoryIfMissing(it) }
288- }
289-
290-
291- /* *
292- * Convenience property to get the connector error directory that is used in all cases where no message type related directories are defined.
293- * @see getEffectiveSourceErrorFolder
294- */
295- val effectiveConnectorSourceErrorFolder: Path
296- @JsonIgnore
297- get() = (sourceErrorFolder ? : Path .of(EMPTY_STRING )).let { errorDir ->
298- sourceFolder.resolve(errorDir.resolve(getDateNow()))
299- .also { createDirectoryIfMissing(it) }
300- }
252+ fun getEffectiveSourceErrorFolder (): Path =
253+ when (sourceErrorFolder) {
254+ null -> sourceFolder.resolve(ERROR_DIR_NAME )
255+ sourceFolder -> sourceFolder.resolve(ERROR_DIR_NAME )
256+ else -> sourceErrorFolder
257+ }.let { createDirectoryIfMissing(it) }
301258
302259 override fun toString (): String {
303260 return " Connector(connectorId='$connectorId ', targetFolder=$targetFolder , sourceFolder=$sourceFolder , " +
@@ -309,23 +266,8 @@ internal data class Connector(
309266 EMPTY_STRING
310267 } +
311268 " contentType=$contentType , uploadArchiveEnabled=$sourceArchiveEnabled , sourceArchiveFolder=$sourceArchiveFolder , " +
312- " effectiveSourceArchiveFolder=${effectiveConnectorSourceArchiveFolder} , " +
313- if (sourceArchiveEnabled && effectiveDocTypeFolders.isNotEmpty())
314- " additionalEffectiveSourceArchiveFolders=[${
315- effectiveDocTypeFolders.entries.joinToString(" ; " ) { " ${it.key} =${getEffectiveSourceArchiveFolder(it.value.sourceFolder!! )} " }
316- } ], "
317- else {
318- EMPTY_STRING
319- } +
320- " sourceErrorFolder=$sourceErrorFolder , effectiveSourceErrorFolder=${effectiveConnectorSourceErrorFolder} " +
321- if (effectiveDocTypeFolders.isNotEmpty())
322- " additionalEffectiveSourceErrorFolders=[${
323- effectiveDocTypeFolders.entries.filter { it.value.sourceFolder != null }
324- .joinToString(" , " ) { " ${it.key} =${getEffectiveSourceErrorFolder(it.value.sourceFolder!! )} " }
325- } ], "
326- else {
327- EMPTY_STRING
328- } +
269+ " effectiveSourceArchiveFolder=${getEffectiveSourceArchiveFolder()} , " +
270+ " sourceErrorFolder=$sourceErrorFolder , effectiveSourceErrorFolder=${getEffectiveSourceErrorFolder()} " +
329271 " mode=$mode )"
330272 }
331273
0 commit comments