Search in sources :

Example 11 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultModuleManager method detectLocaleChange.

// -------------------------------------------------------------------------
// Module detection
// -------------------------------------------------------------------------
private synchronized void detectLocaleChange() {
    if (localeManager.getCurrentLocale().equals(currentLocale)) {
        return;
    }
    currentLocale = localeManager.getCurrentLocale();
    I18n i18n = i18nManager.getI18n();
    modulesByNamespace.values().forEach(m -> m.setDisplayName(i18n.getString(m.getName())));
    modulesByName.values().forEach(m -> m.setDisplayName(i18n.getString(m.getName())));
}
Also used : I18n(org.hisp.dhis.i18n.I18n)

Example 12 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultModuleManager method detectModules.

private synchronized void detectModules() {
    if (modulesDetected) {
        return;
    }
    I18n i18n = i18nManager.getI18n();
    for (PackageConfig packageConfig : getPackageConfigs()) {
        String name = packageConfig.getName();
        String namespace = packageConfig.getNamespace();
        String displayName = i18n.getString(name);
        log.debug("Package config: " + name + ", " + namespace);
        if (packageConfig.getAllActionConfigs().size() == 0) {
            log.debug("Ignoring action package with no actions: " + name);
            continue;
        }
        if (namespace == null || namespace.length() == 0) {
            throw new RuntimeException("Missing namespace in action package: " + name);
        }
        if (modulesByName.containsKey(name)) {
            throw new RuntimeException("Two action packages have the same name: " + name);
        }
        if (modulesByNamespace.containsKey(namespace)) {
            Module module = modulesByNamespace.get(namespace);
            throw new RuntimeException("These action packages have the same namespace: " + name + " and " + module.getName());
        }
        Module module = new Module(name, namespace);
        module.setDisplayName(displayName);
        modulesByName.put(name, module);
        modulesByNamespace.put(namespace, module);
        boolean include = !menuModuleExclusions.contains(name);
        if (packageConfig.getActionConfigs().containsKey(defaultActionName) && include) {
            module.setDefaultAction(".." + namespace + "/" + defaultActionName + ".action");
            menuModules.add(module);
            log.debug("Has default action: " + name);
        } else {
            log.debug("Doesn't have default action: " + name);
        }
    }
    Collections.sort(menuModules, moduleComparator);
    log.debug("Menu modules detected: " + menuModules);
    modulesDetected = true;
    currentLocale = localeManager.getCurrentLocale();
}
Also used : PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) I18n(org.hisp.dhis.i18n.I18n)

Example 13 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultDataSetReportService method getSectionDataSetReport.

private List<Grid> getSectionDataSetReport(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters, boolean selectedUnitOnly) {
    I18nFormat format = i18nManager.getI18nFormat();
    I18n i18n = i18nManager.getI18n();
    List<Section> sections = new ArrayList<>(dataSet.getSections());
    sections.sort(new SectionOrderComparator());
    Map<String, Object> valueMap = dataSetReportStore.getAggregatedValues(dataSet, periods, unit, filters);
    Map<String, Object> subTotalMap = dataSetReportStore.getAggregatedSubTotals(dataSet, periods, unit, filters);
    Map<String, Object> totalMap = dataSetReportStore.getAggregatedTotals(dataSet, periods, unit, filters);
    List<Grid> grids = new ArrayList<>();
    for (Section section : sections) {
        for (CategoryCombo categoryCombo : section.getCategoryCombos()) {
            Grid grid = new ListGrid().setTitle(section.getName() + SPACE + categoryCombo.getName()).setSubtitle(unit.getName() + SPACE + formatPeriods(periods, format));
            // -----------------------------------------------------------------
            // Grid headers
            // -----------------------------------------------------------------
            grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
            List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
            for (CategoryOptionCombo optionCombo : optionCombos) {
                grid.addHeader(new GridHeader(optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false));
            }
            if (// Sub-total
            categoryCombo.doSubTotals() && !selectedUnitOnly) {
                for (CategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
                    grid.addHeader(new GridHeader(categoryOption.getName(), false, false));
                }
            }
            if (// Total
            categoryCombo.doTotal() && !selectedUnitOnly) {
                grid.addHeader(new GridHeader(TOTAL_HEADER, false, false));
            }
            // -----------------------------------------------------------------
            // Grid values
            // -----------------------------------------------------------------
            List<DataElement> dataElements = new ArrayList<>(section.getDataElementsByCategoryCombo(categoryCombo));
            FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
            for (DataElement dataElement : dataElements) {
                grid.addRow();
                // Data
                grid.addValue(new GridValue(dataElement.getFormNameFallback()));
                for (// Values
                CategoryOptionCombo optionCombo : // Values
                optionCombos) {
                    Map<Object, Object> attributes = new HashMap<>();
                    attributes.put(ATTR_DE, dataElement.getUid());
                    attributes.put(ATTR_CO, optionCombo.getUid());
                    Object value;
                    if (selectedUnitOnly) {
                        value = getSelectedUnitValue(dataElement, periods, unit, optionCombo);
                    } else {
                        value = valueMap.get(dataElement.getUid() + SEPARATOR + optionCombo.getUid());
                    }
                    grid.addValue(new GridValue(value, attributes));
                }
                if (// Sub-total
                categoryCombo.doSubTotals() && !selectedUnitOnly) {
                    for (CategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
                        Object value = subTotalMap.get(dataElement.getUid() + SEPARATOR + categoryOption.getUid());
                        grid.addValue(new GridValue(value));
                    }
                }
                if (// Total
                categoryCombo.doTotal() && !selectedUnitOnly) {
                    Object value = totalMap.get(String.valueOf(dataElement.getUid()));
                    grid.addValue(new GridValue(value));
                }
            }
            grids.add(grid);
        }
    }
    return grids;
}
Also used : HashMap(java.util.HashMap) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Section(org.hisp.dhis.dataset.Section) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) GridValue(org.hisp.dhis.common.GridValue) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) I18n(org.hisp.dhis.i18n.I18n)

Example 14 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class I18nController method postI18n.

@PostMapping
@ResponseBody
public I18nOutput postI18n(@RequestParam(value = "package", required = false, defaultValue = "org.hisp.dhis") String searchPackage, HttpServletResponse response, InputStream inputStream) throws Exception {
    I18n i18n = i18nManager.getI18n(searchPackage);
    I18nOutput output = new I18nOutput();
    I18nInput input = jsonMapper.readValue(inputStream, I18nInput.class);
    for (String key : input) {
        String value = i18n.getString(key);
        if (value != null) {
            output.getTranslations().put(key, value);
        }
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    return output;
}
Also used : I18nOutput(org.hisp.dhis.webapi.webdomain.i18n.I18nOutput) I18nInput(org.hisp.dhis.webapi.webdomain.i18n.I18nInput) I18n(org.hisp.dhis.i18n.I18n) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class ProgramRuleController method validateCondition.

@PostMapping(value = "/condition/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage validateCondition(@RequestBody String condition, @RequestParam String programId) {
    I18n i18n = i18nManager.getI18n();
    RuleValidationResult result = programRuleEngineService.getDescription(condition, programId);
    if (result.isValid()) {
        return new DescriptiveWebMessage(Status.OK, HttpStatus.OK).setDescription(result.getDescription()).setMessage(i18n.getString(ProgramIndicator.VALID));
    }
    String description = null;
    if (result.getErrorMessage() != null) {
        description = result.getErrorMessage();
    } else if (result.getException() != null) {
        description = result.getException().getMessage();
    }
    return new DescriptiveWebMessage(Status.ERROR, HttpStatus.OK).setDescription(description).setMessage(i18n.getString(ProgramIndicator.EXPRESSION_NOT_VALID));
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) I18n(org.hisp.dhis.i18n.I18n) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

I18n (org.hisp.dhis.i18n.I18n)33 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)4 Date (java.util.Date)3 LinkedHashSet (java.util.LinkedHashSet)3 Locale (java.util.Locale)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)3 Period (org.hisp.dhis.period.Period)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Action (com.opensymphony.xwork2.Action)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2