Search in sources :

Example 1 with Translator

use of org.obiba.core.translator.Translator in project mica2 by obiba.

the class ModelAwareTranslator method translateModel.

public <T extends ModelAware> void translateModel(String locale, T modelAwareObject) {
    if (locale == null)
        return;
    Translator translator = JsonTranslator.buildSafeTranslator(() -> micaConfigService.getTranslations(locale, false));
    new ForLocale(translator).translateModel(modelAwareObject);
}
Also used : JsonTranslator(org.obiba.core.translator.JsonTranslator) Translator(org.obiba.core.translator.Translator)

Example 2 with Translator

use of org.obiba.core.translator.Translator in project mica2 by obiba.

the class SpecificStudyReportGenerator method report.

public void report(String networkId, String locale, OutputStream outputStream) throws IOException {
    List<String> studyIds = networkService.findById(networkId).getStudyIds();
    Translator translator = JsonTranslator.buildSafeTranslator(() -> micaConfigService.getTranslations(locale, false));
    report(translator, studyIds, locale, outputStream);
}
Also used : JsonTranslator(org.obiba.core.translator.JsonTranslator) Translator(org.obiba.core.translator.Translator) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 3 with Translator

use of org.obiba.core.translator.Translator 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;
}
Also used : RegexHashMap(org.obiba.mica.core.support.RegexHashMap) PopulationConfig(org.obiba.mica.micaConfig.domain.PopulationConfig) HarmonizationPopulationConfig(org.obiba.mica.micaConfig.domain.HarmonizationPopulationConfig) StudyDatasetConfig(org.obiba.mica.micaConfig.domain.StudyDatasetConfig) NetworkConfig(org.obiba.mica.micaConfig.domain.NetworkConfig) DataCollectionEventConfig(org.obiba.mica.micaConfig.domain.DataCollectionEventConfig) HarmonizationDatasetConfig(org.obiba.mica.micaConfig.domain.HarmonizationDatasetConfig) ProjectConfig(org.obiba.mica.micaConfig.domain.ProjectConfig) HarmonizationPopulationConfig(org.obiba.mica.micaConfig.domain.HarmonizationPopulationConfig) StudyConfig(org.obiba.mica.micaConfig.domain.StudyConfig) HarmonizationStudyConfig(org.obiba.mica.micaConfig.domain.HarmonizationStudyConfig) JsonTranslator(org.obiba.core.translator.JsonTranslator) PrefixedValueTranslator(org.obiba.core.translator.PrefixedValueTranslator) Translator(org.obiba.core.translator.Translator) HarmonizationStudyConfig(org.obiba.mica.micaConfig.domain.HarmonizationStudyConfig)

Example 4 with Translator

use of org.obiba.core.translator.Translator in project mica2 by obiba.

the class EntityConfigTranslator method translateSchemaForm.

/**
 * Translates both schema and definition JSON strings defined in the entity configuration.
 *
 * @param locale
 * @param entityConfig
 * @param <T>
 */
public <T extends EntityConfig> void translateSchemaForm(String locale, T entityConfig) {
    if (StringUtils.isEmpty(locale))
        return;
    Translator translator = JsonTranslator.buildSafeTranslator(() -> micaConfigService.getTranslations(locale, false));
    translator = new PrefixedValueTranslator(translator);
    TranslationUtils translationUtils = new TranslationUtils();
    entityConfig.setSchema(translationUtils.translate(entityConfig.getSchema(), translator));
    entityConfig.setDefinition(translationUtils.translate(entityConfig.getDefinition(), translator));
}
Also used : JsonTranslator(org.obiba.core.translator.JsonTranslator) Translator(org.obiba.core.translator.Translator) PrefixedValueTranslator(org.obiba.core.translator.PrefixedValueTranslator) PrefixedValueTranslator(org.obiba.core.translator.PrefixedValueTranslator) TranslationUtils(org.obiba.core.translator.TranslationUtils)

Example 5 with Translator

use of org.obiba.core.translator.Translator in project mica2 by obiba.

the class SpecificStudyReportGenerator method report.

public void report(String rqlQuery, OutputStream outputStream) throws IOException {
    JoinQuery joinQuery = searcher.makeJoinQuery(rqlQuery);
    List<String> studyIds = joinQueryExecutor.query(QueryType.STUDY, joinQuery).getStudyResultDto().getExtension(MicaSearch.StudyResultDto.result).getSummariesList().stream().map(Mica.StudySummaryDto::getId).collect(toList());
    Translator translator = JsonTranslator.buildSafeTranslator(() -> micaConfigService.getTranslations(joinQuery.getLocale(), false));
    report(translator, studyIds, joinQuery.getLocale(), outputStream);
}
Also used : JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) JsonTranslator(org.obiba.core.translator.JsonTranslator) Translator(org.obiba.core.translator.Translator) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Mica(org.obiba.mica.web.model.Mica)

Aggregations

JsonTranslator (org.obiba.core.translator.JsonTranslator)6 Translator (org.obiba.core.translator.Translator)6 LocalizedString (org.obiba.mica.core.domain.LocalizedString)3 PrefixedValueTranslator (org.obiba.core.translator.PrefixedValueTranslator)2 Strings (com.google.common.base.Strings)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 TranslationUtils (org.obiba.core.translator.TranslationUtils)1 DocumentSet (org.obiba.mica.core.domain.DocumentSet)1 DocumentSetService (org.obiba.mica.core.service.DocumentSetService)1 RegexHashMap (org.obiba.mica.core.support.RegexHashMap)1 DataCollectionEventConfig (org.obiba.mica.micaConfig.domain.DataCollectionEventConfig)1 HarmonizationDatasetConfig (org.obiba.mica.micaConfig.domain.HarmonizationDatasetConfig)1 HarmonizationPopulationConfig (org.obiba.mica.micaConfig.domain.HarmonizationPopulationConfig)1 HarmonizationStudyConfig (org.obiba.mica.micaConfig.domain.HarmonizationStudyConfig)1 NetworkConfig (org.obiba.mica.micaConfig.domain.NetworkConfig)1 PopulationConfig (org.obiba.mica.micaConfig.domain.PopulationConfig)1 ProjectConfig (org.obiba.mica.micaConfig.domain.ProjectConfig)1