diff --git a/README.md b/README.md index f1b89d3..29fd408 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ aixm-update-gen [OPTIONS] ``` ``` Options: - -r, --remark TEXT This text will be placed in the annotation element. - -h, --help Show this message and exit + -r, --remark TEXT This text will be placed in the annotation element. + -c, --omit-correction This instructs the program to not create the + correction timeslices. + -h, --help Show this message and exit Arguments: The new effective date, e.g. "2022-12-24T00:00:00Z". diff --git a/build.gradle.kts b/build.gradle.kts index 0c03d7c..0aebe73 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,20 +1,19 @@ plugins { - kotlin("jvm") version "1.3.70" + kotlin("jvm") version "1.5.31" application } group = "com.solitec.aixm" -version = "1.0.1" +version = "1.0.2" repositories { mavenCentral() } dependencies { - implementation(kotlin("stdlib-jdk8")) - implementation("com.github.ajalt:clikt:2.6.0") - testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31") + implementation("com.github.ajalt:clikt:2.8.0") + testImplementation("org.jetbrains.kotlin:kotlin-test:1.5.31") } tasks { @@ -34,5 +33,5 @@ tasks.test { } application { - mainClassName = "com.solitec.aixm.updgen.MainKt" + mainClass.set("com.solitec.aixm.updgen.MainKt") } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..69a9715 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/com/solitec/aixm/updgen/AIXMUpdateGenerator.kt b/src/main/kotlin/com/solitec/aixm/updgen/AIXMUpdateGenerator.kt index d1353d0..a300108 100644 --- a/src/main/kotlin/com/solitec/aixm/updgen/AIXMUpdateGenerator.kt +++ b/src/main/kotlin/com/solitec/aixm/updgen/AIXMUpdateGenerator.kt @@ -134,20 +134,23 @@ class AIXMUpdateGenerator(private val outputStream: OutputStream, private val pa // clone timeSlice val updateTimeSlice = XPathTool.extractNode(feature, """aixm:timeSlice""") - val cancelTimeSlice = updateTimeSlice?.cloneNode(true) - feature.insertBefore(cancelTimeSlice, updateTimeSlice) + if (!params.omitCorrections) { + val cancelTimeSlice = updateTimeSlice?.cloneNode(true) - // "cancelation" timeSlice - XPathTool.extractNode(cancelTimeSlice!!, """descendant::gml:validTime/gml:TimePeriod/gml:endPosition""")?.also { - it.removeAllAttributes() - it.textContent = params.effectiveDate.toXMLFormat() + feature.insertBefore(cancelTimeSlice, updateTimeSlice) + + // "cancelation" timeSlice + XPathTool.extractNode(cancelTimeSlice!!, """descendant::gml:validTime/gml:TimePeriod/gml:endPosition""")?.also { + it.removeAllAttributes() + it.textContent = params.effectiveDate.toXMLFormat() + } + XPathTool.extractNode(cancelTimeSlice, """descendant::aixm:correctionNumber""")?.incrementContent() } - XPathTool.extractNode(cancelTimeSlice, """descendant::aixm:correctionNumber""")?.incrementContent() // "update" timeSlice - regenerateGmlIds(updateTimeSlice) - XPathTool.extractNode(updateTimeSlice!!, """descendant::gml:validTime/gml:TimePeriod/gml:beginPosition""")?.also { + regenerateGmlIds(updateTimeSlice!!) + XPathTool.extractNode(updateTimeSlice, """descendant::gml:validTime/gml:TimePeriod/gml:beginPosition""")?.also { it.textContent = params.effectiveDate.toXMLFormat() } @@ -272,4 +275,4 @@ class AIXMUpdateGenerator(private val outputStream: OutputStream, private val pa * @param effectiveDate The new effective date. * @param remark The optional remark. */ -data class GeneratorParams(val effectiveDate: XMLGregorianCalendar, val remark: String?) +data class GeneratorParams(val effectiveDate: XMLGregorianCalendar, val remark: String?, val omitCorrections: Boolean) diff --git a/src/main/kotlin/com/solitec/aixm/updgen/Main.kt b/src/main/kotlin/com/solitec/aixm/updgen/Main.kt index 4bae710..5662f65 100644 --- a/src/main/kotlin/com/solitec/aixm/updgen/Main.kt +++ b/src/main/kotlin/com/solitec/aixm/updgen/Main.kt @@ -35,6 +35,7 @@ package com.solitec.aixm.updgen import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.convert +import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.file import java.io.BufferedInputStream @@ -53,6 +54,7 @@ class AixmUpdateGenCLI : CliktCommand(name = "aixm-update-gen", help = """ XMLTool.parseXMLDateTime(it) } private val remark by option("-r", "--remark", help = "This text will be placed in the annotation element.") + private val flagOmitCorrection by option("-c", "--omit-correction", help = "This instructs the program to not create the correction timeslices.").flag() private val inputFile by argument("", help = "An AIXM 5.1 Basic Message file as input.").file(mustExist = true) private val outputFile by argument("", help = "The output file.").file() @@ -60,7 +62,7 @@ class AixmUpdateGenCLI : CliktCommand(name = "aixm-update-gen", help = """ override fun run() { val inputStream = BufferedInputStream(inputFile.inputStream()) val outputStream = BufferedOutputStream(outputFile.outputStream()) - val params = GeneratorParams(effectiveDate, remark) + val params = GeneratorParams(effectiveDate, remark, flagOmitCorrection) try { outputStream.use { AIXMUpdateGenerator.execute(inputStream, outputStream, params)