Skip to content

Commit

Permalink
#322 use host prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mgramin committed May 18, 2019
1 parent e148b47 commit 3c51437
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import org.springframework.stereotype.Service
@ConfigurationProperties(prefix = "conf")
open class EndpointList(val endpoints: List<SimpleEndpoint>) {

fun getConnectionByName(name: String) = endpoints.first { v -> v.name().equals(name, ignoreCase = true) }
fun getByName(name: String) = endpoints.first { v -> v.name().equals(name, ignoreCase = true) }

fun getConnectionsByMask(name: String) = endpoints.filter { v -> v.name().matches(name.toRegex()) }
fun getByMask(mask: String) = endpoints.filter { v -> v.name().matches(mask.toRegex()) }

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ApiController {
@RequestMapping(value = ["/api/{connectionName}/types"])
fun types(@PathVariable connectionName: String): String {
val jsonArray = JsonArray()
FsResourceType(endpointList.getConnectionsByMask(connectionName), emptyList())
FsResourceType(endpointList.getByMask(connectionName), emptyList())
.resourceTypes()
.forEach { jsonArray.add(it.toJson()) }
return jsonArray.toString()
Expand All @@ -75,7 +75,7 @@ class ApiController {
@RequestMapping(value = ["/api/{connectionName}/types/{typeMask}"])
fun typesByMask(@PathVariable connectionName: String, @PathVariable typeMask: String): String {
val jsonArray = JsonArray()
FsResourceType(endpointList.getConnectionsByMask(connectionName), emptyList())
FsResourceType(endpointList.getByMask(connectionName), emptyList())
.resourceTypes()
.filter { it.name().matches(wildcardToRegex(typeMask)) }
.forEach { jsonArray.add(it.toJson()) }
Expand All @@ -91,7 +91,7 @@ class ApiController {
val jsonArray = JsonArray()
val uri = SqlPlaceholdersWrapper(
DbUri("$connection/$type"))
FsResourceType(listOf(endpointList.getConnectionByName(uri.connection())), emptyList())
FsResourceType(listOf(endpointList.getByName(uri.connection())), emptyList())
.resourceTypes()
.asSequence()
.filter { v -> v.name().equals(uri.type(), ignoreCase = true) }
Expand All @@ -109,7 +109,7 @@ class ApiController {
val jsonArray = JsonArray()
val uri = SqlPlaceholdersWrapper(
DbUri("$connection/$type/$path"))
FsResourceType(listOf(endpointList.getConnectionByName(uri.connection())), emptyList())
FsResourceType(listOf(endpointList.getByName(uri.connection())), emptyList())
.resourceTypes()
.asSequence()
.filter { v -> v.name().equals(uri.type(), ignoreCase = true) }
Expand All @@ -134,7 +134,7 @@ class ApiController {
getListResponseEntityHeaders(SqlPlaceholdersWrapper(DbUri("$connection/$type/$path")))

private fun getListResponseEntityHeaders(uri: Uri): ResponseEntity<List<Map<String, Any>>> {
val connections = endpointList.getConnectionsByMask(uri.connection())
val connections = endpointList.getByMask(uri.connection())
try {
val headers = FsResourceType(connections, dbDialectList.dialects)
.read(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SwaggerController {

private fun getSwaggerDescription(request: HttpServletRequest, connectionName: String): Swagger {
val fsResourceTypes = FsResourceType(
listOf(endpointList.getConnectionByName(connectionName)), emptyList())
listOf(endpointList.getByName(connectionName)), emptyList())
val resourceTypes = fsResourceTypes.resourceTypes()
val swagger = Swagger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ internal class EndpointListTest {
@ParameterizedTest
@ValueSource(strings = ["test", "dev", "prod"])
fun getConnectionByName(connectionName: String) {
assertEquals(connectionName, endpointList.getConnectionByName(connectionName).name())
assertEquals(connectionName, endpointList.getByName(connectionName).name())
}

@ParameterizedTest
@ValueSource(strings = ["test", "dev", "prod"])
fun getConnectionsByMask(connectionMask: String) {
assertEquals(connectionMask, endpointList.getConnectionsByMask(connectionMask).first().name())
assertEquals(connectionMask, endpointList.getByMask(connectionMask).first().name())
}

@Test
Expand Down

0 comments on commit 3c51437

Please sign in to comment.