Search in sources :

Example 1 with MaintenanceEventRT

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DateTime(org.joda.time.DateTime) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with MaintenanceEventRT

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with MaintenanceEventRT

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;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) CronTimerTrigger(com.serotonin.timer.CronTimerTrigger) MaintenanceEventRT(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DateTime(org.joda.time.DateTime)

Example 4 with MaintenanceEventRT

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");
    }
}
Also used : CronTimerTrigger(com.serotonin.timer.CronTimerTrigger) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) IOException(java.io.IOException) JsonException(com.serotonin.json.JsonException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) DateTime(org.joda.time.DateTime)

Example 5 with MaintenanceEventRT

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;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MaintenanceEventRT(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Aggregations

ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 DateTime (org.joda.time.DateTime)3 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)2 TranslatableIllegalStateException (com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 MaintenanceEventRT (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)2 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)1 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 JsonException (com.serotonin.json.JsonException)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)1 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)1 IOException (java.io.IOException)1