The invite pop up will show only user collaborating with DMP that the current user also is collaborating (ref #258)
This commit is contained in:
parent
75fc400349
commit
391a88a236
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.eudat.data.dao.entities;
|
||||||
|
|
||||||
|
import eu.eudat.data.dao.DatabaseAccessLayer;
|
||||||
|
import eu.eudat.data.entities.UserAssociation;
|
||||||
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface UserAssociationDao extends DatabaseAccessLayer<UserAssociation, UUID> {
|
||||||
|
|
||||||
|
public List<UserAssociation> getAssociated(UserInfo userId);
|
||||||
|
|
||||||
|
public Boolean areAssociated(UserInfo firstUser, UserInfo secondUser);
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package eu.eudat.data.dao.entities;
|
||||||
|
|
||||||
|
import eu.eudat.data.dao.DatabaseAccess;
|
||||||
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||||
|
import eu.eudat.data.entities.UserAssociation;
|
||||||
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Component("UserAssociationDao")
|
||||||
|
public class UserAssociationDaoImpl extends DatabaseAccess<UserAssociation> implements UserAssociationDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UserAssociationDaoImpl(DatabaseService<UserAssociation> databaseService) {
|
||||||
|
super(databaseService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAssociation createOrUpdate(UserAssociation item) {
|
||||||
|
return this.getDatabaseService().createOrUpdate(item, UserAssociation.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<UserAssociation> createOrUpdateAsync(UserAssociation item) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAssociation find(UUID id) {
|
||||||
|
return this.getDatabaseService().getQueryable(UserAssociation.class).where(((builder, root) -> builder.equal(root.get("id"), id))).getSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAssociation find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(UserAssociation item) {
|
||||||
|
this.getDatabaseService().delete(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryableList<UserAssociation> asQueryable() {
|
||||||
|
return this.getDatabaseService().getQueryable(UserAssociation.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserAssociation> getAssociated(UserInfo userId) {
|
||||||
|
return this.getDatabaseService().getQueryable(UserAssociation.class).where(((builder, root) ->
|
||||||
|
builder.or(builder.equal(root.get("firstUser"), userId), builder.equal(root.get("secondUser"), userId)))).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean areAssociated(UserInfo firstUser, UserInfo secondUser) {
|
||||||
|
return this.getDatabaseService().getQueryable(UserAssociation.class).where(((builder, root) ->
|
||||||
|
builder.or(
|
||||||
|
builder.and(
|
||||||
|
builder.equal(root.get("firstUser"), firstUser),
|
||||||
|
builder.equal(root.get("secondUser"), secondUser)
|
||||||
|
),
|
||||||
|
builder.and(
|
||||||
|
builder.equal(root.get("secondUser"), firstUser),
|
||||||
|
builder.equal(root.get("firstUser"), secondUser)
|
||||||
|
)
|
||||||
|
))).count() > 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package eu.eudat.data.entities;
|
||||||
|
|
||||||
|
import eu.eudat.queryable.queryableentity.DataEntity;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "\"UserAssociation\"")
|
||||||
|
public class UserAssociation implements DataEntity<UserAssociation, UUID> {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
||||||
|
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@OneToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"firstUser\"")
|
||||||
|
private UserInfo firstUser;
|
||||||
|
|
||||||
|
@OneToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "\"secondUser\"")
|
||||||
|
private UserInfo secondUser;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserInfo getFirstUser() {
|
||||||
|
return firstUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstUser(UserInfo firstUser) {
|
||||||
|
this.firstUser = firstUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserInfo getSecondUser() {
|
||||||
|
return secondUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondUser(UserInfo secondUser) {
|
||||||
|
this.secondUser = secondUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(UserAssociation entity) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getKeys() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAssociation buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,8 +48,8 @@ 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(@RequestBody UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException {
|
ResponseEntity<ResponseItem<List<UserInfoInvitationModel>>> getUsers(Principal principal) throws IllegalAccessException, InstantiationException {
|
||||||
List<UserInfoInvitationModel> users = invitationsManager.getUsers(userInfoRequestItem);
|
List<UserInfoInvitationModel> users = invitationsManager.getUsers(principal);
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.DMP;
|
||||||
|
import eu.eudat.data.entities.UserAssociation;
|
||||||
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.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
|
@ -38,15 +39,27 @@ public class InvitationsManager {
|
||||||
UserDMP userDMP = new UserDMP();
|
UserDMP userDMP = new UserDMP();
|
||||||
userDMP.setUser(userInfo);
|
userDMP.setUser(userInfo);
|
||||||
userInfoToUserDmp.add(userDMP);
|
userInfoToUserDmp.add(userDMP);
|
||||||
|
if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(principalUser, userInfo)) {
|
||||||
|
UserAssociation userAssociation = new UserAssociation();
|
||||||
|
userAssociation.setFirstUser(principalUser);
|
||||||
|
userAssociation.setSecondUser(userInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DMP dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan());
|
DMP dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan());
|
||||||
apiContext.getUtilitiesService().getInvitationService().createInvitations(apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao(), apiContext.getUtilitiesService().getMailService(), invitation.getUsers().stream().map(item -> item.toDataModel()).collect(Collectors.toList()), dataManagementPlan, principalUser);
|
apiContext.getUtilitiesService().getInvitationService().createInvitations(apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao(), apiContext.getUtilitiesService().getMailService(), invitation.getUsers().stream().map(item -> item.toDataModel()).collect(Collectors.toList()), dataManagementPlan, principalUser);
|
||||||
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userInfoToUserDmp, dataManagementPlan);
|
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userInfoToUserDmp, dataManagementPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserInfoInvitationModel> getUsers(UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException {
|
public List<UserInfoInvitationModel> getUsers(Principal principal) throws InstantiationException, IllegalAccessException {
|
||||||
QueryableList<UserInfo> users = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria());
|
UserInfo principalUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||||
List<UserInfoInvitationModel> userModels = users.select(item -> new UserInfoInvitationModel().fromDataModel(item));
|
List<UserInfo> users = apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().getAssociated(principalUser).stream().map(userAssociation -> {
|
||||||
|
if (userAssociation.getFirstUser().getId().equals(principal.getId())) {
|
||||||
|
return userAssociation.getSecondUser();
|
||||||
|
} else {
|
||||||
|
return userAssociation.getFirstUser();
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
List<UserInfoInvitationModel> userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList());
|
||||||
return userModels;
|
return userModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +73,12 @@ public class InvitationsManager {
|
||||||
userDMP.setUser(invitedUser);
|
userDMP.setUser(invitedUser);
|
||||||
userDMP.setDmp(invitation.getDmp());
|
userDMP.setDmp(invitation.getDmp());
|
||||||
userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
|
userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
|
||||||
|
if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) {
|
||||||
|
UserAssociation userAssociation = new UserAssociation();
|
||||||
|
userAssociation.setFirstUser(invitedUser);
|
||||||
|
userAssociation.setSecondUser(invitation.getUser());
|
||||||
|
apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation);
|
||||||
|
}
|
||||||
DMP datamanagementPlan = invitation.getDmp();
|
DMP datamanagementPlan = invitation.getDmp();
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
||||||
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan);
|
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan);
|
||||||
|
|
|
@ -56,5 +56,7 @@ public interface DatabaseRepository {
|
||||||
|
|
||||||
NotificationDao getNotificationDao();
|
NotificationDao getNotificationDao();
|
||||||
|
|
||||||
|
UserAssociationDao getUserAssociationDao();
|
||||||
|
|
||||||
<T> void detachEntity(T entity);
|
<T> void detachEntity(T entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
||||||
private FunderDao funderDao;
|
private FunderDao funderDao;
|
||||||
private LockDao lockDao;
|
private LockDao lockDao;
|
||||||
private NotificationDao notificationDao;
|
private NotificationDao notificationDao;
|
||||||
|
private UserAssociationDao userAssociationDao;
|
||||||
|
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@ -290,6 +291,16 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
||||||
return notificationDao;
|
return notificationDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserAssociationDao getUserAssociationDao() {
|
||||||
|
return userAssociationDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setUserAssociationDao(UserAssociationDao userAssociationDao) {
|
||||||
|
this.userAssociationDao = userAssociationDao;
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setNotificationDao(NotificationDao notificationDao) {
|
public void setNotificationDao(NotificationDao notificationDao) {
|
||||||
this.notificationDao = notificationDao;
|
this.notificationDao = notificationDao;
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
CREATE TABLE public."UserAssociation" (
|
||||||
|
id uuid NOT NULL,
|
||||||
|
"firstUser" uuid NOT NULL,
|
||||||
|
"secondUser" uuid NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE public."UserAssociation" OWNER TO dmptool;
|
||||||
|
|
||||||
|
ALTER TABLE ONLY public."UserAssociation"
|
||||||
|
ADD CONSTRAINT pk_user_association PRIMARY KEY (id);
|
||||||
|
|
||||||
|
ALTER TABLE ONLY public."UserAssociation"
|
||||||
|
ADD CONSTRAINT fk_userinfo_user_association_1 FOREIGN KEY ("firstUser") REFERENCES public."UserInfo"(id);
|
||||||
|
|
||||||
|
ALTER TABLE ONLY public."UserAssociation"
|
||||||
|
ADD CONSTRAINT fk_userinfo_user_association_2 FOREIGN KEY ("secondUser") REFERENCES public."UserInfo"(id);
|
||||||
|
|
||||||
|
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.002', '2020-05-04 13:42:00.000000+03', now(), 'Add User Association');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue