Search in sources :

Example 71 with PermissionHolder

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

the class WatchListModelMapping method unmap.

@Override
public WatchListVO unmap(Object from, PermissionHolder user, RestModelMapper mapper) throws ValidationException {
    WatchListModel model = (WatchListModel) from;
    WatchListVO vo = model.toVO();
    vo.setReadPermission(model.getReadPermission() != null ? model.getReadPermission().getPermission() : new MangoPermission());
    vo.setEditPermission(model.getEditPermission() != null ? model.getEditPermission().getPermission() : new MangoPermission());
    if (vo.getType() == WatchListType.STATIC && model.getPoints() != null) {
        vo.setPointList(model.getPoints().stream().map(m -> {
            DataPointSummary summary = new DataPointSummary();
            summary.setXid(m.getXid());
            return summary;
        }).collect(Collectors.toList()));
    }
    return vo;
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 72 with PermissionHolder

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

the class WatchListSummaryModelMapping method map.

@Override
public WatchListSummaryModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
    WatchListVO vo = (WatchListVO) from;
    WatchListSummaryModel model = new WatchListSummaryModel(vo);
    model.setReadPermission(new MangoPermissionModel(vo.getReadPermission()));
    model.setEditPermission(new MangoPermissionModel(vo.getEditPermission()));
    return model;
}
Also used : MangoPermissionModel(com.infiniteautomation.mango.rest.latest.model.permissions.MangoPermissionModel) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 73 with PermissionHolder

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

the class WatchListRestController method create.

@ApiOperation(value = "Create New WatchList")
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<WatchListModel> create(@RequestBody WatchListModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    WatchListVO vo = service.insert(mapping.unmap(model, user, mapper));
    URI location = builder.path("/watch-lists/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 74 with PermissionHolder

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

the class WatchListRestController method update.

@ApiOperation(value = "Update a WatchList", notes = "Requires edit permission")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<WatchListModel> update(@ApiParam(value = "XID of WatchList to update", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "WatchList of update", required = true, allowMultiple = false) @RequestBody WatchListModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    WatchListVO vo = service.update(xid, mapping.unmap(model, user, mapper));
    URI location = builder.path("/watch-lists/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with PermissionHolder

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

the class WatchListRestController method partialUpdate.

@ApiOperation(value = "Partially update a WatchList", notes = "Requires edit permission")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<WatchListModel> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated WatchList", required = true) @PatchVORequestBody(service = WatchListService.class, modelClass = WatchListModel.class) WatchListModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    WatchListVO vo = service.update(xid, mapping.unmap(model, user, mapper));
    URI location = builder.path("/watch-lists/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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