Skip to content

Commit 421899c

Browse files
committed
1 parent ac99d52 commit 421899c

File tree

14 files changed

+392
-203
lines changed

14 files changed

+392
-203
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import com.github.mgramin.sqlboot.model.uri.impl.DbUri
4343
import com.github.mgramin.sqlboot.model.uri.impl.FakeUri
4444
import com.github.mgramin.sqlboot.sql.select.SelectQuery
4545
import com.github.mgramin.sqlboot.sql.select.impl.SimpleSelectQuery
46+
import com.github.mgramin.sqlboot.sql.select.wrappers.CustomFilteredSelectQuery
4647
import com.github.mgramin.sqlboot.sql.select.wrappers.FilteredSelectQuery
4748
import com.github.mgramin.sqlboot.sql.select.wrappers.GrafanaSelectQuery
4849
import com.github.mgramin.sqlboot.sql.select.wrappers.JdbcSelectQuery
@@ -131,8 +132,10 @@ class SqlResourceType(
131132
GrafanaSelectQuery(
132133
PaginatedSelectQuery(
133134
OrderedSelectQuery(
134-
FilteredSelectQuery(
135-
simpleSelectQuery, uri.path()),
135+
CustomFilteredSelectQuery(
136+
FilteredSelectQuery(
137+
simpleSelectQuery, uri.path()),
138+
uri.filter()),
136139
uri.orderedColumns()),
137140
uri,
138141
paginationQueryTemplate)),

src/main/kotlin/com/github/mgramin/sqlboot/model/resourcetype/wrappers/list/WhereWrapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class WhereWrapper(private val origin: ResourceType) : ResourceType {
5656
val resources = origin.read(uri)
5757
return resources
5858
.filter { resource ->
59-
for (i in 0 until uri.path().size) {
59+
for (i in uri.path().indices) {
6060
val contains = resource.dbUri().path()[i]
6161
.toLowerCase().contains(uri.path()[i]
6262
.toLowerCase()) || uri.path()[i] == "%"

src/main/kotlin/com/github/mgramin/sqlboot/model/uri/Uri.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
package com.github.mgramin.sqlboot.model.uri
3434

3535
import com.fasterxml.jackson.annotation.JsonProperty
36+
import com.google.gson.JsonObject
37+
import com.google.gson.JsonParser
3638
import org.apache.commons.lang3.StringUtils
3739
import java.io.Serializable
3840

@@ -124,4 +126,12 @@ interface Uri : Serializable {
124126
.toMap()
125127
}
126128

129+
fun filter(): JsonObject {
130+
return if (params().containsKey("filter")) {
131+
JsonParser().parse(params()["filter"]).asJsonObject
132+
} else {
133+
JsonObject()
134+
}
135+
}
136+
127137
}

src/main/kotlin/com/github/mgramin/sqlboot/model/uri/impl/DbUri.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class DbUri : Uri {
5858

5959
constructor(uriString: String) {
6060
try {
61-
val str = uriString.replace("|", "%7C")
62-
val uri = URI(str)
63-
61+
val uri = URI(uriString.replace("|", "%7C").replace("{", "%7B").replace("}", "%7D").replace(":", "%3A").replace(""""""", "%22"))
6462
val pathMap: Map<Int, String> = uri.path
6563
.split("/")
6664
.filter { it.isNotEmpty() }
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* BSD 3-Clause License
3+
*
4+
* Copyright (c) 2019, CROC Inc.
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice, this
11+
* list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* 3. Neither the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived from
19+
* this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package com.github.mgramin.sqlboot.sql.select.wrappers
34+
35+
import com.github.mgramin.sqlboot.sql.select.SelectQuery
36+
import com.google.gson.JsonObject
37+
38+
39+
class CustomFilteredSelectQuery(
40+
private val origin: SelectQuery,
41+
private val filter: JsonObject
42+
) : SelectQuery {
43+
44+
override fun query(): String {
45+
return if (filter.entrySet().size > 0) {
46+
val whereCondition = filter.entrySet()
47+
.joinToString(prefix = "where ", separator = " and ") { """${it.key} = '${it.value.asString}'""" }
48+
"""select *
49+
| from (${origin.query()}) q
50+
| $whereCondition""".trimMargin()
51+
} else {
52+
origin.query()
53+
}
54+
}
55+
56+
override fun properties() = origin.properties()
57+
58+
override fun columns() = origin.columns()
59+
60+
override fun execute(variables: Map<String, Any>) = origin.execute(variables)
61+
}

src/main/kotlin/com/github/mgramin/sqlboot/sql/select/wrappers/FilteredSelectQuery.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class FilteredSelectQuery(
4242
override fun properties() = origin.properties()
4343

4444
override fun query(): String {
45+
println("!!!!!!!!!!!!!!!!")
4546
return if (path.isEmpty()) {
4647
origin.query()
4748
} else {
@@ -51,8 +52,8 @@ class FilteredSelectQuery(
5152
.mapIndexed { index, s -> """lower(${s.key}) like lower('${path[index]}')""" }
5253
.joinToString(prefix = "where ", separator = " and ")
5354
"""select *
54-
| from (${origin.query()}) q
55-
| $whereCondition""".trimMargin()
55+
| from (${origin.query()}) q
56+
| $whereCondition""".trimMargin()
5657
}
5758
}
5859

src/main/malewicz/src/components/ConnectionsListPanel.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
</template>
1818

1919
<script>
20-
export default {
21-
name: 'ConnectionsListPanel',
22-
data() {
23-
return {}
24-
}
20+
export default {
21+
name: 'ConnectionsListPanel',
22+
data () {
23+
return {}
2524
}
25+
}
2626
</script>

src/main/malewicz/src/components/CustomComponent.vue

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,57 +48,57 @@
4848
</div>
4949
</template>
5050
<script>
51-
import moment from 'moment'
51+
import moment from 'moment'
5252
53-
export default {
54-
name: 'CustomComponent',
55-
props: {
56-
met: {},
57-
props: {}
53+
export default {
54+
name: 'CustomComponent',
55+
props: {
56+
met: {},
57+
props: {}
58+
},
59+
filters: {
60+
formatDate: function (value) {
61+
if (value) {
62+
return moment(String(value)).format('DD.MM.YYYY HH:mm:ss')
63+
}
64+
},
65+
round: function (value, decimals) {
66+
if (typeof value !== 'number') {
67+
return value
68+
}
69+
if (!value) {
70+
value = 0
71+
}
72+
if (!decimals) {
73+
decimals = 0
74+
}
75+
value = Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals)
76+
return value
5877
},
59-
filters: {
60-
formatDate: function (value) {
61-
if (value) {
62-
return moment(String(value)).format('DD.MM.YYYY HH:mm:ss')
63-
}
64-
},
65-
round: function (value, decimals) {
66-
if(typeof value !== 'number'){
67-
return value
68-
}
69-
if(!value) {
70-
value = 0;
71-
}
72-
if (!decimals) {
73-
decimals = 0;
74-
}
75-
value = Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals)
76-
return value;
77-
},
78-
prettyByte: function (num) {
79-
if (typeof num !== 'number' || isNaN(num)) {
80-
throw new TypeError('Expected a number');
81-
}
78+
prettyByte: function (num) {
79+
if (typeof num !== 'number' || isNaN(num)) {
80+
throw new TypeError('Expected a number')
81+
}
8282
83-
var exponent;
84-
var unit;
85-
var neg = num < 0;
86-
var units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
83+
var exponent
84+
var unit
85+
var neg = num < 0
86+
var units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
8787
88-
if (neg) {
89-
num = -num;
90-
}
88+
if (neg) {
89+
num = -num
90+
}
9191
92-
if (num < 1) {
93-
return (neg ? '-' : '') + num + ' B';
94-
}
92+
if (num < 1) {
93+
return (neg ? '-' : '') + num + ' B'
94+
}
9595
96-
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1);
97-
num = (num / Math.pow(1000, exponent)).toFixed(2) * 1;
98-
unit = units[exponent];
96+
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1)
97+
num = (num / Math.pow(1000, exponent)).toFixed(2) * 1
98+
unit = units[exponent]
9999
100-
return (neg ? '-' : '') + num + ' ' + unit;
101-
}
100+
return (neg ? '-' : '') + num + ' ' + unit
102101
}
103102
}
103+
}
104104
</script>

src/main/malewicz/src/components/HelloWorld.vue

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@
2626

2727
<script>
2828
29-
import TypesListPanel from './TypesListPanel'
30-
import ConnectionsListPanel from './ConnectionsListPanel'
31-
import ObjectsTablePanel from './ObjectsTablePanel'
29+
import TypesListPanel from './TypesListPanel'
30+
import ConnectionsListPanel from './ConnectionsListPanel'
31+
import ObjectsTablePanel from './ObjectsTablePanel'
3232
33-
export default {
34-
data: () => ({
33+
export default {
34+
data: () => ({
3535
drawer: true,
3636
drawerRight: true,
3737
right: null,
3838
left: null
3939
}),
4040
41-
props: ['panel'],
42-
name: 'HelloWorld',
43-
components: {ObjectsTablePanel, ConnectionsListPanel, TypesListPanel},
44-
watch: {
45-
$route(to, from) {
46-
this.$store.commit('changeUri', to.fullPath)
47-
},
48-
getSimpleUri: function (newUri, oldUri) {
49-
this.$router.push({path: '/' + newUri})
50-
}
41+
props: ['panel'],
42+
name: 'HelloWorld',
43+
components: {ObjectsTablePanel, ConnectionsListPanel, TypesListPanel},
44+
watch: {
45+
$route (to, from) {
46+
this.$store.commit('changeUri', to.fullPath)
5147
},
52-
computed: {
53-
getSimpleUri() {
54-
return this.$store.getters.getSimpleUri
55-
}
56-
},
57-
created: function () {
58-
this.$store.commit('changeUri', this.$router.currentRoute.fullPath)
48+
getSimpleUri: function (newUri, oldUri) {
49+
this.$router.push({path: '/' + newUri})
50+
}
51+
},
52+
computed: {
53+
getSimpleUri () {
54+
return this.$store.getters.getSimpleUri
5955
}
56+
},
57+
created: function () {
58+
this.$store.commit('changeUri', this.$router.currentRoute.fullPath)
6059
}
60+
}
6161
6262
</script>

0 commit comments

Comments
 (0)