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 { fun toKey(value: String): String {
return value.replace(WHITESPACE, "").toLowerCase() return value.replace(WHITESPACE, "").toLowerCase()

View File

@ -30,14 +30,12 @@ class NodeController : Controller() {
fun validate(nodeData: NodeData): NodeConfig? { fun validate(nodeData: NodeData): NodeConfig? {
val config = NodeConfig( val config = NodeConfig(
nodeData.legalName.value, nodeData.legalName.value.trim(),
nodeData.artemisPort.value, nodeData.artemisPort.value,
nodeData.nearestCity.value, nodeData.nearestCity.value.trim(),
nodeData.webPort.value nodeData.webPort.value
) )
log.info("Node key: " + config.key)
if (nodes.putIfAbsent(config.key, config) != null) { if (nodes.putIfAbsent(config.key, config) != null) {
return null return null
} }
@ -51,8 +49,12 @@ class NodeController : Controller() {
val nextPort: Int val nextPort: Int
get() { return port.andIncrement } get() { return port.andIncrement }
fun exists(name: String): Boolean { fun keyExists(key: String): Boolean {
return nodes.keys.contains(toKey(name)) return nodes.keys.contains(key)
}
fun nameExists(name: String): Boolean {
return keyExists(toKey(name))
} }
fun chooseNetworkMap(config: NodeConfig) { fun chooseNetworkMap(config: NodeConfig) {

View File

@ -4,6 +4,7 @@ import java.text.DecimalFormat
import javafx.util.converter.NumberStringConverter import javafx.util.converter.NumberStringConverter
import net.corda.demobench.model.NodeController import net.corda.demobench.model.NodeController
import net.corda.demobench.model.NodeDataModel import net.corda.demobench.model.NodeDataModel
import net.corda.demobench.model.toKey
import net.corda.demobench.ui.CloseableTab import net.corda.demobench.ui.CloseableTab
import tornadofx.* import tornadofx.*
@ -13,7 +14,7 @@ class NodeTabView : Fragment() {
private val main by inject<DemoBenchView>() private val main by inject<DemoBenchView>()
private val INTEGER_FORMAT = DecimalFormat() private val INTEGER_FORMAT = DecimalFormat()
private val NOT_NUMBER = Regex("[^\\d]") private val NOT_NUMBER = "[^\\d]".toRegex()
private val model = NodeDataModel() private val model = NodeDataModel()
private val controller by inject<NodeController>() private val controller by inject<NodeController>()
@ -27,22 +28,31 @@ class NodeTabView : Fragment() {
minWidth = 200.0 minWidth = 200.0
maxWidth = 200.0 maxWidth = 200.0
validator { validator {
if ((it == null) || it.isBlank()) { if (it == null) {
error("Node name is required") error("Node name is required")
} else if (controller.exists(it)) { } else {
val name = it.trim()
if (name.isEmpty()) {
error("Node name is required")
} else if (controller.nameExists(name)) {
error("Node with this name already exists") error("Node with this name already exists")
} else if (name.length > 10) {
error("Name is too long")
} else { } else {
null null
} }
} }
} }
} }
}
field("Nearest City") { field("Nearest City") {
textfield(model.nearestCity) { textfield(model.nearestCity) {
minWidth = 200.0 minWidth = 200.0
maxWidth = 200.0 maxWidth = 200.0
validator { validator {
if (it.isNullOrBlank()) { if (it == null) {
error("Nearest city is required")
} else if (it.trim().isEmpty()) {
error("Nearest city is required") error("Nearest city is required")
} else { } else {
null null