Package org.forgerock.audit.util
Class ElasticsearchUtil
- java.lang.Object
- 
- org.forgerock.audit.util.ElasticsearchUtil
 
- 
 public final class ElasticsearchUtil extends Object Utilities for working with Elasticsearch.
- 
- 
Field SummaryFields Modifier and Type Field Description protected static StringFIELD_NAMES_FIELDJSON field-name of normalized field-names.protected static StringNORMALIZED_FIELDJSON field-name of metadata to assist in de-normalization.static com.fasterxml.jackson.databind.ObjectMapperOBJECT_MAPPERJacksonObjectMapperfor working with JSON.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonValuedenormalizeJson(JsonValue value)De-normalizes JSON that was previously normalized bynormalizeJson(JsonValue).static StringnormalizeJson(JsonValue value)Normalizes JSON to conform to Elasticsearch data-format restrictions.static JsonPointernormalizeJsonPointer(JsonPointer ptr)Replaces periods inJsonPointerkeys with underscore.static booleanrenameField(JsonValue jsonValue, String oldKey, String newKey)Renames a field within the givenJsonValue.protected static StringreplaceKeyPeriodsWithUnderscores(String json)Replaces all period-characters in JSON keys with underscore-characters [ref].protected static JsonValuerestoreKeyPeriods(JsonValue value, JsonValue normalized)Reverses the normalization steps preformed byreplaceKeyPeriodsWithUnderscores(String).
 
- 
- 
- 
Field Detail- 
OBJECT_MAPPERpublic static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER JacksonObjectMapperfor working with JSON.
 - 
NORMALIZED_FIELDprotected static final String NORMALIZED_FIELD JSON field-name of metadata to assist in de-normalization.- See Also:
- Constant Field Values
 
 - 
FIELD_NAMES_FIELDprotected static final String FIELD_NAMES_FIELD JSON field-name of normalized field-names.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
normalizeJsonpublic static String normalizeJson(JsonValue value) throws IOException 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 _normalizedfield if any normalization was necessary
- Throws:
- IOException- If unable to parse the json.
 
 - 
denormalizeJsonpublic static JsonValue denormalizeJson(JsonValue value) throws IOException 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.
 
 - 
replaceKeyPeriodsWithUnderscoresprotected static String replaceKeyPeriodsWithUnderscores(String json) throws IOException Replaces all period-characters in JSON keys with underscore-characters [ref]. If normalization is required, thefieldNamesfield will be added to thenormalizedmetadata.- Parameters:
- json- JSON- Stringinput
- Returns:
- Resulting JSON String
- Throws:
- IOException- If unable to parse the json.
 
 - 
restoreKeyPeriodsprotected static JsonValue restoreKeyPeriods(JsonValue value, JsonValue normalized) throws IOException Reverses the normalization steps preformed byreplaceKeyPeriodsWithUnderscores(String).- Parameters:
- value- JSON input
- normalized- De-normalization metadata, which this method may add to
- Returns:
- Resulting JSON
- Throws:
- IOException- If unable to parse the json.
 
 - 
normalizeJsonPointerpublic static JsonPointer normalizeJsonPointer(JsonPointer ptr) Replaces periods inJsonPointerkeys with underscore.- Parameters:
- ptr- The- JsonPointerto normalize.
- Returns:
- A normalized JsonPointer.
 
 - 
renameFieldpublic static boolean renameField(JsonValue jsonValue, String oldKey, String newKey) Renames a field within the givenJsonValue.- Parameters:
- jsonValue-- JsonValueto have a top-level field renamed
- oldKey- Old field name
- newKey- New field name (field must not already exist)
- Returns:
- trueif field was found and renamed, and- falseotherwise
 
 
- 
 
-