use of com.infiniteautomation.mango.rest.latest.bulk.VoAction in project ma-modules-public by infiniteautomation.
the class UserRestController method bulkUserOperation.
@ApiOperation(value = "Bulk get/create/update/delete users", notes = "User must have read/edit permission for the user")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<UserBulkResponse, AbstractRestException>> bulkUserOperation(@RequestBody UserBulkRequest requestBody, HttpServletRequest servletRequest, Authentication authentication, UriComponentsBuilder builder) {
VoAction defaultAction = requestBody.getAction();
UserModel defaultBody = requestBody.getBody();
List<UserIndividualRequest> 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<UserBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_USER, resourceId, expiration, timeout, (resource) -> {
UserBulkResponse bulkResponse = new UserBulkResponse();
int i = 0;
resource.progressOrSuccess(bulkResponse, i++, requests.size());
for (UserIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
PermissionHolder resourceUser = Common.getUser();
UserIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, resourceUser, servletRequest, authentication, reqBuilder);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
return null;
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/users/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<>(responseBody, headers, HttpStatus.CREATED);
}
use of com.infiniteautomation.mango.rest.latest.bulk.VoAction in project ma-modules-public by infiniteautomation.
the class PublishedPointsRestController method doIndividualRequest.
private PublishedPointIndividualResponse doIndividualRequest(PublishedPointIndividualRequest request, VoAction defaultAction, AbstractPublishedPointModel<?> defaultBody, PermissionHolder user, UriComponentsBuilder builder) {
PublishedPointIndividualResponse result = new PublishedPointIndividualResponse();
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);
AbstractPublishedPointModel<?> 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.get(xid, user));
break;
case CREATE:
if (body == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "body"));
}
result.setBody(body);
result.setBody(this.create(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.update(xid, body, user, builder).getBody());
break;
case DELETE:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.delete(xid, user, builder));
break;
}
} catch (Exception e) {
result.exceptionCaught(e);
}
return result;
}
use of com.infiniteautomation.mango.rest.latest.bulk.VoAction 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.bulk.VoAction in project ma-modules-public by infiniteautomation.
the class EventDetectorsRestController method doIndividualRequest.
// TODO improve performance by tracking all data sources that need to be restarted and restart at the end?
private EventDetectorIndividualResponse doIndividualRequest(EventDetectorIndividualRequest request, boolean restart, VoAction defaultAction, AbstractEventDetectorModel<? extends AbstractEventDetectorVO> defaultBody, UriComponentsBuilder builder) {
EventDetectorIndividualResponse result = new EventDetectorIndividualResponse();
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);
AbstractEventDetectorModel<? extends AbstractEventDetectorVO> body = request.getBody() == null ? defaultBody : request.getBody();
PermissionHolder user = Common.getUser();
switch(action) {
case GET:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.getByXid(xid, user));
break;
case CREATE:
if (body == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "body"));
}
result.setBody(body);
result.setBody(this.create(restart, 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.update(xid, body, restart, user, builder).getBody());
break;
case DELETE:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.delete(xid, user, builder).getBody());
break;
}
} catch (Exception e) {
result.exceptionCaught(e);
}
return result;
}
use of com.infiniteautomation.mango.rest.latest.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, 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);
}
Aggregations