Search in sources :

Example 1 with MaintenanceEventVO

use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO 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 MaintenanceEventVO

use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsDwr method getMaintenanceEvents.

@DwrPermission(admin = true)
public ProcessResult getMaintenanceEvents() {
    ProcessResult response = new ProcessResult();
    final Translations translations = getTranslations();
    List<MaintenanceEventVO> events = new MaintenanceEventDao().getMaintenanceEvents();
    Collections.sort(events, new Comparator<MaintenanceEventVO>() {

        @Override
        public int compare(MaintenanceEventVO m1, MaintenanceEventVO m2) {
            return m1.getDescription().translate(translations).compareTo(m1.getDescription().translate(translations));
        }
    });
    response.addData(MODEL_ATTR_EVENTS, events);
    List<IntStringPair> dataSources = new ArrayList<IntStringPair>();
    for (DataSourceVO<?> ds : DataSourceDao.instance.getDataSources()) dataSources.add(new IntStringPair(ds.getId(), ds.getName()));
    response.addData("dataSources", dataSources);
    return response;
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Translations(com.serotonin.m2m2.i18n.Translations) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with MaintenanceEventVO

use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.

the class MaintenanceEventEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
    JsonObject maintenanceEvent = jsonValue.toJsonObject();
    String xid = maintenanceEvent.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = maintenanceEventDao.generateUniqueXid();
    MaintenanceEventVO vo = maintenanceEventDao.getMaintenanceEvent(xid);
    if (vo == null) {
        vo = new MaintenanceEventVO();
        vo.setXid(xid);
    }
    try {
        importContext.getReader().readInto(vo, maintenanceEvent);
        // Now validate it. Use a new response object so we can distinguish errors in this vo from other errors.
        ProcessResult voResponse = new ProcessResult();
        vo.validate(voResponse);
        if (voResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(voResponse, "emport.maintenanceEvent.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = vo.isNew();
            RTMDefinition.instance.saveMaintenanceEvent(vo);
            importContext.addSuccessMessage(isnew, "emport.maintenanceEvent.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 4 with MaintenanceEventVO

use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.

the class MaintenanceEventDao method toRecord.

@Override
protected Record toRecord(MaintenanceEventVO me) {
    Record record = table.newRecord();
    record.set(table.xid, me.getXid());
    record.set(table.alias, me.getName());
    record.set(table.alarmLevel, me.getAlarmLevel().value());
    record.set(table.scheduleType, me.getScheduleType());
    record.set(table.disabled, boolToChar(me.isDisabled()));
    record.set(table.activeYear, me.getActiveYear());
    record.set(table.activeMonth, me.getActiveMonth());
    record.set(table.activeDay, me.getActiveDay());
    record.set(table.activeHour, me.getActiveHour());
    record.set(table.activeMinute, me.getActiveMinute());
    record.set(table.activeSecond, me.getActiveSecond());
    record.set(table.activeCron, me.getActiveCron());
    record.set(table.inactiveYear, me.getInactiveYear());
    record.set(table.inactiveMonth, me.getInactiveMonth());
    record.set(table.inactiveDay, me.getInactiveDay());
    record.set(table.inactiveHour, me.getInactiveHour());
    record.set(table.inactiveMinute, me.getInactiveMinute());
    record.set(table.inactiveSecond, me.getInactiveSecond());
    record.set(table.inactiveCron, me.getInactiveCron());
    record.set(table.timeoutPeriods, me.getTimeoutPeriods());
    record.set(table.timeoutPeriodType, me.getTimeoutPeriodType());
    record.set(table.togglePermissionId, me.getTogglePermission().getId());
    return record;
}
Also used : Record(org.jooq.Record) MaintenanceEventsRecord(com.serotonin.m2m2.maintenanceEvents.db.tables.records.MaintenanceEventsRecord)

Example 5 with MaintenanceEventVO

use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.

the class MaintenanceEventDao method getForDataPoint.

/**
 * Get all maintenance events that have this data point in their list OR the its data source in the list
 */
public void getForDataPoint(String dataPointXid, Consumer<MaintenanceEventVO> callback) {
    DataPointVO vo = dataPointDao.getByXid(dataPointXid);
    if (vo == null)
        return;
    getForDataPoint(vo, callback);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO)

Aggregations

MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)17 ArrayList (java.util.ArrayList)9 ApiOperation (io.swagger.annotations.ApiOperation)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 MaintenanceEventModel (com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel)7 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)7 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)5 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)5 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)3 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 URI (java.net.URI)3 HashSet (java.util.HashSet)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 MaintenanceEventsService (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService)2