Skip to content

Commit 6334d57

Browse files
committed
1 parent 2eccca9 commit 6334d57

File tree

11 files changed

+122
-120
lines changed

11 files changed

+122
-120
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
[![Join the chat at https://gitter.im/sqlboot/Lobby](https://badges.gitter.im/sqlboot/Lobby.svg)](https://gitter.im/sqlboot/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1212
[![EO badge](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org/)
1313
[![DevOps By Rultor.com](http://www.rultor.com/b/sql-boot/sql-boot)](http://www.rultor.com/p/sql-boot/sql-boot)
14+
[![Hits-of-Code](https://hitsofcode.com/github/sql-boot/sql-boot)](https://hitsofcode.com/view/github/sql-boot/sql-boot)
15+
1416

1517
Advanced REST-wrapper for your own SQL-queries (actually not only SQL).
1618

src/main/kotlin/com/github/mgramin/sqlboot/model/resource/impl/FakeDbResource.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import com.github.mgramin.sqlboot.model.resource.DbResource
2828
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
2929
import com.github.mgramin.sqlboot.model.resourcetype.impl.FakeResourceType
3030
import com.github.mgramin.sqlboot.model.uri.Uri
31-
import com.google.common.collect.ImmutableMap.of
3231

3332
/**
3433
* Created by maksim on 22.05.17.
@@ -48,9 +47,10 @@ class FakeDbResource(private val uri: Uri) : DbResource {
4847
}
4948

5049
override fun headers(): Map<String, Any> {
51-
return of<String, Any>("schema", "hr",
52-
"table", "persons",
53-
"file", "table.hr.persons.sql")
50+
return mapOf(
51+
"schema" to "hr",
52+
"table" to "persons",
53+
"file" to "table.hr.persons.sql")
5454
}
5555

5656
override fun body(): String {

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/Metadata.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.github.mgramin.sqlboot.model.resourcetype
33
import com.fasterxml.jackson.annotation.JsonAutoDetect
44
import com.google.gson.Gson
55
import com.google.gson.reflect.TypeToken
6-
import java.util.HashMap
6+
import java.util.*
77

88
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
99
data class Metadata(

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/impl/FakeResourceType.kt

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,19 @@ import java.util.Arrays.asList
3939
*/
4040
class FakeResourceType : ResourceType {
4141

42-
override fun aliases(): List<String> {
43-
return asList("fake_resource_type", "fake_type", "frt", "f")
44-
}
45-
46-
override fun path(): List<String> {
47-
return arrayListOf("schema", "table", "index")
48-
}
49-
50-
override fun read(uri: Uri): Flux<DbResource> {
51-
return sequenceOf(
52-
FakeDbResource(DbUri("prod/table/hr.persons")),
53-
FakeDbResource(DbUri("prod/table/hr.users")),
54-
FakeDbResource(DbUri("prod/table/hr.jobs"))).toFlux()
55-
}
56-
57-
override fun metaData(uri: Uri): List<Metadata> {
58-
return listOf(Metadata("@schema", "Schema name"),
59-
Metadata("@table", "Table name"),
60-
Metadata("@index", "Index name"))
61-
}
42+
override fun aliases() = asList("fake_resource_type", "fake_type", "frt", "f")
43+
44+
override fun path() = arrayListOf("schema", "table", "index")
45+
46+
override fun read(uri: Uri): Flux<DbResource> =
47+
sequenceOf(
48+
FakeDbResource(DbUri("prod/table/hr.persons")),
49+
FakeDbResource(DbUri("prod/table/hr.users")),
50+
FakeDbResource(DbUri("prod/table/hr.jobs"))).toFlux()
51+
52+
override fun metaData(uri: Uri) =
53+
listOf(Metadata("@schema", "Schema name"),
54+
Metadata("@table", "Table name"),
55+
Metadata("@index", "Index name"))
56+
6257
}

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/wrappers/header/DbNameWrapper.kt

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,27 @@ import reactor.core.publisher.Flux
3434
class DbNameWrapper(private val origin: ResourceType,
3535
private val dbConnection: DbConnection) : ResourceType {
3636

37-
override fun aliases(): List<String> {
38-
return origin.aliases()
39-
}
40-
41-
override fun path(): List<String> {
42-
return origin.path()
43-
}
44-
45-
override fun metaData(uri: Uri): List<Metadata> = origin.metaData(uri) + Metadata("database", "Database name")
46-
47-
override fun read(uri: Uri): Flux<DbResource> {
48-
return origin.read(uri).map {
49-
return@map object : DbResource {
50-
51-
override fun name(): String {
52-
return it.name()
53-
}
54-
55-
override fun type(): ResourceType {
56-
return it.type()
57-
}
58-
59-
override fun dbUri(): Uri {
60-
return it.dbUri()
61-
}
62-
63-
override fun headers(): Map<String, Any> {
64-
val headers = it.headers().toMutableMap()
65-
headers["database"] = dbConnection.name()
66-
return headers
67-
}
68-
69-
override fun body(): String {
70-
return it.body()
71-
}
72-
}
73-
}
74-
}
37+
override fun aliases() = origin.aliases()
38+
39+
override fun path() = origin.path()
40+
41+
override fun metaData(uri: Uri) = origin.metaData(uri) + Metadata("database", "Database name")
42+
43+
override fun read(uri: Uri): Flux<DbResource> =
44+
origin
45+
.read(uri)
46+
.map {
47+
return@map object : DbResource {
48+
override fun name() = it.name()
49+
override fun type() = it.type()
50+
override fun dbUri() = it.dbUri()
51+
override fun body() = it.body()
52+
override fun headers(): Map<String, Any> {
53+
val headers = it.headers().toMutableMap()
54+
headers["database"] = dbConnection.name()
55+
return headers
56+
}
57+
}
58+
}
7559

7660
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.mgramin.sqlboot.model.resourcetype.wrappers.header
2+
3+
import com.github.mgramin.sqlboot.model.resource.DbResource
4+
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
5+
import com.github.mgramin.sqlboot.model.uri.Uri
6+
import reactor.core.publisher.Flux
7+
8+
9+
class TypeWrapper(private val origin: ResourceType) : ResourceType {
10+
11+
override fun aliases() = origin.aliases()
12+
13+
override fun path() = origin.path()
14+
15+
override fun metaData(uri: Uri) = origin.metaData(uri)
16+
17+
override fun read(uri: Uri): Flux<DbResource> =
18+
origin
19+
.read(uri)
20+
.map {
21+
return@map object : DbResource {
22+
override fun name() = it.name()
23+
override fun type() = it.type()
24+
override fun dbUri() = it.dbUri()
25+
override fun body() = it.body()
26+
override fun headers(): Map<String, Any> {
27+
return it.headers().toMutableMap()
28+
}
29+
30+
}
31+
}
32+
33+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import org.springframework.web.bind.annotation.RequestMapping
4444
import org.springframework.web.bind.annotation.RequestMethod.GET
4545
import org.springframework.web.bind.annotation.RequestMethod.POST
4646
import org.springframework.web.bind.annotation.RestController
47-
import java.util.ArrayList
47+
import java.util.*
4848
import javax.servlet.http.HttpServletRequest
4949

5050
/**

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired
3232
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
3333
import org.springframework.context.annotation.ComponentScan
3434
import org.springframework.http.MediaType
35-
import org.springframework.web.bind.annotation.CrossOrigin
36-
import org.springframework.web.bind.annotation.GetMapping
37-
import org.springframework.web.bind.annotation.RequestMapping
38-
import org.springframework.web.bind.annotation.ResponseBody
39-
import org.springframework.web.bind.annotation.RestController
35+
import org.springframework.web.bind.annotation.*
4036
import reactor.core.publisher.Flux
4137
import reactor.core.publisher.toFlux
4238
import reactor.core.scheduler.Schedulers

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ package com.github.mgramin.sqlboot.rest.controllers
2727
import com.fasterxml.jackson.core.JsonProcessingException
2828
import com.github.mgramin.sqlboot.model.connection.DbConnectionList
2929
import com.github.mgramin.sqlboot.model.resourcetype.impl.FsResourceType
30-
import io.swagger.models.Info
31-
import io.swagger.models.ModelImpl
32-
import io.swagger.models.Operation
33-
import io.swagger.models.Path
34-
import io.swagger.models.Response
35-
import io.swagger.models.Scheme
36-
import io.swagger.models.Swagger
30+
import io.swagger.models.*
3731
import io.swagger.models.parameters.Parameter
3832
import io.swagger.models.parameters.PathParameter
3933
import io.swagger.models.parameters.QueryParameter
@@ -48,8 +42,7 @@ import org.springframework.web.bind.annotation.PathVariable
4842
import org.springframework.web.bind.annotation.RequestMapping
4943
import org.springframework.web.bind.annotation.RequestMethod
5044
import org.springframework.web.bind.annotation.RequestParam
51-
import java.util.ArrayList
52-
import java.util.Arrays
45+
import java.util.*
5346
import java.util.stream.Collectors
5447
import javax.servlet.http.HttpServletRequest
5548

src/main/kotlin/com/github/mgramin/sqlboot/tools/files/file/impl/MarkdownFile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.commonmark.node.FencedCodeBlock
3030
import org.commonmark.node.Heading
3131
import org.commonmark.node.Text
3232
import org.commonmark.parser.Parser
33-
import java.util.LinkedHashMap
33+
import java.util.*
3434

3535
/**
3636
* @author Maksim Gramin ([email protected])

0 commit comments

Comments
 (0)