use of org.obiba.mica.core.support.RegexHashMap in project mica2 by obiba.
the class EntityConfigKeyTranslationService method getCompleteConfigTranslationMap.
public RegexHashMap getCompleteConfigTranslationMap(String serviceTypename, String locale) {
RegexHashMap translationMap = new RegexHashMap();
Translator translator = JsonTranslator.buildSafeTranslator(() -> micaConfigService.getTranslations(locale, false));
beanFieldToTranslationKeyMap.forEach((key, translationKey) -> translationMap.put(key, translator.translate(translationKey)));
switch(serviceTypename) {
case "individual-study":
Optional<StudyConfig> optionalIndividualStudySchemaForm = individualStudyConfigService.findComplete();
Optional<PopulationConfig> optionalPopulationSchemaForm = populationConfigService.findComplete();
Optional<DataCollectionEventConfig> optionalDataCollectionEventSchemaForm = dataCollectionEventConfigService.findComplete();
if (optionalIndividualStudySchemaForm.isPresent()) {
StudyConfig individualStudySchemaForm = optionalIndividualStudySchemaForm.get();
translateSchemaForm(translator, individualStudySchemaForm);
translationMap.putAll(getTranslationMap(individualStudySchemaForm, ""));
}
if (optionalPopulationSchemaForm.isPresent()) {
PopulationConfig populationSchemaForm = optionalPopulationSchemaForm.get();
translateSchemaForm(translator, populationSchemaForm);
translationMap.putAll(getTranslationMap(populationSchemaForm, "^populations\\[\\d+\\]\\."));
}
if (optionalDataCollectionEventSchemaForm.isPresent()) {
DataCollectionEventConfig dataCollectionEventSchemaForm = optionalDataCollectionEventSchemaForm.get();
translateSchemaForm(translator, dataCollectionEventSchemaForm);
translationMap.putAll(getTranslationMap(dataCollectionEventSchemaForm, "^populations\\[\\d+\\]\\.dataCollectionEvents\\[\\d+\\]\\."));
}
break;
case "harmonization-study":
Optional<HarmonizationStudyConfig> optionalHarmonizationStudySchemaForm = harmonizationStudyConfigService.findComplete();
Optional<HarmonizationPopulationConfig> optionalHarmonizationPopulationSchemaForm = harmonizationPopulationConfigService.findComplete();
if (optionalHarmonizationStudySchemaForm.isPresent()) {
HarmonizationStudyConfig harmonizationStudySchemaForm = optionalHarmonizationStudySchemaForm.get();
translateSchemaForm(translator, harmonizationStudySchemaForm);
translationMap.putAll(getTranslationMap(harmonizationStudySchemaForm, ""));
}
if (optionalHarmonizationPopulationSchemaForm.isPresent()) {
HarmonizationPopulationConfig harmonizationPopulationSchemaForm = optionalHarmonizationPopulationSchemaForm.get();
translateSchemaForm(translator, harmonizationPopulationSchemaForm);
translationMap.putAll(getTranslationMap(harmonizationPopulationSchemaForm, "^populations\\[\\d+\\]\\."));
}
break;
case "network":
Optional<NetworkConfig> optionalNetworkSchemaForm = networkConfigService.findComplete();
if (optionalNetworkSchemaForm.isPresent()) {
NetworkConfig networkSchemaForm = optionalNetworkSchemaForm.get();
translateSchemaForm(translator, networkSchemaForm);
translationMap.putAll(getTranslationMap(networkSchemaForm, ""));
}
break;
case "collected-dataset":
Optional<StudyDatasetConfig> optionalStudyDatasetSchemaForm = studyDatasetConfigService.findComplete();
if (optionalStudyDatasetSchemaForm.isPresent()) {
StudyDatasetConfig studyDatasetSchemaForm = optionalStudyDatasetSchemaForm.get();
translateSchemaForm(translator, studyDatasetSchemaForm);
translationMap.putAll(getTranslationMap(studyDatasetSchemaForm, ""));
}
break;
case "harmonized-dataset":
Optional<HarmonizationDatasetConfig> optionalHarmonizationDatasetSchemaForm = harmonizationDatasetConfigService.findComplete();
if (optionalHarmonizationDatasetSchemaForm.isPresent()) {
HarmonizationDatasetConfig harmonizationDatasetSchemaForm = optionalHarmonizationDatasetSchemaForm.get();
translateSchemaForm(translator, harmonizationDatasetSchemaForm);
translationMap.putAll(getTranslationMap(harmonizationDatasetSchemaForm, ""));
}
break;
case "project":
Optional<ProjectConfig> optionalProjectSchemaForm = projectConfigService.findComplete();
if (optionalProjectSchemaForm.isPresent()) {
ProjectConfig projectSchemaForm = optionalProjectSchemaForm.get();
translateSchemaForm(translator, projectSchemaForm);
translationMap.putAll(getTranslationMap(projectSchemaForm, ""));
}
break;
default:
break;
}
return translationMap;
}
use of org.obiba.mica.core.support.RegexHashMap in project mica2 by obiba.
the class AbstractGitPersistableResource method diff.
@GET
@Path("/_diff")
public Response diff(@NotNull @QueryParam("left") String left, @NotNull @QueryParam("right") String right, @QueryParam("locale") @DefaultValue("en") String locale) {
checkPermission("/draft/" + getService().getTypeName(), "VIEW");
T1 leftCommit = getService().getFromCommit(getService().findDraft(getId()), left);
T1 rightCommit = getService().getFromCommit(getService().findDraft(getId()), right);
Map<String, Object> data = new HashMap<>();
try {
MapDifference<String, Object> difference = DocumentDifferenceService.diff(leftCommit, rightCommit);
RegexHashMap completeConfigTranslationMap = entityConfigKeyTranslationService.getCompleteConfigTranslationMap(getService().getTypeName(), locale);
data = DocumentDifferenceService.withTranslations(difference, completeConfigTranslationMap);
} catch (JsonProcessingException e) {
//
}
return Response.ok(data, MediaType.APPLICATION_JSON_TYPE).build();
}
use of org.obiba.mica.core.support.RegexHashMap in project mica2 by obiba.
the class DocumentDifferenceService method flatten.
public static Map<String, Object> flatten(Object object) throws JsonProcessingException {
Map<String, Object> map = new RegexHashMap();
if (object == null)
return map;
final String string = mapper.writeValueAsString(object);
JSONArray array = JsonPath.using(Configuration.builder().options(Option.AS_PATH_LIST).build()).parse(string).read("$..*");
array.stream().map(Object::toString).filter(key -> !key.startsWith("$['logo']") && !key.startsWith("$['createdDate']") && !key.startsWith("$['lastModifiedDate']") && !key.startsWith("$['membershipSortOrder']")).forEach(key -> {
Object read = JsonPath.parse(string).read(key);
if (read != null && !(read instanceof Map) && !(read instanceof List)) {
String processedKey = key.replaceAll("(\\$\\[')|('\\])", "").replaceAll("(\\[')", ".");
map.put(processedKey, read);
}
});
return map;
}
use of org.obiba.mica.core.support.RegexHashMap 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