Example usage for org.joda.time DateTime getMillis

List of usage examples for org.joda.time DateTime getMillis

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillis.

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.serotonin.mango.rt.maint.DataPurge.java

License:Open Source License

private void eventPurge() {
    DateTime cutoff = DateUtils.truncateDateTime(new DateTime(runtime), Common.TimePeriods.DAYS);
    cutoff = DateUtils.minus(cutoff, SystemSettingsDao.getIntValue(SystemSettingsDao.EVENT_PURGE_PERIOD_TYPE),
            SystemSettingsDao.getIntValue(SystemSettingsDao.EVENT_PURGE_PERIODS));

    int deleteCount = new EventDao().purgeEventsBefore(cutoff.getMillis());
    if (deleteCount > 0)
        log.info("Event purge ended, " + deleteCount + " events deleted");
}

From source file:com.serotonin.mango.rt.maint.DataPurge.java

License:Open Source License

private void reportPurge() {
    DateTime cutoff = DateUtils.truncateDateTime(new DateTime(runtime), Common.TimePeriods.DAYS);
    cutoff = DateUtils.minus(cutoff, SystemSettingsDao.getIntValue(SystemSettingsDao.REPORT_PURGE_PERIOD_TYPE),
            SystemSettingsDao.getIntValue(SystemSettingsDao.REPORT_PURGE_PERIODS));

    int deleteCount = new ReportDao().purgeReportsBefore(cutoff.getMillis());
    if (deleteCount > 0)
        log.info("Report purge ended, " + deleteCount + " report instances deleted");
}

From source file:com.serotonin.mango.vo.event.ScheduledEventVO.java

License:Open Source License

public void validate(DwrResponseI18n response) {
    if (StringUtils.isLengthGreaterThan(alias, 50))
        response.addContextualMessage("alias", "scheduledEvents.validate.aliasTooLong");

    // Check that cron patterns are ok.
    if (scheduleType == TYPE_CRON) {
        try {//from   www . j  a  v  a  2  s.  com
            new CronTimerTrigger(activeCron);
        } catch (Exception e) {
            response.addContextualMessage("activeCron", "scheduledEvents.validate.activeCron", e.getMessage());
        }

        if (returnToNormal) {
            try {
                new CronTimerTrigger(inactiveCron);
            } catch (Exception e) {
                response.addContextualMessage("inactiveCron", "scheduledEvents.validate.inactiveCron",
                        e.getMessage());
            }
        }
    }

    // Test that the triggers can be created.
    ScheduledEventRT rt = createRuntime();
    try {
        rt.createTrigger(true);
    } catch (RuntimeException e) {
        response.addContextualMessage("activeCron", "scheduledEvents.validate.activeTrigger", e.getMessage());
    }

    if (returnToNormal) {
        try {
            rt.createTrigger(false);
        } catch (RuntimeException e) {
            response.addContextualMessage("inactiveCron", "scheduledEvents.validate.inactiveTrigger",
                    e.getMessage());
        }
    }

    // If the event is once, make sure the active time is earlier than the inactive time.
    if (scheduleType == TYPE_ONCE && returnToNormal) {
        DateTime adt = new DateTime(activeYear, activeMonth, activeDay, activeHour, activeMinute, activeSecond,
                0);
        DateTime idt = new DateTime(inactiveYear, inactiveMonth, inactiveDay, inactiveHour, inactiveMinute,
                inactiveSecond, 0);
        if (idt.getMillis() <= adt.getMillis())
            response.addContextualMessage("scheduleType", "scheduledEvents.validate.invalidRtn");
    }
}

From source file:com.serotonin.mango.vo.report.ReportInstance.java

License:Open Source License

public ReportInstance(ReportVO template) {
    userId = template.getUserId();//from w w w  .  j  a  v a2 s  . c om
    name = template.getName();
    includeEvents = template.getIncludeEvents();
    includeUserComments = template.isIncludeUserComments();

    if (template.getDateRangeType() == ReportVO.DATE_RANGE_TYPE_RELATIVE) {
        if (template.getRelativeDateType() == ReportVO.RELATIVE_DATE_TYPE_PREVIOUS) {
            DateTime date = DateUtils.truncateDateTime(new DateTime(), template.getPreviousPeriodType());
            reportEndTime = date.getMillis();
            date = DateUtils.minus(date, template.getPreviousPeriodType(), template.getPreviousPeriodCount());
            reportStartTime = date.getMillis();
        } else {
            DateTime date = new DateTime();
            reportEndTime = date.getMillis();
            date = DateUtils.minus(date, template.getPastPeriodType(), template.getPastPeriodCount());
            reportStartTime = date.getMillis();
        }
    } else {
        if (!template.isFromNone()) {
            DateTime date = new DateTime(template.getFromYear(), template.getFromMonth(), template.getFromDay(),
                    template.getFromHour(), template.getFromMinute(), 0, 0);
            reportStartTime = date.getMillis();
        }

        if (!template.isToNone()) {
            DateTime date = new DateTime(template.getToYear(), template.getToMonth(), template.getToDay(),
                    template.getToHour(), template.getToMinute(), 0, 0);
            reportEndTime = date.getMillis();
        }
    }
}

From source file:com.serotonin.mango.web.dwr.DataPointDetailsDwr.java

License:Open Source License

@MethodFilter
public DwrResponseI18n getImageChartData(int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute,
        int fromSecond, boolean fromNone, int toYear, int toMonth, int toDay, int toHour, int toMinute,
        int toSecond, boolean toNone, int width, int height) {
    DateTime from = createDateTime(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, fromNone);
    DateTime to = createDateTime(toYear, toMonth, toDay, toHour, toMinute, toSecond, toNone);

    StringBuilder htmlData = new StringBuilder();
    htmlData.append("<img src=\"chart/ft_");
    htmlData.append(System.currentTimeMillis());
    htmlData.append('_');
    htmlData.append(fromNone ? -1 : from.getMillis());
    htmlData.append('_');
    htmlData.append(toNone ? -1 : to.getMillis());
    htmlData.append('_');
    htmlData.append(getDataPointVO().getId());
    htmlData.append(".png?w=");
    htmlData.append(width);/*  w  ww  .  ja v  a 2  s .  c o  m*/
    htmlData.append("&h=");
    htmlData.append(height);
    htmlData.append("\" alt=\"" + getMessage("common.imageChart") + "\"/>");

    DwrResponseI18n response = new DwrResponseI18n();
    response.addData("chart", htmlData.toString());
    addAsof(response);
    return response;
}

From source file:com.serotonin.mango.web.dwr.EventsDwr.java

License:Open Source License

private LongPair getDateRange(int dateRangeType, int relativeDateType, int previousPeriodCount,
        int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear,
        int fromMonth, int fromDay, int fromHour, int fromMinute, int fromSecond, boolean toNone, int toYear,
        int toMonth, int toDay, int toHour, int toMinute, int toSecond) {
    LongPair range = new LongPair(-1, -1);

    if (dateRangeType == DATE_RANGE_TYPE_RELATIVE) {
        if (relativeDateType == RELATIVE_DATE_TYPE_PREVIOUS) {
            DateTime dt = DateUtils.truncateDateTime(new DateTime(), previousPeriodType);
            range.setL2(dt.getMillis());
            dt = DateUtils.minus(dt, previousPeriodType, previousPeriodCount);
            range.setL1(dt.getMillis());
        } else {/* w  w w  .  j  ava 2 s  .  co  m*/
            DateTime dt = new DateTime();
            range.setL2(dt.getMillis());
            dt = DateUtils.minus(dt, pastPeriodType, pastPeriodCount);
            range.setL1(dt.getMillis());
        }
    } else if (dateRangeType == DATE_RANGE_TYPE_SPECIFIC) {
        if (!fromNone) {
            DateTime dt = new DateTime(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, 0);
            range.setL1(dt.getMillis());
        }

        if (!toNone) {
            DateTime dt = new DateTime(toYear, toMonth, toDay, toHour, toMinute, toSecond, 0);
            range.setL2(dt.getMillis());
        }
    }

    return range;
}

From source file:com.serotonin.mango.web.dwr.WatchListDwr.java

License:Open Source License

/**
 * Method for creating image charts of the points on the watch list.
 *//* w w w  . j a  v  a 2s .  c  om*/
public String getImageChartData(int[] pointIds, int fromYear, int fromMonth, int fromDay, int fromHour,
        int fromMinute, int fromSecond, boolean fromNone, int toYear, int toMonth, int toDay, int toHour,
        int toMinute, int toSecond, boolean toNone, int width, int height) {
    DateTime from = createDateTime(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, fromNone);
    DateTime to = createDateTime(toYear, toMonth, toDay, toHour, toMinute, toSecond, toNone);

    StringBuilder htmlData = new StringBuilder();
    htmlData.append("<img src=\"achart/ft_");
    htmlData.append(System.currentTimeMillis());
    htmlData.append('_');
    htmlData.append(fromNone ? -1 : from.getMillis());
    htmlData.append('_');
    htmlData.append(toNone ? -1 : to.getMillis());

    boolean pointsFound = false;
    // Add the list of points that are numeric.
    List<DataPointVO> watchList = Common.getUser().getWatchList().getPointList();
    for (DataPointVO dp : watchList) {
        int dtid = dp.getPointLocator().getDataTypeId();
        if ((dtid == DataTypes.NUMERIC || dtid == DataTypes.BINARY || dtid == DataTypes.MULTISTATE)
                && ArrayUtils.contains(pointIds, dp.getId())) {
            pointsFound = true;
            htmlData.append('_');
            htmlData.append(dp.getId());
        }
    }

    if (!pointsFound)
        // There are no chartable points, so abort the image creation.
        return getMessage("watchlist.noChartables");

    htmlData.append(".png?w=");
    htmlData.append(width);
    htmlData.append("&h=");
    htmlData.append(height);
    htmlData.append("\" alt=\"" + getMessage("common.imageChart") + "\"/>");

    return htmlData.toString();
}

From source file:com.seyren.mongo.MongoStore.java

License:Apache License

@Override
public Check saveCheck(Check check) {
    DBObject findObject = forId(check.getId());

    DateTime lastCheck = check.getLastCheck();

    DBObject partialObject = object("name", check.getName()).with("description", check.getDescription())
            .with("target", check.getTarget()).with("from", Strings.emptyToNull(check.getFrom()))
            .with("until", Strings.emptyToNull(check.getUntil())).with("warn", check.getWarn().toPlainString())
            .with("error", check.getError().toPlainString()).with("enabled", check.isEnabled())
            .with("live", check.isLive()).with("allowNoData", check.isAllowNoData())
            .with("lastCheck", lastCheck == null ? null : new Date(lastCheck.getMillis()))
            .with("state", check.getState().toString());

    DBObject setObject = object("$set", partialObject);

    getChecksCollection().update(findObject, setObject);

    return check;
}

From source file:com.seyren.mongo.MongoStore.java

License:Apache License

@Override
public Check updateStateAndLastCheck(String checkId, AlertType state, DateTime lastCheck) {
    DBObject findObject = forId(checkId);

    DBObject partialObject = object("lastCheck", new Date(lastCheck.getMillis())).with("state",
            state.toString());/*ww w  .  java  2  s .c o  m*/

    DBObject setObject = object("$set", partialObject);

    getChecksCollection().update(findObject, setObject);

    return getCheck(checkId);
}

From source file:com.seyren.mongo.MongoStore.java

License:Apache License

@Override
public void deleteAlerts(String checkId, DateTime before) {
    DBObject query = object("checkId", checkId);

    if (before != null) {
        query.put("timestamp", object("$lt", new Date(before.getMillis())));
    }// ww w. ja v a  2  s .c  o m

    getAlertsCollection().remove(query);
}