@@ -26,7 +26,6 @@ package com.github.mgramin.sqlboot.rest.controllers
2626
2727import com.github.mgramin.sqlboot.exceptions.BootException
2828import com.github.mgramin.sqlboot.model.connection.DbConnectionList
29- import com.github.mgramin.sqlboot.model.resource.DbResource
3029import com.github.mgramin.sqlboot.model.resourcetype.Metadata
3130import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
3231import 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 ,
0 commit comments