Search in sources :

Example 66 with PermissionHolder

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

Example 67 with PermissionHolder

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

Example 68 with PermissionHolder

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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RequestParam(org.springframework.web.bind.annotation.RequestParam) BiFunction(java.util.function.BiFunction) StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) PublisherService(com.infiniteautomation.mango.spring.service.PublisherService) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) StringUtils(org.apache.commons.lang3.StringUtils) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) ArrayList(java.util.ArrayList) RestModelMapper(com.infiniteautomation.mango.rest.latest.model.RestModelMapper) PatchVORequestBody(com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody) LinkedHashMap(java.util.LinkedHashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) StreamedArrayWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedArrayWithTotal) URI(java.net.URI) Api(io.swagger.annotations.Api) HttpHeaders(org.springframework.http.HttpHeaders) AbstractPublishedPointModel(com.infiniteautomation.mango.rest.latest.model.publisher.AbstractPublishedPointModel) RQLUtils(com.infiniteautomation.mango.util.RQLUtils) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) RestController(org.springframework.web.bind.annotation.RestController) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) StreamedSeroJsonVORqlQuery(com.infiniteautomation.mango.rest.latest.model.StreamedSeroJsonVORqlQuery) ASTNode(net.jazdw.rql.parser.ASTNode) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) MediaTypes(com.serotonin.m2m2.web.MediaTypes) ResponseEntity(org.springframework.http.ResponseEntity) AbstractPublisherModel(com.infiniteautomation.mango.rest.latest.model.publisher.AbstractPublisherModel) Collections(java.util.Collections) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) PublishedPointService(com.infiniteautomation.mango.spring.service.PublishedPointService) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ASTNode(net.jazdw.rql.parser.ASTNode) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with PermissionHolder

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

Example 70 with PermissionHolder

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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RequestParam(org.springframework.web.bind.annotation.RequestParam) BiFunction(java.util.function.BiFunction) StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) PublisherService(com.infiniteautomation.mango.spring.service.PublisherService) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) RestModelMapper(com.infiniteautomation.mango.rest.latest.model.RestModelMapper) PatchVORequestBody(com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody) LinkedHashMap(java.util.LinkedHashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) StreamedArrayWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedArrayWithTotal) Api(io.swagger.annotations.Api) URI(java.net.URI) HttpHeaders(org.springframework.http.HttpHeaders) RQLUtils(com.infiniteautomation.mango.util.RQLUtils) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RestController(org.springframework.web.bind.annotation.RestController) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) HttpStatus(org.springframework.http.HttpStatus) StreamedSeroJsonVORqlQuery(com.infiniteautomation.mango.rest.latest.model.StreamedSeroJsonVORqlQuery) ASTNode(net.jazdw.rql.parser.ASTNode) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) MediaTypes(com.serotonin.m2m2.web.MediaTypes) ResponseEntity(org.springframework.http.ResponseEntity) AbstractPublisherModel(com.infiniteautomation.mango.rest.latest.model.publisher.AbstractPublisherModel) Collections(java.util.Collections) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) PublishedPointService(com.infiniteautomation.mango.spring.service.PublishedPointService) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ASTNode(net.jazdw.rql.parser.ASTNode) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) 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