use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsJavascriptTestUtility method delete.
@Override
public MaintenanceEventVO delete(String xid) throws NotFoundException, PermissionException {
return this.runAs.runAs(permissions, () -> {
MaintenanceEventVO vo = meService.get(xid);
meService.ensureEditPermission(permissions, vo);
return vo;
});
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsService method commonValidation.
public ProcessResult commonValidation(MaintenanceEventVO vo) {
ProcessResult response = super.validate(vo);
if ((vo.getDataSources().size() < 1) && (vo.getDataPoints().size() < 1)) {
response.addContextualMessage("dataSources", "validate.invalidValue");
response.addContextualMessage("dataPoints", "validate.invalidValue");
}
// Validate that the ids are legit
for (int i = 0; i < vo.getDataSources().size(); i++) {
DataSourceVO ds = DataSourceDao.getInstance().get(vo.getDataSources().get(i));
if (ds == null) {
response.addContextualMessage("dataSources[" + i + "]", "validate.invalidValue");
}
}
for (int i = 0; i < vo.getDataPoints().size(); i++) {
DataPointVO dp = DataPointDao.getInstance().get(vo.getDataPoints().get(i));
if (dp == null) {
response.addContextualMessage("dataPoints[" + i + "]", "validate.invalidValue");
}
}
// Check that cron patterns are ok.
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_CRON) {
try {
new CronTimerTrigger(vo.getActiveCron());
} catch (Exception e) {
response.addContextualMessage("activeCron", "maintenanceEvents.validate.activeCron", e.getMessage());
}
try {
new CronTimerTrigger(vo.getInactiveCron());
} catch (Exception e) {
response.addContextualMessage("inactiveCron", "maintenanceEvents.validate.inactiveCron", e.getMessage());
}
}
// Test that the triggers can be created.
MaintenanceEventRT rt = new MaintenanceEventRT(vo);
try {
rt.createTrigger(true);
} catch (RuntimeException e) {
response.addContextualMessage("activeCron", "maintenanceEvents.validate.activeTrigger", e.getMessage());
}
try {
rt.createTrigger(false);
} catch (RuntimeException e) {
response.addContextualMessage("inactiveCron", "maintenanceEvents.validate.inactiveTrigger", e.getMessage());
}
// If the event is once, make sure the active time is earlier than the inactive time.
if (vo.getScheduleType() == MaintenanceEventVO.TYPE_ONCE) {
DateTime adt = new DateTime(vo.getActiveYear(), vo.getActiveMonth(), vo.getActiveDay(), vo.getActiveHour(), vo.getActiveMinute(), vo.getActiveSecond(), 0);
DateTime idt = new DateTime(vo.getInactiveYear(), vo.getInactiveMonth(), vo.getInactiveDay(), vo.getInactiveHour(), vo.getInactiveMinute(), vo.getInactiveSecond(), 0);
if (idt.getMillis() <= adt.getMillis())
response.addContextualMessage("scheduleType", "maintenanceEvents.validate.invalidRtn");
if (vo.getTimeoutPeriods() > 0) {
if (!Common.TIME_PERIOD_CODES.isValidId(vo.getTimeoutPeriods()))
response.addContextualMessage("updatePeriodType", "validate.invalidValue");
}
}
return response;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsRestController method create.
@ApiOperation(value = "Create new maintenance event", notes = "User must have global data source permission")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<MaintenanceEventModel> create(@ApiParam(value = "Updated maintenance event", required = true) @RequestBody(required = true) MaintenanceEventModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
MaintenanceEventVO vo = service.insert(model.toVO());
URI location = builder.path("/maintenance-events/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new MaintenanceEventModel(vo), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsRestController method update.
@ApiOperation(value = "Update an existing maintenance event")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<MaintenanceEventModel> update(@PathVariable String xid, @ApiParam(value = "Updated maintenance event", required = true) @RequestBody(required = true) MaintenanceEventModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
MaintenanceEventVO vo = service.update(xid, model.toVO());
URI location = builder.path("/maintenance-events/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new MaintenanceEventModel(vo), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsRestController method getForPointsByIds.
@ApiOperation(value = "Find Maintenance Events linked to data points by point IDs", notes = "Returns a map of point ids to a list of events that have this data point in their list OR the its data source in the list", response = Map.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/query/get-for-points-by-ids/{pointIds}")
public Map<Integer, List<MaintenanceEventModel>> getForPointsByIds(@PathVariable(required = true) List<Integer> pointIds, HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
Map<Integer, List<MaintenanceEventModel>> map = new HashMap<>();
for (Integer id : pointIds) {
List<MaintenanceEventModel> models = new ArrayList<>();
map.put(id, models);
dao.getForDataPoint(id, new Consumer<MaintenanceEventVO>() {
@Override
public void accept(MaintenanceEventVO vo) {
MaintenanceEventModel model = new MaintenanceEventModel(vo);
fillDataPoints(model);
fillDataSources(model);
models.add(model);
}
});
}
return map;
}
Aggregations