The invite pop up will show only user collaborating with DMP that the current user also is collaborating (ref #258)
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;
|
||||
}
|
||||
}
|
@ -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