use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method getMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvent(int id) {
ProcessResult response = new ProcessResult();
MaintenanceEventVO me;
boolean activated = false;
if (id == Common.NEW_ID) {
DateTime dt = new DateTime();
me = new MaintenanceEventVO();
me.setXid(new MaintenanceEventDao().generateUniqueXid());
me.setActiveYear(dt.getYear());
me.setInactiveYear(dt.getYear());
me.setActiveMonth(dt.getMonthOfYear());
me.setInactiveMonth(dt.getMonthOfYear());
} else {
me = new MaintenanceEventDao().getMaintenanceEvent(id);
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(me.getId());
if (rt != null)
activated = rt.isEventActive();
}
response.addData("me", me);
response.addData("activated", activated);
return response;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsDwr method toggleMaintenanceEvent.
@DwrPermission(admin = true)
public ProcessResult toggleMaintenanceEvent(int id) {
ProcessResult response = new ProcessResult();
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(id);
boolean activated = false;
if (rt == null)
response.addMessage(new TranslatableMessage("maintenanceEvents.toggle.disabled"));
else
activated = rt.toggle();
response.addData("activated", activated);
return response;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsService method commonValidation.
public ProcessResult commonValidation(MaintenanceEventVO vo) {
ProcessResult response = super.validate(vo);
if ((vo.getDataSources().size() < 1) && (vo.getDataPoints().size() < 1)) {
response.addContextualMessage("dataSources", "validate.invalidValue");
response.addContextualMessage("dataPoints", "validate.invalidValue");
}
// Validate that the ids are legit
for (int i = 0; i < vo.getDataSources().size(); i++) {
DataSourceVO ds = DataSourceDao.getInstance().get(vo.getDataSources().get(i));
if (ds == null) {
response.addContextualMessage("dataSources[" + i + "]", "validate.invalidValue");
}
}
for (int i = 0; i < vo.getDataPoints().size(); i++) {
DataPointVO dp = DataPointDao.getInstance().get(vo.getDataPoints().get(i));
if (dp == null) {
response.addContextualMessage("dataPoints[" + i + "]", "validate.invalidValue");
}
}
// Check that cron patterns are ok.
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_CRON) {
try {
new CronTimerTrigger(vo.getActiveCron());
} catch (Exception e) {
response.addContextualMessage("activeCron", "maintenanceEvents.validate.activeCron", e.getMessage());
}
try {
new CronTimerTrigger(vo.getInactiveCron());
} catch (Exception e) {
response.addContextualMessage("inactiveCron", "maintenanceEvents.validate.inactiveCron", e.getMessage());
}
}
// Test that the triggers can be created.
MaintenanceEventRT rt = new MaintenanceEventRT(vo);
try {
rt.createTrigger(true);
} catch (RuntimeException e) {
response.addContextualMessage("activeCron", "maintenanceEvents.validate.activeTrigger", e.getMessage());
}
try {
rt.createTrigger(false);
} catch (RuntimeException e) {
response.addContextualMessage("inactiveCron", "maintenanceEvents.validate.inactiveTrigger", e.getMessage());
}
// If the event is once, make sure the active time is earlier than the inactive time.
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_ONCE) {
DateTime adt = new DateTime(vo.getActiveYear(), vo.getActiveMonth(), vo.getActiveDay(), vo.getActiveHour(), vo.getActiveMinute(), vo.getActiveSecond(), 0);
DateTime idt = new DateTime(vo.getInactiveYear(), vo.getInactiveMonth(), vo.getInactiveDay(), vo.getInactiveHour(), vo.getInactiveMinute(), vo.getInactiveSecond(), 0);
if (idt.getMillis() <= adt.getMillis())
response.addContextualMessage("scheduleType", "maintenanceEvents.validate.invalidRtn");
if (vo.getTimeoutPeriods() > 0) {
if (!Common.TIME_PERIOD_CODES.isValidId(vo.getTimeoutPeriods()))
response.addContextualMessage("updatePeriodType", "validate.invalidValue");
}
}
return response;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT in project ma-modules-public by infiniteautomation.
the class MaintenanceEventVO method validate.
public void validate(ProcessResult response) {
if (StringValidation.isLengthGreaterThan(alias, 50))
response.addContextualMessage("alias", "maintenanceEvents.validate.aliasTooLong");
if (dataSourceId <= 0)
response.addContextualMessage("dataSourceId", "validate.invalidValue");
// Check that cron patterns are ok.
if (scheduleType == TYPE_CRON) {
try {
new CronTimerTrigger(activeCron);
} catch (Exception e) {
response.addContextualMessage("activeCron", "maintenanceEvents.validate.activeCron", e.getMessage());
}
try {
new CronTimerTrigger(inactiveCron);
} catch (Exception e) {
response.addContextualMessage("inactiveCron", "maintenanceEvents.validate.inactiveCron", e.getMessage());
}
}
// Test that the triggers can be created.
MaintenanceEventRT rt = new MaintenanceEventRT(this);
try {
rt.createTrigger(true);
} catch (RuntimeException e) {
response.addContextualMessage("activeCron", "maintenanceEvents.validate.activeTrigger", e.getMessage());
}
try {
rt.createTrigger(false);
} catch (RuntimeException e) {
response.addContextualMessage("inactiveCron", "maintenanceEvents.validate.inactiveTrigger", e.getMessage());
}
// If the event is once, make sure the active time is earlier than the inactive time.
if (scheduleType == TYPE_ONCE) {
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", "maintenanceEvents.validate.invalidRtn");
}
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsService method getEventRT.
public MaintenanceEventRT getEventRT(String xid) throws NotFoundException, PermissionException, TranslatableIllegalStateException {
PermissionHolder user = Common.getUser();
MaintenanceEventVO existing = dao.getByXid(xid);
if (existing == null)
throw new NotFoundException();
ensureTogglePermission(existing, user);
MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(existing.getId());
if (rt == null)
throw new TranslatableIllegalStateException(new TranslatableMessage("maintenanceEvents.toggle.disabled"));
return rt;
}
Aggregations