Skip to content

Commit c1a3350

Browse files
committed
#322 rename connectionList
1 parent a2b796b commit c1a3350

File tree

13 files changed

+49
-51
lines changed

13 files changed

+49
-51
lines changed

pom.xml

+3-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
~ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
2020
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
~ SOFTWARE.
2424
-->
@@ -189,11 +189,6 @@
189189
<artifactId>h2</artifactId>
190190
</dependency>
191191

192-
<dependency>
193-
<groupId>com.google.code.gson</groupId>
194-
<artifactId>gson</artifactId>
195-
</dependency>
196-
197192
<dependency>
198193
<groupId>io.swagger</groupId>
199194
<artifactId>swagger-parser</artifactId>
@@ -228,9 +223,8 @@
228223
</dependency>
229224

230225
<dependency>
231-
<groupId>org.json</groupId>
232-
<artifactId>json</artifactId>
233-
<version>20171018</version>
226+
<groupId>com.google.code.gson</groupId>
227+
<artifactId>gson</artifactId>
234228
</dependency>
235229

236230
<dependency>

src/main/kotlin/com/github/mgramin/sqlboot/model/connection/Endpoint.kt

+2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ interface Endpoint {
3030

3131
fun name(): String
3232

33+
@Deprecated("Move to properties")
3334
fun dialect(): String
3435

36+
@Deprecated("Move to SQLResourceType")
3537
fun getDataSource(): DataSource
3638

3739
fun properties(): Map<String, Any>

src/main/kotlin/com/github/mgramin/sqlboot/model/connection/DbConnectionList.kt src/main/kotlin/com/github/mgramin/sqlboot/model/connection/EndpointList.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import org.springframework.stereotype.Service
3636
@Service
3737
@Configuration
3838
@ConfigurationProperties(prefix = "conf")
39-
open class DbConnectionList(val connections: List<SimpleEndpoint>) {
39+
open class EndpointList(val endpoints: List<SimpleEndpoint>) {
4040

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

43-
fun getConnectionsByMask(name: String) = connections.filter { v -> v.name().matches(name.toRegex()) }
43+
fun getConnectionsByMask(name: String) = endpoints.filter { v -> v.name().matches(name.toRegex()) }
4444

4545
}

src/main/kotlin/com/github/mgramin/sqlboot/model/connection/SimpleEndpoint.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ package com.github.mgramin.sqlboot.model.connection
2626

2727
import com.fasterxml.jackson.annotation.JsonIgnore
2828
import org.apache.tomcat.jdbc.pool.DataSource
29-
import org.json.JSONObject
3029
import org.springframework.core.io.Resource
30+
import com.google.gson.Gson
31+
import com.google.gson.reflect.TypeToken
32+
3133

3234
/**
3335
* @author Maksim Gramin ([email protected])
@@ -37,7 +39,6 @@ import org.springframework.core.io.Resource
3739
open class SimpleEndpoint(
3840
var name: String? = null,
3941
@JsonIgnore var baseFolder: Resource? = null,
40-
var url: String? = null,
4142
var user: String? = null,
4243
@JsonIgnore var password: String? = null,
4344
var driverClassName: String? = null,
@@ -52,7 +53,9 @@ open class SimpleEndpoint(
5253

5354
private var dataSource: DataSource? = null
5455

55-
override fun properties() = JSONObject(properties).toMap()
56+
override fun properties(): Map<String, Any> {
57+
return Gson().fromJson(properties, object : TypeToken<Map<String, Any>>() {}.type)
58+
}
5659

5760

5861
@JsonIgnore
@@ -64,8 +67,8 @@ open class SimpleEndpoint(
6467
if (driverClassName != null) {
6568
dataSourceNew.driverClassName = driverClassName
6669
}
67-
if (url != null) {
68-
dataSourceNew.url = url
70+
if (properties()["url"] != null) {
71+
dataSourceNew.url = properties()["url"].toString()
6972
}
7073
if (user != null) {
7174
dataSourceNew.username = user

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/wrappers/body/BodyWrapper.kt

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import com.github.mgramin.sqlboot.model.resourcetype.Metadata
3030
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
3131
import com.github.mgramin.sqlboot.model.uri.Uri
3232
import com.github.mgramin.sqlboot.template.generator.TemplateGenerator
33-
import org.json.JSONObject
3433
import reactor.core.publisher.Flux
3534

3635
/**

src/main/kotlin/com/github/mgramin/sqlboot/rest/controllers/ApiController.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
package com.github.mgramin.sqlboot.rest.controllers
2626

2727
import com.github.mgramin.sqlboot.exceptions.BootException
28-
import com.github.mgramin.sqlboot.model.connection.DbConnectionList
28+
import com.github.mgramin.sqlboot.model.connection.EndpointList
2929
import com.github.mgramin.sqlboot.model.dialect.DbDialectList
3030
import com.github.mgramin.sqlboot.model.resourcetype.impl.FsResourceType
3131
import com.github.mgramin.sqlboot.model.uri.Uri
@@ -57,7 +57,7 @@ import javax.servlet.http.HttpServletRequest
5757
class ApiController {
5858

5959
@Autowired
60-
private lateinit var dbConnectionList: DbConnectionList
60+
private lateinit var endpointList: EndpointList
6161

6262
@Autowired
6363
private lateinit var dbDialectList: DbDialectList
@@ -66,7 +66,7 @@ class ApiController {
6666
@RequestMapping(value = ["/api/{connectionName}/types"])
6767
fun types(@PathVariable connectionName: String): String {
6868
val jsonArray = JsonArray()
69-
FsResourceType(dbConnectionList.getConnectionsByMask(connectionName), emptyList())
69+
FsResourceType(endpointList.getConnectionsByMask(connectionName), emptyList())
7070
.resourceTypes()
7171
.forEach { jsonArray.add(it.toJson()) }
7272
return jsonArray.toString()
@@ -75,7 +75,7 @@ class ApiController {
7575
@RequestMapping(value = ["/api/{connectionName}/types/{typeMask}"])
7676
fun typesByMask(@PathVariable connectionName: String, @PathVariable typeMask: String): String {
7777
val jsonArray = JsonArray()
78-
FsResourceType(dbConnectionList.getConnectionsByMask(connectionName), emptyList())
78+
FsResourceType(endpointList.getConnectionsByMask(connectionName), emptyList())
7979
.resourceTypes()
8080
.filter { it.name().matches(wildcardToRegex(typeMask)) }
8181
.forEach { jsonArray.add(it.toJson()) }
@@ -91,7 +91,7 @@ class ApiController {
9191
val jsonArray = JsonArray()
9292
val uri = SqlPlaceholdersWrapper(
9393
DbUri("$connection/$type"))
94-
FsResourceType(listOf(dbConnectionList.getConnectionByName(uri.connection())), emptyList())
94+
FsResourceType(listOf(endpointList.getConnectionByName(uri.connection())), emptyList())
9595
.resourceTypes()
9696
.asSequence()
9797
.filter { v -> v.name().equals(uri.type(), ignoreCase = true) }
@@ -109,7 +109,7 @@ class ApiController {
109109
val jsonArray = JsonArray()
110110
val uri = SqlPlaceholdersWrapper(
111111
DbUri("$connection/$type/$path"))
112-
FsResourceType(listOf(dbConnectionList.getConnectionByName(uri.connection())), emptyList())
112+
FsResourceType(listOf(endpointList.getConnectionByName(uri.connection())), emptyList())
113113
.resourceTypes()
114114
.asSequence()
115115
.filter { v -> v.name().equals(uri.type(), ignoreCase = true) }
@@ -134,7 +134,7 @@ class ApiController {
134134
getListResponseEntityHeaders(SqlPlaceholdersWrapper(DbUri("$connection/$type/$path")))
135135

136136
private fun getListResponseEntityHeaders(uri: Uri): ResponseEntity<List<Map<String, Any>>> {
137-
val connections = dbConnectionList.getConnectionsByMask(uri.connection())
137+
val connections = endpointList.getConnectionsByMask(uri.connection())
138138
try {
139139
val headers = FsResourceType(connections, dbDialectList.dialects)
140140
.read(uri)

src/main/kotlin/com/github/mgramin/sqlboot/rest/controllers/DbConnectionsController.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
package com.github.mgramin.sqlboot.rest.controllers
2626

2727
import com.github.mgramin.sqlboot.model.connection.Endpoint
28-
import com.github.mgramin.sqlboot.model.connection.DbConnectionList
28+
import com.github.mgramin.sqlboot.model.connection.EndpointList
2929
import com.github.mgramin.sqlboot.model.connection.SimpleEndpoint
3030
import org.springframework.beans.factory.annotation.Autowired
3131
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -49,17 +49,17 @@ import reactor.core.scheduler.Schedulers
4949
@ComponentScan(basePackages = ["com.github.mgramin.sqlboot.model.resource_type"])
5050
@EnableAutoConfiguration
5151
@CrossOrigin
52-
class DbConnectionsController @Autowired constructor(private val dbConnectionList: DbConnectionList) {
52+
class DbConnectionsController @Autowired constructor(private val endpointList: EndpointList) {
5353

5454
val allDbConnections: List<SimpleEndpoint>
55-
@RequestMapping(value = ["/connections"])
56-
get() = dbConnectionList.connections
55+
@RequestMapping(value = ["/endpoints"])
56+
get() = endpointList.endpoints
5757

58-
@GetMapping(value = ["/connections/health"], produces = [MediaType.TEXT_EVENT_STREAM_VALUE])
58+
@GetMapping(value = ["/endpoints/health"], produces = [MediaType.TEXT_EVENT_STREAM_VALUE])
5959
@ResponseBody
6060
internal fun health(): Flux<Endpoint> {
61-
return dbConnectionList
62-
.connections
61+
return endpointList
62+
.endpoints
6363
.toFlux()
6464
.parallel()
6565
.runOn(Schedulers.elastic())

src/main/kotlin/com/github/mgramin/sqlboot/rest/controllers/SwaggerController.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
package com.github.mgramin.sqlboot.rest.controllers
2626

2727
import com.fasterxml.jackson.core.JsonProcessingException
28-
import com.github.mgramin.sqlboot.model.connection.DbConnectionList
28+
import com.github.mgramin.sqlboot.model.connection.EndpointList
2929
import com.github.mgramin.sqlboot.model.resourcetype.impl.FsResourceType
3030
import io.swagger.models.Info
3131
import io.swagger.models.ModelImpl
@@ -56,7 +56,7 @@ import javax.servlet.http.HttpServletRequest
5656
class SwaggerController {
5757

5858
@Autowired
59-
private lateinit var dbConnectionList: DbConnectionList
59+
private lateinit var endpointList: EndpointList
6060

6161

6262
@RequestMapping(method = [RequestMethod.GET, RequestMethod.POST], path = ["/api"], produces = [MediaType.APPLICATION_JSON_VALUE])
@@ -92,7 +92,7 @@ class SwaggerController {
9292

9393
private fun getSwaggerDescription(request: HttpServletRequest, connectionName: String): Swagger {
9494
val fsResourceTypes = FsResourceType(
95-
listOf(dbConnectionList.getConnectionByName(connectionName)), emptyList())
95+
listOf(endpointList.getConnectionByName(connectionName)), emptyList())
9696
val resourceTypes = fsResourceTypes.resourceTypes()
9797
val swagger = Swagger()
9898

@@ -102,9 +102,9 @@ class SwaggerController {
102102
swagger.info = Info().version("v1").title("API specification")
103103
swagger.schemes = Arrays.asList(Scheme.HTTP, Scheme.HTTPS)
104104

105-
swagger.path("/connections",
105+
swagger.path("/endpoints",
106106
Path().get(Operation()
107-
.tag("connections")
107+
.tag("endpoints")
108108
.response(200,
109109
Response()
110110
.description("Ok")

src/main/resources/application.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ conf:
4848
driverClassName: org.h2.Driver
4949
properties: >
5050
{
51+
"url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';"
5152
"color": "red",
5253
"description": "Production demo db",
5354
"css_class": "fas fa-fw fa-2x fa-bicycle"

src/test/kotlin/com/github/mgramin/sqlboot/model/connection/EndpointListTest.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@ import org.springframework.test.context.junit.jupiter.SpringExtension
3737

3838
@ExtendWith(SpringExtension::class)
3939
@EnableAutoConfiguration
40-
@ContextConfiguration(classes = [DbConnectionList::class], initializers = [ConfigFileApplicationContextInitializer::class])
40+
@ContextConfiguration(classes = [EndpointList::class], initializers = [ConfigFileApplicationContextInitializer::class])
4141
internal class EndpointListTest {
4242

4343
@Autowired
44-
lateinit var dbConnectionList: DbConnectionList
44+
lateinit var endpointList: EndpointList
4545

4646
@ParameterizedTest
4747
@ValueSource(strings = ["test", "dev", "prod"])
4848
fun getConnectionByName(connectionName: String) {
49-
assertEquals(connectionName, dbConnectionList.getConnectionByName(connectionName).name())
49+
assertEquals(connectionName, endpointList.getConnectionByName(connectionName).name())
5050
}
5151

5252
@ParameterizedTest
5353
@ValueSource(strings = ["test", "dev", "prod"])
5454
fun getConnectionsByMask(connectionMask: String) {
55-
assertEquals(connectionMask, dbConnectionList.getConnectionsByMask(connectionMask).first().name())
55+
assertEquals(connectionMask, endpointList.getConnectionsByMask(connectionMask).first().name())
5656
}
5757

5858
@Test
5959
fun getConnections() {
60-
assertEquals(4, dbConnectionList.connections.count())
60+
assertEquals(4, endpointList.endpoints.count())
6161
}
6262

6363
}

src/test/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/FsResourceTypeTest.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ class FsResourceTypeTest {
5656
dbMd.name = "unit_test_db_md"
5757
dbMd.dialect = "h2"
5858
dbMd.baseFolder = FileSystemResource("conf/h2/md/database")
59-
dbMd.url = "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';"
6059
dbMd.paginationQueryTemplate = "${'$'}{query} offset ${'$'}{uri.pageSize()*(uri.pageNumber()-1)} limit ${'$'}{uri.pageSize()}"
60+
dbMd.properties = """{ "url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';" }"""
6161

6262
dbSql.name = "unit_test_db_sql"
6363
dbSql.dialect = "h2"
6464
dbSql.baseFolder = FileSystemResource("conf/h2/sql/database")
65-
dbSql.url = "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';"
66-
dbSql.paginationQueryTemplate = "${'$'}{query} offset ${'$'}{uri.pageSize()*(uri.pageNumber()-1)} limit ${'$'}{uri.pageSize()}"
6765
dbSql.paginationQueryTemplate = "${'$'}{query} offset ${'$'}{uri.pageSize()*(uri.pageNumber()-1)} limit ${'$'}{uri.pageSize()}"
66+
dbSql.properties = """{ "url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';" }"""
6867
}
6968

7069
@ParameterizedTest

src/test/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/SqlResourceTypeTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class SqlResourceTypeTest {
5353
db.name = "unit_test_db"
5454
db.dialect = "h2"
5555
db.baseFolder = FileSystemResource("conf/h2/database")
56-
db.url = "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';"
5756
db.paginationQueryTemplate = "${'$'}{query} offset ${'$'}{uri.pageSize()*(uri.pageNumber()-1)} limit ${'$'}{uri.pageSize()}"
57+
db.properties = """{ "url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';" }"""
5858
}
5959

6060
@Test

src/test/resources/application.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ conf:
55
paginationQueryTemplate: >
66
${query} offset ${uri.pageSize()*(uri.pageNumber()-1)} limit ${uri.pageSize()}
77
8-
connections:
8+
endpoints:
99
- name: h2
1010
dialect: h2
1111
baseFolder: file:conf/h2/md/database
12-
url: jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';
1312
driverClassName: org.h2.Driver
1413
properties: >
1514
{
15+
"url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';",
1616
"visible": false,
1717
"description": "Embedded db for unit tests only"
1818
}
1919
- name: dev
2020
dialect: h2
2121
baseFolder: file:conf/h2/md/database
22-
url: jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';
2322
driverClassName: org.h2.Driver
2423
properties: >
2524
{
25+
"url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';",
2626
"visible": false,
2727
"color": "green",
2828
"description": "Develop demo db",
@@ -31,10 +31,10 @@ conf:
3131
- name: test
3232
dialect: h2
3333
baseFolder: file:conf/h2/md/database
34-
url: jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';
3534
driverClassName: org.h2.Driver
3635
properties: >
3736
{
37+
"url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';",
3838
"visible": false,
3939
"color": "orange",
4040
"description": "Testing demo db",
@@ -43,10 +43,10 @@ conf:
4343
- name: prod
4444
dialect: h2
4545
baseFolder: file:conf/h2/md/database
46-
url: jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';
4746
driverClassName: org.h2.Driver
4847
properties: >
4948
{
49+
"url": "jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'classpath:schema.sql';",
5050
"visible": false,
5151
"color": "red",
5252
"description": "Production demo db",

0 commit comments

Comments
 (0)