use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class MailingListRestController method partialUpdate.
@ApiOperation(value = "Partially update a Mailing List", notes = "Requires edit permission", response = MailingListWithRecipientsModel.class)
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<MailingListModel> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated mailing list", required = true) @PatchVORequestBody(service = MailingListService.class, modelClass = MailingListWithRecipientsModel.class) MailingListWithRecipientsModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
MailingList vo = service.update(xid, mapping.unmap(model, user, mapper));
URI location = builder.path("/mailing-lists/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishedPointsRestController method exportPublishedPoint.
@ApiOperation(value = "Export formatted for Configuration Import")
@RequestMapping(method = RequestMethod.GET, value = "/export/{xid}", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, Object> exportPublishedPoint(@ApiParam(value = "Valid published point XID", required = true) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
PublishedPointVO vo = service.get(xid);
Map<String, Object> export = new LinkedHashMap<>();
export.put("publishedPoints", Collections.singletonList(vo));
return export;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class PublishedPointsRestController method bulkPublishedPointOperation.
@ApiOperation(value = "Bulk get/create/update/delete published points", notes = "User be superadmin")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<PublishedPointBulkResponse, AbstractRestException>> bulkPublishedPointOperation(@RequestBody PublishedPointBulkRequest requestBody, UriComponentsBuilder builder) {
VoAction defaultAction = requestBody.getAction();
AbstractPublishedPointModel<?> defaultBody = requestBody.getBody();
List<PublishedPointIndividualRequest> requests = requestBody.getRequests();
if (requests == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
} else if (requests.isEmpty()) {
throw new BadRequestException(new TranslatableMessage("rest.error.cantBeEmpty", "requests"));
}
String resourceId = requestBody.getId();
Long expiration = requestBody.getExpiration();
Long timeout = requestBody.getTimeout();
TemporaryResource<PublishedPointBulkResponse, AbstractRestException> responseBody = resourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_PUBLISHED_POINT, resourceId, expiration, timeout, (resource) -> {
PublishedPointBulkResponse bulkResponse = new PublishedPointBulkResponse();
int i = 0;
resource.progressOrSuccess(bulkResponse, i++, requests.size());
PermissionHolder resourceUser = Common.getUser();
for (PublishedPointIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
PublishedPointIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, resourceUser, reqBuilder);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
return null;
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/published-points/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<>(responseBody, headers, HttpStatus.CREATED);
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class DataPointRestController method doIndividualRequest.
private DataPointIndividualResponse doIndividualRequest(DataPointIndividualRequest request, VoAction defaultAction, DataPointModel defaultBody, PermissionHolder user, UriComponentsBuilder builder) {
DataPointIndividualResponse result = new DataPointIndividualResponse();
try {
String xid = request.getXid();
result.setXid(xid);
VoAction action = request.getAction() == null ? defaultAction : request.getAction();
if (action == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "action"));
}
result.setAction(action);
DataPointModel body = request.getBody() == null ? defaultBody : request.getBody();
switch(action) {
case GET:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.getDataPoint(xid, user));
break;
case CREATE:
if (body == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "body"));
}
result.setBody(body);
result.setBody(this.createDataPoint(body, user, builder).getBody());
break;
case UPDATE:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
if (body == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "body"));
}
result.setBody(body);
result.setBody(this.updateDataPoint(xid, body, user, builder).getBody());
break;
case DELETE:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.deleteDataPoint(xid, user));
break;
}
} catch (Exception e) {
result.exceptionCaught(e);
}
return result;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class ServerRestController method restart.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Restart Mango", notes = "Returns location url in header for status updates while web interface is still active")
@RequestMapping(method = RequestMethod.PUT, value = "/restart")
public ResponseEntity<Void> restart(@RequestParam(value = "delay", required = false) Long delay, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder, HttpServletRequest request) {
IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
lifecycle.scheduleShutdown(delay, true, user);
URI location = builder.path("/status/mango").buildAndExpand().toUri();
return getResourceCreated(null, location);
}
Aggregations