Delete QueryAccess and Privilege related class.
Change-Id: I47cf6a539d540635424840a7a97d373291d883cd
diff --git a/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java b/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
index a015b0e..e12f080 100644
--- a/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
+++ b/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
@@ -9,8 +9,6 @@
public enum PredefinedRole {
GROUP_ADMIN,
GROUP_MEMBER,
- @Deprecated
- QUERY_ACCESS_ADMIN,
QUERY_ACCESS;
// USER_GROUP_ADMIN(1), USER_GROUP_MEMBER(2), VC_ACCESS_ADMIN(
diff --git a/src/main/java/de/ids_mannheim/korap/constant/QueryAccessStatus.java b/src/main/java/de/ids_mannheim/korap/constant/QueryAccessStatus.java
deleted file mode 100644
index 3b4f786..0000000
--- a/src/main/java/de/ids_mannheim/korap/constant/QueryAccessStatus.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package de.ids_mannheim.korap.constant;
-
-import de.ids_mannheim.korap.entity.QueryAccess;
-
-/**
- * Defines possible statuses of {@link QueryAccess}
- *
- * @author margaretha
- * @see QueryAccess
- *
- */
-public enum QueryAccessStatus {
-
- ACTIVE, DELETED,
- // has not been used yet
- PENDING,
- // access for hidden group
- // maybe not necessary?
- HIDDEN;
-}
diff --git a/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java b/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java
deleted file mode 100644
index bf4e4dc..0000000
--- a/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package de.ids_mannheim.korap.dao;
-
-import java.util.List;
-
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import de.ids_mannheim.korap.constant.PrivilegeType;
-import de.ids_mannheim.korap.entity.Privilege;
-import de.ids_mannheim.korap.entity.Privilege_;
-import de.ids_mannheim.korap.entity.Role;
-import de.ids_mannheim.korap.entity.Role_;
-import jakarta.persistence.EntityManager;
-import jakarta.persistence.PersistenceContext;
-import jakarta.persistence.Query;
-import jakarta.persistence.criteria.CriteriaBuilder;
-import jakarta.persistence.criteria.CriteriaQuery;
-import jakarta.persistence.criteria.Root;
-
-/**
- * Manages database queries and transactions regarding
- * {@link Privilege} entity or database table.
- *
- * @see Privilege
- * @see PrivilegeType
- * @see Role
- *
- * @author margaretha
- *
- */
-@Deprecated
-@Transactional
-@Repository
-public class PrivilegeDao {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- public void addPrivilegesToRole (Role role,
- List<PrivilegeType> privilegeTypes) {
- for (PrivilegeType type : privilegeTypes) {
- Privilege privilege = new Privilege(type, role);
- entityManager.persist(privilege);
- }
- }
-
- public void deletePrivilegeFromRole (int roleId,
- PrivilegeType privilegeType) {
- List<Privilege> privilegeList = retrievePrivilegeByRoleId(roleId);
- for (Privilege p : privilegeList) {
- if (p.getName().equals(privilegeType)) {
- entityManager.remove(p);
- break;
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- public List<Privilege> retrievePrivilegeByRoleId (int roleId) {
- CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
- CriteriaQuery<Privilege> query = criteriaBuilder
- .createQuery(Privilege.class);
-
- Root<Privilege> root = query.from(Privilege.class);
- root.fetch(Privilege_.role);
- query.select(root);
- query.where(criteriaBuilder
- .equal(root.get(Privilege_.role).get(Role_.id), roleId));
- Query q = entityManager.createQuery(query);
- return q.getResultList();
- }
-}
diff --git a/src/main/java/de/ids_mannheim/korap/dao/QueryAccessDao.java b/src/main/java/de/ids_mannheim/korap/dao/QueryAccessDao.java
deleted file mode 100644
index 10bf684..0000000
--- a/src/main/java/de/ids_mannheim/korap/dao/QueryAccessDao.java
+++ /dev/null
@@ -1,279 +0,0 @@
-package de.ids_mannheim.korap.dao;
-
-import java.util.List;
-
-import jakarta.persistence.EntityManager;
-import jakarta.persistence.NoResultException;
-import jakarta.persistence.PersistenceContext;
-import jakarta.persistence.Query;
-import jakarta.persistence.TypedQuery;
-import jakarta.persistence.criteria.CriteriaBuilder;
-import jakarta.persistence.criteria.CriteriaQuery;
-import jakarta.persistence.criteria.Join;
-import jakarta.persistence.criteria.Predicate;
-import jakarta.persistence.criteria.Root;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import de.ids_mannheim.korap.constant.PredefinedRole;
-import de.ids_mannheim.korap.constant.PrivilegeType;
-import de.ids_mannheim.korap.constant.QueryAccessStatus;
-import de.ids_mannheim.korap.entity.UserGroup;
-import de.ids_mannheim.korap.entity.UserGroupMember;
-import de.ids_mannheim.korap.entity.UserGroup_;
-import de.ids_mannheim.korap.entity.QueryAccess;
-import de.ids_mannheim.korap.entity.QueryAccess_;
-import de.ids_mannheim.korap.entity.QueryDO;
-import de.ids_mannheim.korap.entity.QueryDO_;
-import de.ids_mannheim.korap.entity.Role;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.service.UserGroupService;
-import de.ids_mannheim.korap.utils.ParameterChecker;
-
-/**
- * Manages database queries and transactions regarding
- * {@link QueryAccess} entity and its corresponding database
- * table.
- *
- * @author margaretha
- *
- * @see QueryAccess
- * @see Query
- */
-@Deprecated
-@Transactional
-@Repository
-public class QueryAccessDao {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- @Autowired
- private RoleDao roleDao;
- @Autowired
- private UserGroupMemberDao memberDao;
-
- public QueryAccess retrieveAccessById (int accessId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(accessId, "accessId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- query.select(access);
- query.where(builder.equal(access.get(QueryAccess_.id), accessId));
- Query q = entityManager.createQuery(query);
- try {
- return (QueryAccess) q.getSingleResult();
- }
- catch (NoResultException e) {
- throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
- "Query access is not found", String.valueOf(accessId));
- }
- }
-
- // for query-access admins
- public List<QueryAccess> retrieveActiveAccessByQuery (int queryId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(queryId, "queryId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- Join<QueryAccess, QueryDO> accessQuery = access
- .join(QueryAccess_.query);
-
- Predicate p = builder.and(
- builder.equal(accessQuery.get(QueryDO_.id), queryId),
- builder.equal(access.get(QueryAccess_.status),
- QueryAccessStatus.ACTIVE));
- query.select(access);
- query.where(p);
- TypedQuery<QueryAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<QueryAccess> retrieveActiveAccessByQuery (String queryCreator,
- String queryName) throws KustvaktException {
- ParameterChecker.checkStringValue(queryCreator, "queryCreator");
- ParameterChecker.checkStringValue(queryName, "queryName");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- Join<QueryAccess, QueryDO> accessQuery = access
- .join(QueryAccess_.query);
-
- Predicate p = builder.and(
- builder.equal(accessQuery.get(QueryDO_.name), queryName),
- builder.equal(accessQuery.get(QueryDO_.createdBy),
- queryCreator),
- builder.equal(access.get(QueryAccess_.status),
- QueryAccessStatus.ACTIVE));
- query.select(access);
- query.where(p);
- TypedQuery<QueryAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<QueryAccess> retrieveAllAccess () throws KustvaktException {
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
- Root<QueryAccess> access = query.from(QueryAccess.class);
- query.select(access);
- TypedQuery<QueryAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<QueryAccess> retrieveAllAccessByQuery (String queryCreator,
- String queryName) throws KustvaktException {
- ParameterChecker.checkStringValue(queryCreator, "queryCreator");
- ParameterChecker.checkStringValue(queryName, "queryName");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- Join<QueryAccess, QueryDO> accessQuery = access
- .join(QueryAccess_.query);
-
- Predicate conditions = builder.and(
- builder.equal(accessQuery.get(QueryDO_.createdBy),
- queryCreator),
- builder.equal(accessQuery.get(QueryDO_.name), queryName));
- query.select(access);
- query.where(conditions);
- TypedQuery<QueryAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<QueryAccess> retrieveAllAccessByGroup (int groupId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(groupId, "groupId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- Join<QueryAccess, UserGroup> accessQuery = access
- .join(QueryAccess_.userGroup);
-
- query.select(access);
- query.where(builder.equal(accessQuery.get(UserGroup_.id), groupId));
- TypedQuery<QueryAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<QueryAccess> retrieveActiveAccessByGroup (int groupId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(groupId, "groupId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- Join<QueryAccess, UserGroup> accessQuery = access
- .join(QueryAccess_.userGroup);
-
- Predicate p = builder.and(
- builder.equal(accessQuery.get(UserGroup_.id), groupId),
- builder.equal(access.get(QueryAccess_.status),
- QueryAccessStatus.ACTIVE));
-
- query.select(access);
- query.where(p);
- TypedQuery<QueryAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- /**
- * Hidden accesses are only created for published or system query.
- *
- * Warn: The actual hidden accesses are not checked.
- *
- * @param queryId
- * queryId
- * @return true if there is a hidden access, false otherwise
- * @throws KustvaktException
- */
- public QueryAccess retrieveHiddenAccess (int queryId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(queryId, "queryId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryAccess> query = builder
- .createQuery(QueryAccess.class);
-
- Root<QueryAccess> access = query.from(QueryAccess.class);
- Join<QueryAccess, QueryDO> accessQuery = access
- .join(QueryAccess_.query);
-
- Predicate p = builder.and(
- builder.equal(accessQuery.get(QueryDO_.id), queryId),
- builder.equal(access.get(QueryAccess_.status),
- QueryAccessStatus.HIDDEN)
- // ,
- // builder.notEqual(access.get(QueryAccess_.deletedBy),
- // "NULL")
- );
-
- query.select(access);
- query.where(p);
-
- try {
- Query q = entityManager.createQuery(query);
- return (QueryAccess) q.getSingleResult();
- }
- catch (NoResultException e) {
- return null;
- }
- }
-
- @Deprecated
- public void createAccessToQuery (QueryDO query, UserGroup userGroup)
- throws KustvaktException {
-
- List<UserGroupMember> members = memberDao
- .retrieveMemberByGroupId(userGroup.getId());
-
- Role r1 = new Role(PredefinedRole.QUERY_ACCESS,
- PrivilegeType.READ_QUERY, userGroup, query);
- roleDao.addRole(r1);
-
- for (UserGroupMember member : members) {
- member.getRoles().add(r1);
- memberDao.updateMember(member);
- }
-// QueryAccess queryAccess = new QueryAccess();
-// queryAccess.setQuery(query);
-// queryAccess.setUserGroup(userGroup);
-// queryAccess.setCreatedBy(createdBy);
-// queryAccess.setStatus(status);
-// entityManager.persist(queryAccess);
- }
-
- public void deleteAccess (QueryAccess access, String deletedBy) {
- // soft delete
-
- // hard delete
- if (!entityManager.contains(access)) {
- access = entityManager.merge(access);
- }
- entityManager.remove(access);
- }
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java b/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java
index 4026284..800be3d 100644
--- a/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java
+++ b/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java
@@ -12,13 +12,10 @@
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.entity.QueryAccess;
-import de.ids_mannheim.korap.entity.QueryAccess_;
import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.entity.QueryDO_;
import de.ids_mannheim.korap.entity.Role;
import de.ids_mannheim.korap.entity.Role_;
-import de.ids_mannheim.korap.entity.UserGroup;
import de.ids_mannheim.korap.entity.UserGroupMember;
import de.ids_mannheim.korap.entity.UserGroupMember_;
import de.ids_mannheim.korap.entity.UserGroup_;
diff --git a/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java b/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
index f8b0474..5444a96 100644
--- a/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
+++ b/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
@@ -11,10 +11,7 @@
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
import de.ids_mannheim.korap.constant.PrivilegeType;
-import de.ids_mannheim.korap.constant.QueryAccessStatus;
import de.ids_mannheim.korap.constant.UserGroupStatus;
-import de.ids_mannheim.korap.entity.QueryAccess;
-import de.ids_mannheim.korap.entity.QueryAccess_;
import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.entity.QueryDO_;
import de.ids_mannheim.korap.entity.Role;
diff --git a/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java b/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java
index 2ecfa38..e2445e4 100644
--- a/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java
+++ b/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java
@@ -7,7 +7,6 @@
import org.springframework.stereotype.Component;
import de.ids_mannheim.korap.dto.QueryAccessDto;
-import de.ids_mannheim.korap.entity.QueryAccess;
import de.ids_mannheim.korap.entity.Role;
import de.ids_mannheim.korap.entity.UserGroupMember;
@@ -23,25 +22,6 @@
@Component
public class QueryAccessConverter {
- public List<QueryAccessDto> createQueryAccessDto (
- List<QueryAccess> accessList) {
- List<QueryAccessDto> dtos = new ArrayList<>(accessList.size());
- for (QueryAccess access : accessList) {
- QueryAccessDto dto = new QueryAccessDto();
-// dto.setAccessId(access.getId());
-// dto.setCreatedBy(access.getCreatedBy());
-
- dto.setQueryId(access.getQuery().getId());
- dto.setQueryName(access.getQuery().getName());
-
- dto.setUserGroupId(access.getUserGroup().getId());
- dto.setUserGroupName(access.getUserGroup().getName());
-
- dtos.add(dto);
- }
- return dtos;
- }
-
public List<QueryAccessDto> createRoleDto (Set<Role> roles) {
List<QueryAccessDto> dtos = new ArrayList<>(roles.size());
for (Role role : roles) {
diff --git a/src/main/java/de/ids_mannheim/korap/entity/Privilege.java b/src/main/java/de/ids_mannheim/korap/entity/Privilege.java
deleted file mode 100644
index 9a03c59..0000000
--- a/src/main/java/de/ids_mannheim/korap/entity/Privilege.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package de.ids_mannheim.korap.entity;
-
-import jakarta.persistence.Entity;
-import jakarta.persistence.EnumType;
-import jakarta.persistence.Enumerated;
-import jakarta.persistence.FetchType;
-import jakarta.persistence.GeneratedValue;
-import jakarta.persistence.GenerationType;
-import jakarta.persistence.Id;
-import jakarta.persistence.JoinColumn;
-import jakarta.persistence.ManyToOne;
-import jakarta.persistence.Table;
-
-import de.ids_mannheim.korap.constant.PrivilegeType;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Describes privilege table listing users and their roles.
- *
- * @author margaretha
- *
- */
-@Deprecated
-@Getter
-@Setter
-@Entity
-@Table(name = "privilege")
-public class Privilege {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- @Enumerated(EnumType.STRING)
- private PrivilegeType name;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "role_id", referencedColumnName = "id")
- private Role role;
-
- public Privilege () {}
-
- public Privilege (PrivilegeType name, Role role) {
- this.name = name;
- this.role = role;
- }
-
- public String toString () {
- return "id=" + id + ", name=" + name + ", role=" + role;
- }
-}
diff --git a/src/main/java/de/ids_mannheim/korap/entity/QueryAccess.java b/src/main/java/de/ids_mannheim/korap/entity/QueryAccess.java
deleted file mode 100644
index 1e0c3ea..0000000
--- a/src/main/java/de/ids_mannheim/korap/entity/QueryAccess.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package de.ids_mannheim.korap.entity;
-
-import jakarta.persistence.Column;
-import jakarta.persistence.Entity;
-import jakarta.persistence.EnumType;
-import jakarta.persistence.Enumerated;
-import jakarta.persistence.FetchType;
-import jakarta.persistence.GeneratedValue;
-import jakarta.persistence.GenerationType;
-import jakarta.persistence.Id;
-import jakarta.persistence.JoinColumn;
-import jakarta.persistence.ManyToOne;
-import jakarta.persistence.Table;
-
-import de.ids_mannheim.korap.constant.QueryAccessStatus;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Describes the relationship between virtual corpora and user groups,
- * i.e. which groups may access which virtual corpora, and the history
- * of group-access management.
- *
- * @author margaretha
- * @see QueryDO
- * @see UserGroup
- */
-@Deprecated
-@Setter
-@Getter
-@Entity
-@Table(name = "query_access")
-public class QueryAccess {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- @Column(name = "created_by")
- private String createdBy;
- @Column(name = "approved_by")
- private String approvedBy;
- @Column(name = "deleted_by")
- private String deletedBy;
-
- @Enumerated(EnumType.STRING)
- private QueryAccessStatus status;
-
- @ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "query_id", referencedColumnName = "id")
- private QueryDO query;
-
- @ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "user_group_id", referencedColumnName = "id")
- private UserGroup userGroup;
-
- @Override
- public String toString () {
- return "id=" + id + ", query= " + query + ", userGroup= " + userGroup;
- }
-}
diff --git a/src/main/java/de/ids_mannheim/korap/service/QueryService.java b/src/main/java/de/ids_mannheim/korap/service/QueryService.java
index 42fd7cb..cf3f70e 100644
--- a/src/main/java/de/ids_mannheim/korap/service/QueryService.java
+++ b/src/main/java/de/ids_mannheim/korap/service/QueryService.java
@@ -25,7 +25,6 @@
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.dao.AdminDao;
-import de.ids_mannheim.korap.dao.QueryAccessDao;
import de.ids_mannheim.korap.dao.QueryDao;
import de.ids_mannheim.korap.dao.RoleDao;
import de.ids_mannheim.korap.dao.UserGroupDao;
@@ -34,7 +33,6 @@
import de.ids_mannheim.korap.dto.QueryDto;
import de.ids_mannheim.korap.dto.converter.QueryAccessConverter;
import de.ids_mannheim.korap.dto.converter.QueryConverter;
-import de.ids_mannheim.korap.entity.QueryAccess;
import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.entity.Role;
import de.ids_mannheim.korap.entity.UserGroup;
@@ -89,8 +87,6 @@
private UserGroupMemberDao memberDao;
@Autowired
- private QueryAccessDao accessDao;
- @Autowired
private AdminDao adminDao;
@Autowired
private UserGroupService userGroupService;
@@ -539,47 +535,47 @@
}
}
- public List<QueryAccessDto> listQueryAccessByUsername (String username)
- throws KustvaktException {
- List<QueryAccess> accessList = new ArrayList<>();
- if (adminDao.isAdmin(username)) {
- accessList = accessDao.retrieveAllAccess();
- }
- else {
- List<UserGroup> groups = userGroupService
- .retrieveUserGroup(username);
- for (UserGroup g : groups) {
- if (userGroupService.isUserGroupAdmin(username, g)) {
- accessList.addAll(
- accessDao.retrieveActiveAccessByGroup(g.getId()));
- }
- }
- }
- return accessConverter.createQueryAccessDto(accessList);
- }
-
- public List<QueryAccessDto> listQueryAccessByQuery (String username,
- String queryCreator, String queryName) throws KustvaktException {
-
- List<QueryAccess> accessList;
- if (adminDao.isAdmin(username)) {
- accessList = accessDao.retrieveAllAccessByQuery(queryCreator,
- queryName);
- }
- else {
- accessList = accessDao.retrieveActiveAccessByQuery(queryCreator,
- queryName);
- List<QueryAccess> filteredAccessList = new ArrayList<>();
- for (QueryAccess access : accessList) {
- UserGroup userGroup = access.getUserGroup();
- if (userGroupService.isUserGroupAdmin(username, userGroup)) {
- filteredAccessList.add(access);
- }
- }
- accessList = filteredAccessList;
- }
- return accessConverter.createQueryAccessDto(accessList);
- }
+// public List<QueryAccessDto> listQueryAccessByUsername (String username)
+// throws KustvaktException {
+// List<QueryAccess> accessList = new ArrayList<>();
+// if (adminDao.isAdmin(username)) {
+// accessList = accessDao.retrieveAllAccess();
+// }
+// else {
+// List<UserGroup> groups = userGroupService
+// .retrieveUserGroup(username);
+// for (UserGroup g : groups) {
+// if (userGroupService.isUserGroupAdmin(username, g)) {
+// accessList.addAll(
+// accessDao.retrieveActiveAccessByGroup(g.getId()));
+// }
+// }
+// }
+// return accessConverter.createQueryAccessDto(accessList);
+// }
+//
+// public List<QueryAccessDto> listQueryAccessByQuery (String username,
+// String queryCreator, String queryName) throws KustvaktException {
+//
+// List<QueryAccess> accessList;
+// if (adminDao.isAdmin(username)) {
+// accessList = accessDao.retrieveAllAccessByQuery(queryCreator,
+// queryName);
+// }
+// else {
+// accessList = accessDao.retrieveActiveAccessByQuery(queryCreator,
+// queryName);
+// List<QueryAccess> filteredAccessList = new ArrayList<>();
+// for (QueryAccess access : accessList) {
+// UserGroup userGroup = access.getUserGroup();
+// if (userGroupService.isUserGroupAdmin(username, userGroup)) {
+// filteredAccessList.add(access);
+// }
+// }
+// accessList = filteredAccessList;
+// }
+// return accessConverter.createQueryAccessDto(accessList);
+// }
public List<QueryAccessDto> listRolesByGroup (String username,
String groupName) throws KustvaktException {
diff --git a/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java b/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
index da81edb..6a4fa8b 100644
--- a/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
+++ b/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
@@ -170,13 +170,6 @@
return dtos;
}
- public List<UserGroupMember> retrieveQueryAccessAdmins (UserGroup userGroup)
- throws KustvaktException {
- List<UserGroupMember> groupAdmins = groupMemberDao.retrieveMemberByRole(
- userGroup.getId(), PredefinedRole.QUERY_ACCESS_ADMIN);
- return groupAdmins;
- }
-
private Set<Role> prepareMemberRoles (UserGroup userGroup) {
Role r1 = new Role(PredefinedRole.GROUP_MEMBER,
PrivilegeType.DELETE_MEMBER, userGroup);
diff --git a/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java b/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
index 9ba7efa..879963e 100644
--- a/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
+++ b/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
@@ -44,13 +44,13 @@
* VirtualCorpusController defines web APIs related to virtual corpus
* (VC) such as creating, deleting and listing user virtual corpora.
* All the APIs in this class are available to logged-in users, except
- * retrieving info of system VC.
+ * retrieving a VC info.
*
- * This class also includes APIs related to virtual corpus access
- * (VCA) such as sharing and publishing VC. When a VC is published,
- * it is shared with all users, but not always listed like system
- * VC. It is listed for a user, once when he/she have searched for the
- * VC. A VC can be published by creating or editing the VC.
+ * This class also includes web-services to share and publish VC. When
+ * a VC is published, it is shared with all users, but not always listed
+ * like system VC. It is listed for a user, once when he/she have searched
+ * for the VC. A VC can be published by creating a new VC with type PUBLISHED
+ * or editing an existing VC.
*
* VC name must follow the following regex [a-zA-Z_0-9-.], other
* characters are not allowed.
@@ -202,18 +202,17 @@
}
/**
- * Lists all virtual corpora available to the user.
- *
- * System-admins can list available vc for a specific user by
- * specifiying the username parameter.
+ * Lists all virtual corpora (VC) available to the authenticated
+ * user including PRIVATE VC created by the user, SYSTEM VC
+ * defined by system-admins, and PROJECT VC available to
+ * user-groups, wherein the user is a member of. The list can be
+ * filtered to show only SYSTEM VC or VC owned by the user.
*
- * Normal users cannot list virtual corpora
- * available for other users. Thus, username parameter is optional
- * and must be identical to the authenticated username.
+ * This web-service requires OAuth2 access token with scope:
+ * vc_info.
*
* @param securityContext
- * @param username
- * a username (optional)
+ * @param filter filter the list by system, own, or empty (default)
* @return a list of virtual corpora
*/
@GET
@@ -282,9 +281,7 @@
}
/**
- * Only the VC owner and system admins can delete VC. VCA admins
- * can delete VC-accesses e.g. of project VC, but not the VC
- * themselves.
+ * Group and system admins can delete VC.
*
* @param securityContext
* @param createdBy
@@ -313,7 +310,7 @@
/**
* VC can only be shared with a group, not individuals.
- * Only VCA admins are allowed to share VC and the VC must have
+ * Only group admins are allowed to share VC and the VC must have
* been created by themselves.
*
* <br /><br />
@@ -406,14 +403,10 @@
return Response.ok().build();
}
-
-
-
/**
- * Lists active VC-accesses available to user.
+ * Lists all member roles in a group.
*
- * Only available to VCA and system admins.
- * For system admins, list all VCA regardless of status.
+ * Only available to group and system admins.
*
* @param securityContext
* @return a list of VC accesses
@@ -427,17 +420,10 @@
.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.VC_ACCESS_INFO);
- if (groupName != null && !groupName.isEmpty()) {
- return service.listRolesByGroup(context.getUsername(),
- groupName);
- }
- else {
- return service.listQueryAccessByUsername(context.getUsername());
- }
+ return service.listRolesByGroup(context.getUsername(), groupName);
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
-
}
diff --git a/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java b/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
index 6f5ce5e..1943118 100644
--- a/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
@@ -5,8 +5,6 @@
import java.util.List;
import java.util.Set;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,14 +31,13 @@
@Test
public void testRetrieveMemberByRole () throws KustvaktException {
UserGroup group = createDoryGroup();
-
// dory group
- List<UserGroupMember> vcaAdmins = dao.retrieveMemberByRole(group.getId(),
- PredefinedRole.QUERY_ACCESS_ADMIN);
+ List<UserGroupMember> groupAdmins = dao.retrieveMemberByRole(
+ group.getId(), PredefinedRole.GROUP_ADMIN);
// System.out.println(vcaAdmins);
- assertEquals(1, vcaAdmins.size());
- assertEquals(vcaAdmins.get(0).getUserId(), "dory");
-
+ assertEquals(1, groupAdmins.size());
+ assertEquals(groupAdmins.get(0).getUserId(), "dory");
+
deleteUserGroup(group.getId(), "dory");
}
@@ -56,14 +53,14 @@
UserGroupMember member = dao.retrieveMemberById("dory", groupId);
Set<Role> roles = member.getRoles();
- assertEquals(6, roles.size());
+ assertEquals(5, roles.size());
roles.add(newRole);
member.setRoles(roles);
dao.updateMember(member);
member = dao.retrieveMemberById("dory", groupId);
member.getRoles();
- assertEquals(7, roles.size());
+ assertEquals(6, roles.size());
deleteUserGroup(group.getId(), "dory");
}
diff --git a/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java b/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
deleted file mode 100644
index cd846d9..0000000
--- a/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package de.ids_mannheim.korap.service;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.List;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-import de.ids_mannheim.korap.constant.QueryType;
-import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.constant.UserGroupStatus;
-import de.ids_mannheim.korap.dto.QueryAccessDto;
-import de.ids_mannheim.korap.dto.QueryDto;
-import de.ids_mannheim.korap.entity.QueryDO;
-import de.ids_mannheim.korap.entity.UserGroup;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.input.QueryJson;
-
-@ExtendWith(SpringExtension.class)
-@ContextConfiguration("classpath:test-config.xml")
-public class VirtualCorpusServiceTest {
-
- @Autowired
- private QueryService vcService;
-
- @Autowired
- private UserGroupService groupService;
-
- @Test
- public void testCreateNonUniqueVC () throws KustvaktException {
- // EM: message differs depending on the database used
- // for testing. The message below is from sqlite.
- // thrown.expectMessage("A UNIQUE constraint failed "
- // + "(UNIQUE constraint failed: virtual_corpus.name, "
- // + "virtual_corpus.created_by)");
- QueryJson vc = new QueryJson();
- vc.setCorpusQuery("corpusSigle=GOE");
- vc.setType(ResourceType.PRIVATE);
- vc.setQueryType(QueryType.VIRTUAL_CORPUS);
- assertThrows(KustvaktException.class,
- () -> vcService.storeQuery(vc, "dory-vc", "dory", "dory"));
- }
-
- @Test
- public void createDeletePublishVC () throws KustvaktException {
- String vcName = "new-published-vc";
- QueryJson vc = new QueryJson();
- vc.setCorpusQuery("corpusSigle=GOE");
- vc.setType(ResourceType.PUBLISHED);
- vc.setQueryType(QueryType.VIRTUAL_CORPUS);
- String username = "VirtualCorpusServiceTest";
- vcService.storeQuery(vc, vcName, username, username);
- List<QueryAccessDto> accesses = vcService
- .listQueryAccessByUsername("admin");
- int size = accesses.size();
- QueryAccessDto dto = accesses.get(accesses.size() - 1);
- assertEquals(vcName, dto.getQueryName());
-// assertEquals(dto.getCreatedBy(), "system");
- assertTrue(dto.getUserGroupName().startsWith("auto"));
- // check hidden group
- int groupId = dto.getUserGroupId();
- UserGroup group = groupService.retrieveUserGroupById(groupId);
- assertEquals(UserGroupStatus.HIDDEN, group.getStatus());
- // delete vc
- vcService.deleteQueryByName(username, vcName, username,
- QueryType.VIRTUAL_CORPUS);
- // check hidden access
- accesses = vcService.listQueryAccessByUsername("admin");
- assertEquals(size - 1, accesses.size());
- // check hidden group
- KustvaktException e = assertThrows(KustvaktException.class,
- () -> groupService.retrieveUserGroupById(groupId));
- assertEquals("Group with id " + groupId + " is not found",
- e.getMessage());
- }
-
- @Test
- public void testEditPublishVC () throws KustvaktException {
- String username = "dory";
- int vcId = 2;
- String vcName = "group-vc";
- QueryDO existingVC = vcService.searchQueryByName(username, vcName,
- username, QueryType.VIRTUAL_CORPUS);
- QueryJson vcJson = new QueryJson();
- vcJson.setType(ResourceType.PUBLISHED);
- vcService.editQuery(existingVC, vcJson, vcName, username);
- // check VC
- QueryDto vcDto = vcService.searchQueryById("dory", vcId);
- assertEquals(vcName, vcDto.getName());
- assertEquals(ResourceType.PUBLISHED.displayName(), vcDto.getType());
- // check access
- List<QueryAccessDto> accesses = vcService
- .listQueryAccessByUsername("admin");
- int size = accesses.size();
- QueryAccessDto dto = accesses.get(accesses.size() - 1);
- assertEquals(vcName, dto.getQueryName());
-// assertEquals(dto.getCreatedBy(), "system");
- assertTrue(dto.getUserGroupName().startsWith("auto"));
- // check auto hidden group
- int groupId = dto.getUserGroupId();
- UserGroup group = groupService.retrieveUserGroupById(groupId);
- assertEquals(UserGroupStatus.HIDDEN, group.getStatus());
- // 2nd edit (withdraw from publication)
- vcJson = new QueryJson();
- vcJson.setType(ResourceType.PROJECT);
- vcService.editQuery(existingVC, vcJson, vcName, username);
- // check VC
- vcDto = vcService.searchQueryById("dory", vcId);
- assertEquals(vcDto.getName(), "group-vc");
- assertEquals(ResourceType.PROJECT.displayName(), vcDto.getType());
- // check access
- accesses = vcService.listQueryAccessByUsername("admin");
- assertEquals(size - 1, accesses.size());
- KustvaktException e = assertThrows(KustvaktException.class,
- () -> groupService.retrieveUserGroupById(groupId));
- assertEquals("Group with id " + groupId + " is not found",
- e.getMessage());
- }
-}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
index 6b5627d..d8dff83 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
@@ -24,8 +24,9 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.controller.usergroup.UserGroupTestBase;
-public class OAuth2AccessTokenTest extends OAuth2TestBase {
+public class OAuth2AccessTokenTest extends UserGroupTestBase {
private String userAuthHeader;
@@ -46,6 +47,12 @@
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(node.at("/scope").asText(), "all");
String accessToken = node.at("/access_token").asText();
+
+ createDoryGroup();
+ createMarlinGroup();
+ inviteMember(marlinGroupName, "marlin", "dory");
+ subscribe(marlinGroupName, "dory");
+
// test list user group
response = target().path(API_VERSION).path("group").request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
@@ -53,6 +60,9 @@
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(2, node.size());
+
+ deleteGroupByName(doryGroupName, "dory");
+ deleteGroupByName(marlinGroupName, "marlin");
}
@Test
@@ -72,7 +82,7 @@
.header(Attributes.AUTHORIZATION, "Bearer " + token).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(4, node.size());
+ assertEquals(3, node.size());
}
@Test
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
index bf653bc..44019ae 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
@@ -245,7 +245,7 @@
Form form = new Form();
form.param("memberUsername", "dory");
form.param("role", PredefinedRole.GROUP_ADMIN.name());
- form.param("role", PredefinedRole.QUERY_ACCESS_ADMIN.name());
+ form.param("role", PredefinedRole.QUERY_ACCESS.name());
addMemberRole(marlinGroupName, "marlin", form);
// dory is a group admin in marlin-group
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java
index ab72b75..a3b3a12 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java
@@ -4,7 +4,6 @@
import java.util.Set;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -110,7 +109,7 @@
Form form = new Form();
form.param("memberUsername", "marlin");
form.param("role", PredefinedRole.GROUP_ADMIN.name());
- form.param("role", PredefinedRole.QUERY_ACCESS_ADMIN.name());
+ form.param("role", PredefinedRole.QUERY_ACCESS.name());
addMemberRole(doryGroupName, "dory", form);
UserGroupMember member = memberDao.retrieveMemberById("marlin",