Search in sources :

Example 11 with I18nFormat

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

the class EventReportController method postProcessEntity.

//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
protected void postProcessEntity(EventReport report) throws Exception {
    report.populateAnalyticalProperties();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit organisationUnit : report.getOrganisationUnits()) {
        report.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
    }
    I18nFormat format = i18nManager.getI18nFormat();
    if (report.getPeriods() != null && !report.getPeriods().isEmpty()) {
        for (Period period : report.getPeriods()) {
            period.setName(format.formatPeriod(period));
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 12 with I18nFormat

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

the class DefaultReportService method renderHtmlReport.

@Override
public void renderHtmlReport(Writer writer, String uid, Date date, String ou) {
    Report report = getReport(uid);
    OrganisationUnit organisationUnit = null;
    List<OrganisationUnit> organisationUnitHierarchy = new ArrayList<>();
    List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
    List<String> periods = new ArrayList<>();
    I18nFormat format = i18nManager.getI18nFormat();
    if (ou != null) {
        organisationUnit = organisationUnitService.getOrganisationUnit(ou);
        if (organisationUnit != null) {
            organisationUnitHierarchy.add(organisationUnit);
            OrganisationUnit parent = organisationUnit;
            while (parent.getParent() != null) {
                parent = parent.getParent();
                organisationUnitHierarchy.add(parent);
            }
            organisationUnitChildren.addAll(organisationUnit.getChildren());
        }
    }
    Calendar calendar = PeriodType.getCalendar();
    if (report != null && report.hasRelativePeriods()) {
        if (calendar.isIso8601()) {
            for (Period period : report.getRelatives().getRelativePeriods(date, format, true)) {
                periods.add(period.getIsoDate());
            }
        } else {
            periods = IdentifiableObjectUtils.getLocalPeriodIdentifiers(report.getRelatives().getRelativePeriods(date, format, true), calendar);
        }
    }
    String dateString = DateUtils.getMediumDateString(date);
    if (date != null && !calendar.isIso8601()) {
        dateString = calendar.formattedDate(calendar.fromIso(date));
    }
    final VelocityContext context = new VelocityContext();
    context.put("report", report);
    context.put("organisationUnit", organisationUnit);
    context.put("organisationUnitHierarchy", organisationUnitHierarchy);
    context.put("organisationUnitChildren", organisationUnitChildren);
    context.put("date", dateString);
    context.put("periods", periods);
    context.put("format", format);
    context.put("encoder", ENCODER);
    new VelocityManager().getEngine().getTemplate("html-report.vm").merge(context, writer);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) JasperReport(net.sf.jasperreports.engine.JasperReport) Report(org.hisp.dhis.report.Report) VelocityContext(org.apache.velocity.VelocityContext) VelocityManager(org.hisp.dhis.system.velocity.VelocityManager) Calendar(org.hisp.dhis.calendar.Calendar) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) TextUtils.getCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 13 with I18nFormat

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

the class DefaultI18nManager method getI18nFormat.

@Override
public I18nFormat getI18nFormat() {
    I18nFormat formatter = new I18nFormat(getGlobalResourceBundle());
    formatter.init();
    return formatter;
}
Also used : I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 14 with I18nFormat

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

the class ChartController method postProcessEntity.

//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
public void postProcessEntity(Chart chart) throws Exception {
    chart.populateAnalyticalProperties();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit organisationUnit : chart.getOrganisationUnits()) {
        chart.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
    }
    if (chart.getPeriods() != null && !chart.getPeriods().isEmpty()) {
        I18nFormat format = i18nManager.getI18nFormat();
        for (Period period : chart.getPeriods()) {
            period.setName(format.formatPeriod(period));
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 15 with I18nFormat

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

the class I18nInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    Action action = (Action) invocation.getAction();
    I18n i18n = i18nManager.getI18n(action.getClass());
    I18nFormat i18nFormat = i18nManager.getI18nFormat();
    Locale locale = localeManager.getCurrentLocale();
    // ---------------------------------------------------------------------
    // Make the objects available for web templates
    // ---------------------------------------------------------------------
    Map<String, Object> i18nMap = new HashMap<>(3);
    i18nMap.put(KEY_I18N, i18n);
    i18nMap.put(KEY_I18N_FORMAT, i18nFormat);
    i18nMap.put(KEY_LOCALE, locale);
    invocation.getStack().push(i18nMap);
    // ---------------------------------------------------------------------
    // Set the objects in the action class if the properties exist
    // ---------------------------------------------------------------------
    Map<?, ?> contextMap = invocation.getInvocationContext().getContextMap();
    try {
        Ognl.setValue(KEY_I18N, contextMap, action, i18n);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_I18N_FORMAT, contextMap, action, i18nFormat);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_LOCALE, contextMap, action, locale);
    } catch (NoSuchPropertyException ignored) {
    }
    return invocation.invoke();
}
Also used : Locale(java.util.Locale) Action(com.opensymphony.xwork2.Action) HashMap(java.util.HashMap) NoSuchPropertyException(ognl.NoSuchPropertyException) I18nFormat(org.hisp.dhis.i18n.I18nFormat) I18n(org.hisp.dhis.i18n.I18n)

Aggregations

I18nFormat (org.hisp.dhis.i18n.I18nFormat)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 Period (org.hisp.dhis.period.Period)7 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JasperReport (net.sf.jasperreports.engine.JasperReport)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)2 TextUtils.getCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString)2 Report (org.hisp.dhis.report.Report)2 ReportTable (org.hisp.dhis.reporttable.ReportTable)2 Action (com.opensymphony.xwork2.Action)1 Connection (java.sql.Connection)1 Locale (java.util.Locale)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 NoSuchPropertyException (ognl.NoSuchPropertyException)1 VelocityContext (org.apache.velocity.VelocityContext)1 Calendar (org.hisp.dhis.calendar.Calendar)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1