Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Path Search Panel endpoints (prefs and blobs) #439

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ dependencies {
api "org.owasp.encoder:encoder:1.2.3"
api "com.esotericsoftware:kryo:5.6.0"

api "com.jayway.jsonpath:json-path:2.9.0"
api "com.github.java-json-tools:json-patch:1.13"
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* Copyright © 2025 Extremely Heavy Industries Inc.
*/

package io.xh.hoist.admin

import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.Configuration
import com.jayway.jsonpath.Option
import io.xh.hoist.BaseController
import io.xh.hoist.jsonblob.JsonBlob
import io.xh.hoist.security.Access

@Access(['HOIST_ADMIN_READER'])
class JsonBlobSearchAdminController extends BaseController {

def searchByJsonPath() {
Configuration conf = Configuration.builder()
.options(
Option.SUPPRESS_EXCEPTIONS,
Option.ALWAYS_RETURN_LIST
).build()

List<JsonBlob> results = JsonBlob.list().findAll { entry ->
def result = JsonPath.using(conf).parse(entry.value).read(params.path)
return result.size() > 0
}

def ret = results.collect { it ->
[
type: it.type,
token: it.token,
name: it.name,
owner: it.owner,
lastUpdated: it.lastUpdated,
json: it.value
]
}
renderJSON(ret)
}

def getMatchingNodes(String json, String path, boolean asPathList) {
Configuration conf = asPathList
? Configuration.builder().options(Option.AS_PATH_LIST, Option.ALWAYS_RETURN_LIST).build()
: Configuration.defaultConfiguration()

def ret = JsonPath.using(conf).parse(json).read(path)
renderJSON(ret)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* Copyright © 2025 Extremely Heavy Industries Inc.
*/

package io.xh.hoist.admin

import com.jayway.jsonpath.Configuration
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.Option
import io.xh.hoist.BaseController
import io.xh.hoist.pref.Preference
import io.xh.hoist.pref.UserPreference
import io.xh.hoist.security.Access

@Access(['HOIST_ADMIN_READER'])
class PreferenceJsonSearchAdminController extends BaseController {

def searchByJsonPath() {
Configuration conf = Configuration.builder()
.options(
Option.SUPPRESS_EXCEPTIONS,
Option.ALWAYS_RETURN_LIST
).build()

List<Preference> jsonPrefs = Preference.findAllByType('json')
List<UserPreference> userPrefs = jsonPrefs.collect { UserPreference.findAllByPreference(it) }.flatten()
List<UserPreference> results = userPrefs.findAll { entry ->
def result = JsonPath.using(conf).parse(entry.userValue).read(params.path)
return result.size() > 0
}

def ret = results.collect { it ->
[
id: it.id,
name: it.preference.name,
groupName: it.preference.groupName,
owner: it.username,
lastUpdated: it.lastUpdated,
json: it.userValue
]
}
renderJSON(ret)
}

def getMatchingNodes(String json, String path, boolean asPathList) {
Configuration conf = asPathList
? Configuration.builder().options(Option.AS_PATH_LIST, Option.ALWAYS_RETURN_LIST).build()
: Configuration.defaultConfiguration()

def ret = JsonPath.using(conf).parse(json).read(path)
renderJSON(ret)
}

}
Loading