Search in sources :

Example 31 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)

Example 32 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 33 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 34 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class MaintenanceEventTypeModelMapping method map.

@Override
public MaintenanceEventTypeModel map(Object o, PermissionHolder user, RestModelMapper mapper) {
    MaintenanceEventType type = (MaintenanceEventType) o;
    MaintenanceEventVO vo = MaintenanceEventDao.getInstance().get(type.getReferenceId1());
    MaintenanceEventTypeModel model;
    if (vo != null)
        model = new MaintenanceEventTypeModel(type, new MaintenanceEventModel(vo));
    else
        model = new MaintenanceEventTypeModel(type);
    return model;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) MaintenanceEventType(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventType)

Example 35 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsService method validate.

@Override
public ProcessResult validate(MaintenanceEventVO vo) {
    ProcessResult result = commonValidation(vo);
    PermissionHolder user = Common.getUser();
    permissionService.validatePermission(result, "togglePermission", user, vo.getTogglePermission());
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Aggregations

PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)120 ApiOperation (io.swagger.annotations.ApiOperation)97 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)97 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)64 ResponseEntity (org.springframework.http.ResponseEntity)53 HttpHeaders (org.springframework.http.HttpHeaders)50 URI (java.net.URI)48 ArrayList (java.util.ArrayList)37 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)34 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)29 List (java.util.List)27 User (com.serotonin.m2m2.vo.User)25 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)24 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)24 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)19 HashMap (java.util.HashMap)19 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)18 Common (com.serotonin.m2m2.Common)18 Collectors (java.util.stream.Collectors)17 Role (com.serotonin.m2m2.vo.role.Role)16