Search in sources :

Example 1 with PastAndCurrentPeriodFilter

use of org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter in project dhis2-core by dhis2.

the class GetReportParamsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    selectionTreeManager.setSelectedOrganisationUnit(user.getOrganisationUnit());
    if (uid != null) {
        ReportTable reportTable = reportTableService.getReportTable(uid, ReportTableService.MODE_REPORT_TABLE);
        if (reportTable != null) {
            reportParams = reportTable.getReportParams();
            if (reportParams.isParamReportingMonth() && reportTable.getRelatives() != null) {
                CalendarPeriodType periodType = (CalendarPeriodType) reportTable.getRelatives().getPeriodType();
                periods = periodType.generateLast5Years(new Date());
                Collections.reverse(periods);
                FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
                for (Period period : periods) {
                    period.setName(format.formatPeriod(period));
                }
            }
        }
    }
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Example 2 with PastAndCurrentPeriodFilter

use of org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter in project dhis2-core by dhis2.

the class GetReportParamsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    if (mode == null || uid == null) {
        return SUCCESS;
    }
    RelativePeriods relatives = null;
    if (MODE_REPORT_TABLE.equals(mode)) {
        ReportTable reportTable = reportTableService.getReportTable(uid);
        if (reportTable != null) {
            reportParams = reportTable.getReportParams();
            relatives = reportTable.getRelatives();
        }
    } else if (MODE_REPORT.equals(mode)) {
        Report report = reportService.getReport(uid);
        if (report != null && report.isTypeReportTable()) {
            reportParams = report.getReportTable().getReportParams();
            relatives = report.getReportTable().getRelatives();
        } else if (report != null && (report.isTypeJdbc() || report.isTypeHtml())) {
            reportParams = report.getReportParams();
            relatives = report.getRelatives();
        }
        if (type == null && report != null) {
            // Set type based on report
            type = report.getType();
        }
    }
    if (reportParams != null && reportParams.isParamReportingMonth() && relatives != null) {
        CalendarPeriodType periodType = (CalendarPeriodType) relatives.getPeriodType();
        List<Period> periods = periodType.generateLast5Years(new Date());
        Collections.reverse(periods);
        FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
        Calendar calendar = PeriodType.getCalendar();
        for (Period period_ : periods) {
            BaseIdentifiableObject period = new BaseIdentifiableObject();
            if (calendar.isIso8601()) {
                period.setUid(period_.getIsoDate());
                period.setDisplayName(format.formatPeriod(period_));
            } else {
                DateTimeUnit dateTimeUnit = calendar.fromIso(period_.getStartDate());
                period.setUid(period_.getPeriodType().getIsoDate(dateTimeUnit));
                period.setDisplayName(format.formatPeriod(period_));
            }
            this.periods.add(period);
        }
    }
    return SUCCESS;
}
Also used : RelativePeriods(org.hisp.dhis.period.RelativePeriods) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Report(org.hisp.dhis.report.Report) Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Example 3 with PastAndCurrentPeriodFilter

use of org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter in project dhis2-core by dhis2.

the class FormUtilsImpl method getPeriodsForDataSet.

@Override
public List<Period> getPeriodsForDataSet(Integer dataSetId, int first, int max) {
    Validate.notNull(dataSetId);
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    CalendarPeriodType periodType;
    if (dataSet.getPeriodType().getName().equalsIgnoreCase("Yearly")) {
        periodType = new YearlyPeriodType();
    } else {
        periodType = (CalendarPeriodType) dataSet.getPeriodType();
    }
    if (dataSet.getOpenFuturePeriods() > 0) {
        List<Period> periods = periodType.generatePeriods(new Date());
        Collections.reverse(periods);
        return periods;
    } else {
        List<Period> periods = periodType.generateLast5Years(new Date());
        FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
        Collections.reverse(periods);
        if (periods.size() > (first + max)) {
            periods = periods.subList(first, max);
        }
        return periods;
    }
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter)

Example 4 with PastAndCurrentPeriodFilter

use of org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter in project dhis2-core by dhis2.

the class GetLockExceptionFormAction method getPeriodsForDataSet.

private List<Period> getPeriodsForDataSet(int id) {
    DataSet dataSet = dataSetService.getDataSet(id);
    if (dataSet == null) {
        return new ArrayList<>();
    }
    CalendarPeriodType periodType = (CalendarPeriodType) dataSet.getPeriodType();
    List<Period> periods = periodType.generateLast5Years(new Date());
    FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
    Collections.reverse(periods);
    if (periods.size() > 10) {
        periods = periods.subList(0, 10);
    }
    return periods;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Aggregations

CalendarPeriodType (org.hisp.dhis.period.CalendarPeriodType)4 Period (org.hisp.dhis.period.Period)4 PastAndCurrentPeriodFilter (org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter)4 Date (java.util.Date)3 DataSet (org.hisp.dhis.dataset.DataSet)2 ReportTable (org.hisp.dhis.reporttable.ReportTable)2 ArrayList (java.util.ArrayList)1 Calendar (org.hisp.dhis.calendar.Calendar)1 DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)1 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)1 RelativePeriods (org.hisp.dhis.period.RelativePeriods)1 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)1 Report (org.hisp.dhis.report.Report)1 User (org.hisp.dhis.user.User)1