@@ -29,6 +29,7 @@ import com.github.mgramin.sqlboot.model.connection.DbConnectionList
2929import com.github.mgramin.sqlboot.model.resourcetype.Metadata
3030import com.github.mgramin.sqlboot.model.resourcetype.ResourceType
3131import com.github.mgramin.sqlboot.model.resourcetype.impl.composite.FsResourceTypes
32+ import com.github.mgramin.sqlboot.model.uri.Uri
3233import com.github.mgramin.sqlboot.model.uri.impl.DbUri
3334import com.github.mgramin.sqlboot.model.uri.impl.FakeUri
3435import com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper
@@ -67,77 +68,27 @@ class ApiController {
6768 }
6869
6970
70- @RequestMapping(value = [" /api/{connectionName}/headers/ **" ], method = [GET , POST ])
71+ @RequestMapping(value = [" /api/{connectionName}/**" ], method = [GET , POST ])
7172 fun getResourcesHeadersJson (
7273 request : HttpServletRequest ,
7374 @PathVariable connectionName : String
7475 ): ResponseEntity <List <Map <String , Any >>> {
75- val filter = request.servletPath
76+ val uriString = request.servletPath
7677 .split(" /" )
78+ .asSequence()
7779 .filter { it.isNotEmpty() }
7880 .filter { it != " api" }
79- .filterIndexed{ index, _ -> index != 0 && index != 1 }
81+ .filter { it != " headers" }
82+ .filterIndexed { index, _ -> index != 0 }
8083 .joinToString(separator = " /" ) { it }
81- return getListResponseEntityHeaders(request, connectionName, filter)
84+ val uri: Uri = SqlPlaceholdersWrapper (DbUri (parseUri(uriString, request)))
85+ return getListResponseEntityHeaders(uri, connectionName)
8286 }
8387
84-
85-
86- @RequestMapping(value = [" /api/{connectionName}/meta/{type}" ], method = [GET , POST ])
87- fun getResourceMetadata (
88- request : HttpServletRequest ,
89- @PathVariable connectionName : String ,
90- @PathVariable type : String
91- ): ResponseEntity <List <Metadata >> {
92- val uri = SqlPlaceholdersWrapper (DbUri (parseUri(type, request)))
93- return responseEntity(connectionName, uri)
94- }
95-
96-
97- @RequestMapping(value = [" /api/{connectionName}/meta/{type}/{path:.+}" ], method = [GET , POST ])
98- fun getResourceMetadata2 (
99- request : HttpServletRequest ,
100- @PathVariable connectionName : String ,
101- @PathVariable type : String ,
102- @PathVariable path : String
103- ): ResponseEntity <List <Metadata >> {
104- val uri = SqlPlaceholdersWrapper (DbUri (parseUri(path, request)))
105- return responseEntity(connectionName, uri)
106- }
107-
108-
109- @RequestMapping(value = [" /api/{connectionName}/meta/{type}/{path:.+}/{action}" ], method = [GET , POST ])
110- fun getResourceMetadata3 (
111- request : HttpServletRequest ,
112- @PathVariable connectionName : String ,
113- @PathVariable type : String ,
114- @PathVariable path : String ,
115- @PathVariable action : String
116- ): ResponseEntity <List <Metadata >> {
117- val uri = SqlPlaceholdersWrapper (DbUri (parseUri(" $type /$path /$action " , request)))
118- return responseEntity(connectionName, uri)
119- }
120-
121- private fun responseEntity (connectionName : String , uri : SqlPlaceholdersWrapper ): ResponseEntity <List <Metadata >> {
122- val fsResourceTypes = FsResourceTypes (
123- listOf (dbConnectionList.getConnectionByName(connectionName)), uri)
124- val resourceType = fsResourceTypes
125- .resourceTypes()
126- .stream()
127- .filter { v -> v.name().equals(uri.type(), ignoreCase = true ) }
128- .findAny()
129- .orElse(null ) ? : return ResponseEntity (ArrayList (), HttpStatus .NO_CONTENT )
130- return ResponseEntity (resourceType.metaData(uri), HttpStatus .OK )
131- }
132-
133-
134-
13588 private fun getListResponseEntityHeaders (
136- request : HttpServletRequest ,
137- connectionName : String ,
138- path : String
89+ uri : Uri ,
90+ connectionName : String
13991 ): ResponseEntity <List <Map <String , Any >>> {
140- val uri = SqlPlaceholdersWrapper (DbUri (parseUri(path, request)))
14192 val connections = dbConnectionList.getConnectionsByMask(connectionName)
14293 try {
14394 val headers = FsResourceTypes (connections, uri)
@@ -159,6 +110,36 @@ class ApiController {
159110 }
160111
161112
113+ @RequestMapping(value = [" /api/meta/{connectionName}/**" ], method = [GET , POST ])
114+ fun getResourceMetadata (
115+ request : HttpServletRequest ,
116+ @PathVariable connectionName : String
117+ ): ResponseEntity <List <Metadata >> {
118+ val uriString = request.servletPath
119+ .split(" /" )
120+ .filter { it.isNotEmpty() }
121+ .filter { it != " api" }
122+ .filter { it != " meta" }
123+ .filterIndexed { index, _ -> index != 0 }
124+ .joinToString(separator = " /" ) { it }
125+ val uri = SqlPlaceholdersWrapper (DbUri (parseUri(uriString, request)))
126+ return responseEntity(connectionName, uri)
127+ }
128+
129+
130+ private fun responseEntity (connectionName : String , uri : Uri ): ResponseEntity <List <Metadata >> {
131+ val fsResourceTypes = FsResourceTypes (
132+ listOf (dbConnectionList.getConnectionByName(connectionName)), uri)
133+ val resourceType = fsResourceTypes
134+ .resourceTypes()
135+ .stream()
136+ .filter { v -> v.name().equals(uri.type(), ignoreCase = true ) }
137+ .findAny()
138+ .orElse(null ) ? : return ResponseEntity (ArrayList (), HttpStatus .NO_CONTENT )
139+ return ResponseEntity (resourceType.metaData(uri), HttpStatus .OK )
140+ }
141+
142+
162143 private fun parseUri (path : String , request : HttpServletRequest ): String {
163144 return if (request.queryString == null || request.queryString.isEmpty()) {
164145 path
0 commit comments