use of org.activityinfo.server.report.util.DateUtilCalendarImpl in project activityinfo by bedatadriven.
the class CubeResource method pivot.
@GET
@Timed(name = "api.rest.sites.pivot")
@Produces("application/json")
public List<Bucket> pivot(@QueryParam("dimension") List<String> dimensions, @QueryParam("form") List<Integer> forms, @QueryParam("month") String monthName) {
Filter filter = new Filter();
if (forms.size() == 0) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Must specify at least one ?form={formId}").build());
}
filter.addRestriction(DimensionType.Activity, forms);
if (monthName != null) {
Month month = Month.parseMonth(monthName);
filter.setEndDateRange(new DateUtilCalendarImpl().monthRange(month));
}
Set<Dimension> pivotDimensions = Sets.newHashSet();
if (forms.size() == 0) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Must specify at least one ?dimension={indicator|form|database|...}").build());
}
for (String dimension : dimensions) {
switch(dimension) {
case "indicator":
pivotDimensions.add(new Dimension(DimensionType.Indicator));
break;
case "site":
pivotDimensions.add(new Dimension(DimensionType.Site));
break;
case "month":
pivotDimensions.add(new DateDimension(DateUnit.MONTH));
break;
case "partner":
pivotDimensions.add(new Dimension(DimensionType.Partner));
break;
default:
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid dimension '" + dimension + "'").build());
}
}
PivotSites query = new PivotSites();
query.setFilter(filter);
query.setDimensions(pivotDimensions);
if (query.isTooBroad()) {
return Lists.newArrayList();
}
PivotSites.PivotResult result = dispatcherSync.execute(query);
return result.getBuckets();
}
use of org.activityinfo.server.report.util.DateUtilCalendarImpl in project activityinfo by bedatadriven.
the class ReportGeneratorTest method testFileName.
@Test
public void testFileName() {
// Input user
User user = new User();
user.setLocale("en");
// Input test data: report model + parameter
Report report = new Report();
report.setFileName("Report ${DATE_RANGE} of Activities");
// Input test data: parameter values
DateUtil dateUtil = new DateUtilCalendarImpl();
DateRange dateRange = dateUtil.monthRange(2009, 1);
// class under test
ReportGenerator generator = new ReportGenerator(null, null, null, null, null);
generator.generate(user, report, null, dateRange);
// VERIFY correct file name
Assert.assertEquals("Report Jan 2009 of Activities", report.getContent().getFileName());
}
Aggregations