use of org.hisp.dhis.period.CalendarPeriodType 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;
}
use of org.hisp.dhis.period.CalendarPeriodType 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;
}
use of org.hisp.dhis.period.CalendarPeriodType in project dhis2-core by dhis2.
the class DefaultPdfDataEntryFormService method getProgramStagePeriodList.
private List<Period> getProgramStagePeriodList() throws ParseException {
PeriodType periodType = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
Period period = setPeriodDateRange(periodType);
return ((CalendarPeriodType) periodType).generatePeriods(period.getStartDate(), period.getEndDate());
}
use of org.hisp.dhis.period.CalendarPeriodType 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;
}
}
use of org.hisp.dhis.period.CalendarPeriodType 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;
}
Aggregations