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();
}
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;
}
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);
}
}
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);
}
}
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());
}
Aggregations