use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.
the class RestExceptionIndividualResponse method exceptionCaught.
/**
* Sets the http status and error fields from the exception
*/
public void exceptionCaught(Throwable exception) {
AbstractRestException e = this.mapException(exception);
this.setHttpStatus(e.getStatus().value());
this.setError(e);
}
use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.
the class EventDetectorsRestController method bulkEventDetectorOperation.
@ApiOperation(value = "Bulk get/create/update/delete event detectors", notes = "User must have read permission for the data point or edit permission for the data source")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<EventDetectorBulkResponse, AbstractRestException>> bulkEventDetectorOperation(@RequestBody EventDetectorBulkRequest requestBody, @ApiParam(value = "Restart the source to load in the changes", required = false, defaultValue = "true", allowMultiple = false) @RequestParam(required = false, defaultValue = "true") boolean restart, UriComponentsBuilder builder) {
VoAction defaultAction = requestBody.getAction();
AbstractEventDetectorModel<? extends AbstractEventDetectorVO> defaultBody = requestBody.getBody();
List<EventDetectorIndividualRequest> 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<EventDetectorBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_EVENT_DETECTOR, resourceId, expiration, timeout, (resource) -> {
EventDetectorBulkResponse bulkResponse = new EventDetectorBulkResponse();
int i = 0;
resource.progressOrSuccess(bulkResponse, i++, requests.size());
for (EventDetectorIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
EventDetectorIndividualResponse individualResponse = doIndividualRequest(request, restart, defaultAction, defaultBody, reqBuilder);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
return null;
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/event-detectors/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<EventDetectorBulkResponse, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkDataPointOperation.
@ApiOperation(value = "Bulk get/create/update/delete data points", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestException>> bulkDataPointOperation(@RequestBody DataPointBulkRequest requestBody, UriComponentsBuilder builder) {
VoAction defaultAction = requestBody.getAction();
DataPointModel defaultBody = requestBody.getBody();
List<DataPointIndividualRequest> 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<DataPointBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT, resourceId, expiration, timeout, (resource) -> {
DataPointBulkResponse bulkResponse = new DataPointBulkResponse();
int i = 0;
resource.progressOrSuccess(bulkResponse, i++, requests.size());
PermissionHolder resourceUser = Common.getUser();
for (DataPointIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
DataPointIndividualResponse 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("/data-points/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method bulkDataPointTagOperation.
@ApiOperation(value = "Bulk get/set/add data point tags for a list of XIDs", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<TagBulkResponse, AbstractRestException>> bulkDataPointTagOperation(@RequestBody TagBulkRequest requestBody, UriComponentsBuilder builder) {
BulkTagAction defaultAction = requestBody.getAction();
Map<String, String> defaultBody = requestBody.getBody();
List<TagIndividualRequest> requests = requestBody.getRequests();
if (requests == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
}
String resourceId = requestBody.getId();
Long expiration = requestBody.getExpiration();
Long timeout = requestBody.getTimeout();
TemporaryResource<TagBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT_TAGS, resourceId, expiration, timeout, (resource) -> {
TagBulkResponse bulkResponse = new TagBulkResponse();
int i = 0;
resource.progress(bulkResponse, i++, requests.size());
for (TagIndividualRequest request : requests) {
TagIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
return null;
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/data-point-tags/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<TagBulkResponse, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
Aggregations