Search in sources :

Example 31 with MaintenanceEventVO

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

the class MaintenanceEventsServiceTest method testCannotRemoveToggleAccess.

@Test
@ExpectValidationException("togglePermission")
public void testCannotRemoveToggleAccess() {
    MaintenanceEventVO vo = newVO(editUser);
    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) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 32 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 33 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 34 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