diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt index 34c0e47db3..24543a9edc 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NetworkMapConfig.kt @@ -16,7 +16,7 @@ open class NetworkMapConfig(legalName: String, artemisPort: Int) { } -private val WHITESPACE = Regex("\\s++") +private val WHITESPACE = "\\s++".toRegex() fun toKey(value: String): String { return value.replace(WHITESPACE, "").toLowerCase() diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt index 297041fc87..8e7d6eb0e0 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt @@ -30,14 +30,12 @@ class NodeController : Controller() { fun validate(nodeData: NodeData): NodeConfig? { val config = NodeConfig( - nodeData.legalName.value, + nodeData.legalName.value.trim(), nodeData.artemisPort.value, - nodeData.nearestCity.value, + nodeData.nearestCity.value.trim(), nodeData.webPort.value ) - log.info("Node key: " + config.key) - if (nodes.putIfAbsent(config.key, config) != null) { return null } @@ -51,8 +49,12 @@ class NodeController : Controller() { val nextPort: Int get() { return port.andIncrement } - fun exists(name: String): Boolean { - return nodes.keys.contains(toKey(name)) + fun keyExists(key: String): Boolean { + return nodes.keys.contains(key) + } + + fun nameExists(name: String): Boolean { + return keyExists(toKey(name)) } fun chooseNetworkMap(config: NodeConfig) { 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 bbc4c60198..243429533d 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 @@ -4,6 +4,7 @@ import java.text.DecimalFormat import javafx.util.converter.NumberStringConverter import net.corda.demobench.model.NodeController import net.corda.demobench.model.NodeDataModel +import net.corda.demobench.model.toKey import net.corda.demobench.ui.CloseableTab import tornadofx.* @@ -13,7 +14,7 @@ class NodeTabView : Fragment() { private val main by inject() private val INTEGER_FORMAT = DecimalFormat() - private val NOT_NUMBER = Regex("[^\\d]") + private val NOT_NUMBER = "[^\\d]".toRegex() private val model = NodeDataModel() private val controller by inject() @@ -27,12 +28,19 @@ class NodeTabView : Fragment() { minWidth = 200.0 maxWidth = 200.0 validator { - if ((it == null) || it.isBlank()) { + if (it == null) { error("Node name is required") - } else if (controller.exists(it)) { - error("Node with this name already exists") } else { - null + val name = it.trim() + if (name.isEmpty()) { + error("Node name is required") + } else if (controller.nameExists(name)) { + error("Node with this name already exists") + } else if (name.length > 10) { + error("Name is too long") + } else { + null + } } } } @@ -42,7 +50,9 @@ class NodeTabView : Fragment() { minWidth = 200.0 maxWidth = 200.0 validator { - if (it.isNullOrBlank()) { + if (it == null) { + error("Nearest city is required") + } else if (it.trim().isEmpty()) { error("Nearest city is required") } else { null