#7183: In DMP invitation, return authors whose name/ email contains the query string given by user (case insensitive).

1. InvitationsManager.java:  Added method "getUsersWithCriteria()" to filter results according to "userInfoRequestItem.getCriteria().getLike()".
2. UserInvitationController.java: In method "getUsers()" added parameter "@RequestBody UserInfoRequestItem userInfoRequestItem" and call new method "invitationsManager.getUsersWithCriteria()" (instead of getUsers()).
This commit is contained in:
Konstantina Galouni 2021-11-22 13:44:41 +02:00
parent 52c7796e8e
commit bb0c398120
2 changed files with 23 additions and 2 deletions

View File

@ -50,8 +50,11 @@ public class UserInvitationController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/getUsers"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/getUsers"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<List<UserInfoInvitationModel>>> getUsers(Principal principal) throws IllegalAccessException, InstantiationException { // ResponseEntity<ResponseItem<List<UserInfoInvitationModel>>> getUsers(Principal principal) throws IllegalAccessException, InstantiationException {
List<UserInfoInvitationModel> users = invitationsManager.getUsers(principal); ResponseEntity<ResponseItem<List<UserInfoInvitationModel>>> getUsers(Principal principal, @RequestBody UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException {
System.out.println(userInfoRequestItem.getCriteria().getLike());
// List<UserInfoInvitationModel> users = invitationsManager.getUsers(principal);
List<UserInfoInvitationModel> users = invitationsManager.getUsersWithCriteria(principal, userInfoRequestItem);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserInfoInvitationModel>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserInfoInvitationModel>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users));
} }
} }

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.UserDMP; import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem;
import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.helpers.StreamDistinctBy; import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
@ -82,6 +83,23 @@ public class InvitationsManager {
return userModels; return userModels;
} }
public List<UserInfoInvitationModel> getUsersWithCriteria(Principal principal, UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException {
List<UserInfo> users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
.getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable()
.where(((builder, root) ->
builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), principal.getId(), Stream.of(0, 1).collect(Collectors.toList()))
.toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser)
.filter(userInfo -> !userInfo.getId().equals(principal.getId())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId))
.filter(userInfo -> (userInfoRequestItem == null || userInfoRequestItem.getCriteria() == null || userInfoRequestItem.getCriteria().getLike() == null
|| userInfo.getName().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase())
|| (userInfo.getEmail().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase()))))
.collect(Collectors.toList());
// .where((builder, root) -> builder.like(builder.upper(root.get("name")), "%" + userInfoRequestItem.getCriteria().getLike().toUpperCase() + "%"))
List<UserInfoInvitationModel> userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList());
return userModels;
}
public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException, JAXBException, IOException { public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException, JAXBException, IOException {
eu.eudat.data.entities.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID); eu.eudat.data.entities.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID);
if (invitation == null) if (invitation == null)