Skip to content

Commit 659805b

Browse files
committed
1 parent 1bb1899 commit 659805b

3 files changed

Lines changed: 24 additions & 86 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerato
3838
import com.github.mgramin.sqlboot.tools.files.file.impl.SimpleFile
3939
import reactor.core.publisher.Flux
4040
import java.io.File
41-
import java.lang.Exception
4241
import java.nio.charset.Charset
4342
import java.nio.charset.StandardCharsets.UTF_8
4443

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

Lines changed: 9 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package com.github.mgramin.sqlboot.rest.controllers
2626

2727
import com.github.mgramin.sqlboot.exceptions.BootException
2828
import com.github.mgramin.sqlboot.model.connection.DbConnectionList
29-
import com.github.mgramin.sqlboot.model.resource.DbResource
3029
import com.github.mgramin.sqlboot.model.resourcetype.Metadata
3130
import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
3231
import com.github.mgramin.sqlboot.model.resourcetype.impl.composite.FsResourceTypes
@@ -68,66 +67,20 @@ class ApiController {
6867
}
6968

7069

71-
@RequestMapping(value = ["/api/{connectionName}/{type}"])
72-
fun getResourcesEntireJson(
73-
request: HttpServletRequest,
74-
@PathVariable connectionName: String,
75-
@PathVariable type: String
76-
): ResponseEntity<List<DbResource>> {
77-
return getListResponseEntity(request, connectionName, type)
78-
}
79-
80-
@RequestMapping(value = ["/api/{connectionName}/{type}/{path:.+}"])
81-
fun getResourcesEntireJson2(
82-
request: HttpServletRequest,
83-
@PathVariable connectionName: String,
84-
@PathVariable type: String,
85-
@PathVariable path: String
86-
): ResponseEntity<List<DbResource>> {
87-
return getListResponseEntity(request, connectionName, "$type/$path")
88-
}
89-
90-
@RequestMapping(value = ["/api/{connectionName}/{type}/{path:.+}/{action}"])
91-
fun getResourcesEntireJson3(
92-
request: HttpServletRequest,
93-
@PathVariable connectionName: String,
94-
@PathVariable type: String,
95-
@PathVariable path: String,
96-
@PathVariable action: String
97-
): ResponseEntity<List<DbResource>> {
98-
return getListResponseEntity(request, connectionName, "$type/$path/$action")
99-
}
100-
101-
102-
@RequestMapping(value = ["/api/{connectionName}/headers/{type}"], method = [GET, POST])
70+
@RequestMapping(value = ["/api/{connectionName}/headers/**"], method = [GET, POST])
10371
fun getResourcesHeadersJson(
10472
request: HttpServletRequest,
105-
@PathVariable connectionName: String,
106-
@PathVariable type: String
107-
): ResponseEntity<List<Map<String, Any>>> {
108-
return getListResponseEntityHeaders(request, connectionName, type)
109-
}
110-
111-
@RequestMapping(value = ["/api/{connectionName}/headers/{type}/{path:.+}"], method = [GET, POST])
112-
fun getResourcesHeadersJson2(
113-
request: HttpServletRequest,
114-
@PathVariable connectionName: String,
115-
@PathVariable type: String,
116-
@PathVariable path: String
73+
@PathVariable connectionName: String
11774
): ResponseEntity<List<Map<String, Any>>> {
118-
return getListResponseEntityHeaders(request, connectionName, "$type/$path")
75+
val filter = request.servletPath
76+
.split("/")
77+
.filter { it.isNotEmpty() }
78+
.filter { it != "api" }
79+
.filterIndexed{ index, _ -> index != 0 && index != 1 }
80+
.joinToString(separator = "/") { it }
81+
return getListResponseEntityHeaders(request, connectionName, filter)
11982
}
12083

121-
@RequestMapping(value = ["/api/{connectionName}/headers/{type}/{path:.+}/{action}"], method = [GET, POST])
122-
fun getResourcesHeadersJson3(
123-
request: HttpServletRequest,
124-
@PathVariable connectionName: String,
125-
@PathVariable type: String,
126-
@PathVariable path: String,
127-
@PathVariable action: String
128-
): ResponseEntity<List<Map<String, Any>>> {
129-
return getListResponseEntityHeaders(request, connectionName, "$type/$path/$action")
130-
}
13184

13285

13386
@RequestMapping(value = ["/api/{connectionName}/meta/{type}"], method = [GET, POST])
@@ -178,31 +131,6 @@ class ApiController {
178131
}
179132

180133

181-
private fun getListResponseEntity(
182-
request: HttpServletRequest,
183-
connectionName: String?,
184-
type: String
185-
): ResponseEntity<List<DbResource>> {
186-
val uri = SqlPlaceholdersWrapper(DbUri(parseUri(type, request)))
187-
val connections = dbConnectionList.getConnectionsByMask(connectionName!!)
188-
val result = ArrayList<DbResource>()
189-
val fsResourceTypes = FsResourceTypes(connections, uri)
190-
try {
191-
val collect = fsResourceTypes.read(uri).collectList().block()
192-
result.addAll(collect)
193-
return if (result.isEmpty()) {
194-
ResponseEntity(result, HttpStatus.NO_CONTENT)
195-
} else {
196-
ResponseEntity(result, HttpStatus.OK)
197-
}
198-
} catch (e: BootException) {
199-
if (e.errorCode == 404) {
200-
return ResponseEntity(result, HttpStatus.NOT_FOUND)
201-
}
202-
return ResponseEntity(result, HttpStatus.INTERNAL_SERVER_ERROR)
203-
}
204-
}
205-
206134

207135
private fun getListResponseEntityHeaders(
208136
request: HttpServletRequest,

src/test/kotlin/com/github/mgramin/sqlboot/rest/controllers/ApiControllerITCase.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package com.github.mgramin.sqlboot.rest.controllers
2626

2727
import com.github.mgramin.sqlboot.rest.Application
2828
import org.junit.jupiter.api.Assertions.assertEquals
29-
import org.junit.jupiter.api.Test
3029
import org.junit.jupiter.api.extension.ExtendWith
3130
import org.junit.jupiter.params.ParameterizedTest
3231
import org.junit.jupiter.params.provider.CsvSource
@@ -52,19 +51,31 @@ class ApiControllerITCase {
5251
private val client: TestRestTemplate? = null
5352

5453

55-
@ParameterizedTest
54+
/*@ParameterizedTest
5655
@CsvSource(
57-
"204#/api/h2/headers/table/foo",
5856
"200#/api/h2/table/BOOKINGS.AIRCRAFTS",
5957
"204#/api/h2/table/not_exist_schema",
6058
"200#/api/h2/table",
6159
"404#/api/h2/not_exist_type",
6260
"200#/api/h2/table/BOOKINGS.AIRPORTS?select=remarks",
61+
delimiter = '#'
62+
)
63+
fun test(code : Int, uri : String) {
64+
val headers = HttpHeaders()
65+
headers.contentType = MediaType.TEXT_PLAIN
66+
val result = client!!.exchange(uri, HttpMethod.GET, HttpEntity<Any>(headers), String::class.java)
67+
assertEquals(code, result.statusCodeValue)
68+
}*/
69+
70+
71+
@ParameterizedTest
72+
@CsvSource(
73+
"204#/api/h2/headers/table/foo",
6374
"200#/api/h2/headers/table/BOOKINGS",
6475
"200#/api/h2/headers/table",
6576
delimiter = '#'
6677
)
67-
fun test(code : Int, uri : String) {
78+
fun testHeaders(code : Int, uri : String) {
6879
val headers = HttpHeaders()
6980
headers.contentType = MediaType.TEXT_PLAIN
7081
val result = client!!.exchange(uri, HttpMethod.GET, HttpEntity<Any>(headers), String::class.java)

0 commit comments

Comments
 (0)