Search in sources :

Example 1 with DateRange

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

the class ReportJsonFactory method decodeFilter.

public Filter decodeFilter(JsonObject filter) {
    Filter elementFilter = new Filter();
    JsonElement jsonMinDate = filter.get("minDate");
    JsonElement jsonMaxDate = filter.get("maxDate");
    DateRange dateRange = new DateRange();
    if (jsonMinDate != null) {
        jsonMinDate.getAsLong();
        Date minDate = new Date(jsonMinDate.getAsLong());
        dateRange.setMinDate(minDate);
    }
    if (jsonMaxDate != null) {
        Date maxDate = new Date(jsonMaxDate.getAsLong());
        dateRange.setMaxDate(maxDate);
    }
    elementFilter.setDateRange(dateRange);
    JsonArray restrictions = (JsonArray) filter.get("restrictions");
    for (int i = 0; i < restrictions.size(); i++) {
        JsonObject rest = (JsonObject) restrictions.get(i);
        JsonArray arr = rest.get("set").getAsJsonArray();
        Set<Integer> set = new HashSet<Integer>();
        Iterator<JsonElement> it = arr.iterator();
        while (it.hasNext()) {
            set.add(it.next().getAsInt());
        }
        elementFilter.addRestriction(DimensionType.valueOf(rest.get("type").getAsString()), set);
    }
    return elementFilter;
}
Also used : JsonArray(com.google.gson.JsonArray) DateRange(org.activityinfo.shared.report.model.DateRange) Filter(org.activityinfo.shared.command.Filter) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) HashSet(java.util.HashSet)

Example 2 with DateRange

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

the class DateUtilGWTImpl method yearRange.

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

Example 3 with DateRange

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

the class RenderReportHtmlHandler method execute.

@Override
@LogException
public CommandResult execute(RenderReportHtml cmd, User user) throws CommandException {
    ReportElement model = cmd.getModel();
    LOGGER.fine("Model: " + model);
    // don't show the title: it will be rendered by the container
    model.setTitle(null);
    generator.generateElement(user, model, new Filter(), new DateRange());
    StringWriter writer = new StringWriter();
    try {
        renderer.render(model, writer);
    } catch (IOException e) {
        throw new CommandException(e);
    }
    return new HtmlResult(writer.toString());
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) StringWriter(java.io.StringWriter) Filter(org.activityinfo.shared.command.Filter) HtmlResult(org.activityinfo.shared.command.result.HtmlResult) ReportElement(org.activityinfo.shared.report.model.ReportElement) IOException(java.io.IOException) CommandException(org.activityinfo.shared.exception.CommandException) LogException(org.activityinfo.server.util.logging.LogException)

Example 4 with DateRange

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

the class ReportMailer method execute.

public void execute(Date today, ReportSubscription sub, Report report) throws IOException {
    // set up authentication for the subscriber of this report
    authProvider.set(sub.getUser());
    DomainFilters.applyUserFilter(sub.getUser(), em);
    // render the report to a temp file
    // generate the report
    reportGenerator.generate(sub.getUser(), report, null, new DateRange());
    ByteArrayOutputStream rtf = new ByteArrayOutputStream();
    rtfReportRenderer.render(report, rtf);
    rtf.close();
    try {
        mailReport(sub, report, today, rtf.toByteArray());
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Report mailing of " + sub.getTemplate().getId() + " failed for user " + sub.getUser().getEmail(), e);
    }
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 5 with DateRange

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

the class DateUtilCalendarImpl method yearRange.

@Override
public DateRange yearRange(int year) {
    DateRange range = new DateRange();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DATE, 1);
    range.setMinDate(calendar.getTime());
    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
    calendar.set(Calendar.DATE, 31);
    range.setMaxDate(calendar.getTime());
    return range;
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) Calendar(java.util.Calendar)

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