Trim node name and nearest city values.

This commit is contained in:
Chris Rankin 2017-01-27 11:55:34 +00:00
parent c670ed6bdd
commit 73e8a73714
3 changed files with 25 additions and 13 deletions

View File

@ -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()

View File

@ -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) {

View File

@ -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<DemoBenchView>()
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<NodeController>()
@ -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