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())));
}
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();
}
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;
}
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;
}
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));
}
Aggregations