Package io.goobi.viewer.controller
Class JsonTools
java.lang.Object
io.goobi.viewer.controller.JsonTools
JsonTools class.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatVersionString
(String json) static String
static org.json.JSONObject
static <T> T
getAsObject
(String json, Class<T> clazz) static Object
getAsObjectForJson
(Object value) static org.json.JSONArray
getDateCentricRecordJsonArray
(org.apache.solr.common.SolrDocumentList result, javax.servlet.http.HttpServletRequest request) JSON array of records grouped by their import date.static String
getGitRevision
(String json) static String
getNestedValue
(org.json.JSONObject json, String key) Return the string value of the given key in the json object or within another json object nested somewhere within the original object.static org.json.JSONArray
getRecordJsonArray
(org.apache.solr.common.SolrDocumentList result, Map<String, org.apache.solr.common.SolrDocumentList> expanded, javax.servlet.http.HttpServletRequest request, String languageToTranslate) Returns aJSONArray
containing JSON objects for everySolrDocument
in the given result.static org.json.JSONObject
getRecordJsonObject
(org.apache.solr.common.SolrDocument doc, String rootUrl, ThumbnailHandler thumbs) Creates a singleJSONObject
with metadata for the given recordSolrDocument
.static org.json.JSONObject
getRecordJsonObject
(org.apache.solr.common.SolrDocument doc, String rootUrl, String language, ThumbnailHandler thumbs) Creates a singleJSONObject
with metadata for the given recordSolrDocument
.static String
getVersion
(String json) static String
static org.json.JSONObject
translateJSONObject
(Locale locale, org.json.JSONObject object)
-
Field Details
-
KEY_MESSAGE
- See Also:
-
KEY_STATUS
- See Also:
-
-
Method Details
-
getRecordJsonArray
public static org.json.JSONArray getRecordJsonArray(org.apache.solr.common.SolrDocumentList result, Map<String, org.apache.solr.common.SolrDocumentList> expanded, javax.servlet.http.HttpServletRequest request, String languageToTranslate) throws IndexUnreachableException, PresentationException, DAOException, ViewerConfigurationExceptionReturns aJSONArray
containing JSON objects for everySolrDocument
in the given result. Order remains the same as in the result list.- Parameters:
result
- aSolrDocumentList
object.expanded
-request
- aHttpServletRequest
object.languageToTranslate
-- Returns:
- a
JSONArray
object. - Throws:
IndexUnreachableException
- if any.PresentationException
- if any.DAOException
- if any.ViewerConfigurationException
- if any.
-
getAsJson
public static org.json.JSONObject getAsJson(org.apache.solr.common.SolrDocument doc, Locale locale) throws com.fasterxml.jackson.core.JsonProcessingException - Parameters:
doc
-locale
-- Returns:
- Given Solr doc as
JSONObject
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getAsJson
public static String getAsJson(Object object) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getAsObject
- Type Parameters:
T
-- Parameters:
json
-clazz
-- Returns:
- T
- Throws:
IOException
-
getAsObjectForJson
- Parameters:
value
-- Returns:
Object
-
translateJSONObject
- Parameters:
locale
-object
-- Returns:
- object translated to locale
-
getDateCentricRecordJsonArray
public static org.json.JSONArray getDateCentricRecordJsonArray(org.apache.solr.common.SolrDocumentList result, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, PresentationException, DAOException, ViewerConfigurationException JSON array of records grouped by their import date.- Parameters:
result
- aSolrDocumentList
object.request
- aHttpServletRequest
object.- Returns:
- a
JSONArray
object. - Throws:
IndexUnreachableException
- if any.PresentationException
- if any.DAOException
- if any.ViewerConfigurationException
- if any.
-
getRecordJsonObject
public static org.json.JSONObject getRecordJsonObject(org.apache.solr.common.SolrDocument doc, String rootUrl, ThumbnailHandler thumbs) throws ViewerConfigurationException Creates a singleJSONObject
with metadata for the given recordSolrDocument
.- Parameters:
doc
- aSolrDocument
object.rootUrl
- aString
object.thumbs
-- Returns:
- a
JSONObject
object. - Throws:
ViewerConfigurationException
- if any.
-
getRecordJsonObject
public static org.json.JSONObject getRecordJsonObject(org.apache.solr.common.SolrDocument doc, String rootUrl, String language, ThumbnailHandler thumbs) Creates a singleJSONObject
with metadata for the given recordSolrDocument
. -
formatVersionString
- Parameters:
json
- JSON string- Returns:
- Version information as a single line string
-
shortFormatVersionString
- Parameters:
json
- JSON string- Returns:
- Only version number and git hash as a single line string
-
getVersion
- Parameters:
json
-- Returns:
String
containing value of "version" from json
-
getGitRevision
- Parameters:
json
-- Returns:
String
containing value of "git-revision" from json
-
getNestedValue
Return the string value of the given key in the json object or within another json object nested somewhere within the original object. If the key is not found anywhere within the object, an empty string is returned. If the value to the key is anything other than a string, a stringified version of the object is returned. This method cannot parse arrays within array. If the key is within that, an empty string is also returned- Parameters:
json
- The json object to parsekey
- the key to find- Returns:
- a
String
. May be empty if the key is not found
-