DemoBench: address review comments

This commit is contained in:
Mike Hearn 2017-04-25 11:19:50 +02:00
parent 238d4e29e2
commit b4e7944a18
4 changed files with 19 additions and 11 deletions

View File

@ -75,15 +75,10 @@ class LegalNameValidatorTest {
@Test
fun `legal name should be capitalized`() {
validateLegalName("Good Legal Name")
validateLegalName("Good legal name")
assertFailsWith(IllegalArgumentException::class) {
validateLegalName("bad name")
}
assertFailsWith(IllegalArgumentException::class) {
validateLegalName("Bad name")
}
assertFailsWith(IllegalArgumentException::class) {
validateLegalName("bad Name")
}

View File

@ -24,6 +24,7 @@ import net.corda.core.utilities.validateLegalName
import net.corda.core.writeLines
import net.corda.demobench.model.*
import net.corda.demobench.ui.CloseableTab
import org.bouncycastle.asn1.x500.style.RFC4519Style.name
import org.controlsfx.control.CheckListView
import tornadofx.*
import java.nio.file.Path
@ -193,6 +194,8 @@ class NodeTabView : Fragment() {
validator {
if (it == null) {
error("Node name is required")
} else if (nodeController.nameExists(normaliseLegalName(it))) {
error("Node with this name already exists")
} else {
try {
validateLegalName(normaliseLegalName(it))

View File

@ -17,6 +17,7 @@ import javafx.scene.layout.StackPane
import javafx.scene.layout.HBox
import javafx.scene.layout.VBox
import javafx.util.Duration
import net.corda.core.failure
import net.corda.core.success
import net.corda.core.then
import net.corda.core.messaging.CordaRPCOps
@ -129,6 +130,7 @@ class NodeTerminalView : Fragment() {
}
private var webURL: URI? = null
private var launchingWebServer = false
/*
* We only want to run one web server for each node.
@ -142,7 +144,13 @@ class NodeTerminalView : Fragment() {
app.hostServices.showDocument(webURL.toString())
return@setOnAction
}
launchWebButton.isDisable = true
// We use our own way to suppress clicks whilst starting as a quick style hack, as the progress spinner
// gets very dim when placed inside a disabled button.
if (launchingWebServer)
return@setOnAction
launchingWebServer = true
val oldLabel = launchWebButton.text
launchWebButton.text = ""
launchWebButton.graphic = ProgressIndicator()
@ -150,16 +158,17 @@ class NodeTerminalView : Fragment() {
log.info("Starting web server for ${config.legalName}")
webServer.open(config) then {
Platform.runLater {
launchWebButton.isDisable = false
launchWebButton.text = oldLabel
launchWebButton.graphic = null
}
} success {
log.info("Web server for ${config.legalName} started on $it")
Platform.runLater {
webURL = it
launchWebButton.text = "Reopen\nweb site"
app.hostServices.showDocument(it.toString())
}
} failure {
launchWebButton.text = oldLabel
}
}
}

View File

@ -159,7 +159,8 @@ class NodeWebServer(val config: WebServerConfig) {
addServlet(staticDir, "/web/${it.first}/*")
}
addServlet(ServletHolder(HelpServlet("/web/${staticDirs.first().first}")), "/")
// If we have at least one static web data directory, redirect / to the right URL.
staticDirs.firstOrNull()?.let { addServlet(ServletHolder(IndexRedirectServlet("/web/${it.first}")), "/") }
// Give the app a slightly better name in JMX rather than a randomly generated one and enable JMX
resourceConfig.addProperties(mapOf(ServerProperties.APPLICATION_NAME to "node.api",
@ -172,7 +173,7 @@ class NodeWebServer(val config: WebServerConfig) {
}
}
private inner class HelpServlet(private val redirectTo: String) : HttpServlet() {
private inner class IndexRedirectServlet(private val redirectTo: String) : HttpServlet() {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.sendRedirect(resp.encodeRedirectURL(redirectTo))
}