Search in sources :

Example 36 with Calendar

use of org.hisp.dhis.calendar.Calendar 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)

Aggregations

Calendar (org.hisp.dhis.calendar.Calendar)36 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)14 Date (java.util.Date)10 Period (org.hisp.dhis.period.Period)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 ArrayList (java.util.ArrayList)5 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 PeriodType (org.hisp.dhis.period.PeriodType)4 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)3 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)2 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 ReportTable (org.hisp.dhis.reporttable.ReportTable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1