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;
}
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);
}
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));
}
}
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);
}
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);
});
}
Aggregations