From 7866dde91bd79badba6d8ed7f764e24e95b457ca Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 5 Feb 2019 15:29:26 +0000 Subject: [PATCH] CORDA-2556: Refactor World City database into a library module. (#4718) * Refactor World City database into a library module. * Migrate CityDatabaseTest into worldmap module. --- settings.gradle | 1 + tools/demobench/build.gradle | 2 +- .../src/main/kotlin/net/corda/demobench/model/NodeData.kt | 4 ++-- .../main/kotlin/net/corda/demobench/views/NodeTabView.kt | 6 +++--- tools/explorer/build.gradle | 1 + .../src/main/kotlin/net/corda/explorer/views/Network.kt | 6 +++--- tools/worldmap/build.gradle | 8 ++++++++ .../net/corda/worldmap}/PhysicalLocationStructures.kt | 4 ++-- .../src/main/resources/net/corda/worldmap}/cities.txt | 0 .../test/kotlin/net/corda/worldmap}/CityDatabaseTest.kt | 2 +- 10 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 tools/worldmap/build.gradle rename tools/{explorer/src/main/kotlin/net/corda/explorer => worldmap/src/main/kotlin/net/corda/worldmap}/PhysicalLocationStructures.kt (97%) rename tools/{explorer/src/main/resources/net/corda/explorer => worldmap/src/main/resources/net/corda/worldmap}/cities.txt (100%) rename tools/{explorer/src/test/kotlin/net/corda/explorer => worldmap/src/test/kotlin/net/corda/worldmap}/CityDatabaseTest.kt (92%) diff --git a/settings.gradle b/settings.gradle index efd159544c..120b0d866b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -45,6 +45,7 @@ include 'tools:shell' include 'tools:shell-cli' include 'tools:network-bootstrapper' include 'tools:cliutils' +include 'tools:worldmap' include 'example-code' project(':example-code').projectDir = file("$settingsDir/docs/source/example-code") include 'samples:attachment-demo:contracts' diff --git a/tools/demobench/build.gradle b/tools/demobench/build.gradle index 74e7df1ddb..950db72eec 100644 --- a/tools/demobench/build.gradle +++ b/tools/demobench/build.gradle @@ -43,10 +43,10 @@ configurations { } dependencies { - compile project(':tools:explorer') compile project(':client:rpc') compile project(':finance:contracts') compile project(':finance:workflows') + compile project(':tools:worldmap') // TornadoFX: A lightweight Kotlin framework for working with JavaFX UI's. compile "no.tornado:tornadofx:$tornadofx_version" diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt index 40b35ca9bf..15e57b1313 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt @@ -5,12 +5,12 @@ import javafx.beans.property.SimpleListProperty import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleStringProperty import javafx.collections.FXCollections.observableArrayList -import net.corda.explorer.CityDatabase +import net.corda.worldmap.CityDatabase import tornadofx.* import java.util.* object SuggestedDetails { - val banks = listOf( + private val banks = listOf( // Mike: Rome? Why Rome? // Roger: Notaries public (also called "notaries", "notarial officers", or "public notaries") hold an office // which can trace its origins back to the ancient Roman Republic, when they were called scribae ("scribes"), diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt index e4c012c3aa..e270d27731 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTabView.kt @@ -18,12 +18,12 @@ import javafx.util.StringConverter import net.corda.core.internal.* import net.corda.demobench.model.* import net.corda.demobench.ui.CloseableTab -import net.corda.explorer.CityDatabase -import net.corda.explorer.WorldMapLocation import net.corda.finance.CHF import net.corda.finance.EUR import net.corda.finance.GBP import net.corda.finance.USD +import net.corda.worldmap.CityDatabase +import net.corda.worldmap.WorldMapLocation import org.controlsfx.control.CheckListView import tornadofx.* import java.nio.file.Path @@ -138,7 +138,7 @@ class NodeTabView : Fragment() { } else { val notaryTypes = listOf(NotaryService(true), NotaryService(false)) val notaryTypeToggleGroup = togglegroup() - notaryTypeToggleGroup.selectedValueProperty().addListener { observValue, oldValue, newValue -> + notaryTypeToggleGroup.selectedValueProperty().addListener { _, oldValue, newValue -> oldValue?.let { model.item.extraServices.removeAll(it) } diff --git a/tools/explorer/build.gradle b/tools/explorer/build.gradle index 959f5b273c..612fea229c 100644 --- a/tools/explorer/build.gradle +++ b/tools/explorer/build.gradle @@ -26,6 +26,7 @@ dependencies { compile project(':node-driver') compile project(':finance:contracts') compile project(':finance:workflows') + compile project(':tools:worldmap') // Capsule is a library for building independently executable fat JARs. // We only need this dependency to compile our Caplet against. diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/Network.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/Network.kt index 647218c625..c56a96c658 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/Network.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/Network.kt @@ -33,11 +33,11 @@ import net.corda.core.identity.Party import net.corda.core.node.NodeInfo import net.corda.core.transactions.WireTransaction import net.corda.core.utilities.toBase58String -import net.corda.explorer.CityDatabase -import net.corda.explorer.ScreenCoordinate -import net.corda.explorer.WorldMapLocation import net.corda.explorer.formatters.PartyNameFormatter import net.corda.explorer.model.CordaView +import net.corda.worldmap.CityDatabase +import net.corda.worldmap.ScreenCoordinate +import net.corda.worldmap.WorldMapLocation import tornadofx.* class Network : CordaView() { diff --git a/tools/worldmap/build.gradle b/tools/worldmap/build.gradle new file mode 100644 index 0000000000..7ccf067acb --- /dev/null +++ b/tools/worldmap/build.gradle @@ -0,0 +1,8 @@ +apply plugin: 'kotlin' + +dependencies { + implementation project(':core') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit" + testImplementation "junit:junit:$junit_version" +} \ No newline at end of file diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/PhysicalLocationStructures.kt b/tools/worldmap/src/main/kotlin/net/corda/worldmap/PhysicalLocationStructures.kt similarity index 97% rename from tools/explorer/src/main/kotlin/net/corda/explorer/PhysicalLocationStructures.kt rename to tools/worldmap/src/main/kotlin/net/corda/worldmap/PhysicalLocationStructures.kt index 18eb966c53..9b4e814aac 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/PhysicalLocationStructures.kt +++ b/tools/worldmap/src/main/kotlin/net/corda/worldmap/PhysicalLocationStructures.kt @@ -1,4 +1,4 @@ -package net.corda.explorer +package net.corda.worldmap import net.corda.core.serialization.CordaSerializable import java.util.* @@ -51,7 +51,7 @@ data class WorldMapLocation(val coordinate: WorldCoordinate, val description: St * A simple lookup table of city names to their coordinates. Lookups are case insensitive. */ object CityDatabase { - private val matcher = Regex("^([a-zA-Z- ]*) \\((..)\\)$") + private val matcher = Regex("^([a-zA-Z- ]*) \\((..)\\)\$") private val caseInsensitiveLookups = HashMap() val cityMap = HashMap() diff --git a/tools/explorer/src/main/resources/net/corda/explorer/cities.txt b/tools/worldmap/src/main/resources/net/corda/worldmap/cities.txt similarity index 100% rename from tools/explorer/src/main/resources/net/corda/explorer/cities.txt rename to tools/worldmap/src/main/resources/net/corda/worldmap/cities.txt diff --git a/tools/explorer/src/test/kotlin/net/corda/explorer/CityDatabaseTest.kt b/tools/worldmap/src/test/kotlin/net/corda/worldmap/CityDatabaseTest.kt similarity index 92% rename from tools/explorer/src/test/kotlin/net/corda/explorer/CityDatabaseTest.kt rename to tools/worldmap/src/test/kotlin/net/corda/worldmap/CityDatabaseTest.kt index 988a13bf68..651c5992c1 100644 --- a/tools/explorer/src/test/kotlin/net/corda/explorer/CityDatabaseTest.kt +++ b/tools/worldmap/src/test/kotlin/net/corda/worldmap/CityDatabaseTest.kt @@ -1,4 +1,4 @@ -package net.corda.explorer +package net.corda.worldmap import org.junit.Assert.assertEquals import org.junit.Test