Search in sources :

Example 81 with PermissionHolder

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();
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 82 with PermissionHolder

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 83 with PermissionHolder

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;
}
Also used : AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 84 with PermissionHolder

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 85 with PermissionHolder

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);
}
Also used : AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)205 ApiOperation (io.swagger.annotations.ApiOperation)98 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)98 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)86 ResponseEntity (org.springframework.http.ResponseEntity)53 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)50 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)50 ArrayList (java.util.ArrayList)50 HttpHeaders (org.springframework.http.HttpHeaders)50 URI (java.net.URI)48 List (java.util.List)43 User (com.serotonin.m2m2.vo.User)37 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)35 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)32 Common (com.serotonin.m2m2.Common)31 Collectors (java.util.stream.Collectors)30 Role (com.serotonin.m2m2.vo.role.Role)29 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)28 Autowired (org.springframework.beans.factory.annotation.Autowired)25 HashMap (java.util.HashMap)24