use of org.obiba.mica.micaConfig.domain.EntityConfig in project mica2 by obiba.
the class EntityConfigKeyTranslationService method getTranslationMap.
private RegexHashMap getTranslationMap(EntityConfig config, String prefix) {
String string = config.getSchema();
JSONArray normalArray = JsonPath.using(Configuration.builder().options(Option.AS_PATH_LIST, Option.ALWAYS_RETURN_LIST, Option.SUPPRESS_EXCEPTIONS).build()).parse(string).read("$..*");
JSONArray itemsArray = JsonPath.using(Configuration.builder().options(Option.AS_PATH_LIST, Option.ALWAYS_RETURN_LIST, Option.SUPPRESS_EXCEPTIONS).build()).parse(string).read("$..items");
RegexHashMap map = new RegexHashMap();
String joinedLocales = getJoinedLocales();
normalArray.stream().map(Object::toString).filter(key -> key.endsWith("['title']")).forEach(key -> {
Object read = JsonPath.parse(string).read(key);
if (read != null) {
String cleanKey = key.replaceAll("(\\$\\[')|('\\])", "").replaceAll("(\\[')", ".").replaceAll("\\.title$", "").replaceAll("^properties\\.", "").replaceAll("\\.properties", "");
String processedKey = (cleanKey.startsWith("_") ? prefix : prefix + "model\\.") + Pattern.quote((cleanKey.startsWith("_") ? cleanKey.substring(1) : cleanKey)) + "(\\[\\d+\\])?" + "(" + joinedLocales + ")?";
map.put(processedKey, read.toString());
}
});
itemsArray.stream().map(Object::toString).forEach(itemkey -> {
Object read = JsonPath.parse(string).read(itemkey);
if (read != null && read instanceof List) {
JSONArray array = (JSONArray) read;
array.forEach(arrayItem -> {
if (arrayItem != null && arrayItem instanceof Map) {
Map itemMap = (Map) arrayItem;
Object key = itemMap.get("key");
Object name = itemMap.get("name");
String cleanKey = itemkey.replaceAll("(\\$\\[')|('\\])", "").replaceAll("(\\[')", ".").replaceAll("\\.items$", "").replaceAll("^properties\\.", "").replaceAll("\\.properties", "") + "." + key.toString();
String processedKey = (cleanKey.startsWith("_") ? prefix : prefix + "model\\.") + Pattern.quote((cleanKey.startsWith("_") ? cleanKey.substring(1) : cleanKey));
map.put(processedKey, name);
}
});
}
});
return map;
}
Aggregations