use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class ReportController method getReport.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getReport(HttpServletRequest request, HttpServletResponse response, String uid, String organisationUnitUid, String isoPeriod, Date date, String type, String contentType, boolean attachment) throws Exception {
Report report = reportService.getReport(uid);
if (report == null) {
throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
}
if (organisationUnitUid == null && report.hasReportTable() && report.getReportTable().hasReportParams() && report.getReportTable().getReportParams().isOrganisationUnitSet()) {
organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
}
if (report.isTypeHtml()) {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, report.getCacheStrategy());
reportService.renderHtmlReport(response.getWriter(), uid, date, organisationUnitUid);
} else {
date = date != null ? date : new DateTime().minusMonths(1).toDate();
Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString(isoPeriod) : new MonthlyPeriodType().createPeriod(date);
String filename = CodecUtils.filenameEncode(report.getName()) + "." + type;
contextUtils.configureResponse(response, contentType, report.getCacheStrategy(), filename, attachment);
JasperPrint print = reportService.renderReport(response.getOutputStream(), uid, period, organisationUnitUid, type);
if ("html".equals(type)) {
request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
}
}
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class EventQueryParamsTest method testReplacePeriodsWithStartEndDates.
@Test
public void testReplacePeriodsWithStartEndDates() {
List<DimensionalItemObject> periods = new ArrayList<>();
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 5, 1, 0, 0).toDate()));
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 6, 1, 0, 0).toDate()));
EventQueryParams params = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, periods)).build();
assertNull(params.getStartDate());
assertNull(params.getEndDate());
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
assertEquals(new DateTime(2014, 4, 1, 0, 0).toDate(), params.getStartDate());
assertEquals(new DateTime(2014, 6, 30, 0, 0).toDate(), params.getEndDate());
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class QueryPlannerTest method setUpTest.
@Override
public void setUpTest() {
PeriodType pt = new MonthlyPeriodType();
itA = createIndicatorType('A');
idObjectManager.save(itA);
inA = createIndicator('A', itA);
inB = createIndicator('B', itA);
idObjectManager.save(inA);
idObjectManager.save(inB);
prA = createProgram('A');
idObjectManager.save(prA);
deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM);
deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT);
deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT);
deE = createDataElement('E', ValueType.TEXT, AggregationType.NONE);
deF = createDataElement('F', ValueType.TEXT, AggregationType.NONE);
deG = createDataElement('G', ValueType.INTEGER, AggregationType.SUM);
deH = createDataElement('H', ValueType.INTEGER, AggregationType.SUM);
dataElementService.addDataElement(deA);
dataElementService.addDataElement(deB);
dataElementService.addDataElement(deC);
dataElementService.addDataElement(deD);
dataElementService.addDataElement(deE);
dataElementService.addDataElement(deF);
dataElementService.addDataElement(deG);
dataElementService.addDataElement(deH);
pdeA = new ProgramDataElementDimensionItem(prA, deA);
pdeB = new ProgramDataElementDimensionItem(prA, deB);
DataSet dsA = createDataSet('A', pt);
DataSet dsB = createDataSet('B', pt);
DataSet dsC = createDataSet('C', pt);
DataSet dsD = createDataSet('D', pt);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
dataSetService.addDataSet(dsC);
dataSetService.addDataSet(dsD);
rrA = new ReportingRate(dsA);
rrB = new ReportingRate(dsB);
rrC = new ReportingRate(dsC);
rrD = new ReportingRate(dsD);
peA = PeriodType.getPeriodFromIsoString("201501");
peB = PeriodType.getPeriodFromIsoString("201502");
coc = categoryService.getDefaultDataElementCategoryOptionCombo();
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
ouC = createOrganisationUnit('C');
ouD = createOrganisationUnit('D');
ouE = createOrganisationUnit('E');
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
organisationUnitService.addOrganisationUnit(ouD);
organisationUnitService.addOrganisationUnit(ouE);
degA = createDataElementGroup('A');
degA.addDataElement(deA);
degA.addDataElement(deB);
dataElementService.addDataElementGroup(degA);
dgsA = createDataElementGroupSet('A');
dgsA.getMembers().add(degA);
dataElementService.addDataElementGroupSet(dgsA);
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class AdxPeriod method parse.
public static Period parse(String periodString) throws AdxException {
String[] tokens = periodString.split("/");
if (tokens.length != 2) {
throw new AdxException(periodString + " not in valid <date>/<duration> format");
}
try {
Period period = null;
PeriodType periodType = null;
Date startDate = DateUtils.getMediumDate(tokens[0]);
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
Duration duration = Duration.valueOf(tokens[1]);
switch(duration) {
case P1D:
periodType = new DailyPeriodType();
break;
case P7D:
periodType = new WeeklyPeriodType();
break;
case P1M:
periodType = new MonthlyPeriodType();
break;
case P2M:
periodType = new BiMonthlyPeriodType();
break;
case P1Q:
periodType = new QuarterlyPeriodType();
break;
case P6M:
switch(cal.get(Calendar.MONTH)) {
case 0:
periodType = new SixMonthlyPeriodType();
break;
case 6:
periodType = new SixMonthlyAprilPeriodType();
break;
default:
throw new AdxException(periodString + "is invalid sixmonthly type");
}
case P1Y:
switch(cal.get(Calendar.MONTH)) {
case 0:
periodType = new YearlyPeriodType();
break;
case 3:
periodType = new FinancialAprilPeriodType();
break;
case 6:
periodType = new FinancialJulyPeriodType();
break;
case 9:
periodType = new FinancialOctoberPeriodType();
break;
default:
throw new AdxException(periodString + "is invalid yearly type");
}
}
if (periodType != null) {
period = periodType.createPeriod(startDate);
} else {
throw new AdxException("Failed to create period type from " + duration);
}
return period;
} catch (IllegalArgumentException ex) {
throw new AdxException(tokens[1] + " is not a supported duration type");
}
}
use of org.hisp.dhis.period.MonthlyPeriodType in project dhis2-core by dhis2.
the class DhisConvenienceTest method createDataSet.
/**
* @param uniqueCharacter A unique character to identify the object.
*/
public static DataSet createDataSet(char uniqueCharacter) {
DataSet dataSet = createDataSet(uniqueCharacter, null);
dataSet.setPeriodType(new MonthlyPeriodType());
return dataSet;
}
Aggregations