Skip to content

Commit

Permalink
updated dependencies, added new flag to omit correction time-slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred Odenstein committed Nov 15, 2021
1 parent bcf3533 commit 3e672ab
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ aixm-update-gen [OPTIONS] <EFFECTIVE-DATE> <INPUT-FILE> <OUTPUT-FILE>
```
```
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:
<EFFECTIVE-DATE> The new effective date, e.g. "2022-12-24T00:00:00Z".
Expand Down
13 changes: 6 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -34,5 +33,5 @@ tasks.test {
}

application {
mainClassName = "com.solitec.aixm.updgen.MainKt"
mainClass.set("com.solitec.aixm.updgen.MainKt")
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
23 changes: 13 additions & 10 deletions src/main/kotlin/com/solitec/aixm/updgen/AIXMUpdateGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion src/main/kotlin/com/solitec/aixm/updgen/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,14 +54,15 @@ 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("<INPUT-FILE>", help = "An AIXM 5.1 Basic Message file as input.").file(mustExist = true)
private val outputFile by argument("<OUTPUT-FILE>", help = "The output file.").file()


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)
Expand Down

0 comments on commit 3e672ab

Please sign in to comment.