use of com.infiniteautomation.mango.rest.latest.model.user.UserIndividualRequest in project ma-modules-public by infiniteautomation.
the class UserRestController method bulkUserOperationCSV.
@ApiOperation(value = "Bulk get/create/update/delete users", notes = "User must have read/edit permission for the user", consumes = MediaTypes.CSV_VALUE)
@RequestMapping(method = RequestMethod.POST, value = "/bulk", consumes = MediaTypes.CSV_VALUE)
public ResponseEntity<TemporaryResource<UserBulkResponse, AbstractRestException>> bulkUserOperationCSV(@RequestBody List<UserActionAndModel> users, HttpServletRequest servletRequest, UriComponentsBuilder builder, Authentication authentication) {
UserBulkRequest bulkRequest = new UserBulkRequest();
bulkRequest.setRequests(users.stream().map(actionAndModel -> {
UserModel u = actionAndModel.getModel();
VoAction action = actionAndModel.getAction();
String originalUsername = actionAndModel.getOriginalUsername();
if (originalUsername == null && u != null) {
originalUsername = u.getUsername();
}
UserIndividualRequest request = new UserIndividualRequest();
request.setAction(action == null ? VoAction.UPDATE : action);
request.setUsername(originalUsername);
request.setBody(u);
return request;
}).collect(Collectors.toList()));
return this.bulkUserOperation(bulkRequest, servletRequest, authentication, builder);
}
use of com.infiniteautomation.mango.rest.latest.model.user.UserIndividualRequest 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);
}
Aggregations