use of com.infiniteautomation.mango.rest.v2.bulk.VoAction 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, AbstractRestV2Exception>> bulkDataPointOperation(@RequestBody DataPointBulkRequest requestBody, @AuthenticationPrincipal User user, 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"));
}
String resourceId = requestBody.getId();
Long expiration = requestBody.getExpiration();
Long timeout = requestBody.getTimeout();
TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT, resourceId, user.getId(), expiration, timeout, (resource) -> {
DataPointBulkResponse bulkResponse = new DataPointBulkResponse();
int i = 0;
resource.progress(bulkResponse, i++, requests.size());
for (DataPointIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
DataPointIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, user, reqBuilder);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/v2/data-points/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>>(responseBody, headers, HttpStatus.CREATED);
}
use of com.infiniteautomation.mango.rest.v2.bulk.VoAction in project ma-modules-public by infiniteautomation.
the class DataPointRestController method doIndividualRequest.
private DataPointIndividualResponse doIndividualRequest(DataPointIndividualRequest request, VoAction defaultAction, DataPointModel defaultBody, User user, UriComponentsBuilder builder) {
DataPointIndividualResponse result = new DataPointIndividualResponse();
try {
String xid = request.getXid();
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(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(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;
}
Aggregations