Package org.forgerock.audit.util
Class ElasticsearchUtil
java.lang.Object
org.forgerock.audit.util.ElasticsearchUtil
Utilities for working with Elasticsearch.
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
JSON field-name of normalized field-names.protected static final String
JSON field-name of metadata to assist in de-normalization.static final com.fasterxml.jackson.databind.ObjectMapper
JacksonObjectMapper
for producing normalized JSON.static final com.fasterxml.jackson.databind.ObjectMapper
JacksonObjectMapper
for working with JSON. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonValue
denormalizeJson
(JsonValue value) De-normalizes JSON that was previously normalized bynormalizeJson(JsonValue)
.static String
normalizeJson
(JsonValue value) Deprecated.static JsonPointer
Replaces periods inJsonPointer
keys with underscore.static boolean
renameField
(JsonValue jsonValue, String oldKey, String newKey) Renames a field within the givenJsonValue
.protected static String
Replaces all period-characters in JSON keys with underscore-characters [ref].protected static JsonValue
restoreKeyPeriods
(JsonValue value, JsonValue normalized) Reverses the normalization steps preformed byreplaceKeyPeriodsWithUnderscores(String)
.
-
Field Details
-
OBJECT_MAPPER
public static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPERJacksonObjectMapper
for working with JSON. -
NORMALIZING_OBJECT_MAPPER
public static final com.fasterxml.jackson.databind.ObjectMapper NORMALIZING_OBJECT_MAPPERJacksonObjectMapper
for producing normalized JSON. -
NORMALIZED_FIELD
JSON field-name of metadata to assist in de-normalization.- See Also:
-
FIELD_NAMES_FIELD
JSON field-name of normalized field-names.- See Also:
-
-
Method Details
-
normalizeJson
Deprecated.UseNORMALIZING_OBJECT_MAPPER
instead.Normalizes JSON to conform to Elasticsearch data-format restrictions. The following normalizations are performed,- Periods in JSON fields (keys) are converted to underscore characters
"_normalized" : { "fieldNames" : { "key_1" : "key.1", "key_2" : "key.2" } }
- Parameters:
value
- JSON value- Returns:
- Resulting JSON, with
_normalized
field if any normalization was necessary - Throws:
IOException
- If unable to parse the json.
-
denormalizeJson
De-normalizes JSON that was previously normalized bynormalizeJson(JsonValue)
.- Parameters:
value
- JSON value- Returns:
- Original, de-normalized JSON
- Throws:
IOException
- If unable to parse the json.
-
replaceKeyPeriodsWithUnderscores
Replaces all period-characters in JSON keys with underscore-characters [ref]. If normalization is required, thefieldNames
field will be added to thenormalized
metadata.- Parameters:
json
- JSONString
input- Returns:
- Resulting JSON
String
- Throws:
IOException
- If unable to parse the json.
-
restoreKeyPeriods
protected static JsonValue restoreKeyPeriods(JsonValue value, JsonValue normalized) throws IOException Reverses the normalization steps preformed byreplaceKeyPeriodsWithUnderscores(String)
.- Parameters:
value
- JSON inputnormalized
- De-normalization metadata, which this method may add to- Returns:
- Resulting JSON
- Throws:
IOException
- If unable to parse the json.
-
normalizeJsonPointer
Replaces periods inJsonPointer
keys with underscore.- Parameters:
ptr
- TheJsonPointer
to normalize.- Returns:
- A normalized
JsonPointer
.
-
renameField
Renames a field within the givenJsonValue
.- Parameters:
jsonValue
-JsonValue
to have a top-level field renamedoldKey
- Old field namenewKey
- New field name (field must not already exist)- Returns:
true
if field was found and renamed, andfalse
otherwise
-
NORMALIZING_OBJECT_MAPPER
instead.