use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishersRestController method partialUpdate.
@ApiOperation(value = "Partially update a publisher", notes = "Requires edit permission")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<AbstractPublisherModel<?, ?>> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated data source", required = true) @PatchVORequestBody(service = PublisherService.class, modelClass = AbstractPublisherModel.class) AbstractPublisherModel<?, ?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
PublisherVO vo = service.update(xid, model.toVO());
insertPoints(vo, model.getPoints(), user);
URI location = builder.path("/publishers/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishersRestController method save.
@ApiOperation(value = "Save publisher")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<AbstractPublisherModel<?, ?>> save(@RequestBody() AbstractPublisherModel<?, ?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
PublisherVO vo = this.service.insert(model.toVO());
insertPoints(vo, model.getPoints(), user);
URI location = builder.path("/publishers/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.CREATED);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishersRestController method exportQuery.
@ApiOperation(value = "Export formatted for Configuration Import by supplying an RQL query", notes = "User must have read permission")
@RequestMapping(method = RequestMethod.GET, value = "/export", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, JsonStreamedArray> exportQuery(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
Map<String, JsonStreamedArray> export = new HashMap<>();
if (permissionService.hasAdminRole(user)) {
export.put("publishers", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null));
} else {
export.put("publishers", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null, vo -> service.hasReadPermission(user, vo)));
}
return export;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishersWithoutPointsRestController method save.
@ApiOperation(value = "Save publisher, if points are supplied in model they will replace all existing points")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<AbstractPublisherModel<?, ?>> save(@RequestBody(required = true) AbstractPublisherModel<?, ?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder, HttpServletRequest request) {
PublisherVO vo = this.service.insert(model.toVO());
URI location = builder.path("/publishers/{xid}").buildAndExpand(new Object[] { vo.getXid() }).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.CREATED);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishersWithoutPointsRestController method exportQuery.
@ApiOperation(value = "Export formatted for Configuration Import by supplying an RQL query", notes = "User must have read permission")
@RequestMapping(method = RequestMethod.GET, value = "/export", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, JsonStreamedArray> exportQuery(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
Map<String, JsonStreamedArray> export = new HashMap<>();
if (permissionService.hasAdminRole(user)) {
export.put("publishers", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null));
} else {
export.put("publishers", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null, vo -> service.hasReadPermission(user, vo)));
}
return export;
}
Aggregations