Search in sources :

Example 1 with DateUtilCalendarImpl

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();
}
Also used : Month(org.activityinfo.model.type.time.Month) PivotSites(org.activityinfo.legacy.shared.command.PivotSites) WebApplicationException(javax.ws.rs.WebApplicationException) Filter(org.activityinfo.legacy.shared.command.Filter) DateUtilCalendarImpl(org.activityinfo.server.report.util.DateUtilCalendarImpl) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) Produces(javax.ws.rs.Produces) Timed(org.activityinfo.server.util.monitoring.Timed) GET(javax.ws.rs.GET)

Example 2 with DateUtilCalendarImpl

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());
}
Also used : DateRange(org.activityinfo.legacy.shared.reports.model.DateRange) User(org.activityinfo.server.database.hibernate.entity.User) Report(org.activityinfo.legacy.shared.reports.model.Report) DateUtil(org.activityinfo.legacy.shared.reports.util.DateUtil) DateUtilCalendarImpl(org.activityinfo.server.report.util.DateUtilCalendarImpl) Test(org.junit.Test)

Aggregations

DateUtilCalendarImpl (org.activityinfo.server.report.util.DateUtilCalendarImpl)2 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)1 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)1 DateRange (org.activityinfo.legacy.shared.reports.model.DateRange)1 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)1 Report (org.activityinfo.legacy.shared.reports.model.Report)1 DateUtil (org.activityinfo.legacy.shared.reports.util.DateUtil)1 Month (org.activityinfo.model.type.time.Month)1 User (org.activityinfo.server.database.hibernate.entity.User)1 Timed (org.activityinfo.server.util.monitoring.Timed)1 Test (org.junit.Test)1