Search in sources :

Example 11 with DateRange

use of org.activityinfo.shared.report.model.DateRange in project activityinfo by bedatadriven.

the class DateRangeDialog method onButtonPressed.

@Override
protected void onButtonPressed(Button button) {
    if (button.getItemId().equals("ok")) {
        if (callback != null) {
            callback.onSelected(new DateRange(date1.getValue(), date2.getValue()));
        }
    }
    this.callback = null;
    hide();
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange)

Example 12 with DateRange

use of org.activityinfo.shared.report.model.DateRange in project activityinfo by bedatadriven.

the class DateUtilGWTImpl method monthRange.

@Override
public DateRange monthRange(int year, int month) {
    DateRange range = new DateRange();
    DateWrapper date = new DateWrapper(year, month - 1, 1);
    range.setMinDate(date.asDate());
    date = date.addMonths(1);
    date = date.addDays(-1);
    range.setMaxDate(date.asDate());
    return range;
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) DateWrapper(com.extjs.gxt.ui.client.util.DateWrapper)

Example 13 with DateRange

use of org.activityinfo.shared.report.model.DateRange in project activityinfo by bedatadriven.

the class RenderElementHandler method execute.

@Override
public CommandResult execute(RenderElement cmd, User user) throws CommandException {
    try {
        Renderer renderer = rendererFactory.get(cmd.getFormat());
        TempStorage storage = storageProvider.allocateTemporaryFile(renderer.getMimeType(), cmd.getFilename() + renderer.getFileSuffix());
        LOGGER.fine("Rendering element: " + cmd + "\nURL: " + storage.getUrl());
        try {
            generator.generateElement(user, cmd.getElement(), new Filter(), new DateRange());
            renderer.render(cmd.getElement(), storage.getOutputStream());
        } finally {
            try {
                storage.getOutputStream().close();
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Exception while closing storage: " + e.getMessage(), e);
            }
        }
        return new UrlResult(storage.getUrl());
    } catch (Exception e) {
        throw new RuntimeException("Exception generating export", e);
    }
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) TempStorage(org.activityinfo.server.report.output.TempStorage) Filter(org.activityinfo.shared.command.Filter) Renderer(org.activityinfo.server.report.renderer.Renderer) CommandException(org.activityinfo.shared.exception.CommandException) UrlResult(org.activityinfo.shared.command.result.UrlResult)

Example 14 with DateRange

use of org.activityinfo.shared.report.model.DateRange in project activityinfo by bedatadriven.

the class ReportServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // first, authenticate the response
    AuthenticationDAO authDAO = injector.getInstance(AuthenticationDAO.class);
    Authentication auth = authDAO.findById(req.getParameter("auth"));
    if (auth == null) {
        resp.setStatus(500);
        return;
    }
    // now apply the user filters
    EntityManager em = injector.getInstance(EntityManager.class);
    DomainFilters.applyUserFilter(auth.getUser(), em);
    // load the report definition by id
    ReportDefinition template = em.find(ReportDefinition.class, Integer.parseInt(req.getParameter("id")));
    Report report = null;
    try {
        report = ReportParserJaxb.parseXml(template.getXml());
    } catch (Exception e) {
        e.printStackTrace();
        resp.setStatus(500);
    }
    // parse parameters
    DateRange dateRange = new DateRange();
    if (req.getParameter("minDate") != null) {
        dateRange.setMinDate(new Date(Long.parseLong(req.getParameter("minDate"))));
    }
    if (req.getParameter("maxDate") != null) {
        dateRange.setMaxDate(new Date(Long.parseLong(req.getParameter("maxDate"))));
    }
    // generate the report content
    ReportGenerator gtor = injector.getInstance(ReportGenerator.class);
    gtor.generate(auth.getUser(), report, null, dateRange);
    // render in the requested format
    RenderElement.Format format = RenderElement.Format.valueOf(req.getParameter("format"));
    RendererFactory factory = injector.getInstance(RendererFactory.class);
    Renderer renderer = factory.get(format);
    // composefile name
    String filename = report.getContent().getFileName() + renderer.getFileSuffix();
    resp.setContentType(renderer.getMimeType());
    resp.addHeader("Content-Disposition", "attachment; filename=" + filename);
    try {
        renderer.render(report, resp.getOutputStream());
    } catch (IOException e) {
        e.printStackTrace();
        resp.setStatus(500);
    }
}
Also used : RenderElement(org.activityinfo.shared.command.RenderElement) Report(org.activityinfo.shared.report.model.Report) AuthenticationDAO(org.activityinfo.server.database.hibernate.dao.AuthenticationDAO) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Date(java.util.Date) EntityManager(javax.persistence.EntityManager) DateRange(org.activityinfo.shared.report.model.DateRange) ReportGenerator(org.activityinfo.server.report.generator.ReportGenerator) RendererFactory(org.activityinfo.server.report.renderer.RendererFactory) Authentication(org.activityinfo.server.database.hibernate.entity.Authentication) Renderer(org.activityinfo.server.report.renderer.Renderer) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 15 with DateRange

use of org.activityinfo.shared.report.model.DateRange in project activityinfo by bedatadriven.

the class EmptyChartsTest method generate.

@Test
public void generate() {
    PivotChartReportElement element = new PivotChartReportElement(Type.StackedBar);
    element.setIndicator(1);
    element.addCategoryDimension(new Dimension(DimensionType.Partner));
    element.addSeriesDimension(new Dimension(DimensionType.Database));
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(Collections.EMPTY_LIST));
    expect(dispatcher.execute(isA(GetDimensionLabels.class))).andReturn(new GetDimensionLabels.DimensionLabels(Collections.EMPTY_MAP));
    replay(dispatcher);
    IndicatorDAO indicatorDAO = createMock(IndicatorDAO.class);
    expect(indicatorDAO.findById(eq(1))).andReturn(new Indicator());
    replay(indicatorDAO);
    PivotChartGenerator generator = new PivotChartGenerator(dispatcher, indicatorDAO);
    generator.generate(new User(), element, new Filter(), new DateRange());
}
Also used : IndicatorDAO(org.activityinfo.server.database.hibernate.dao.IndicatorDAO) GetDimensionLabels(org.activityinfo.shared.command.GetDimensionLabels) User(org.activityinfo.server.database.hibernate.entity.User) Dimension(org.activityinfo.shared.report.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) PivotSites(org.activityinfo.shared.command.PivotSites) DateRange(org.activityinfo.shared.report.model.DateRange) Filter(org.activityinfo.shared.command.Filter) PivotChartGenerator(org.activityinfo.server.report.generator.PivotChartGenerator) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Aggregations

DateRange (org.activityinfo.shared.report.model.DateRange)17 Test (org.junit.Test)5 DateWrapper (com.extjs.gxt.ui.client.util.DateWrapper)4 Filter (org.activityinfo.shared.command.Filter)4 IOException (java.io.IOException)3 Calendar (java.util.Calendar)3 Dimension (org.activityinfo.shared.report.model.Dimension)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 Date (java.util.Date)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 User (org.activityinfo.server.database.hibernate.entity.User)2 Renderer (org.activityinfo.server.report.renderer.Renderer)2 CommandException (org.activityinfo.shared.exception.CommandException)2 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)2 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)2 DateDimension (org.activityinfo.shared.report.model.DateDimension)2 Report (org.activityinfo.shared.report.model.Report)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1