Remove User Association Table
This commit is contained in:
parent
33423b92f6
commit
ba091fad6c
|
@ -1,15 +0,0 @@
|
|||
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);
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.entities.UserAssociation;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
||||
import eu.eudat.models.data.invitation.Invitation;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.userinfo.UserInfoInvitationModel;
|
||||
import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Component
|
||||
public class InvitationsManager {
|
||||
|
@ -33,33 +33,38 @@ public class InvitationsManager {
|
|||
UserInfo principalUser = new UserInfo();
|
||||
principalUser.setId(principal.getId());
|
||||
List<UserInfoInvitationModel> alreadySignedInUsers = invitation.getUsers().stream().filter(item -> item.getId() != null).collect(Collectors.toList());
|
||||
List<UserInfo> alreadySignedInUsersEntities = alreadySignedInUsers.stream().map(item -> item.toDataModel()).collect(Collectors.toList());
|
||||
List<UserInfo> alreadySignedInUsersEntities = alreadySignedInUsers.stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList());
|
||||
List<UserDMP> userInfoToUserDmp = new LinkedList<>();
|
||||
for (UserInfo userInfo : alreadySignedInUsersEntities) {
|
||||
UserDMP userDMP = new UserDMP();
|
||||
userDMP.setUser(userInfo);
|
||||
userInfoToUserDmp.add(userDMP);
|
||||
if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(principalUser, userInfo)) {
|
||||
/*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(principalUser, userInfo)) {
|
||||
UserAssociation userAssociation = new UserAssociation();
|
||||
userAssociation.setFirstUser(principalUser);
|
||||
userAssociation.setSecondUser(userInfo);
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
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(UserInfoInvitationModel::toDataModel).collect(Collectors.toList()), dataManagementPlan, principalUser);
|
||||
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userInfoToUserDmp, dataManagementPlan);
|
||||
}
|
||||
|
||||
public List<UserInfoInvitationModel> getUsers(Principal principal) throws InstantiationException, IllegalAccessException {
|
||||
UserInfo principalUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
/*UserInfo principalUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
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());
|
||||
}).collect(Collectors.toList());*/
|
||||
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)).collect(Collectors.toList());
|
||||
List<UserInfoInvitationModel> userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList());
|
||||
return userModels;
|
||||
}
|
||||
|
@ -74,12 +79,12 @@ public class InvitationsManager {
|
|||
userDMP.setUser(invitedUser);
|
||||
userDMP.setDmp(invitation.getDmp());
|
||||
userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
|
||||
if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) {
|
||||
/*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();
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
||||
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan);
|
||||
|
|
|
@ -56,8 +56,6 @@ public interface DatabaseRepository {
|
|||
|
||||
NotificationDao getNotificationDao();
|
||||
|
||||
UserAssociationDao getUserAssociationDao();
|
||||
|
||||
DoiFunderDao getDoiFunderDao();
|
||||
|
||||
<T> void detachEntity(T entity);
|
||||
|
|
|
@ -37,7 +37,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
|||
private FunderDao funderDao;
|
||||
private LockDao lockDao;
|
||||
private NotificationDao notificationDao;
|
||||
private UserAssociationDao userAssociationDao;
|
||||
private DoiFunderDao doiFunderDao;
|
||||
|
||||
private EntityManager entityManager;
|
||||
|
@ -292,11 +291,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
|||
return notificationDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserAssociationDao getUserAssociationDao() {
|
||||
return userAssociationDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoiFunderDao getDoiFunderDao() {
|
||||
return doiFunderDao;
|
||||
|
@ -307,11 +301,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
|||
this.doiFunderDao = doiFunderDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserAssociationDao(UserAssociationDao userAssociationDao) {
|
||||
this.userAssociationDao = userAssociationDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setNotificationDao(NotificationDao notificationDao) {
|
||||
this.notificationDao = notificationDao;
|
||||
|
|
|
@ -800,19 +800,6 @@ CREATE TABLE public."Service" (
|
|||
|
||||
ALTER TABLE public."Service" OWNER TO :POSTGRES_USER;
|
||||
|
||||
--
|
||||
-- Name: UserAssociation; Type: TABLE; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
||||
CREATE TABLE public."UserAssociation" (
|
||||
id uuid NOT NULL,
|
||||
"firstUser" uuid NOT NULL,
|
||||
"secondUser" uuid NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."UserAssociation" OWNER TO :POSTGRES_USER;
|
||||
|
||||
--
|
||||
-- Name: UserDMP; Type: TABLE; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
@ -1181,14 +1168,6 @@ ALTER TABLE ONLY public."UserToken"
|
|||
ADD CONSTRAINT "UserToken_pkey" PRIMARY KEY ("Token");
|
||||
|
||||
|
||||
--
|
||||
-- Name: UserAssociation pk_user_association; Type: CONSTRAINT; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UserAssociation"
|
||||
ADD CONSTRAINT pk_user_association PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: fki_DMPDMPProfileReference; Type: INDEX; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
@ -1435,22 +1414,6 @@ ALTER TABLE ONLY public."Project"
|
|||
ADD CONSTRAINT fk_project_creator FOREIGN KEY ("CreationUser") REFERENCES public."UserInfo"(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: UserAssociation fk_userinfo_user_association_1; Type: FK CONSTRAINT; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UserAssociation"
|
||||
ADD CONSTRAINT fk_userinfo_user_association_1 FOREIGN KEY ("firstUser") REFERENCES public."UserInfo"(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: UserAssociation fk_userinfo_user_association_2; Type: FK CONSTRAINT; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UserAssociation"
|
||||
ADD CONSTRAINT fk_userinfo_user_association_2 FOREIGN KEY ("secondUser") REFERENCES public."UserInfo"(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: Credential fkey_credential_user; Type: FK CONSTRAINT; Schema: public; Owner: :POSTGRES_USER
|
||||
--
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
DROP TABLE IF EXISTS "UserAssociation";
|
||||
|
||||
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.005', '2020-06-03 12:00:00.000000+03', now(), 'Remove user association table');
|
||||
|
Loading…
Reference in New Issue