Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
d130af96
Commit
d130af96
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Fix tiles endpoint & add test
parent
96c14055
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/tiles.clj
+8
-11
8 additions, 11 deletions
src/metabase/api/tiles.clj
src/metabase/util/schema.clj
+1
-0
1 addition, 0 deletions
src/metabase/util/schema.clj
test/metabase/api/tiles_test.clj
+16
-0
16 additions, 0 deletions
test/metabase/api/tiles_test.clj
with
25 additions
and
11 deletions
src/metabase/api/tiles.clj
+
8
−
11
View file @
d130af96
(
ns
metabase.api.tiles
"`/api/tiles` endpoints."
(
:require
[
clojure.core.match
:refer
[
match
]]
[
clojure.java.io
:as
io
]
[
cheshire.core
:as
json
]
...
...
@@ -101,31 +102,29 @@
(
catch
Throwable
e
(
byte-array
0
))
; return empty byte array if we fail for some reason
(
finally
(
try
(
.close
output-stream
)
(
catch
Throwable
_
))))))
(
u/ignore-exceptions
(
.close
output-stream
)
)))))
;;; # ------------------------------------------------------------ ENDPOINT ------------------------------------------------------------
(
defendpoint
GET
"/:zoom/:x/:y/:lat-field-id/:lon-field-id/:lat-col-idx/:lon-col-idx/"
"This endpoints provides an image with the appropriate pins rendered given a
json query
.
"This endpoints provides an image with the appropriate pins rendered given a
MBQL QUERY (passed as a GET query string param)
.
We evaluate the query and find the set of lat/lon pairs which are relevant and then render the appropriate ones.
It's expected that to render a full map view several calls will be made to this endpoint in parallel."
[
zoom
x
y
lat-field-id
lon-field-id
lat-col-idx
lon-col-idx
query
]
{
zoom
su/IntegerString
x
su/IntegerString
y
su/IntegerString
lat-field-id
su/Int
egerString
GreaterThanZero
lon-field-id
su/Int
egerString
GreaterThanZero
lat-field-id
su/IntGreaterThanZero
lon-field-id
su/IntGreaterThanZero
lat-col-idx
su/IntegerString
lon-col-idx
su/IntegerString
query
su/JSONString
}
(
let
[
zoom
(
Integer/parseInt
zoom
)
x
(
Integer/parseInt
x
)
y
(
Integer/parseInt
y
)
lat-field-id
(
Integer/parseInt
lat-field-id
)
lon-field-id
(
Integer/parseInt
lon-field-id
)
lat-col-idx
(
Integer/parseInt
lat-col-idx
)
lon-col-idx
(
Integer/parseInt
lon-col-idx
)
query
(
json/parse-string
query
keyword
)
...
...
@@ -137,9 +136,7 @@
;; manual ring response here. we simply create an inputstream from the byte[] of our image
{
:status
200
:headers
{
"Content-Type"
"image/png"
}
:body
(
->
(
create-tile
zoom
points
)
tile->byte-array
java.io.ByteArrayInputStream.
)}))
:body
(
java.io.ByteArrayInputStream.
(
tile->byte-array
(
create-tile
zoom
points
)))}))
(
define-routes
)
This diff is collapsed.
Click to expand it.
src/metabase/util/schema.clj
+
1
−
0
View file @
d130af96
...
...
@@ -88,6 +88,7 @@
(
with-api-error-message
(
s/constrained
s/Str
password/is-complex?
)
"Insufficient password strength"
))
;; TODO - maybe rename this to `IntString` so it's consistent with `IntGreaterThanZero`
(
def
IntegerString
"Schema for a string that can be parsed as an integer.
Something that adheres to this schema is guaranteed to to work with `Integer/parseInt`."
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/tiles_test.clj
0 → 100644
+
16
−
0
View file @
d130af96
(
ns
metabase.api.tiles-test
"Tests for `/api/tiles` endpoints."
(
:require
[
cheshire.core
:as
json
]
[
expectations
:refer
:all
]
[
metabase.query-processor.expand
:as
ql
]
[
metabase.test.data
:refer
:all
]
[
metabase.test.data.users
:refer
:all
]))
;;; GET /api/tiles/:zoom/:x/:y/:lat-field-id/:lon-field-id/:lat-col-idx/:lon-col-idx/
(
expect
String
((
user->client
:rasta
)
:get
200
(
format
"tiles/1/1/1/%d/%d/1/1/"
(
id
:venues
:latitude
)
(
id
:venues
:longitude
))
:query
(
json/generate-string
{
:database
(
id
)
:type
:query
:query
(
ql/query
(
ql/source-table
(
id
:venues
)))})))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment