Search in sources :

Example 16 with MaintenanceEventVO

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

the class MaintenanceEventsDwr method saveMaintenanceEvent.

@DwrPermission(admin = true)
public ProcessResult saveMaintenanceEvent(int id, String xid, int dataSourceId, String alias, int alarmLevel, int scheduleType, boolean disabled, int activeYear, int activeMonth, int activeDay, int activeHour, int activeMinute, int activeSecond, String activeCron, int inactiveYear, int inactiveMonth, int inactiveDay, int inactiveHour, int inactiveMinute, int inactiveSecond, String inactiveCron) {
    MaintenanceEventVO e = new MaintenanceEventVO();
    e.setId(id);
    e.setXid(xid);
    e.setDataSourceId(dataSourceId);
    e.setAlias(alias);
    e.setAlarmLevel(alarmLevel);
    e.setScheduleType(scheduleType);
    e.setDisabled(disabled);
    e.setActiveYear(activeYear);
    e.setActiveMonth(activeMonth);
    e.setActiveDay(activeDay);
    e.setActiveHour(activeHour);
    e.setActiveMinute(activeMinute);
    e.setActiveSecond(activeSecond);
    e.setActiveCron(activeCron);
    e.setInactiveYear(inactiveYear);
    e.setInactiveMonth(inactiveMonth);
    e.setInactiveDay(inactiveDay);
    e.setInactiveHour(inactiveHour);
    e.setInactiveMinute(inactiveMinute);
    e.setInactiveSecond(inactiveSecond);
    e.setInactiveCron(inactiveCron);
    ProcessResult response = new ProcessResult();
    MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
    if (StringUtils.isBlank(xid))
        response.addContextualMessage("xid", "validate.required");
    else if (!maintenanceEventDao.isXidUnique(xid, id))
        response.addContextualMessage("xid", "validate.xidUsed");
    e.validate(response);
    // Save the maintenance event
    if (!response.getHasMessages()) {
        RTMDefinition.instance.saveMaintenanceEvent(e);
        response.addData("meId", e.getId());
    }
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 17 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method setReadPermission.

@Override
void setReadPermission(MangoPermission permission, MaintenanceEventVO vo) {
    // A user with read permission for all data points (and sources) in this event has read permission
    if (permission != null) {
        // Get the data points and add our roles to the read roles
        for (int dpId : vo.getDataPoints()) {
            DataPointVO dp = DataPointDao.getInstance().get(dpId);
            dp.setReadPermission(permission);
            DataPointDao.getInstance().update(dp.getId(), dp);
        }
    }
    vo.setTogglePermission(permission);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

Example 18 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method updateVO.

@Override
MaintenanceEventVO updateVO(MaintenanceEventVO existing) {
    MaintenanceEventVO copy = (MaintenanceEventVO) existing.copy();
    copy.setName("new name");
    List<Integer> dataPointIds = new ArrayList<>();
    for (IDataPoint point : createMockDataPoints(10)) {
        dataPointIds.add(point.getId());
    }
    copy.setDataPoints(dataPointIds);
    return copy;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) ArrayList(java.util.ArrayList) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

Example 19 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method setEditPermission.

@Override
void setEditPermission(MangoPermission permission, MaintenanceEventVO vo) {
    // A user with edit permission for the sources of all points (and all data sources sources) in this event has edit permission
    if (permission != null) {
        // Get the data points and add our roles to the read roles
        for (int dpId : vo.getDataPoints()) {
            DataPointVO dp = DataPointDao.getInstance().get(dpId);
            dp.setEditPermission(permission);
            DataPointDao.getInstance().update(dp.getId(), dp);
            DataSourceVO ds = DataSourceDao.getInstance().get(dp.getDataSourceId());
            ds.setEditPermission(permission);
            DataSourceDao.getInstance().update(ds.getId(), ds);
        }
    }
    vo.setTogglePermission(permission);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

Example 20 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method newVO.

@Override
MaintenanceEventVO newVO(User owner) {
    MaintenanceEventVO vo = new MaintenanceEventVO();
    vo.setName(UUID.randomUUID().toString());
    List<Integer> dataPointIds = new ArrayList<>();
    for (IDataPoint point : createMockDataPoints(5)) {
        dataPointIds.add(point.getId());
    }
    vo.setDataPoints(dataPointIds);
    return vo;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) ArrayList(java.util.ArrayList) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

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