use of com.serotonin.timer.CronTimerTrigger in project ma-modules-public by infiniteautomation.
the class ScheduledEventVO method validate.
public void validate(ProcessResult response) {
if (StringValidation.isLengthGreaterThan(alias, 50))
response.addContextualMessage("alias", "scheduledEvents.validate.aliasTooLong");
// Check that cron patterns are ok.
if (scheduleType == TYPE_CRON) {
try {
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");
}
}
use of com.serotonin.timer.CronTimerTrigger in project ma-modules-public by infiniteautomation.
the class ReportVO method validate.
@Override
public void validate(ProcessResult response) {
super.validate(response);
if (points.isEmpty())
response.addContextualMessage("points", "reports.validate.needPoint");
if (dateRangeType != ReportVO.DATE_RANGE_TYPE_RELATIVE && dateRangeType != ReportVO.DATE_RANGE_TYPE_SPECIFIC)
response.addGenericMessage("reports.validate.invalidDateRangeType");
if (relativeDateType != ReportVO.RELATIVE_DATE_TYPE_PAST && relativeDateType != ReportVO.RELATIVE_DATE_TYPE_PREVIOUS)
response.addGenericMessage("reports.validate.invalidRelativeDateType");
if (previousPeriodCount < 1)
response.addContextualMessage("previousPeriodCount", "reports.validate.periodCountLessThan1");
if (pastPeriodCount < 1)
response.addContextualMessage("pastPeriodCount", "reports.validate.periodCountLessThan1");
UserDao dao = UserDao.instance;
User user = dao.getUser(userId);
if (user == null) {
response.addContextualMessage("userId", "reports.validate.userDNE");
}
File t = ReportCommon.instance.getTemplateFile(template);
if (!t.isFile())
response.addContextualMessage("template", "reports.validate.template");
DataPointDao dataPointDao = DataPointDao.instance;
for (ReportPointVO point : points) {
DataPointVO vo = dataPointDao.getDataPoint(point.getPointId(), false);
String pointXid = "unknown";
if (vo != null) {
pointXid = vo.getXid();
try {
Permissions.ensureDataPointReadPermission(user, dataPointDao.getDataPoint(point.getPointId(), false));
} catch (PermissionException e) {
response.addContextualMessage("points", "reports.vaildate.pointDNE");
}
} else {
response.addContextualMessage("points", "reports.validate.pointPermissions", user.getUsername(), pointXid);
}
try {
if (!StringUtils.isBlank(point.getColour()))
ColorUtils.toColor(point.getColour());
} catch (InvalidArgumentException e) {
response.addContextualMessage("points", "reports.validate.colour", point.getColour(), pointXid);
}
if (point.getWeight() <= 0)
response.addContextualMessage("points", "reports.validate.weight");
}
// Validate the schedule
if (schedule) {
if (schedulePeriod == SCHEDULE_CRON) {
try {
new CronTimerTrigger(scheduleCron);
} catch (ParseException e) {
response.addContextualMessage("scheduleCron", "validate.invalidValue");
}
}
}
}
use of com.serotonin.timer.CronTimerTrigger in project ma-modules-public by infiniteautomation.
the class ReportsDwr method saveReport.
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult saveReport(int id, String name, String xid, List<ReportPointVO> points, String template, int includeEvents, boolean includeUserComments, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, boolean schedule, int schedulePeriod, int runDelayMinutes, String scheduleCron, boolean email, boolean includeData, boolean zipData, List<RecipientListEntryBean> recipients) {
ProcessResult response = new ProcessResult();
// Basic validation
validateData(response, name, points, dateRangeType, relativeDateType, previousPeriodCount, pastPeriodCount);
// Validate XID
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!ReportDao.instance.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
if (schedule) {
if (schedulePeriod == ReportVO.SCHEDULE_CRON) {
// Check the cron pattern.
try {
new CronTimerTrigger(scheduleCron);
} catch (Exception e) {
response.addContextualMessage("scheduleCron", "reports.validate.cron", e.getMessage());
}
} else {
if (runDelayMinutes < 0)
response.addContextualMessage("runDelayMinutes", "reports.validate.lessThan0");
else if (runDelayMinutes > 59)
response.addContextualMessage("runDelayMinutes", "reports.validate.greaterThan59");
}
}
if (email && recipients.isEmpty())
response.addContextualMessage("recipients", "reports.validate.needRecip");
if (response.getHasMessages())
return response;
User user = Common.getUser();
ReportDao reportDao = ReportDao.instance;
ReportVO report;
if (id == Common.NEW_ID) {
report = new ReportVO();
report.setUserId(user.getId());
} else
report = reportDao.getReport(id);
ReportCommon.ensureReportPermission(user, report);
// Update the new values.
report.setXid(xid);
report.setName(name);
report.setPoints(points);
report.setTemplate(template);
report.setIncludeEvents(includeEvents);
report.setIncludeUserComments(includeUserComments);
report.setDateRangeType(dateRangeType);
report.setRelativeDateType(relativeDateType);
report.setPreviousPeriodCount(previousPeriodCount);
report.setPreviousPeriodType(previousPeriodType);
report.setPastPeriodCount(pastPeriodCount);
report.setPastPeriodType(pastPeriodType);
report.setFromNone(fromNone);
report.setFromYear(fromYear);
report.setFromMonth(fromMonth);
report.setFromDay(fromDay);
report.setFromHour(fromHour);
report.setFromMinute(fromMinute);
report.setToNone(toNone);
report.setToYear(toYear);
report.setToMonth(toMonth);
report.setToDay(toDay);
report.setToHour(toHour);
report.setToMinute(toMinute);
report.setSchedule(schedule);
report.setSchedulePeriod(schedulePeriod);
report.setRunDelayMinutes(runDelayMinutes);
report.setScheduleCron(scheduleCron);
report.setEmail(email);
report.setIncludeData(includeData);
report.setZipData(zipData);
report.setRecipients(recipients);
// Save the report
reportDao.saveReport(report);
// Conditionally schedule the report.
String host = "";
WebContext webContext = WebContextFactory.get();
int port;
if (webContext != null) {
HttpServletRequest req = webContext.getHttpServletRequest();
host = req.getServerName();
port = req.getLocalPort();
} else {
port = Common.envProps.getInt("web.port", 8080);
}
ReportJob.scheduleReportJob(host, port, report);
// Send back the report id in case this was new.
response.addData("reportId", report.getId());
response.addData("report", report);
return response;
}
use of com.serotonin.timer.CronTimerTrigger in project ma-modules-public by infiniteautomation.
the class MaintenanceEventRT method createTrigger.
public TimerTrigger createTrigger(boolean activeTrigger) {
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_MANUAL)
return null;
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_CRON) {
try {
if (activeTrigger)
return new CronTimerTrigger(vo.getActiveCron());
return new CronTimerTrigger(vo.getInactiveCron());
} catch (ParseException e) {
// Should never happen, so wrap and rethrow
throw new ShouldNeverHappenException(e);
}
}
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_ONCE) {
DateTime dt;
if (activeTrigger)
dt = new DateTime(vo.getActiveYear(), vo.getActiveMonth(), vo.getActiveDay(), vo.getActiveHour(), vo.getActiveMinute(), vo.getActiveSecond(), 0);
else
dt = new DateTime(vo.getInactiveYear(), vo.getInactiveMonth(), vo.getInactiveDay(), vo.getInactiveHour(), vo.getInactiveMinute(), vo.getInactiveSecond(), 0);
return new OneTimeTrigger(new Date(dt.getMillis()));
}
int month = vo.getActiveMonth();
int day = vo.getActiveDay();
int hour = vo.getActiveHour();
int minute = vo.getActiveMinute();
int second = vo.getActiveSecond();
if (!activeTrigger) {
month = vo.getInactiveMonth();
day = vo.getInactiveDay();
hour = vo.getInactiveHour();
minute = vo.getInactiveMinute();
second = vo.getInactiveSecond();
}
StringBuilder expression = new StringBuilder();
expression.append(second).append(' ');
expression.append(minute).append(' ');
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_HOURLY)
expression.append("* * * ?");
else {
expression.append(hour).append(' ');
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_DAILY)
expression.append("* * ?");
else if (vo.getScheduleType() == MaintenanceEventVO.TYPE_WEEKLY)
expression.append("? * ").append(weekdays[day]);
else {
if (day > 0)
expression.append(day);
else if (day == -1)
expression.append('L');
else
expression.append(-day).append('L');
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_MONTHLY)
expression.append(" * ?");
else
expression.append(' ').append(month).append(" ?");
}
}
CronTimerTrigger cronTrigger;
try {
cronTrigger = new CronTimerTrigger(expression.toString());
} catch (ParseException e) {
// Should never happen, so wrap and rethrow
throw new ShouldNeverHappenException(e);
}
return cronTrigger;
}
use of com.serotonin.timer.CronTimerTrigger in project ma-core-public by infiniteautomation.
the class PollingDataSource method beginPolling.
//
//
// Data source interface
//
@Override
public void beginPolling() {
if (cronPattern == null) {
long delay = 0;
if (quantize) {
// Quantize the start.
long now = Common.timer.currentTimeMillis();
delay = pollingPeriodMillis - (now % pollingPeriodMillis);
if (LOG.isDebugEnabled())
LOG.debug("First poll should be at: " + (now + delay));
}
timerTask = new TimeoutTask(new FixedRateTrigger(delay, pollingPeriodMillis), this.timeoutClient);
} else {
try {
timerTask = new TimeoutTask(new CronTimerTrigger(cronPattern), this.timeoutClient);
} catch (ParseException e) {
// Should not happen
throw new RuntimeException(e);
}
}
super.beginPolling();
}
Aggregations