Search in sources :

Example 26 with MaintenanceEventVO

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

the class MaintenanceEventModel method toVO.

@Override
public MaintenanceEventVO toVO() {
    MaintenanceEventVO vo = super.toVO();
    ProcessResult result = new ProcessResult();
    if (dataSources != null) {
        Set<Integer> ids = new HashSet<>();
        for (String xid : dataSources) {
            Integer id = DataSourceDao.getInstance().getIdByXid(xid);
            if (id != null)
                ids.add(id);
            else
                result.addContextualMessage("dataSources", "maintenanceEvents.validate.missingDataSource", xid);
        }
        vo.setDataSources(new ArrayList<>(ids));
    }
    if (dataPoints != null) {
        Set<Integer> ids = new HashSet<>();
        for (String xid : dataPoints) {
            Integer id = DataPointDao.getInstance().getIdByXid(xid);
            if (id != null)
                ids.add(id);
            else
                result.addContextualMessage("dataPoints", "maintenanceEvents.validate.missingDataPoint", xid);
        }
        vo.setDataPoints(new ArrayList<>(ids));
    }
    if (result.getHasMessages())
        throw new ValidationException(result);
    vo.setAlarmLevel(alarmLevel);
    vo.setScheduleType(MaintenanceEventVO.TYPE_CODES.getId(scheduleType));
    vo.setDisabled(disabled == null ? false : disabled);
    vo.setActiveYear(activeYear == null ? 0 : activeYear);
    vo.setActiveMonth(activeMonth == null ? 0 : activeMonth);
    vo.setActiveDay(activeDay == null ? 0 : activeDay);
    vo.setActiveHour(activeHour == null ? 0 : activeHour);
    vo.setActiveMinute(activeMinute == null ? 0 : activeMinute);
    vo.setActiveSecond(activeSecond == null ? 0 : activeSecond);
    vo.setActiveCron(activeCron);
    vo.setInactiveYear(inactiveYear == null ? 0 : inactiveYear);
    vo.setInactiveMonth(inactiveMonth == null ? 0 : inactiveMonth);
    vo.setInactiveDay(inactiveDay == null ? 0 : inactiveDay);
    vo.setInactiveHour(inactiveHour == null ? 0 : inactiveHour);
    vo.setInactiveMinute(inactiveMinute == null ? 0 : inactiveMinute);
    vo.setInactiveSecond(inactiveSecond == null ? 0 : inactiveSecond);
    vo.setInactiveCron(inactiveCron);
    vo.setTimeoutPeriods(timeoutPeriods == null ? 0 : timeoutPeriods);
    vo.setTimeoutPeriodType(Common.TIME_PERIOD_CODES.getId(timeoutPeriodType));
    vo.setTogglePermission(togglePermission != null ? togglePermission.getPermission() : new MangoPermission());
    return vo;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 27 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(int dataPointId, Consumer<MaintenanceEventVO> callback) {
    DataPointVO vo = dataPointDao.get(dataPointId);
    if (vo == null)
        return;
    getForDataPoint(vo, callback);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO)

Example 28 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method assertVoEqual.

@Override
void assertVoEqual(MaintenanceEventVO expected, MaintenanceEventVO actual) {
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getXid(), actual.getXid());
    assertEquals(expected.getName(), actual.getName());
    List<Integer> actualPoints = actual.getDataPoints();
    List<Integer> expectedPoints = expected.getDataPoints();
    assertEquals(expectedPoints.size(), actualPoints.size());
    for (int i = 0; i < expectedPoints.size(); i++) {
        assertEquals(expectedPoints.get(i), actualPoints.get(i));
    }
    List<String> actualPointXids = new ArrayList<>();
    List<String> expectedPointXids = new ArrayList<>();
    dao.getPointXids(actual.getId(), actualPointXids::add);
    dao.getPointXids(expected.getId(), expectedPointXids::add);
    assertEquals(expectedPointXids.size(), actualPointXids.size());
    for (int i = 0; i < expectedPointXids.size(); i++) {
        assertEquals(expectedPointXids.get(i), actualPointXids.get(i));
    }
    List<Integer> actualDataSources = actual.getDataSources();
    List<Integer> expectedDataSources = expected.getDataSources();
    assertEquals(expectedDataSources.size(), actualDataSources.size());
    for (int i = 0; i < expectedDataSources.size(); i++) {
        assertEquals(expectedDataSources.get(i), actualDataSources.get(i));
    }
    List<String> actualDataSourceXids = new ArrayList<>();
    List<String> expectedDataSourceXids = new ArrayList<>();
    dao.getSourceXids(actual.getId(), actualDataSourceXids::add);
    dao.getSourceXids(expected.getId(), expectedDataSourceXids::add);
    assertEquals(expectedDataSourceXids.size(), actualDataSourceXids.size());
    for (int i = 0; i < expectedDataSourceXids.size(); i++) {
        assertEquals(expectedDataSourceXids.get(i), actualDataSourceXids.get(i));
    }
}
Also used : ArrayList(java.util.ArrayList) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

Example 29 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 30 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method testAddReadRoleUserDoesNotHave.

@Test
@Override
public void testAddReadRoleUserDoesNotHave() {
    validation.expectValidationException(getReadPermissionContextKey());
    MaintenanceEventVO vo = newVO(readUser);
    setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        MaintenanceEventVO fromDb = service.get(vo.getId());
        assertVoEqual(vo, fromDb);
        fromDb.setTogglePermission(MangoPermission.superadminOnly());
        service.update(fromDb.getId(), fromDb);
    });
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) Test(org.junit.Test)

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