use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class EventDetectorsRestController method getState.
@ApiOperation(value = "Get Event Detector's internal state", notes = "User must have read permission for the data point", response = AbstractEventDetectorRTModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/runtime/{xid}")
public AbstractEventDetectorRTModel<?> getState(@ApiParam(value = "ID of Event detector", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
AbstractEventDetectorVO vo = service.get(xid);
// For now all detectors are data point type
DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getSourceId());
if (rt == null) {
throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
}
for (PointEventDetectorRT<?> edrt : rt.getEventDetectors()) {
if (edrt.getVO().getId() == vo.getId()) {
return modelMapper.map(edrt, AbstractEventDetectorRTModel.class, user);
}
}
throw new NotFoundRestException();
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class EventHandlersRestController method create.
@ApiOperation(value = "Create an Event Handler", notes = "Requires global Event Handler privileges", response = AbstractEventHandlerModel.class)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<AbstractEventHandlerModel<?>> create(@RequestBody AbstractEventHandlerModel<? extends AbstractEventHandlerVO> model, @ApiParam(value = "User", required = true) @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
AbstractEventHandlerVO vo = service.insert(modelMapper.unMap(model, AbstractEventHandlerVO.class, user));
URI location = builder.path("/event-handlers/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
@SuppressWarnings("unchecked") AbstractEventHandlerModel<? extends AbstractEventHandlerVO> responseModel = modelMapper.map(vo, AbstractEventHandlerModel.class, user);
return new ResponseEntity<>(responseModel, headers, HttpStatus.CREATED);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class EventHandlersRestController method get.
@ApiOperation(value = "Get an Event Handler", response = AbstractEventHandlerModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/{xid}")
public AbstractEventHandlerModel<?> get(@ApiParam(value = "XID to get", required = true) @PathVariable String xid, @ApiParam(value = "User", required = true) @AuthenticationPrincipal PermissionHolder user) {
AbstractEventHandlerVO vo = service.get(xid);
@SuppressWarnings("unchecked") AbstractEventHandlerModel<? extends AbstractEventHandlerVO> model = modelMapper.map(vo, AbstractEventHandlerModel.class, user);
return model;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class EventHandlersRestController method partialUpdate.
@ApiOperation(value = "Partially update an Event Handler", notes = "Requires edit permission", response = AbstractEventHandlerModel.class)
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<AbstractEventHandlerModel<?>> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated maintenance event", required = true) @PatchVORequestBody(service = EventHandlerService.class, modelClass = AbstractEventHandlerModel.class) AbstractEventHandlerModel<? extends AbstractEventHandlerVO> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
AbstractEventHandlerVO vo = service.update(xid, modelMapper.unMap(model, AbstractEventHandlerVO.class, user));
URI location = builder.path("/event-handlers/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
@SuppressWarnings("unchecked") AbstractEventHandlerModel<? extends AbstractEventHandlerVO> responseModel = modelMapper.map(vo, AbstractEventHandlerModel.class, user);
return new ResponseEntity<>(responseModel, headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class EventHandlersRestController method delete.
@ApiOperation(value = "Delete an EventHandler", response = AbstractEventHandlerModel.class)
@RequestMapping(method = RequestMethod.DELETE, value = "/{xid}")
public ResponseEntity<AbstractEventHandlerModel<?>> delete(@ApiParam(value = "XID of EventHandler to delete", required = true) @PathVariable String xid, @ApiParam(value = "User", required = true) @AuthenticationPrincipal PermissionHolder user) {
AbstractEventHandlerVO vo = service.delete(xid);
@SuppressWarnings("unchecked") AbstractEventHandlerModel<? extends AbstractEventHandlerVO> responseModel = modelMapper.map(vo, AbstractEventHandlerModel.class, user);
return ResponseEntity.ok(responseModel);
}
Aggregations