Package io.goobi.viewer.controller
Class JsonTools
java.lang.Object
io.goobi.viewer.controller.JsonTools
JsonTools class.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic org.json.JSONObjectcreateJsonObjectFromSolrDoc(org.apache.solr.common.SolrDocument doc, List<Map<String, String>> fields) static StringformatVersionString(String json) static Stringstatic org.json.JSONObjectstatic <T> TgetAsObject(String json, Class<T> clazz) static ObjectgetAsObjectForJson(Object value) static org.json.JSONArraygetDateCentricRecordJsonArray(org.apache.solr.common.SolrDocumentList result, jakarta.servlet.http.HttpServletRequest request) JSON array of records grouped by their import date.static StringgetGitRevision(String json) static StringgetNestedValue(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.JSONArraygetRecordJsonArray(org.apache.solr.common.SolrDocumentList result, Map<String, org.apache.solr.common.SolrDocumentList> expanded, jakarta.servlet.http.HttpServletRequest request, String languageToTranslate) Returns aJSONArraycontaining JSON objects for everySolrDocumentin the given result.static org.json.JSONObjectgetRecordJsonObject(org.apache.solr.common.SolrDocument doc, String rootUrl, ThumbnailHandler thumbs) Creates a singleJSONObjectwith metadata for the given recordSolrDocument.static org.json.JSONObjectgetRecordJsonObject(org.apache.solr.common.SolrDocument doc, String rootUrl, String language, ThumbnailHandler thumbs) Creates a singleJSONObjectwith metadata for the given recordSolrDocument.static StringgetVersion(String json) static Stringstatic org.json.JSONObjecttranslateJSONObject(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, jakarta.servlet.http.HttpServletRequest request, String languageToTranslate) throws IndexUnreachableException, PresentationException, DAOException, ViewerConfigurationExceptionReturns aJSONArraycontaining JSON objects for everySolrDocumentin the given result. Order remains the same as in the result list.- Parameters:
result- aSolrDocumentListobject.expanded-request- aHttpServletRequestobject.languageToTranslate-- Returns:
- a
JSONArrayobject. - 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, jakarta.servlet.http.HttpServletRequest request) throws IndexUnreachableException, PresentationException, DAOException, ViewerConfigurationException JSON array of records grouped by their import date.- Parameters:
result- aSolrDocumentListobject.request- aHttpServletRequestobject.- Returns:
- a
JSONArrayobject. - 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 singleJSONObjectwith metadata for the given recordSolrDocument.- Parameters:
doc- aSolrDocumentobject.rootUrl- aStringobject.thumbs-- Returns:
- a
JSONObjectobject. - 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 singleJSONObjectwith 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:
Stringcontaining value of "version" from json
-
getGitRevision
- Parameters:
json-- Returns:
Stringcontaining 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
-
createJsonObjectFromSolrDoc
public static org.json.JSONObject createJsonObjectFromSolrDoc(org.apache.solr.common.SolrDocument doc, List<Map<String, String>> fields) - Parameters:
doc- Solr doc containing the source metadatafields- Field mappings- Returns:
JSONObject
-