Search in sources :

Example 11 with MaintenanceEventVO

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;
    });
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)

Example 12 with MaintenanceEventVO

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;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) CronTimerTrigger(com.serotonin.timer.CronTimerTrigger) MaintenanceEventRT(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DateTime(org.joda.time.DateTime)

Example 13 with MaintenanceEventVO

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);
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) HttpHeaders(org.springframework.http.HttpHeaders) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with MaintenanceEventVO

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);
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) HttpHeaders(org.springframework.http.HttpHeaders) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with MaintenanceEventVO

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;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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