Renamed virtual corpus to query.
Change-Id: I28791ad86276d1507da0632178d5bf7d53cebbda
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
index 8ef8070..faa150c 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
@@ -20,9 +20,9 @@
import de.ids_mannheim.korap.KrillCollection;
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.service.VirtualCorpusService;
+import de.ids_mannheim.korap.service.QueryService;
import de.ids_mannheim.korap.util.QueryException;
import de.ids_mannheim.korap.web.SearchKrill;
@@ -38,7 +38,7 @@
@Autowired
private SearchKrill searchKrill;
@Autowired
- private VirtualCorpusService vcService;
+ private QueryService vcService;
public static Logger jlog = LogManager.getLogger(NamedVCLoader.class);
public static boolean DEBUG = false;
@@ -92,7 +92,7 @@
if (json != null) {
cacheVC(json, filename);
try {
- VirtualCorpus vc = vcService.searchVCByName("system",
+ QueryDO vc = vcService.searchQueryByName("system",
filename, "system", QueryType.VIRTUAL_CORPUS);
if (vc != null) {
if (DEBUG) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java b/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
index d784cb0..6e794aa 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
@@ -6,7 +6,7 @@
*
*/
public enum PredefinedRole {
- USER_GROUP_ADMIN(1), USER_GROUP_MEMBER(2), VC_ACCESS_ADMIN(3), VC_ACCESS_MEMBER(4);
+ USER_GROUP_ADMIN(1), USER_GROUP_MEMBER(2), QUERY_ACCESS_ADMIN(3), QUERY_ACCESS_MEMBER(4);
private int id;
private String name;
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/QueryAccessStatus.java b/full/src/main/java/de/ids_mannheim/korap/constant/QueryAccessStatus.java
new file mode 100644
index 0000000..de78d54
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/QueryAccessStatus.java
@@ -0,0 +1,19 @@
+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/full/src/main/java/de/ids_mannheim/korap/constant/ResourceType.java b/full/src/main/java/de/ids_mannheim/korap/constant/ResourceType.java
index 27cd9b8..8c2e2ac 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/ResourceType.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/ResourceType.java
@@ -1,8 +1,8 @@
package de.ids_mannheim.korap.constant;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
-/** Defines types of {@link VirtualCorpus}
+/** Defines types of {@link QueryDO}
*
* @author margaretha
*
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java b/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java
deleted file mode 100644
index 437038c..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package de.ids_mannheim.korap.constant;
-
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
-
-/** Defines possible statuses of {@link VirtualCorpusAccess}
- *
- * @author margaretha
- * @see VirtualCorpusAccess
- *
- */
-public enum VirtualCorpusAccessStatus {
-
- ACTIVE, DELETED,
- // has not been used yet
- PENDING,
- // access for hidden group
- // maybe not necessary?
- HIDDEN;
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/QueryAccessDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/QueryAccessDao.java
new file mode 100644
index 0000000..f28c4ee
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/QueryAccessDao.java
@@ -0,0 +1,265 @@
+package de.ids_mannheim.korap.dao;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
+import de.ids_mannheim.korap.entity.UserGroup;
+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.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+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
+ */
+@Transactional
+@Repository
+public class QueryAccessDao {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ 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;
+ }
+ }
+
+ public void createAccessToQuery (QueryDO query,
+ UserGroup userGroup, String createdBy,
+ QueryAccessStatus status) {
+ 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/full/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java
new file mode 100644
index 0000000..27d3b9f
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/QueryDao.java
@@ -0,0 +1,372 @@
+package de.ids_mannheim.korap.dao;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.NonUniqueResultException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+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.constant.UserGroupStatus;
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
+import de.ids_mannheim.korap.entity.QueryDO;
+import de.ids_mannheim.korap.entity.QueryDO_;
+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_;
+import de.ids_mannheim.korap.entity.QueryAccess;
+import de.ids_mannheim.korap.entity.QueryAccess_;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.user.User.CorpusAccess;
+import de.ids_mannheim.korap.utils.ParameterChecker;
+
+/**
+ * QueryDao manages database queries and transactions
+ * regarding KorAP queries, e.g. retrieving and storing queries.
+ *
+ * @author margaretha
+ *
+ */
+@Transactional
+@Repository
+public class QueryDao {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ public int createQuery (String name, ResourceType type,
+ QueryType queryType, CorpusAccess requiredAccess, String koralQuery,
+ String definition, String description, String status,
+ boolean isCached, String createdBy, String query,
+ String queryLanguage) throws KustvaktException {
+
+ QueryDO q = new QueryDO();
+ q.setName(name);
+ q.setType(type);
+ q.setQueryType(queryType);
+ q.setRequiredAccess(requiredAccess);
+ q.setKoralQuery(koralQuery);
+ q.setDefinition(definition);
+ q.setDescription(description);
+ q.setStatus(status);
+ q.setCreatedBy(createdBy);
+ q.setCached(isCached);
+ q.setQuery(query);
+ q.setQueryLanguage(queryLanguage);
+
+ entityManager.persist(q);
+ return q.getId();
+ }
+
+ public void editQuery (QueryDO query, String name,
+ ResourceType type, CorpusAccess requiredAccess, String koralQuery,
+ String definition, String description, String status,
+ boolean isCached) throws KustvaktException {
+
+ if (name != null && !name.isEmpty()) {
+ query.setName(name);
+ }
+ if (type != null) {
+ query.setType(type);
+ }
+ if (requiredAccess != null) {
+ query.setRequiredAccess(requiredAccess);
+ }
+ if (koralQuery != null) {
+ query.setKoralQuery(koralQuery);
+ }
+ if (definition != null && !definition.isEmpty()) {
+ query.setDefinition(definition);
+ }
+ if (description != null && !description.isEmpty()) {
+ query.setDescription(description);
+ }
+ if (status != null && !status.isEmpty()) {
+ query.setStatus(status);
+ }
+ query.setCached(isCached);
+ entityManager.merge(query);
+ }
+
+ public void deleteQuery (QueryDO query)
+ throws KustvaktException {
+ if (!entityManager.contains(query)) {
+ query = entityManager.merge(query);
+ }
+ entityManager.remove(query);
+
+ }
+
+ /**
+ * System admin function.
+ *
+ * Retrieves queries by creator and type. If type is not
+ * specified, retrieves queries of all types. If createdBy is not
+ * specified, retrieves queries of all users.
+ *
+ * @param type
+ * {@link ResourceType}
+ * @param createdBy
+ * username of the query creator
+ * @return a list of {@link Query}
+ * @throws KustvaktException
+ */
+ @SuppressWarnings("unchecked")
+ public List<QueryDO> retrieveQueryByType (ResourceType type,
+ String createdBy, QueryType queryType) throws KustvaktException {
+
+ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> criteriaQuery =
+ criteriaBuilder.createQuery(QueryDO.class);
+ Root<QueryDO> query = criteriaQuery.from(QueryDO.class);
+
+ Predicate conditions = criteriaBuilder
+ .equal(query.get(QueryDO_.queryType), queryType);
+ if (createdBy != null && !createdBy.isEmpty()) {
+ conditions = criteriaBuilder.and(conditions, criteriaBuilder.equal(
+ query.get(QueryDO_.createdBy), createdBy));
+ if (type != null) {
+ conditions = criteriaBuilder.and(conditions, criteriaBuilder
+ .equal(query.get(QueryDO_.type), type));
+ }
+ }
+ else if (type != null) {
+ conditions = criteriaBuilder.and(conditions, criteriaBuilder
+ .equal(query.get(QueryDO_.type), type));
+ }
+
+ criteriaQuery.select(query);
+ criteriaQuery.where(conditions);
+ Query q = entityManager.createQuery(criteriaQuery);
+ return q.getResultList();
+ }
+
+ public QueryDO retrieveQueryById (int id) throws KustvaktException {
+ ParameterChecker.checkIntegerValue(id, "id");
+
+ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> criteriaQuery =
+ criteriaBuilder.createQuery(QueryDO.class);
+ Root<QueryDO> query = criteriaQuery.from(QueryDO.class);
+ criteriaQuery.select(query);
+ criteriaQuery.where(criteriaBuilder.equal(query.get(QueryDO_.id),
+ id));
+
+ QueryDO qe = null;
+ try {
+ Query q = entityManager.createQuery(criteriaQuery);
+ qe = (QueryDO) q.getSingleResult();
+ }
+ catch (NoResultException e) {
+ throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
+ "Query with id: " + id + " is not found",
+ String.valueOf(id), e);
+ }
+ return qe;
+ }
+
+ public QueryDO retrieveQueryByName (String queryName, String createdBy)
+ throws KustvaktException {
+ ParameterChecker.checkStringValue(createdBy, "createdBy");
+ ParameterChecker.checkStringValue(queryName, "queryName");
+
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> criteriaQuery =
+ builder.createQuery(QueryDO.class);
+
+ Root<QueryDO> query = criteriaQuery.from(QueryDO.class);
+
+ Predicate condition = builder.and(
+ builder.equal(query.get(QueryDO_.createdBy),
+ createdBy),
+ builder.equal(query.get(QueryDO_.name), queryName));
+
+ criteriaQuery.select(query);
+ criteriaQuery.where(condition);
+
+ Query q = entityManager.createQuery(criteriaQuery);
+ QueryDO qe = null;
+ try {
+ qe = (QueryDO) q.getSingleResult();
+ }
+ catch (NoResultException e) {
+ return null;
+ }
+ catch (NonUniqueResultException e) {
+ String code = createdBy + "/" + queryName;
+ throw new KustvaktException(StatusCodes.NON_UNIQUE_RESULT_FOUND,
+ "Non unique result found for query: retrieve query by name "
+ + code,
+ String.valueOf(code), e);
+ }
+ return qe;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<QueryDO> retrieveOwnerQuery (String userId,
+ QueryType queryType) throws KustvaktException {
+ ParameterChecker.checkStringValue(userId, "userId");
+
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> cq =
+ builder.createQuery(QueryDO.class);
+
+ Root<QueryDO> query = cq.from(QueryDO.class);
+ Predicate conditions = builder.and(
+ builder.equal(query.get(QueryDO_.createdBy),
+ userId),
+ builder.equal(query.get(QueryDO_.queryType),
+ queryType));
+
+ cq.select(query);
+ cq.where(conditions);
+
+ Query q = entityManager.createQuery(cq);
+ return q.getResultList();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<QueryDO> retrieveOwnerQueryByType (String userId,
+ ResourceType type) throws KustvaktException {
+ ParameterChecker.checkStringValue(userId, "userId");
+
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> cq =
+ builder.createQuery(QueryDO.class);
+
+ Root<QueryDO> query = cq.from(QueryDO.class);
+ cq.select(query);
+
+ Predicate p = builder.and(
+ builder.equal(query.get(QueryDO_.createdBy),
+ userId),
+ builder.equal(query.get(QueryDO_.type), type));
+ cq.where(p);
+
+ Query q = entityManager.createQuery(cq);
+ return q.getResultList();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<QueryDO> retrieveGroupQueryByUser (String userId, QueryType queryType)
+ throws KustvaktException {
+ ParameterChecker.checkStringValue(userId, "userId");
+
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> cq =
+ builder.createQuery(QueryDO.class);
+
+ Root<QueryDO> query = cq.from(QueryDO.class);
+ Join<QueryDO, QueryAccess> access =
+ query.join(QueryDO_.queryAccess);
+
+ // Predicate corpusStatus = builder.and(
+ // builder.notEqual(access.get(QueryAccess_.status),
+ // VirtualCorpusAccessStatus.HIDDEN),
+ // builder.notEqual(access.get(QueryAccess_.status),
+ // VirtualCorpusAccessStatus.DELETED));
+
+ Predicate type = builder
+ .equal(query.get(QueryDO_.queryType), queryType);
+
+ Predicate accessStatus =
+ builder.notEqual(access.get(QueryAccess_.status),
+ QueryAccessStatus.DELETED);
+
+ Predicate userGroupStatus =
+ builder.notEqual(access.get(QueryAccess_.userGroup)
+ .get(UserGroup_.status), UserGroupStatus.DELETED);
+ Join<UserGroup, UserGroupMember> members = access
+ .join(QueryAccess_.userGroup).join(UserGroup_.members);
+
+ Predicate memberStatus = builder.equal(
+ members.get(UserGroupMember_.status), GroupMemberStatus.ACTIVE);
+
+ Predicate user =
+ builder.equal(members.get(UserGroupMember_.userId), userId);
+
+ cq.select(query);
+ cq.where(
+ builder.and(type, accessStatus, userGroupStatus, memberStatus, user));
+
+ Query q = entityManager.createQuery(cq);
+ return q.getResultList();
+ }
+
+ public List<QueryDO> retrieveQueryByUser (String userId,
+ QueryType queryType) throws KustvaktException {
+ ParameterChecker.checkStringValue(userId, "userId");
+ ParameterChecker.checkObjectValue(queryType, "queryType");
+
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> criteriaQuery =
+ builder.createQuery(QueryDO.class);
+
+ Root<QueryDO> query = criteriaQuery.from(QueryDO.class);
+ Predicate predicate = builder.and(
+ builder.equal(query.get(QueryDO_.queryType),
+ queryType),
+ builder.or(builder.equal(
+ query.get(QueryDO_.createdBy), userId),
+ builder.equal(query.get(QueryDO_.type),
+ ResourceType.SYSTEM)));
+
+ criteriaQuery.select(query);
+ criteriaQuery.where(predicate);
+ criteriaQuery.distinct(true);
+ Query q = entityManager.createQuery(criteriaQuery);
+
+ @SuppressWarnings("unchecked")
+ List<QueryDO> queryList = q.getResultList();
+ List<QueryDO> groupQuery = retrieveGroupQueryByUser(userId, queryType);
+ Set<QueryDO> querySet = new HashSet<QueryDO>();
+ querySet.addAll(queryList);
+ querySet.addAll(groupQuery);
+
+ List<QueryDO> merger = new ArrayList<QueryDO>(querySet.size());
+ merger.addAll(querySet);
+ Collections.sort(merger);
+ return merger;
+ }
+
+ // for admins
+ @SuppressWarnings("unchecked")
+ public List<QueryDO> retrieveQueryByGroup (int groupId)
+ throws KustvaktException {
+ ParameterChecker.checkIntegerValue(groupId, "groupId");
+
+ CriteriaBuilder builder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<QueryDO> criteriaQuery =
+ builder.createQuery(QueryDO.class);
+
+ Root<QueryDO> query = criteriaQuery.from(QueryDO.class);
+ Join<QueryDO, QueryAccess> queryAccess =
+ query.join(QueryDO_.queryAccess);
+ Join<QueryAccess, UserGroup> accessGroup =
+ queryAccess.join(QueryAccess_.userGroup);
+
+ criteriaQuery.select(query);
+ criteriaQuery.where(builder.equal(accessGroup.get(UserGroup_.id), groupId));
+ Query q = entityManager.createQuery(criteriaQuery);
+ return q.getResultList();
+ }
+
+}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/QueryReferenceDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/QueryReferenceDao.java
deleted file mode 100644
index 0cb4ae7..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/dao/QueryReferenceDao.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package de.ids_mannheim.korap.dao;
-
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.NonUniqueResultException;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Join;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-
-import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.utils.ParameterChecker;
-
-import de.ids_mannheim.korap.entity.QueryReference;
-import de.ids_mannheim.korap.entity.QueryReference_;
-
-/**
- * QueryReferenceDao manages database queries and transactions
- * regarding query fragments, e.g. retrieving and storing queries
- * for embedding in more complex queries.
- *
- * Based on VirtualCorpusDao.
- *
- * @author diewald
- *
- */
-
-@Transactional
-@Repository
-public class QueryReferenceDao {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- /**
- * Create query reference and return ID.
- * Does not support any access management yet
- */
- public int createQuery(
- String qName,
- ResourceType type,
- // CorpusAccess requiredAccess,
- String koralQuery,
- String definition,
- String description,
- String status,
- String createdBy
- ) throws KustvaktException {
-
- QueryReference q = new QueryReference();
- q.setName(qName);
- q.setType(type);
- q.setKoralQuery(koralQuery);
- q.setDefinition(definition);
- q.setDescription(description);
- q.setStatus(status);
- q.setCreatedBy(createdBy);
-
- // Maybe unused
- q.setRequiredAccess("");
-
- entityManager.persist(q);
- return q.getId();
- };
-
-
- /**
- * Retrieve a single query reference based on its name.
- */
- public QueryReference retrieveQueryByName (String qName, String createdBy)
- throws KustvaktException {
- ParameterChecker.checkStringValue(createdBy, "createdBy");
- ParameterChecker.checkStringValue(qName, "q");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<QueryReference> query =
- builder.createQuery(QueryReference.class);
-
- Root<QueryReference> qref = query.from(QueryReference.class);
-
- Predicate condition = builder.and(
- builder.equal(qref.get(QueryReference_.createdBy),
- createdBy),
- builder.equal(qref.get(QueryReference_.name), qName));
-
- query.select(qref);
- query.where(condition);
-
- Query q = entityManager.createQuery(query);
- QueryReference qr = null;
- try {
- qr = (QueryReference) q.getSingleResult();
- }
- catch (NoResultException e) {
- return null;
- }
- catch (NonUniqueResultException e) {
- String refCode = createdBy + "/" + qName;
- throw new KustvaktException(StatusCodes.NON_UNIQUE_RESULT_FOUND,
- "Non unique result found for query: retrieve virtual corpus by name "
- + refCode,
- String.valueOf(refCode), e);
- }
- return qr;
- };
-
- /**
- * Remove a query reference from the database.
- */
- public void deleteQueryReference (QueryReference q)
- throws KustvaktException {
- if (!entityManager.contains(q)) {
- q = entityManager.merge(q);
- }
- entityManager.remove(q);
- }
-};
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
index 7564121..6527d37 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
@@ -22,16 +22,16 @@
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
import de.ids_mannheim.korap.constant.UserGroupStatus;
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
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_;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess_;
-import de.ids_mannheim.korap.entity.VirtualCorpus_;
+import de.ids_mannheim.korap.entity.QueryDO;
+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.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.ParameterChecker;
@@ -72,7 +72,7 @@
roles.add(roleDao
.retrieveRoleById(PredefinedRole.USER_GROUP_ADMIN.getId()));
roles.add(roleDao
- .retrieveRoleById(PredefinedRole.VC_ACCESS_ADMIN.getId()));
+ .retrieveRoleById(PredefinedRole.QUERY_ACCESS_ADMIN.getId()));
UserGroupMember owner = new UserGroupMember();
owner.setUserId(createdBy);
@@ -233,37 +233,37 @@
}
}
- public UserGroup retrieveHiddenGroupByVC (int vcId)
+ public UserGroup retrieveHiddenGroupByQuery (int queryId)
throws KustvaktException {
- ParameterChecker.checkIntegerValue(vcId, "vcId");
+ ParameterChecker.checkIntegerValue(queryId, "queryId");
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
- CriteriaQuery<UserGroup> query =
+ CriteriaQuery<UserGroup> criteriaQuery =
criteriaBuilder.createQuery(UserGroup.class);
- Root<UserGroup> root = query.from(UserGroup.class);
- Join<UserGroup, VirtualCorpusAccess> access =
- root.join(UserGroup_.virtualCorpusAccess);
- Join<VirtualCorpusAccess, VirtualCorpus> vc =
- access.join(VirtualCorpusAccess_.virtualCorpus);
+ Root<UserGroup> root = criteriaQuery.from(UserGroup.class);
+ Join<UserGroup, QueryAccess> access =
+ root.join(UserGroup_.queryAccess);
+ Join<QueryAccess, QueryDO> query =
+ access.join(QueryAccess_.query);
Predicate p = criteriaBuilder.and(
criteriaBuilder.equal(root.get(UserGroup_.status),
UserGroupStatus.HIDDEN),
- criteriaBuilder.equal(vc.get(VirtualCorpus_.id), vcId));
+ criteriaBuilder.equal(query.get(QueryDO_.id), queryId));
- query.select(root);
- query.where(p);
- Query q = entityManager.createQuery(query);
+ criteriaQuery.select(root);
+ criteriaQuery.where(p);
+ Query q = entityManager.createQuery(criteriaQuery);
try {
return (UserGroup) q.getSingleResult();
}
catch (NoResultException e) {
throw new KustvaktException(StatusCodes.NO_RESULT_FOUND,
- "No hidden group for virtual corpus with id " + vcId
+ "No hidden group for query with id " + queryId
+ " is found",
- String.valueOf(vcId), e);
+ String.valueOf(queryId), e);
}
}
@@ -325,51 +325,51 @@
}
- public void addVCToGroup (VirtualCorpus virtualCorpus, String createdBy,
- VirtualCorpusAccessStatus status, UserGroup group) {
- VirtualCorpusAccess accessGroup = new VirtualCorpusAccess();
+ public void addQueryToGroup (QueryDO query, String createdBy,
+ QueryAccessStatus status, UserGroup group) {
+ QueryAccess accessGroup = new QueryAccess();
accessGroup.setCreatedBy(createdBy);
accessGroup.setStatus(status);
accessGroup.setUserGroup(group);
- accessGroup.setVirtualCorpus(virtualCorpus);
+ accessGroup.setQuery(query);;
entityManager.persist(accessGroup);
}
- public void addVCToGroup (List<VirtualCorpus> virtualCorpora,
+ public void addQueryToGroup (List<QueryDO> queries,
String createdBy, UserGroup group,
- VirtualCorpusAccessStatus status) {
+ QueryAccessStatus status) {
- for (VirtualCorpus vc : virtualCorpora) {
- addVCToGroup(vc, createdBy, status, group);
+ for (QueryDO q : queries) {
+ addQueryToGroup(q, createdBy, status, group);
}
}
- public void deleteVCFromGroup (int virtualCorpusId, int groupId)
+ public void deleteQueryFromGroup (int queryId, int groupId)
throws KustvaktException {
- ParameterChecker.checkIntegerValue(virtualCorpusId, "virtualCorpusId");
+ ParameterChecker.checkIntegerValue(queryId, "queryId");
ParameterChecker.checkIntegerValue(groupId, "groupId");
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- criteriaBuilder.createQuery(VirtualCorpusAccess.class);
+ CriteriaQuery<QueryAccess> criteriaQuery =
+ criteriaBuilder.createQuery(QueryAccess.class);
- Root<VirtualCorpusAccess> root = query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, VirtualCorpus> vc =
- root.join(VirtualCorpusAccess_.virtualCorpus);
- Join<VirtualCorpusAccess, UserGroup> group =
- root.join(VirtualCorpusAccess_.userGroup);
+ Root<QueryAccess> root = criteriaQuery.from(QueryAccess.class);
+ Join<QueryAccess, QueryDO> queryAccess =
+ root.join(QueryAccess_.query);
+ Join<QueryAccess, UserGroup> group =
+ root.join(QueryAccess_.userGroup);
- Predicate virtualCorpus = criteriaBuilder
- .equal(vc.get(VirtualCorpus_.id), virtualCorpusId);
+ Predicate query = criteriaBuilder
+ .equal(queryAccess.get(QueryDO_.id), queryId);
Predicate userGroup =
criteriaBuilder.equal(group.get(UserGroup_.id), groupId);
- query.select(root);
- query.where(criteriaBuilder.and(virtualCorpus, userGroup));
- Query q = entityManager.createQuery(query);
- VirtualCorpusAccess vcAccess =
- (VirtualCorpusAccess) q.getSingleResult();
- entityManager.remove(vcAccess);
+ criteriaQuery.select(root);
+ criteriaQuery.where(criteriaBuilder.and(query, userGroup));
+ Query q = entityManager.createQuery(criteriaQuery);
+ QueryAccess access =
+ (QueryAccess) q.getSingleResult();
+ entityManager.remove(access);
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java
deleted file mode 100644
index 3b372ab..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java
+++ /dev/null
@@ -1,266 +0,0 @@
-package de.ids_mannheim.korap.dao;
-
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Join;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
-import de.ids_mannheim.korap.entity.UserGroup;
-import de.ids_mannheim.korap.entity.UserGroup_;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess_;
-import de.ids_mannheim.korap.entity.VirtualCorpus_;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.oauth2.constant.OAuth2Error;
-import de.ids_mannheim.korap.utils.ParameterChecker;
-
-/**
- * Manages database queries and transactions regarding
- * {@link VirtualCorpusAccess} entity and its corresponding database
- * table.
- *
- * @author margaretha
- *
- * @see VirtualCorpusAccess
- * @see VirtualCorpus
- */
-@Transactional
-@Repository
-public class VirtualCorpusAccessDao {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- public VirtualCorpusAccess retrieveAccessById (int accessId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(accessId, "accessId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- query.select(access);
- query.where(
- builder.equal(access.get(VirtualCorpusAccess_.id), accessId));
- Query q = entityManager.createQuery(query);
- try{
- return (VirtualCorpusAccess) q.getSingleResult();
- }
- catch (NoResultException e) {
- throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
- "Virtual corpus access is not found",
- String.valueOf(accessId));
- }
- }
-
- // for vca admins
- public List<VirtualCorpusAccess> retrieveActiveAccessByVC (int vcId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(vcId, "vcId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, VirtualCorpus> accessVC =
- access.join(VirtualCorpusAccess_.virtualCorpus);
-
- Predicate p = builder.and(
- builder.equal(accessVC.get(VirtualCorpus_.id), vcId),
- builder.equal(access.get(VirtualCorpusAccess_.status),
- VirtualCorpusAccessStatus.ACTIVE));
- query.select(access);
- query.where(p);
- TypedQuery<VirtualCorpusAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<VirtualCorpusAccess> retrieveActiveAccessByVC (String vcCreator,
- String vcName) throws KustvaktException {
- ParameterChecker.checkStringValue(vcCreator, "vcCreator");
- ParameterChecker.checkStringValue(vcCreator, "vcName");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, VirtualCorpus> accessVC =
- access.join(VirtualCorpusAccess_.virtualCorpus);
-
- Predicate p = builder.and(
- builder.equal(accessVC.get(VirtualCorpus_.name), vcName),
- builder.equal(accessVC.get(VirtualCorpus_.createdBy), vcCreator),
- builder.equal(access.get(VirtualCorpusAccess_.status),
- VirtualCorpusAccessStatus.ACTIVE));
- query.select(access);
- query.where(p);
- TypedQuery<VirtualCorpusAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<VirtualCorpusAccess> retrieveAllAccess ()
- throws KustvaktException {
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- query.select(access);
- TypedQuery<VirtualCorpusAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<VirtualCorpusAccess> retrieveAllAccessByVC (String vcCreator,
- String vcName) throws KustvaktException {
- ParameterChecker.checkStringValue(vcCreator, "vcCreator");
- ParameterChecker.checkStringValue(vcCreator, "vcName");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, VirtualCorpus> accessVC =
- access.join(VirtualCorpusAccess_.virtualCorpus);
-
- Predicate conditions = builder.and(
- builder.equal(accessVC.get(VirtualCorpus_.createdBy),
- vcCreator),
- builder.equal(accessVC.get(VirtualCorpus_.name), vcName));
- query.select(access);
- query.where(conditions);
- TypedQuery<VirtualCorpusAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<VirtualCorpusAccess> retrieveAllAccessByGroup (int groupId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(groupId, "groupId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, UserGroup> accessVC =
- access.join(VirtualCorpusAccess_.userGroup);
-
- query.select(access);
- query.where(builder.equal(accessVC.get(UserGroup_.id), groupId));
- TypedQuery<VirtualCorpusAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<VirtualCorpusAccess> retrieveActiveAccessByGroup (int groupId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(groupId, "groupId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, UserGroup> accessVC =
- access.join(VirtualCorpusAccess_.userGroup);
-
- Predicate p =
- builder.and(builder.equal(accessVC.get(UserGroup_.id), groupId),
- builder.equal(access.get(VirtualCorpusAccess_.status),
- VirtualCorpusAccessStatus.ACTIVE));
-
- query.select(access);
- query.where(p);
- TypedQuery<VirtualCorpusAccess> q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- /**
- * Hidden accesses are only created for published or system VC.
- *
- * Warn: The actual hidden accesses are not checked.
- *
- * @param vcId
- * vcId
- * @return true if there is a hidden access, false otherwise
- * @throws KustvaktException
- */
- public VirtualCorpusAccess retrieveHiddenAccess (int vcId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(vcId, "vcId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpusAccess> query =
- builder.createQuery(VirtualCorpusAccess.class);
-
- Root<VirtualCorpusAccess> access =
- query.from(VirtualCorpusAccess.class);
- Join<VirtualCorpusAccess, VirtualCorpus> accessVC =
- access.join(VirtualCorpusAccess_.virtualCorpus);
-
- Predicate p = builder.and(
- builder.equal(accessVC.get(VirtualCorpus_.id), vcId),
- builder.equal(access.get(VirtualCorpusAccess_.status),
- VirtualCorpusAccessStatus.HIDDEN)
- // ,
- // builder.notEqual(access.get(VirtualCorpusAccess_.deletedBy),
- // "NULL")
- );
-
- query.select(access);
- query.where(p);
-
- try {
- Query q = entityManager.createQuery(query);
- return (VirtualCorpusAccess) q.getSingleResult();
- }
- catch (NoResultException e) {
- return null;
- }
- }
-
- public void createAccessToVC (VirtualCorpus virtualCorpus,
- UserGroup userGroup, String createdBy,
- VirtualCorpusAccessStatus status) {
- VirtualCorpusAccess vca = new VirtualCorpusAccess();
- vca.setVirtualCorpus(virtualCorpus);
- vca.setUserGroup(userGroup);
- vca.setCreatedBy(createdBy);
- vca.setStatus(status);
- entityManager.persist(vca);
- }
-
- public void deleteAccess (VirtualCorpusAccess access, String deletedBy) {
- // soft delete
-
- // hard delete
- if (!entityManager.contains(access)) {
- access = entityManager.merge(access);
- }
- entityManager.remove(access);
- }
-
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
deleted file mode 100644
index e4f02fa..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
+++ /dev/null
@@ -1,382 +0,0 @@
-package de.ids_mannheim.korap.dao;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.NonUniqueResultException;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Join;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-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.constant.UserGroupStatus;
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
-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_;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess_;
-import de.ids_mannheim.korap.entity.VirtualCorpus_;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.user.User.CorpusAccess;
-import de.ids_mannheim.korap.utils.ParameterChecker;
-
-/**
- * VirtualCorpusDao manages database queries and transactions
- * regarding virtual corpora, e.g. retrieving and storing virtual
- * corpora.
- *
- * @author margaretha
- *
- */
-@Transactional
-@Repository
-public class VirtualCorpusDao {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- public int createVirtualCorpus (String name, ResourceType type,
- QueryType queryType, CorpusAccess requiredAccess, String koralQuery,
- String definition, String description, String status,
- boolean isCached, String createdBy, String query,
- String queryLanguage) throws KustvaktException {
-
- VirtualCorpus vc = new VirtualCorpus();
- vc.setName(name);
- vc.setType(type);
- vc.setQueryType(queryType);
- vc.setRequiredAccess(requiredAccess);
- vc.setKoralQuery(koralQuery);
- vc.setDefinition(definition);
- vc.setDescription(description);
- vc.setStatus(status);
- vc.setCreatedBy(createdBy);
- vc.setCached(isCached);
- vc.setQuery(query);
- vc.setQueryLanguage(queryLanguage);
-
- entityManager.persist(vc);
- return vc.getId();
- }
-
- public void editVirtualCorpus (VirtualCorpus vc, String name,
- ResourceType type, CorpusAccess requiredAccess, String koralQuery,
- String definition, String description, String status,
- boolean isCached) throws KustvaktException {
-
- if (name != null && !name.isEmpty()) {
- vc.setName(name);
- }
- if (type != null) {
- vc.setType(type);
- }
- if (requiredAccess != null) {
- vc.setRequiredAccess(requiredAccess);
- }
- if (koralQuery != null) {
- vc.setKoralQuery(koralQuery);
- }
- if (definition != null && !definition.isEmpty()) {
- vc.setDefinition(definition);
- }
- if (description != null && !description.isEmpty()) {
- vc.setDescription(description);
- }
- if (status != null && !status.isEmpty()) {
- vc.setStatus(status);
- }
- vc.setCached(isCached);
- entityManager.merge(vc);
- }
-
- public void deleteVirtualCorpus (VirtualCorpus vc)
- throws KustvaktException {
- if (!entityManager.contains(vc)) {
- vc = entityManager.merge(vc);
- }
- entityManager.remove(vc);
-
- }
-
- /**
- * System admin function.
- *
- * Retrieves virtual corpus by creator and type. If type is not
- * specified,
- * retrieves virtual corpora of all types. If createdBy is not
- * specified,
- * retrieves virtual corpora of all users.
- *
- * @param type
- * {@link ResourceType}
- * @param createdBy
- * username of the virtual corpus creator
- * @return a list of {@link VirtualCorpus}
- * @throws KustvaktException
- */
- @SuppressWarnings("unchecked")
- public List<VirtualCorpus> retrieveVCByType (ResourceType type,
- String createdBy, QueryType queryType) throws KustvaktException {
-
- CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- criteriaBuilder.createQuery(VirtualCorpus.class);
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
-
- Predicate conditions = criteriaBuilder
- .equal(virtualCorpus.get(VirtualCorpus_.queryType), queryType);
- if (createdBy != null && !createdBy.isEmpty()) {
- conditions = criteriaBuilder.and(conditions, criteriaBuilder.equal(
- virtualCorpus.get(VirtualCorpus_.createdBy), createdBy));
- if (type != null) {
- conditions = criteriaBuilder.and(conditions, criteriaBuilder
- .equal(virtualCorpus.get(VirtualCorpus_.type), type));
- }
- }
- else if (type != null) {
- conditions = criteriaBuilder.and(conditions, criteriaBuilder
- .equal(virtualCorpus.get(VirtualCorpus_.type), type));
- }
-
- query.select(virtualCorpus);
- query.where(conditions);
- Query q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public VirtualCorpus retrieveVCById (int id) throws KustvaktException {
- ParameterChecker.checkIntegerValue(id, "id");
-
- CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- criteriaBuilder.createQuery(VirtualCorpus.class);
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- query.select(virtualCorpus);
- query.where(criteriaBuilder.equal(virtualCorpus.get(VirtualCorpus_.id),
- id));
-
- VirtualCorpus vc = null;
- try {
- Query q = entityManager.createQuery(query);
- vc = (VirtualCorpus) q.getSingleResult();
- }
- catch (NoResultException e) {
- throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
- "Virtual corpus with id: " + id + " is not found",
- String.valueOf(id), e);
- }
- return vc;
- }
-
- public VirtualCorpus retrieveVCByName (String vcName, String createdBy)
- throws KustvaktException {
- ParameterChecker.checkStringValue(createdBy, "createdBy");
- ParameterChecker.checkStringValue(vcName, "vcName");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- builder.createQuery(VirtualCorpus.class);
-
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
-
- Predicate condition = builder.and(
- builder.equal(virtualCorpus.get(VirtualCorpus_.createdBy),
- createdBy),
- builder.equal(virtualCorpus.get(VirtualCorpus_.name), vcName));
-
- query.select(virtualCorpus);
- query.where(condition);
-
- Query q = entityManager.createQuery(query);
- VirtualCorpus vc = null;
- try {
- vc = (VirtualCorpus) q.getSingleResult();
- }
- catch (NoResultException e) {
- return null;
- // String vcCode = createdBy + "/" + vcName;
- // throw new
- // KustvaktException(StatusCodes.NO_RESULT_FOUND,
- // "No result found for query: retrieve virtual corpus by
- // name "
- // + vcCode,
- // String.valueOf(vcCode), e);
- }
- catch (NonUniqueResultException e) {
- String vcCode = createdBy + "/" + vcName;
- throw new KustvaktException(StatusCodes.NON_UNIQUE_RESULT_FOUND,
- "Non unique result found for query: retrieve virtual corpus by name "
- + vcCode,
- String.valueOf(vcCode), e);
- }
- return vc;
- }
-
- @SuppressWarnings("unchecked")
- public List<VirtualCorpus> retrieveOwnerVC (String userId,
- QueryType queryType) throws KustvaktException {
- ParameterChecker.checkStringValue(userId, "userId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- builder.createQuery(VirtualCorpus.class);
-
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- Predicate conditions = builder.and(
- builder.equal(virtualCorpus.get(VirtualCorpus_.createdBy),
- userId),
- builder.equal(virtualCorpus.get(VirtualCorpus_.queryType),
- queryType));
-
- query.select(virtualCorpus);
- query.where(conditions);
-
- Query q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- @SuppressWarnings("unchecked")
- public List<VirtualCorpus> retrieveOwnerVCByType (String userId,
- ResourceType type) throws KustvaktException {
- ParameterChecker.checkStringValue(userId, "userId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- builder.createQuery(VirtualCorpus.class);
-
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- query.select(virtualCorpus);
-
- Predicate p = builder.and(
- builder.equal(virtualCorpus.get(VirtualCorpus_.createdBy),
- userId),
- builder.equal(virtualCorpus.get(VirtualCorpus_.type), type));
- query.where(p);
-
- Query q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- @SuppressWarnings("unchecked")
- public List<VirtualCorpus> retrieveGroupVCByUser (String userId, QueryType queryType)
- throws KustvaktException {
- ParameterChecker.checkStringValue(userId, "userId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- builder.createQuery(VirtualCorpus.class);
-
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- Join<VirtualCorpus, VirtualCorpusAccess> access =
- virtualCorpus.join(VirtualCorpus_.virtualCorpusAccess);
-
- // Predicate corpusStatus = builder.and(
- // builder.notEqual(access.get(VirtualCorpusAccess_.status),
- // VirtualCorpusAccessStatus.HIDDEN),
- // builder.notEqual(access.get(VirtualCorpusAccess_.status),
- // VirtualCorpusAccessStatus.DELETED));
-
- Predicate type = builder
- .equal(virtualCorpus.get(VirtualCorpus_.queryType), queryType);
-
- Predicate corpusStatus =
- builder.notEqual(access.get(VirtualCorpusAccess_.status),
- VirtualCorpusAccessStatus.DELETED);
-
- Predicate userGroupStatus =
- builder.notEqual(access.get(VirtualCorpusAccess_.userGroup)
- .get(UserGroup_.status), UserGroupStatus.DELETED);
- Join<UserGroup, UserGroupMember> members = access
- .join(VirtualCorpusAccess_.userGroup).join(UserGroup_.members);
-
- Predicate memberStatus = builder.equal(
- members.get(UserGroupMember_.status), GroupMemberStatus.ACTIVE);
-
- Predicate user =
- builder.equal(members.get(UserGroupMember_.userId), userId);
-
- query.select(virtualCorpus);
- query.where(
- builder.and(type, corpusStatus, userGroupStatus, memberStatus, user));
-
- Query q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
- public List<VirtualCorpus> retrieveVCByUser (String userId,
- QueryType queryType) throws KustvaktException {
- ParameterChecker.checkStringValue(userId, "userId");
- ParameterChecker.checkObjectValue(queryType, "queryType");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- builder.createQuery(VirtualCorpus.class);
-
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- Predicate predicate = builder.and(
- builder.equal(virtualCorpus.get(VirtualCorpus_.queryType),
- queryType),
- builder.or(builder.equal(
- virtualCorpus.get(VirtualCorpus_.createdBy), userId),
- builder.equal(virtualCorpus.get(VirtualCorpus_.type),
- ResourceType.SYSTEM)));
-
- query.select(virtualCorpus);
- query.where(predicate);
- query.distinct(true);
- Query q = entityManager.createQuery(query);
-
- @SuppressWarnings("unchecked")
- List<VirtualCorpus> vcList = q.getResultList();
- List<VirtualCorpus> groupVC = retrieveGroupVCByUser(userId, queryType);
- Set<VirtualCorpus> vcSet = new HashSet<VirtualCorpus>();
- vcSet.addAll(vcList);
- vcSet.addAll(groupVC);
-
- List<VirtualCorpus> merger = new ArrayList<VirtualCorpus>(vcSet.size());
- merger.addAll(vcSet);
- Collections.sort(merger);
- return merger;
- }
-
- // for admins
- @SuppressWarnings("unchecked")
- public List<VirtualCorpus> retrieveVCByGroup (int groupId)
- throws KustvaktException {
- ParameterChecker.checkIntegerValue(groupId, "groupId");
-
- CriteriaBuilder builder = entityManager.getCriteriaBuilder();
- CriteriaQuery<VirtualCorpus> query =
- builder.createQuery(VirtualCorpus.class);
-
- Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- Join<VirtualCorpus, VirtualCorpusAccess> corpusAccess =
- virtualCorpus.join(VirtualCorpus_.virtualCorpusAccess);
- Join<VirtualCorpusAccess, UserGroup> accessGroup =
- corpusAccess.join(VirtualCorpusAccess_.userGroup);
-
- query.select(virtualCorpus);
- query.where(builder.equal(accessGroup.get(UserGroup_.id), groupId));
- Query q = entityManager.createQuery(query);
- return q.getResultList();
- }
-
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/QueryAccessDto.java
similarity index 64%
rename from full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java
rename to full/src/main/java/de/ids_mannheim/korap/dto/QueryAccessDto.java
index d79b7d3..9687317 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/QueryAccessDto.java
@@ -4,7 +4,7 @@
import lombok.Setter;
/**
- * Defines the structure of virtual corpus accesses, e.g. as JSON
+ * Defines the structure of query accesses, e.g. as JSON
* objects in HTTP Responses.
*
* @author margaretha
@@ -12,18 +12,18 @@
*/
@Getter
@Setter
-public class VirtualCorpusAccessDto {
+public class QueryAccessDto {
private int accessId;
private String createdBy;
- private int vcId;
- private String vcName;
+ private int queryId;
+ private String queryName;
private int userGroupId;
private String userGroupName;
@Override
public String toString () {
- return "accessId=" + accessId + ", createdBy=" + createdBy + " , vcId="
- + vcId + ", vcName=" + vcName + ", userGroupId=" + userGroupId
+ return "accessId=" + accessId + ", createdBy=" + createdBy + " , queryId="
+ + queryId + ", queryName=" + queryName + ", userGroupId=" + userGroupId
+ ", userGroupName=" + userGroupName;
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/QueryDto.java
similarity index 83%
rename from full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
rename to full/src/main/java/de/ids_mannheim/korap/dto/QueryDto.java
index f6863c4..fe221cf 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/QueryDto.java
@@ -4,11 +4,11 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.JsonNode;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import lombok.Getter;
import lombok.Setter;
-/** Defines the structure of {@link VirtualCorpus} description to be
+/** Defines the structure of {@link QueryDO} description to be
* sent as JSON objects in HTTP responses.
*
* @author margaretha
@@ -17,7 +17,7 @@
@Getter
@Setter
@JsonInclude(Include.NON_DEFAULT)
-public class VirtualCorpusDto {
+public class QueryDto {
private int id;
private String name;
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java
new file mode 100644
index 0000000..5dfad63
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/converter/QueryAccessConverter.java
@@ -0,0 +1,42 @@
+package de.ids_mannheim.korap.dto.converter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.stereotype.Component;
+
+import de.ids_mannheim.korap.dto.QueryAccessDto;
+import de.ids_mannheim.korap.entity.QueryAccess;
+
+/**
+ * QueryAccessConverter prepares data transfer objects (DTOs)
+ * from {@link QueryAccess} entities. DTO structure defines
+ * controllers output, namely the structure of JSON objects in HTTP
+ * responses.
+ *
+ * @author margaretha
+ *
+ */
+@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;
+ }
+
+}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/QueryConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/QueryConverter.java
new file mode 100644
index 0000000..4d9052e
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/converter/QueryConverter.java
@@ -0,0 +1,51 @@
+package de.ids_mannheim.korap.dto.converter;
+
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import de.ids_mannheim.korap.dto.QueryDto;
+import de.ids_mannheim.korap.entity.QueryDO;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+/**
+ * QueryConverter prepares data transfer objects (DTOs) from
+ * {@link QueryDO} entities. DTO structure defines controllers
+ * output, namely the structure of JSON objects in HTTP responses.
+ *
+ * @author margaretha
+ *
+ */
+@Component
+public class QueryConverter {
+
+ public QueryDto createQueryDto (QueryDO query,
+ String statistics) throws KustvaktException {
+
+ QueryDto dto = new QueryDto();
+ dto.setId(query.getId());
+ dto.setName(query.getName());
+ dto.setCreatedBy(query.getCreatedBy());
+ dto.setRequiredAccess(query.getRequiredAccess().name());
+ dto.setStatus(query.getStatus());
+ dto.setDescription(query.getDescription());
+ dto.setType(query.getType().displayName());
+
+ dto.setQuery(query.getQuery());
+ dto.setQueryLanguage(query.getQueryLanguage());
+
+ JsonNode kq = JsonUtils.readTree(query.getKoralQuery());
+ dto.setKoralQuery(kq);
+
+ if (statistics != null) {
+ JsonNode node = JsonUtils.readTree(statistics);
+ dto.setNumberOfDoc(node.at("/documents").asInt());
+ dto.setNumberOfParagraphs(node.at("/paragraphs").asInt());
+ dto.setNumberOfSentences(node.at("/sentences").asInt());
+ dto.setNumberOfTokens(node.at("/tokens").asInt());
+ }
+ return dto;
+
+ }
+}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusAccessConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusAccessConverter.java
deleted file mode 100644
index 74ebeec..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusAccessConverter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package de.ids_mannheim.korap.dto.converter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.stereotype.Component;
-
-import de.ids_mannheim.korap.dto.VirtualCorpusAccessDto;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
-
-/**
- * VirtualCorpusAccessConverter prepares data transfer objects (DTOs)
- * from {@link VirtualCorpusAccess} entities. DTO structure defines
- * controllers output, namely the structure of JSON objects in HTTP
- * responses.
- *
- * @author margaretha
- *
- */
-@Component
-public class VirtualCorpusAccessConverter {
-
- public List<VirtualCorpusAccessDto> createVCADto (
- List<VirtualCorpusAccess> accessList) {
- List<VirtualCorpusAccessDto> dtos = new ArrayList<>(accessList.size());
- for (VirtualCorpusAccess access : accessList) {
- VirtualCorpusAccessDto dto = new VirtualCorpusAccessDto();
- dto.setAccessId(access.getId());
- dto.setCreatedBy(access.getCreatedBy());
-
- dto.setVcId(access.getVirtualCorpus().getId());
- dto.setVcName(access.getVirtualCorpus().getName());
-
- dto.setUserGroupId(access.getUserGroup().getId());
- dto.setUserGroupName(access.getUserGroup().getName());
-
- dtos.add(dto);
- }
- return dtos;
- }
-
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
deleted file mode 100644
index 974c6b9..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package de.ids_mannheim.korap.dto.converter;
-
-import org.springframework.stereotype.Component;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-import de.ids_mannheim.korap.dto.VirtualCorpusDto;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.utils.JsonUtils;
-
-/**
- * VirtualCorpusConverter prepares data transfer objects (DTOs) from
- * {@link VirtualCorpus} entities. DTO structure defines controllers
- * output, namely the structure of JSON objects in HTTP responses.
- *
- * @author margaretha
- *
- */
-@Component
-public class VirtualCorpusConverter {
-
- public VirtualCorpusDto createVirtualCorpusDto (VirtualCorpus vc,
- String statistics) throws KustvaktException {
-
- VirtualCorpusDto dto = new VirtualCorpusDto();
- dto.setId(vc.getId());
- dto.setName(vc.getName());
- dto.setCreatedBy(vc.getCreatedBy());
- dto.setRequiredAccess(vc.getRequiredAccess().name());
- dto.setStatus(vc.getStatus());
- dto.setDescription(vc.getDescription());
- dto.setType(vc.getType().displayName());
-
- dto.setQuery(vc.getQuery());
- dto.setQueryLanguage(vc.getQueryLanguage());
-
- JsonNode kq = JsonUtils.readTree(vc.getKoralQuery());
- dto.setKoralQuery(kq);
-
- if (statistics != null) {
- JsonNode node = JsonUtils.readTree(statistics);
- dto.setNumberOfDoc(node.at("/documents").asInt());
- dto.setNumberOfParagraphs(node.at("/paragraphs").asInt());
- dto.setNumberOfSentences(node.at("/sentences").asInt());
- dto.setNumberOfTokens(node.at("/tokens").asInt());
- }
- return dto;
-
- }
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java b/full/src/main/java/de/ids_mannheim/korap/entity/QueryAccess.java
similarity index 77%
rename from full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java
rename to full/src/main/java/de/ids_mannheim/korap/entity/QueryAccess.java
index ba80f59..a7b518a 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/QueryAccess.java
@@ -12,7 +12,7 @@
import javax.persistence.ManyToOne;
import javax.persistence.Table;
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
import lombok.Getter;
import lombok.Setter;
@@ -21,14 +21,14 @@
* of group-access management.
*
* @author margaretha
- * @see VirtualCorpus
+ * @see QueryDO
* @see UserGroup
*/
@Setter
@Getter
@Entity
-@Table(name = "virtual_corpus_access")
-public class VirtualCorpusAccess {
+@Table(name = "query_access")
+public class QueryAccess {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -41,11 +41,11 @@
private String deletedBy;
@Enumerated(EnumType.STRING)
- private VirtualCorpusAccessStatus status;
+ private QueryAccessStatus status;
@ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "virtual_corpus_id", referencedColumnName = "id")
- private VirtualCorpus virtualCorpus;
+ @JoinColumn(name = "query_id", referencedColumnName = "id")
+ private QueryDO query;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_group_id", referencedColumnName = "id")
@@ -54,7 +54,7 @@
@Override
public String toString () {
- return "id=" + id + ", virtualCorpus= " + virtualCorpus
+ return "id=" + id + ", query= " + query
+ ", userGroup= " + userGroup;
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java b/full/src/main/java/de/ids_mannheim/korap/entity/QueryDO.java
similarity index 76%
rename from full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
rename to full/src/main/java/de/ids_mannheim/korap/entity/QueryDO.java
index 6cb08ea..4e95e22 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/QueryDO.java
@@ -21,23 +21,22 @@
import lombok.Setter;
/**
- * Describes the virtual corpora table and its relation to
- * VirtualCorpusAccess.
+ * Describes the query table and its relation to {@link QueryAccess}.
*
- * Any user may create a virtual corpus and share it to a user group.
- * However, if the user is not a user-group admin, the virtual corpus
+ * Any user may create a query and share it to a user group.
+ * However, if the user is not a user-group admin, the query
* will not be shared until a user-group admin accept his/her request.
*
* @author margaretha
*
- * @see VirtualCorpusAccess
+ * @see QueryAccess
* @see UserGroup
*/
@Setter
@Getter
@Entity
-@Table(name = "virtual_corpus")
-public class VirtualCorpus implements Comparable<VirtualCorpus> {
+@Table(name = "query")
+public class QueryDO implements Comparable<QueryDO> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -50,7 +49,7 @@
@Enumerated(EnumType.STRING)
@Column(name = "required_access")
private CorpusAccess requiredAccess;
- @Column(name = "corpus_query")
+ @Column(name = "koral_query")
private String koralQuery;
private String definition;
@Column(name = "created_by")
@@ -65,15 +64,15 @@
@Column(name = "query_language")
private String queryLanguage;
- @OneToMany(mappedBy = "virtualCorpus", fetch = FetchType.LAZY,
+ @OneToMany(mappedBy = "query", fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE)
- private List<VirtualCorpusAccess> virtualCorpusAccess;
+ private List<QueryAccess> queryAccess;
@Override
public String toString () {
return "id=" + id + ", name= " + name + ", type= " + type + ", status= "
+ status + ", description=" + description + ", requiredAccess="
- + requiredAccess + ", corpusQuery= " + koralQuery
+ + requiredAccess + ", koralQuery= " + koralQuery
+ ", definition= " + definition + ", createdBy= " + createdBy;
}
@@ -89,12 +88,12 @@
@Override
public boolean equals (Object obj) {
- VirtualCorpus vc = (VirtualCorpus) obj;
- return (this.id == vc.getId()) ? true : false;
+ QueryDO query = (QueryDO) obj;
+ return (this.id == query.getId()) ? true : false;
}
@Override
- public int compareTo (VirtualCorpus o) {
+ public int compareTo (QueryDO o) {
if (this.getId() > o.getId()) {
return 1;
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/QueryReference.java b/full/src/main/java/de/ids_mannheim/korap/entity/QueryReference.java
deleted file mode 100644
index 1a9c843..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/entity/QueryReference.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package de.ids_mannheim.korap.entity;
-
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-
-import de.ids_mannheim.korap.constant.ResourceType;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Describes the query reference table.
- *
- * It is yet not as complete as the Virtual Corpus implementation,
- * as it has no mechanism for sharing any query references.
- *
- * @author diewald
- *
- * @see VirtualCorpus
- */
-@Setter
-@Getter
-@Entity
-@Table(name = "query_reference")
-public class QueryReference implements Comparable<QueryReference> {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- private String name;
- @Enumerated(EnumType.STRING)
- private ResourceType type;
- private String status;
- private String description;
- // @Enumerated(EnumType.STRING)
- @Column(name = "required_access")
- private String requiredAccess;
- //private CorpusAccess requiredAccess;
- @Column(name = "query")
- private String koralQuery;
- private String definition;
- @Column(name = "created_by")
- private String createdBy;
-
- /*
- @OneToMany(mappedBy = "queryReference", fetch = FetchType.LAZY,
- cascade = CascadeType.REMOVE)
- private List<VirtualCorpusAccess> virtualCorpusAccess;
- */
-
- @Override
- public String toString () {
- return "id=" + id +
- ", name= " + name +
- ", type= " + type +
- ", status= " + status +
- ", description=" + description +
- // ", requiredAccess=" + requiredAccess +
- ", query= " + koralQuery +
- ", definition= " + definition +
- ", createdBy= " + createdBy;
- }
-
- @Override
- public int hashCode () {
- int prime = 37;
- int result = 1;
- result = prime * result + id;
- result = prime * result + name.hashCode();
- result = prime * result + createdBy.hashCode();
- return result;
- }
-
- @Override
- public boolean equals (Object obj) {
- QueryReference q = (QueryReference) obj;
- return (this.id == q.getId()) ? true : false;
- }
-
- @Override
- public int compareTo (QueryReference o) {
- if (this.getId() > o.getId()) {
- return 1;
- }
- else if (this.getId() < o.getId()) {
- return -1;
- }
- return 0;
- }
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/UserGroup.java b/full/src/main/java/de/ids_mannheim/korap/entity/UserGroup.java
index 0f2d7fd..3612ea9 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/UserGroup.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/UserGroup.java
@@ -20,7 +20,7 @@
/**
* Describes user group table and its relations to UserGroupMember and
- * VirtualCorpusAccess.
+ * {@link QueryAccess}.
*
* Any user may create a user group and send invitations to group
* member by username. Any group member may reject the invitation
@@ -28,7 +28,7 @@
*
* @author margaretha
* @see UserGroupMember
- * @see VirtualCorpusAccess
+ * @see QueryAccess
*/
@Setter
@Getter
@@ -56,7 +56,7 @@
@OneToMany(mappedBy = "userGroup", fetch = FetchType.LAZY,
cascade = CascadeType.REMOVE)
- private List<VirtualCorpusAccess> virtualCorpusAccess;
+ private List<QueryAccess> queryAccess;
@Override
public String toString () {
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java
index 4b7e755..f14bf56 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/QueryReferenceRewrite.java
@@ -8,11 +8,11 @@
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.constant.QueryType;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.rewrite.KoralNode.RewriteIdentifier;
-import de.ids_mannheim.korap.service.VirtualCorpusService;
+import de.ids_mannheim.korap.service.QueryService;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -29,7 +29,7 @@
public class QueryReferenceRewrite implements RewriteTask.RewriteQuery {
@Autowired
- private VirtualCorpusService service;
+ private QueryService service;
@Override
public KoralNode rewriteQuery (KoralNode node,
@@ -63,7 +63,7 @@
}
}
- VirtualCorpus qr = service.searchVCByName(username,
+ QueryDO qr = service.searchQueryByName(username,
queryRefName, queryRefOwner, QueryType.QUERY);
if (qr == null) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
index 297680e..7ea386f 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
@@ -8,10 +8,10 @@
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.constant.QueryType;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.rewrite.KoralNode.RewriteIdentifier;
-import de.ids_mannheim.korap.service.VirtualCorpusService;
+import de.ids_mannheim.korap.service.QueryService;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.util.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -29,7 +29,7 @@
@Autowired
private KustvaktConfiguration config;
@Autowired
- private VirtualCorpusService vcService;
+ private QueryService queryService;
@Override
public KoralNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
@@ -71,8 +71,8 @@
koralNode.get("ref"));
}
- VirtualCorpus vc =
- vcService.searchVCByName(username, vcName, vcOwner, QueryType.VIRTUAL_CORPUS);
+ QueryDO vc =
+ queryService.searchQueryByName(username, vcName, vcOwner, QueryType.VIRTUAL_CORPUS);
if (!vc.isCached()) {
rewriteVC(vc, koralNode);
}
@@ -105,7 +105,7 @@
koralNode.set("ref", ref, new RewriteIdentifier("ref", ref));
}
- private void rewriteVC (VirtualCorpus vc, KoralNode koralNode)
+ private void rewriteVC (QueryDO vc, KoralNode koralNode)
throws KustvaktException {
String koralQuery = vc.getKoralQuery();
JsonNode kq = JsonUtils.readTree(koralQuery).at("/collection");
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java b/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java
deleted file mode 100644
index c7e0f8b..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java
+++ /dev/null
@@ -1,301 +0,0 @@
-package de.ids_mannheim.korap.service;
-
-import java.sql.SQLException;
-
-import java.util.regex.Pattern;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.utils.ParameterChecker;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import de.ids_mannheim.korap.utils.JsonUtils;
-
-import de.ids_mannheim.korap.dao.AdminDao;
-import de.ids_mannheim.korap.dao.QueryReferenceDao;
-
-import de.ids_mannheim.korap.constant.ResourceType;
-
-import de.ids_mannheim.korap.entity.QueryReference;
-
-
-/**
- * This service is similar to VirtualCorpusService,
- * while not as complete.
- * For the moment, e.g., there is no mechanism supported to
- * share a query reference with other users or groups.
- * Only private queries are supported.
- *
- * @author diewald
- */
-@Deprecated
-@Service
-public class QueryReferenceService {
-
- public static Pattern qNamePattern = Pattern.compile("[-\\w.]+");
-
- @Autowired
- private AdminDao adminDao;
-
- @Autowired
- private QueryReferenceDao qDao;
-
-
- /**
- * Serch for a query by its name.
- */
- public JsonNode searchQueryByName (String username,
- String qName,
- String createdBy) throws KustvaktException {
-
- QueryReference qr = qDao.retrieveQueryByName(qName, createdBy);
- if (qr == null) {
- String refCode = createdBy + "/" + qName;
- throw new KustvaktException(
- StatusCodes.NO_RESOURCE_FOUND,
- "Query reference " + refCode + " is not found.",
- String.valueOf(refCode));
- }
-
- // TODO:
- // checkVCAcess(q, username);
- return JsonUtils.readTree(qr.getKoralQuery());
- };
-
-
- /**
- * Store a query in the database.
- */
- public void storeQuery (String qJson,
- String qName,
- String createdBy)
- throws KustvaktException {
-
- // TODO:
- // This doesn't support a whole bunch of applicable
- // information from VCs, like 'definition', 'description',
- // 'status' etc.
-
- storeQuery(
- qJson,
- qName,
- "",
- createdBy
- );
- }
-
-
- /**
- * Store a query in the database.
- */
- public void storeQuery (String qJson,
- String qName,
- String desc,
- String username)
- throws KustvaktException {
- ParameterChecker.checkStringValue(qJson, "q");
- ParameterChecker.checkNameValue(qName, "qName");
-
- if (!qNamePattern.matcher(qName).matches()) {
- throw new KustvaktException(
- StatusCodes.INVALID_ARGUMENT,
- "Query name must only contain letters, numbers, "
- + "underscores, hypens and spaces",
- qName);
- }
-
- if (username.equals("system") && !adminDao.isAdmin(username)) {
- throw new KustvaktException(
- StatusCodes.AUTHORIZATION_FAILED,
- "Unauthorized operation for user: " + username, username);
- };
-
- int qId = 0;
- try {
- qId = qDao.createQuery(
- qName,
- ResourceType.PRIVATE,
- qJson,
- "", // TODO: definition,
- desc,
- "", // TODO: status,
- username);
-
- }
- catch (Exception e) {
- Throwable cause = e;
- Throwable lastCause = null;
- while ((cause = cause.getCause()) != null
- && !cause.equals(lastCause)) {
- if (cause instanceof SQLException) {
- break;
- }
- lastCause = cause;
- }
- throw new KustvaktException(
- StatusCodes.DB_INSERT_FAILED,
- cause.getMessage()
- );
- };
-
- // TODO:
- // This doesn't publish the query, if it is meant to be published
- // based on its type.
- };
-
- /*
- public Status handlePutRequest (String username,
- String qCreator,
- String qName,
- String qJson) throws KustvaktException {
-
- verifyUsername(username, qCreator);
- String q = vcDao.retrieveQueryByName(qName, qCreator);
- // ParameterChecker.checkObjectValue(qJson, "request entity");
- ParameterChecker.checkStringValue(qJson, "q");
- if (q == null) {
- storeQuery(qJson, qName, username);
- return Status.CREATED;
- }
- else {
- editQuery(q, qJson, qName, username);
- return Status.NO_CONTENT;
- };
- };
- */
-
- /*
- public void editQuery (QueryRefrence existingQ,
- String newQJson,
- String qName,
- String username) throws KustvaktException {
-
- if (!username.equals(existingQ.getCreatedBy())
- && !adminDao.isAdmin(username)) {
- throw new KustvaktException(
- StatusCodes.AUTHORIZATION_FAILED,
- "Unauthorized operation for user: " + username, username);
- };
-
- String corpusQuery = newVC.getCorpusQuery();
-
- if (newQJson != null && !newQJson.isEmpty()) {
- koralQuery = serializeCorpusQuery(corpusQuery);
- requiredAccess = determineRequiredAccess(newVC.isCached(), vcName,
- koralQuery);
- };
-
- VirtualCorpusType type = newVC.getType();
- if (type != null) {
- if (existingVC.getType().equals(VirtualCorpusType.PUBLISHED)) {
- // withdraw from publication
- if (!type.equals(VirtualCorpusType.PUBLISHED)) {
- VirtualCorpusAccess hiddenAccess =
- accessDao.retrieveHiddenAccess(existingVC.getId());
- deleteVCAccess(hiddenAccess.getId(), "system");
- int groupId = hiddenAccess.getUserGroup().getId();
- userGroupService.deleteAutoHiddenGroup(groupId, "system");
- // EM: should the users within the hidden group receive
- // notifications?
- }
- // else remains the same
- }
- else if (type.equals(VirtualCorpusType.PUBLISHED)) {
- publishVC(existingVC.getId());
- }
- }
-
- vcDao.editVirtualCorpus(existingVC, vcName, type, requiredAccess,
- koralQuery, newVC.getDefinition(), newVC.getDescription(),
- newVC.getStatus(), newVC.isCached());
- }
- */
-
-
- /**
- * Only admin and the owner of the virtual corpus are allowed to
- * delete a virtual corpus.
- */
- public void deleteQueryByName (
- String username,
- String qName,
- String createdBy
- ) throws KustvaktException {
-
- QueryReference q = qDao.retrieveQueryByName(qName, createdBy);
-
- if (q == null) {
- String refCode = createdBy + "/" + qName;
- throw new KustvaktException(
- StatusCodes.NO_RESOURCE_FOUND,
- "Query reference " + refCode + " is not found.",
- String.valueOf(refCode));
- }
-
- // Check if the user created the qr or is admin
- else if (q.getCreatedBy().equals(username)
- || adminDao.isAdmin(username)) {
- // TODO:
- // Here checks for publication status is missing
- qDao.deleteQueryReference(q);
- }
-
- else {
- throw new KustvaktException(
- StatusCodes.AUTHORIZATION_FAILED,
- "Unauthorized operation for user: " + username, username);
- };
- };
-
-
- /*
- public void editVC (
- VirtualCorpus existingVC,
- VirtualCorpusJson newVC,
- String vcName,
- String username) throws KustvaktException {
-
- if (!username.equals(existingVC.getCreatedBy())
- && !adminDao.isAdmin(username)) {
- throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
- "Unauthorized operation for user: " + username, username);
- }
-
- String koralQuery = null;
- CorpusAccess requiredAccess = null;
- String corpusQuery = newVC.getCorpusQuery();
- if (corpusQuery != null && !corpusQuery.isEmpty()) {
- koralQuery = serializeCorpusQuery(corpusQuery);
- requiredAccess = determineRequiredAccess(newVC.isCached(), vcName,
- koralQuery);
- }
-
- VirtualCorpusType type = newVC.getType();
- if (type != null) {
- if (existingVC.getType().equals(VirtualCorpusType.PUBLISHED)) {
- // withdraw from publication
- if (!type.equals(VirtualCorpusType.PUBLISHED)) {
- VirtualCorpusAccess hiddenAccess =
- accessDao.retrieveHiddenAccess(existingVC.getId());
- deleteVCAccess(hiddenAccess.getId(), "system");
- int groupId = hiddenAccess.getUserGroup().getId();
- userGroupService.deleteAutoHiddenGroup(groupId, "system");
- // EM: should the users within the hidden group receive
- // notifications?
- }
- // else remains the same
- }
- else if (type.equals(VirtualCorpusType.PUBLISHED)) {
- publishVC(existingVC.getId());
- }
- }
-
- vcDao.editVirtualCorpus(existingVC, vcName, type, requiredAccess,
- koralQuery, newVC.getDefinition(), newVC.getDescription(),
- newVC.getStatus(), newVC.isCached());
- }
- */
-};
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java b/full/src/main/java/de/ids_mannheim/korap/service/QueryService.java
similarity index 67%
rename from full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
rename to full/src/main/java/de/ids_mannheim/korap/service/QueryService.java
index 3204656..2289a47 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/QueryService.java
@@ -21,19 +21,19 @@
import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.QueryType;
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.dao.AdminDao;
-import de.ids_mannheim.korap.dao.VirtualCorpusAccessDao;
-import de.ids_mannheim.korap.dao.VirtualCorpusDao;
-import de.ids_mannheim.korap.dto.VirtualCorpusAccessDto;
-import de.ids_mannheim.korap.dto.VirtualCorpusDto;
-import de.ids_mannheim.korap.dto.converter.VirtualCorpusAccessConverter;
-import de.ids_mannheim.korap.dto.converter.VirtualCorpusConverter;
+import de.ids_mannheim.korap.dao.QueryAccessDao;
+import de.ids_mannheim.korap.dao.QueryDao;
+import de.ids_mannheim.korap.dto.QueryAccessDto;
+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.UserGroup;
import de.ids_mannheim.korap.entity.UserGroupMember;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
+import de.ids_mannheim.korap.entity.QueryDO;
+import de.ids_mannheim.korap.entity.QueryAccess;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
@@ -48,26 +48,26 @@
/**
* VirtualCorpusService handles the logic behind
* {@link VirtualCorpusController}.
- * It communicates with {@link VirtualCorpusDao} and returns
- * {@link VirtualCorpusDto} to {@link VirtualCorpusController}.
+ * It communicates with {@link QueryDao} and returns
+ * {@link QueryDto} to {@link VirtualCorpusController}.
*
* @author margaretha
*
*/
@Service
-public class VirtualCorpusService {
+public class QueryService {
public static Logger jlog =
- LogManager.getLogger(VirtualCorpusService.class);
+ LogManager.getLogger(QueryService.class);
public static boolean DEBUG = false;
public static Pattern queryNamePattern = Pattern.compile("[-\\w.]+");
@Autowired
- private VirtualCorpusDao vcDao;
+ private QueryDao queryDao;
@Autowired
- private VirtualCorpusAccessDao accessDao;
+ private QueryAccessDao accessDao;
@Autowired
private AdminDao adminDao;
@Autowired
@@ -77,9 +77,9 @@
@Autowired
private FullConfiguration config;
@Autowired
- private VirtualCorpusConverter converter;
+ private QueryConverter converter;
@Autowired
- private VirtualCorpusAccessConverter accessConverter;
+ private QueryAccessConverter accessConverter;
private void verifyUsername (String contextUsername, String pathUsername)
throws KustvaktException {
@@ -91,14 +91,14 @@
}
}
- public List<VirtualCorpusDto> listOwnerVC (String username,
- String vcCreator, QueryType queryType) throws KustvaktException {
- verifyUsername(username, vcCreator);
- List<VirtualCorpus> vcList = vcDao.retrieveOwnerVC(username, queryType);
- return createVCDtos(vcList, queryType);
+ public List<QueryDto> listOwnerQuery (String username,
+ String queryCreator, QueryType queryType) throws KustvaktException {
+ verifyUsername(username, queryCreator);
+ List<QueryDO> list = queryDao.retrieveOwnerQuery(username, queryType);
+ return createQueryDtos(list, queryType);
}
- public List<VirtualCorpusDto> listAvailableVCForUser (
+ public List<QueryDto> listAvailableQueryForUser (
String authenticatedUsername, String username, QueryType queryType)
throws KustvaktException {
@@ -115,22 +115,22 @@
else {
username = authenticatedUsername;
}
- List<VirtualCorpus> vcList =
- vcDao.retrieveVCByUser(username, queryType);
- return createVCDtos(vcList, queryType);
+ List<QueryDO> list =
+ queryDao.retrieveQueryByUser(username, queryType);
+ return createQueryDtos(list, queryType);
}
- public List<VirtualCorpusDto> listVCByType (String username,
+ public List<QueryDto> listQueryByType (String username,
String createdBy, ResourceType type, QueryType queryType)
throws KustvaktException {
boolean isAdmin = adminDao.isAdmin(username);
if (isAdmin) {
- List<VirtualCorpus> virtualCorpora =
- vcDao.retrieveVCByType(type, createdBy, queryType);
+ List<QueryDO> virtualCorpora =
+ queryDao.retrieveQueryByType(type, createdBy, queryType);
Collections.sort(virtualCorpora);
- return createVCDtos(virtualCorpora, queryType);
+ return createQueryDtos(virtualCorpora, queryType);
}
else {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
@@ -138,51 +138,51 @@
}
}
- private ArrayList<VirtualCorpusDto> createVCDtos (
- List<VirtualCorpus> vcList, QueryType queryType)
+ private ArrayList<QueryDto> createQueryDtos (
+ List<QueryDO> queryList, QueryType queryType)
throws KustvaktException {
- ArrayList<VirtualCorpusDto> dtos = new ArrayList<>(vcList.size());
- VirtualCorpus vc;
- Iterator<VirtualCorpus> i = vcList.iterator();
+ ArrayList<QueryDto> dtos = new ArrayList<>(queryList.size());
+ QueryDO query;
+ Iterator<QueryDO> i = queryList.iterator();
while (i.hasNext()) {
- vc = i.next();
- String json = vc.getKoralQuery();
+ query = i.next();
+ String json = query.getKoralQuery();
String statistics = null;
if (queryType.equals(QueryType.VIRTUAL_CORPUS)) {
statistics = krill.getStatistics(json);
}
- VirtualCorpusDto vcDto =
- converter.createVirtualCorpusDto(vc, statistics);
- dtos.add(vcDto);
+ QueryDto dto =
+ converter.createQueryDto(query, statistics);
+ dtos.add(dto);
}
return dtos;
}
/**
- * Only admin and the owner of the virtual corpus are allowed to
- * delete a virtual corpus.
+ * Only admin and the owner of the query are allowed to
+ * delete a query.
*
* @param username
* username
- * @param vcId
- * virtual corpus id
+ * @param queryId
+ * query id
* @throws KustvaktException
*/
@Deprecated
public void deleteVC (String username, int vcId) throws KustvaktException {
- VirtualCorpus vc = vcDao.retrieveVCById(vcId);
+ QueryDO vc = queryDao.retrieveQueryById(vcId);
if (vc.getCreatedBy().equals(username) || adminDao.isAdmin(username)) {
if (vc.getType().equals(ResourceType.PUBLISHED)) {
- VirtualCorpusAccess access =
+ QueryAccess access =
accessDao.retrieveHiddenAccess(vcId);
accessDao.deleteAccess(access, "system");
userGroupService.deleteAutoHiddenGroup(
access.getUserGroup().getId(), "system");
}
- vcDao.deleteVirtualCorpus(vc);
+ queryDao.deleteQuery(vc);
}
else {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
@@ -196,37 +196,37 @@
*
* @param username
* username
- * @param vcName
+ * @param queryName
* virtual corpus name
* @param createdBy
* virtual corpus creator
* @throws KustvaktException
*/
- public void deleteVCByName (String username, String vcName,
+ public void deleteQueryByName (String username, String queryName,
String createdBy) throws KustvaktException {
- VirtualCorpus vc = vcDao.retrieveVCByName(vcName, createdBy);
+ QueryDO query = queryDao.retrieveQueryByName(queryName, createdBy);
- if (vc == null) {
- String vcCode = createdBy + "/" + vcName;
+ if (query == null) {
+ String code = createdBy + "/" + queryName;
throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
- "Virtual corpus " + vcCode + " is not found.",
- String.valueOf(vcCode));
+ "Virtual corpus " + code + " is not found.",
+ String.valueOf(code));
}
- else if (vc.getCreatedBy().equals(username)
+ else if (query.getCreatedBy().equals(username)
|| adminDao.isAdmin(username)) {
- if (vc.getType().equals(ResourceType.PUBLISHED)) {
- VirtualCorpusAccess access =
- accessDao.retrieveHiddenAccess(vc.getId());
+ if (query.getType().equals(ResourceType.PUBLISHED)) {
+ QueryAccess access =
+ accessDao.retrieveHiddenAccess(query.getId());
accessDao.deleteAccess(access, "system");
userGroupService.deleteAutoHiddenGroup(
access.getUserGroup().getId(), "system");
}
- if (KrillCollection.cache.get(vc.getName()) != null) {
- KrillCollection.cache.remove(vc.getName());
+ if (KrillCollection.cache.get(query.getName()) != null) {
+ KrillCollection.cache.remove(query.getName());
}
- vcDao.deleteVirtualCorpus(vc);
+ queryDao.deleteQuery(query);
}
else {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
@@ -234,34 +234,26 @@
}
}
- // @Deprecated
- // public void editVC (VirtualCorpusJson vcJson, String username)
- // throws KustvaktException {
- // ParameterChecker.checkIntegerValue(vcJson.getId(), "id");
- // VirtualCorpus vc = vcDao.retrieveVCById(vcJson.getId());
- // editVC(vc, vcJson, vcJson.getName(), username);
- // }
+ public Status handlePutRequest (String username, String queryCreator,
+ String queryName, QueryJson queryJson) throws KustvaktException {
- public Status handlePutRequest (String username, String vcCreator,
- String vcName, QueryJson queryJson) throws KustvaktException {
-
- verifyUsername(username, vcCreator);
- VirtualCorpus vc = vcDao.retrieveVCByName(vcName, vcCreator);
+ verifyUsername(username, queryCreator);
+ QueryDO query = queryDao.retrieveQueryByName(queryName, queryCreator);
ParameterChecker.checkObjectValue(queryJson, "request entity");
- if (vc == null) {
- storeQuery(queryJson, vcName, username);
+ if (query == null) {
+ storeQuery(queryJson, queryName, username);
return Status.CREATED;
}
else {
- editVC(vc, queryJson, vcName, username);
+ editQuery(query, queryJson, queryName, username);
return Status.NO_CONTENT;
}
}
- public void editVC (VirtualCorpus existingVC, QueryJson newVC,
- String vcName, String username) throws KustvaktException {
+ public void editQuery (QueryDO existingQuery, QueryJson newQuery,
+ String queryName, String username) throws KustvaktException {
- if (!username.equals(existingVC.getCreatedBy())
+ if (!username.equals(existingQuery.getCreatedBy())
&& !adminDao.isAdmin(username)) {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
"Unauthorized operation for user: " + username, username);
@@ -269,21 +261,21 @@
String koralQuery = null;
CorpusAccess requiredAccess = null;
- String corpusQuery = newVC.getCorpusQuery();
+ String corpusQuery = newQuery.getCorpusQuery();
if (corpusQuery != null && !corpusQuery.isEmpty()) {
koralQuery = serializeCorpusQuery(corpusQuery);
- requiredAccess = determineRequiredAccess(newVC.isCached(), vcName,
+ requiredAccess = determineRequiredAccess(newQuery.isCached(), queryName,
koralQuery);
}
- ResourceType type = newVC.getType();
+ ResourceType type = newQuery.getType();
if (type != null) {
- if (existingVC.getType().equals(ResourceType.PUBLISHED)) {
+ if (existingQuery.getType().equals(ResourceType.PUBLISHED)) {
// withdraw from publication
if (!type.equals(ResourceType.PUBLISHED)) {
- VirtualCorpusAccess hiddenAccess =
- accessDao.retrieveHiddenAccess(existingVC.getId());
- deleteVCAccess(hiddenAccess.getId(), "system");
+ QueryAccess hiddenAccess =
+ accessDao.retrieveHiddenAccess(existingQuery.getId());
+ deleteQueryAccess(hiddenAccess.getId(), "system");
int groupId = hiddenAccess.getUserGroup().getId();
userGroupService.deleteAutoHiddenGroup(groupId, "system");
// EM: should the users within the hidden group
@@ -293,31 +285,31 @@
// else remains the same
}
else if (type.equals(ResourceType.PUBLISHED)) {
- publishVC(existingVC.getId());
+ publishQuery(existingQuery.getId());
}
}
- vcDao.editVirtualCorpus(existingVC, vcName, type, requiredAccess,
- koralQuery, newVC.getDefinition(), newVC.getDescription(),
- newVC.getStatus(), newVC.isCached());
+ queryDao.editQuery(existingQuery, queryName, type, requiredAccess,
+ koralQuery, newQuery.getDefinition(), newQuery.getDescription(),
+ newQuery.getStatus(), newQuery.isCached());
}
- private void publishVC (int vcId) throws KustvaktException {
+ private void publishQuery (int queryId) throws KustvaktException {
- VirtualCorpusAccess access = accessDao.retrieveHiddenAccess(vcId);
+ QueryAccess access = accessDao.retrieveHiddenAccess(queryId);
// check if hidden access exists
if (access == null) {
- VirtualCorpus vc = vcDao.retrieveVCById(vcId);
+ QueryDO query = queryDao.retrieveQueryById(queryId);
// create and assign a new hidden group
int groupId = userGroupService.createAutoHiddenGroup();
UserGroup autoHidden =
userGroupService.retrieveUserGroupById(groupId);
- accessDao.createAccessToVC(vc, autoHidden, "system",
- VirtualCorpusAccessStatus.HIDDEN);
+ accessDao.createAccessToQuery(query, autoHidden, "system",
+ QueryAccessStatus.HIDDEN);
}
else {
// should not happened
- jlog.error("Cannot publish VC with id: " + vcId
+ jlog.error("Cannot publish query with id: " + queryId
+ ". Hidden access exists! Access id: " + access.getId());
}
}
@@ -370,12 +362,13 @@
determineRequiredAccess(isCached, queryName, koralQuery);
}
- if (DEBUG) jlog.debug("Storing virtul corpus or query: " + queryName
- + "in the database ");
+ if (DEBUG){
+ jlog.debug("Storing query: " + queryName + "in the database ");
+ }
int queryId = 0;
try {
- queryId = vcDao.createVirtualCorpus(queryName, type, queryType,
+ queryId = queryDao.createQuery(queryName, type, queryType,
requiredAccess, koralQuery, definition, description, status,
isCached, username, query, queryLanguage);
@@ -394,7 +387,7 @@
cause.getMessage());
}
if (type.equals(ResourceType.PUBLISHED)) {
- publishVC(queryId);
+ publishQuery(queryId);
}
}
@@ -469,17 +462,17 @@
return (numberOfDoc > 0) ? true : false;
}
- public void shareVC (String username, String createdBy, String vcName,
+ public void shareQuery (String username, String createdBy, String queryName,
String groupName) throws KustvaktException {
- VirtualCorpus vc = vcDao.retrieveVCByName(vcName, createdBy);
- if (vc == null) {
- String vcCode = createdBy + "/" + vcName;
+ QueryDO query = queryDao.retrieveQueryByName(queryName, createdBy);
+ if (query == null) {
+ String code = createdBy + "/" + queryName;
throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
- "Virtual corpus " + vcCode + " is not found.",
- String.valueOf(vcCode));
+ "Query " + code + " is not found.",
+ String.valueOf(code));
}
- if (!username.equals(vc.getCreatedBy())
+ if (!username.equals(query.getCreatedBy())
&& !adminDao.isAdmin(username)) {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
"Unauthorized operation for user: " + username, username);
@@ -488,15 +481,15 @@
UserGroup userGroup =
userGroupService.retrieveUserGroupByName(groupName);
- if (!isVCAccessAdmin(userGroup, username)
+ if (!isQueryAccessAdmin(userGroup, username)
&& !adminDao.isAdmin(username)) {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
"Unauthorized operation for user: " + username, username);
}
else {
try {
- accessDao.createAccessToVC(vc, userGroup, username,
- VirtualCorpusAccessStatus.ACTIVE);
+ accessDao.createAccessToQuery(query, userGroup, username,
+ QueryAccessStatus.ACTIVE);
}
catch (Exception e) {
Throwable cause = e;
@@ -512,15 +505,15 @@
cause.getMessage());
}
- vcDao.editVirtualCorpus(vc, null, ResourceType.PROJECT, null, null,
- null, null, null, vc.isCached());
+ queryDao.editQuery(query, null, ResourceType.PROJECT, null, null,
+ null, null, null, query.isCached());
}
}
- private boolean isVCAccessAdmin (UserGroup userGroup, String username)
+ private boolean isQueryAccessAdmin (UserGroup userGroup, String username)
throws KustvaktException {
List<UserGroupMember> accessAdmins =
- userGroupService.retrieveVCAccessAdmins(userGroup);
+ userGroupService.retrieveQueryAccessAdmins(userGroup);
for (UserGroupMember m : accessAdmins) {
if (username.equals(m.getUserId())) {
return true;
@@ -545,9 +538,9 @@
// }
// }
- public List<VirtualCorpusAccessDto> listVCAccessByUsername (String username)
+ public List<QueryAccessDto> listQueryAccessByUsername (String username)
throws KustvaktException {
- List<VirtualCorpusAccess> accessList = new ArrayList<>();
+ List<QueryAccess> accessList = new ArrayList<>();
if (adminDao.isAdmin(username)) {
accessList = accessDao.retrieveAllAccess();
}
@@ -555,46 +548,46 @@
List<UserGroup> groups =
userGroupService.retrieveUserGroup(username);
for (UserGroup g : groups) {
- if (isVCAccessAdmin(g, username)) {
+ if (isQueryAccessAdmin(g, username)) {
accessList.addAll(
accessDao.retrieveActiveAccessByGroup(g.getId()));
}
}
}
- return accessConverter.createVCADto(accessList);
+ return accessConverter.createQueryAccessDto(accessList);
}
- public List<VirtualCorpusAccessDto> listVCAccessByVC (String username,
- String vcCreator, String vcName) throws KustvaktException {
+ public List<QueryAccessDto> listQueryAccessByQuery (String username,
+ String queryCreator, String queryName) throws KustvaktException {
- List<VirtualCorpusAccess> accessList;
+ List<QueryAccess> accessList;
if (adminDao.isAdmin(username)) {
- accessList = accessDao.retrieveAllAccessByVC(vcCreator, vcName);
+ accessList = accessDao.retrieveAllAccessByQuery(queryCreator, queryName);
}
else {
- accessList = accessDao.retrieveActiveAccessByVC(vcCreator, vcName);
- List<VirtualCorpusAccess> filteredAccessList = new ArrayList<>();
- for (VirtualCorpusAccess access : accessList) {
+ accessList = accessDao.retrieveActiveAccessByQuery(queryCreator, queryName);
+ List<QueryAccess> filteredAccessList = new ArrayList<>();
+ for (QueryAccess access : accessList) {
UserGroup userGroup = access.getUserGroup();
- if (isVCAccessAdmin(userGroup, username)) {
+ if (isQueryAccessAdmin(userGroup, username)) {
filteredAccessList.add(access);
}
}
accessList = filteredAccessList;
}
- return accessConverter.createVCADto(accessList);
+ return accessConverter.createQueryAccessDto(accessList);
}
@Deprecated
- public List<VirtualCorpusAccessDto> listVCAccessByGroup (String username,
+ public List<QueryAccessDto> listVCAccessByGroup (String username,
int groupId) throws KustvaktException {
UserGroup userGroup = userGroupService.retrieveUserGroupById(groupId);
- List<VirtualCorpusAccess> accessList;
+ List<QueryAccess> accessList;
if (adminDao.isAdmin(username)) {
accessList = accessDao.retrieveAllAccessByGroup(groupId);
}
- else if (isVCAccessAdmin(userGroup, username)) {
+ else if (isQueryAccessAdmin(userGroup, username)) {
accessList = accessDao.retrieveActiveAccessByGroup(groupId);
}
else {
@@ -602,19 +595,19 @@
"Unauthorized operation for user: " + username, username);
}
- return accessConverter.createVCADto(accessList);
+ return accessConverter.createQueryAccessDto(accessList);
}
- public List<VirtualCorpusAccessDto> listVCAccessByGroup (String username,
+ public List<QueryAccessDto> listQueryAccessByGroup (String username,
String groupName) throws KustvaktException {
UserGroup userGroup =
userGroupService.retrieveUserGroupByName(groupName);
- List<VirtualCorpusAccess> accessList;
+ List<QueryAccess> accessList;
if (adminDao.isAdmin(username)) {
accessList = accessDao.retrieveAllAccessByGroup(userGroup.getId());
}
- else if (isVCAccessAdmin(userGroup, username)) {
+ else if (isQueryAccessAdmin(userGroup, username)) {
accessList =
accessDao.retrieveActiveAccessByGroup(userGroup.getId());
}
@@ -622,15 +615,15 @@
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
"Unauthorized operation for user: " + username, username);
}
- return accessConverter.createVCADto(accessList);
+ return accessConverter.createQueryAccessDto(accessList);
}
- public void deleteVCAccess (int accessId, String username)
+ public void deleteQueryAccess (int accessId, String username)
throws KustvaktException {
- VirtualCorpusAccess access = accessDao.retrieveAccessById(accessId);
+ QueryAccess access = accessDao.retrieveAccessById(accessId);
UserGroup userGroup = access.getUserGroup();
- if (isVCAccessAdmin(userGroup, username)
+ if (isQueryAccessAdmin(userGroup, username)
|| adminDao.isAdmin(username)) {
accessDao.deleteAccess(access, username);
}
@@ -641,49 +634,49 @@
}
- public VirtualCorpus searchVCByName (String username, String vcName,
+ public QueryDO searchQueryByName (String username, String queryName,
String createdBy, QueryType queryType) throws KustvaktException {
- VirtualCorpus vc = vcDao.retrieveVCByName(vcName, createdBy);
- if (vc == null) {
- String vcCode = createdBy + "/" + vcName;
+ QueryDO query = queryDao.retrieveQueryByName(queryName, createdBy);
+ if (query == null) {
+ String code = createdBy + "/" + queryName;
throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
- queryType.displayName()+ " " + vcCode + " is not found.",
- String.valueOf(vcCode));
+ queryType.displayName()+ " " + code + " is not found.",
+ String.valueOf(code));
}
- checkVCAccess(vc, username);
- return vc;
+ checkQueryAccess(query, username);
+ return query;
}
- public VirtualCorpusDto retrieveVCByName (String username, String vcName,
+ public QueryDto retrieveQueryByName (String username, String queryName,
String createdBy, QueryType queryType) throws KustvaktException {
- VirtualCorpus vc = searchVCByName(username, vcName, createdBy, queryType);
- String json = vc.getKoralQuery();
+ QueryDO query = searchQueryByName(username, queryName, createdBy, queryType);
+ String json = query.getKoralQuery();
String statistics = null;
- if (vc.getQueryType().equals(QueryType.VIRTUAL_CORPUS)) {
+ if (query.getQueryType().equals(QueryType.VIRTUAL_CORPUS)) {
statistics = krill.getStatistics(json);
}
- return converter.createVirtualCorpusDto(vc, statistics);
+ return converter.createQueryDto(query, statistics);
}
- public VirtualCorpusDto searchVCById (String username, int vcId)
+ public QueryDto searchQueryById (String username, int queryId)
throws KustvaktException {
- VirtualCorpus vc = vcDao.retrieveVCById(vcId);
- checkVCAccess(vc, username);
- String json = vc.getKoralQuery();
+ QueryDO query = queryDao.retrieveQueryById(queryId);
+ checkQueryAccess(query, username);
+ String json = query.getKoralQuery();
String statistics = krill.getStatistics(json);
- return converter.createVirtualCorpusDto(vc, statistics);
+ return converter.createQueryDto(query, statistics);
}
- private void checkVCAccess (VirtualCorpus vc, String username)
+ private void checkQueryAccess (QueryDO query, String username)
throws KustvaktException {
- ResourceType type = vc.getType();
+ ResourceType type = query.getType();
if (!adminDao.isAdmin(username)
- && !username.equals(vc.getCreatedBy())) {
+ && !username.equals(query.getCreatedBy())) {
if (type.equals(ResourceType.PRIVATE)
|| (type.equals(ResourceType.PROJECT)
- && !hasAccess(username, vc.getId()))) {
+ && !hasAccess(username, query.getId()))) {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
"Unauthorized operation for user: " + username,
username);
@@ -691,9 +684,9 @@
else if (ResourceType.PUBLISHED.equals(type)
&& !username.equals("guest")) {
- // add user in the VC's auto group
+ // add user in the query's auto group
UserGroup userGroup = userGroupService
- .retrieveHiddenUserGroupByVC(vc.getId());
+ .retrieveHiddenUserGroupByQuery(query.getId());
try {
userGroupService.addGroupMember(username, userGroup,
"system", GroupMemberStatus.ACTIVE);
@@ -708,12 +701,12 @@
}
}
- private boolean hasAccess (String username, int vcId)
+ private boolean hasAccess (String username, int queryId)
throws KustvaktException {
UserGroup userGroup;
- List<VirtualCorpusAccess> accessList =
- accessDao.retrieveActiveAccessByVC(vcId);
- for (VirtualCorpusAccess access : accessList) {
+ List<QueryAccess> accessList =
+ accessDao.retrieveActiveAccessByQuery(queryId);
+ for (QueryAccess access : accessList) {
userGroup = access.getUserGroup();
if (userGroupService.isMember(username, userGroup)) {
return true;
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java b/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
index 7b0724f..077ce9d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
@@ -137,9 +137,9 @@
return userGroupDao.retrieveGroupByName(groupName, false);
}
- public UserGroup retrieveHiddenUserGroupByVC (int vcId)
+ public UserGroup retrieveHiddenUserGroupByQuery (int queryId)
throws KustvaktException {
- return userGroupDao.retrieveHiddenGroupByVC(vcId);
+ return userGroupDao.retrieveHiddenGroupByQuery(queryId);
}
public List<UserGroupDto> retrieveUserGroupByStatus (String username,
@@ -172,10 +172,10 @@
}
}
- public List<UserGroupMember> retrieveVCAccessAdmins (UserGroup userGroup)
+ public List<UserGroupMember> retrieveQueryAccessAdmins (UserGroup userGroup)
throws KustvaktException {
List<UserGroupMember> groupAdmins = groupMemberDao.retrieveMemberByRole(
- userGroup.getId(), PredefinedRole.VC_ACCESS_ADMIN.getId());
+ userGroup.getId(), PredefinedRole.QUERY_ACCESS_ADMIN.getId());
return groupAdmins;
}
@@ -185,7 +185,7 @@
memberRoles.add(roleDao.retrieveRoleById(
PredefinedRole.USER_GROUP_MEMBER.getId()));
memberRoles.add(roleDao
- .retrieveRoleById(PredefinedRole.VC_ACCESS_MEMBER.getId()));
+ .retrieveRoleById(PredefinedRole.QUERY_ACCESS_MEMBER.getId()));
}
}
@@ -194,15 +194,15 @@
* Do not include owners in group members.
*
* {@link PredefinedRole#USER_GROUP_MEMBER} and
- * {@link PredefinedRole#VC_ACCESS_MEMBER} roles are
+ * {@link PredefinedRole#QUERY_ACCESS_MEMBER} roles are
* automatically assigned to each group member.
*
* {@link PredefinedRole#USER_GROUP_MEMBER} restrict users
* to see other group members and allow users to remove
* themselves from the groups.
*
- * {@link PredefinedRole#VC_ACCESS_MEMBER} allow user to
- * read group VC.
+ * {@link PredefinedRole#QUERY_ACCESS_MEMBER} allow user to
+ * read group query.
*
* @see /full/src/main/resources/db/predefined/V3.2__insert_predefined_roles.sql
*
@@ -318,7 +318,7 @@
* @param userGroup
* a user group
* @param createdBy
- * the user (VCA/system) adding the user the user-group
+ * the user (query-access admin/system) adding the user the user-group
* @param status
* the status of the membership
* @throws KustvaktException
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java
index 4f42679..2ebd938 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java
@@ -22,11 +22,11 @@
import de.ids_mannheim.korap.constant.OAuth2Scope;
import de.ids_mannheim.korap.constant.QueryType;
-import de.ids_mannheim.korap.dto.VirtualCorpusDto;
+import de.ids_mannheim.korap.dto.QueryDto;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.oauth2.service.OAuth2ScopeService;
import de.ids_mannheim.korap.security.context.TokenContext;
-import de.ids_mannheim.korap.service.VirtualCorpusService;
+import de.ids_mannheim.korap.service.QueryService;
import de.ids_mannheim.korap.web.KustvaktResponseHandler;
import de.ids_mannheim.korap.web.filter.APIVersionFilter;
import de.ids_mannheim.korap.web.filter.AuthenticationFilter;
@@ -53,7 +53,7 @@
@Autowired
private KustvaktResponseHandler kustvaktResponseHandler;
@Autowired
- private VirtualCorpusService service;
+ private QueryService service;
@Autowired
private OAuth2ScopeService scopeService;
@@ -113,7 +113,7 @@
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
@ResourceFilters({ APIVersionFilter.class, AuthenticationFilter.class,
DemoUserFilter.class, PiwikFilter.class })
- public VirtualCorpusDto retrieveQueryByName (
+ public QueryDto retrieveQueryByName (
@Context SecurityContext securityContext,
@PathParam("createdBy") String createdBy,
@PathParam("qName") String qName) {
@@ -121,7 +121,7 @@
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
- return service.retrieveVCByName(context.getUsername(), qName,
+ return service.retrieveQueryByName(context.getUsername(), qName,
createdBy, QueryType.QUERY);
}
catch (KustvaktException e) {
@@ -161,17 +161,31 @@
*/
- // TODO: List all queries available to the logged in user
+ /**
+ * Lists all queries available to the authenticated user.
+ *
+ * System-admins can list available queries for a specific user by
+ * specifiying the username parameter.
+ *
+ * Normal users cannot list queries available for other users.
+ * Thus, username parameter is optional
+ * and must be identical to the authenticated username.
+ *
+ * @param securityContext
+ * @param username
+ * a username (optional)
+ * @return a list of queries
+ */
@GET
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
- public List<VirtualCorpusDto> listAvailableQuery (
+ public List<QueryDto> listAvailableQuery (
@Context SecurityContext securityContext,
@QueryParam("username") String username) {
TokenContext context =
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
- List<VirtualCorpusDto> dtos = service.listAvailableVCForUser(
+ List<QueryDto> dtos = service.listAvailableQueryForUser(
context.getUsername(), username, QueryType.QUERY);
return dtos;
}
@@ -179,7 +193,39 @@
throw kustvaktResponseHandler.throwit(e);
}
}
- // TODO: List all queries of a sepcific user
+
+// // TODO: List all queries of a sepcific user
+// /**
+// * Lists all queries created by a user. This list is only
+// * available to the owner of the queries. Users, except system-admins,
+// * are not allowed to list queries created by other users.
+// *
+// * Thus, the path parameter "createdBy" must be the same as the
+// * authenticated username.
+// *
+// * @param securityContext
+// * @return a list of queries created by the user
+// * in the security context.
+// */
+// @GET
+// @Path("~{createdBy}")
+// @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
+// public List<VirtualCorpusDto> listUserVC (
+// @PathParam("createdBy") String createdBy,
+// @Context SecurityContext securityContext) {
+// TokenContext context =
+// (TokenContext) securityContext.getUserPrincipal();
+// try {
+// scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
+// return service.listOwnerVC(context.getUsername(), createdBy,
+// QueryType.QUERY);
+// }
+// catch (KustvaktException e) {
+// throw kustvaktResponseHandler.throwit(e);
+// }
+// }
+
+
// TODO: Some admin routes missing.
// TODO: Some sharing routes missing
};
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
index 14b4ed2..8f74282 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
@@ -25,12 +25,12 @@
import de.ids_mannheim.korap.constant.OAuth2Scope;
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.dto.VirtualCorpusAccessDto;
-import de.ids_mannheim.korap.dto.VirtualCorpusDto;
+import de.ids_mannheim.korap.dto.QueryAccessDto;
+import de.ids_mannheim.korap.dto.QueryDto;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.oauth2.service.OAuth2ScopeService;
import de.ids_mannheim.korap.security.context.TokenContext;
-import de.ids_mannheim.korap.service.VirtualCorpusService;
+import de.ids_mannheim.korap.service.QueryService;
import de.ids_mannheim.korap.web.KustvaktResponseHandler;
import de.ids_mannheim.korap.web.filter.APIVersionFilter;
import de.ids_mannheim.korap.web.filter.AuthenticationFilter;
@@ -66,7 +66,7 @@
@Autowired
private KustvaktResponseHandler kustvaktResponseHandler;
@Autowired
- private VirtualCorpusService service;
+ private QueryService service;
@Autowired
private OAuth2ScopeService scopeService;
@@ -125,7 +125,7 @@
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
@ResourceFilters({ APIVersionFilter.class, AuthenticationFilter.class,
DemoUserFilter.class, PiwikFilter.class })
- public VirtualCorpusDto retrieveVCByName (
+ public QueryDto retrieveVCByName (
@Context SecurityContext securityContext,
@PathParam("createdBy") String createdBy,
@PathParam("vcName") String vcName) {
@@ -133,7 +133,7 @@
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
- return service.retrieveVCByName(context.getUsername(), vcName,
+ return service.retrieveQueryByName(context.getUsername(), vcName,
createdBy, QueryType.VIRTUAL_CORPUS);
}
catch (KustvaktException e) {
@@ -158,14 +158,14 @@
*/
@GET
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
- public List<VirtualCorpusDto> listAvailableVC (
+ public List<QueryDto> listAvailableVC (
@Context SecurityContext securityContext,
@QueryParam("username") String username) {
TokenContext context =
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
- return service.listAvailableVCForUser(context.getUsername(),
+ return service.listAvailableQueryForUser(context.getUsername(),
username, QueryType.VIRTUAL_CORPUS);
}
catch (KustvaktException e) {
@@ -188,14 +188,14 @@
@GET
@Path("~{createdBy}")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
- public List<VirtualCorpusDto> listUserVC (
+ public List<QueryDto> listUserVC (
@PathParam("createdBy") String createdBy,
@Context SecurityContext securityContext) {
TokenContext context =
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
- return service.listOwnerVC(context.getUsername(), createdBy,
+ return service.listOwnerQuery(context.getUsername(), createdBy,
QueryType.VIRTUAL_CORPUS);
}
catch (KustvaktException e) {
@@ -221,7 +221,7 @@
@GET
@Path("list/system-admin")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
- public List<VirtualCorpusDto> listVCByType (
+ public List<QueryDto> listVCByType (
@Context SecurityContext securityContext,
@QueryParam("createdBy") String createdBy,
@QueryParam("type") ResourceType type) {
@@ -229,7 +229,7 @@
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.ADMIN);
- return service.listVCByType(context.getUsername(), createdBy, type,
+ return service.listQueryByType(context.getUsername(), createdBy, type,
QueryType.VIRTUAL_CORPUS);
}
catch (KustvaktException e) {
@@ -259,7 +259,7 @@
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.DELETE_VC);
- service.deleteVCByName(context.getUsername(), vcName, createdBy);
+ service.deleteQueryByName(context.getUsername(), vcName, createdBy);
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
@@ -294,7 +294,7 @@
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.SHARE_VC);
- service.shareVC(context.getUsername(), vcCreator, vcName, groupName);
+ service.shareQuery(context.getUsername(), vcCreator, vcName, groupName);
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
@@ -322,7 +322,7 @@
(TokenContext) securityContext.getUserPrincipal();
try {
scopeService.verifyScope(context, OAuth2Scope.DELETE_VC_ACCESS);
- service.deleteVCAccess(accessId, context.getUsername());
+ service.deleteQueryAccess(accessId, context.getUsername());
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
@@ -342,7 +342,7 @@
@GET
@Path("access")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
- public List<VirtualCorpusAccessDto> listVCAccesses (
+ public List<QueryAccessDto> listVCAccesses (
@Context SecurityContext securityContext,
@QueryParam("groupName") String groupName) {
TokenContext context =
@@ -350,10 +350,10 @@
try {
scopeService.verifyScope(context, OAuth2Scope.VC_ACCESS_INFO);
if (groupName!=null && !groupName.isEmpty()){
- return service.listVCAccessByGroup(context.getUsername(), groupName);
+ return service.listQueryAccessByGroup(context.getUsername(), groupName);
}
else {
- return service.listVCAccessByUsername(context.getUsername());
+ return service.listQueryAccessByUsername(context.getUsername());
}
}
catch (KustvaktException e) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/input/QueryJson.java b/full/src/main/java/de/ids_mannheim/korap/web/input/QueryJson.java
index 8d061a9..8badd38 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/input/QueryJson.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/input/QueryJson.java
@@ -3,17 +3,19 @@
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.service.VirtualCorpusService;
+import de.ids_mannheim.korap.service.QueryService;
+import de.ids_mannheim.korap.web.controller.QueryReferenceController;
import de.ids_mannheim.korap.web.controller.VirtualCorpusController;
import lombok.Getter;
import lombok.Setter;
-/** Java POJO of JSON input of the virtual corpus controller for
- * creating and editing virtual corpora.
+/** Java POJO of JSON input of the virtual corpus and query controllers
+ * for creating and editing virtual corpora and query references.
*
* @author margaretha
* @see VirtualCorpusController
- * @see VirtualCorpusService
+ * @see QueryReferenceController
+ * @see QueryService
*/
@Getter
@Setter
diff --git a/full/src/main/resources/db/predefined/V2.1__insert_predefined_roles.sql b/full/src/main/resources/db/predefined/V2.1__insert_predefined_roles.sql
index 6fb6991..1c3f75f 100644
--- a/full/src/main/resources/db/predefined/V2.1__insert_predefined_roles.sql
+++ b/full/src/main/resources/db/predefined/V2.1__insert_predefined_roles.sql
@@ -1,8 +1,8 @@
-- roles
INSERT INTO role(name) VALUES ("USER_GROUP_ADMIN");
INSERT INTO role(name) VALUES ("USER_GROUP_MEMBER");
-INSERT INTO role(name) VALUES ("VC_ACCESS_ADMIN");
-INSERT INTO role(name) VALUES ("VC_ACCESS_MEMBER");
+INSERT INTO role(name) VALUES ("QUERY_ACCESS_ADMIN");
+INSERT INTO role(name) VALUES ("QUERY_ACCESS_MEMBER");
-- privileges
INSERT INTO privilege(name,role_id)
diff --git a/full/src/main/resources/db/sqlite/V1.1__create_virtual_corpus_tables.sql b/full/src/main/resources/db/sqlite/V1.1__create_virtual_corpus_tables.sql
index febf97b..2a62319 100644
--- a/full/src/main/resources/db/sqlite/V1.1__create_virtual_corpus_tables.sql
+++ b/full/src/main/resources/db/sqlite/V1.1__create_virtual_corpus_tables.sql
@@ -78,10 +78,10 @@
is_cached BOOLEAN DEFAULT 0
);
-CREATE INDEX IF NOT EXISTS virtual_corpus_owner_index ON virtual_corpus(created_by);
-CREATE INDEX IF NOT EXISTS virtual_corpus_type_index ON virtual_corpus(type);
-CREATE UNIQUE INDEX IF NOT EXISTS virtual_corpus_unique_name
- ON virtual_corpus(name,created_by);
+--CREATE INDEX IF NOT EXISTS virtual_corpus_owner_index ON virtual_corpus(created_by);
+--CREATE INDEX IF NOT EXISTS virtual_corpus_type_index ON virtual_corpus(type);
+--CREATE UNIQUE INDEX IF NOT EXISTS virtual_corpus_unique_name
+-- ON virtual_corpus(name,created_by);
CREATE TABLE IF NOT EXISTS virtual_corpus_access (
id INTEGER PRIMARY KEY AUTOINCREMENT,
diff --git a/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql b/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql
index 384faf5..0d3bf8c 100644
--- a/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql
+++ b/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql
@@ -7,6 +7,31 @@
ALTER TABLE virtual_corpus
ADD COLUMN query_language VARCHAR(100) DEFAULT NULL;
+ALTER TABLE virtual_corpus
+RENAME COLUMN corpus_query TO koral_query;
+
+ALTER TABLE virtual_corpus
+RENAME TO query;
+
+DROP INDEX IF EXISTS virtual_corpus_owner_index;
+DROP INDEX IF EXISTS virtual_corpus_type_index;
+DROP INDEX IF EXISTS virtual_corpus_unique_name;
+
+CREATE INDEX IF NOT EXISTS query_owner_index ON query(created_by);
+CREATE INDEX IF NOT EXISTS query_type_index ON query(type);
+CREATE UNIQUE INDEX IF NOT EXISTS query_unique_name
+ ON query(name,created_by);
+
+
+
+ALTER TABLE virtual_corpus_access
+RENAME COLUMN virtual_corpus_id TO query_id;
+
+ALTER TABLE virtual_corpus_access
+RENAME TO query_access;
+
+
+
DROP TABLE IF EXISTS query_reference;
diff --git a/full/src/main/resources/db/test/V3.1__insert_virtual_corpus.sql b/full/src/main/resources/db/test/V3.1__insert_virtual_corpus.sql
index 778fb4b..d9d2c13 100644
--- a/full/src/main/resources/db/test/V3.1__insert_virtual_corpus.sql
+++ b/full/src/main/resources/db/test/V3.1__insert_virtual_corpus.sql
@@ -61,52 +61,52 @@
-- virtual corpora
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status, koral_query)
VALUES ("dory-vc", "PRIVATE", "VIRTUAL_CORPUS", "FREE", "dory", "test vc", "experimental",
'{"collection": { "@type": "koral:docGroup", "operands": [ { "@type": "koral:doc", "key": "corpusSigle", "match": "match:eq", "value": "GOE" }, { "@type": "koral:doc", "key": "creationDate", "match": "match:geq", "type": "type:date", "value": "1820" } ], "operation": "operation:and" }}');
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status, koral_query)
VALUES ("group-vc", "PROJECT", "VIRTUAL_CORPUS", "PUB", "dory", "test vc", "experimental",
'{"collection": { "@type": "koral:docGroup", "operands": [ { "@type": "koral:doc", "key": "corpusSigle", "match": "match:eq", "value": "GOE" }, { "@type": "koral:doc", "key": "creationDate", "match": "match:leq", "type": "type:date", "value": "1810" } ], "operation": "operation:and" }}');
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status, koral_query)
VALUES ("system-vc", "SYSTEM", "VIRTUAL_CORPUS", "ALL", "system", "test vc", "experimental",
'{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status, koral_query)
VALUES ("published-vc", "PUBLISHED", "VIRTUAL_CORPUS", "ALL", "marlin", "test vc", "experimental",
'{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status, koral_query)
VALUES ("marlin-vc", "PRIVATE", "VIRTUAL_CORPUS", "FREE", "marlin", "marlin test share vc", "experimental",
'{"collection": { "@type": "koral:docGroup", "operands": [ { "@type": "koral:doc", "key": "corpusSigle", "match": "match:eq", "value": "GOE" }, { "@type": "koral:doc", "key": "creationDate", "match": "match:geq", "type": "type:date", "value": "1820" } ], "operation": "operation:and" }}');
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status, koral_query)
VALUES ("nemo-vc", "PRIVATE", "VIRTUAL_CORPUS", "ALL", "nemo", "nemo test vc", "experimental",
'{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
-- virtual corpus access
-INSERT INTO virtual_corpus_access(virtual_corpus_id, user_group_id, status, created_by)
+INSERT INTO query_access(query_id, user_group_id, status, created_by)
SELECT
- (SELECT id from virtual_corpus where name = "group-vc"),
+ (SELECT id from query where name = "group-vc"),
(SELECT id from user_group where name = "dory-group"),
"ACTIVE", "dory";
---INSERT INTO virtual_corpus_access(virtual_corpus_id, user_group_id, status, created_by)
+--INSERT INTO query_access(query_id, user_group_id, status, created_by)
-- SELECT
--- (SELECT id from virtual_corpus where name = "system-vc"),
+-- (SELECT id from query where name = "system-vc"),
-- (SELECT id from user_group where name = "all users"),
-- "ACTIVE", "system";
-INSERT INTO virtual_corpus_access(virtual_corpus_id, user_group_id, status, created_by)
+INSERT INTO query_access(query_id, user_group_id, status, created_by)
SELECT
- (SELECT id from virtual_corpus where name = "published-vc"),
+ (SELECT id from query where name = "published-vc"),
(SELECT id from user_group where name = "marlin-group"),
"ACTIVE", "marlin";
-INSERT INTO virtual_corpus_access(virtual_corpus_id, user_group_id, status, created_by)
+INSERT INTO query_access(query_id, user_group_id, status, created_by)
SELECT
- (SELECT id from virtual_corpus where name = "published-vc"),
+ (SELECT id from query where name = "published-vc"),
(SELECT id from user_group where name = "auto-group"),
"HIDDEN", "system";
diff --git a/full/src/main/resources/db/test/V3.3__insert_member_roles.sql b/full/src/main/resources/db/test/V3.3__insert_member_roles.sql
index effbbcb..6832575 100644
--- a/full/src/main/resources/db/test/V3.3__insert_member_roles.sql
+++ b/full/src/main/resources/db/test/V3.3__insert_member_roles.sql
@@ -9,7 +9,7 @@
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
(SELECT id FROM user_group_member WHERE user_id="marlin" AND group_id=1),
- (SELECT id FROM role WHERE name = "VC_ACCESS_ADMIN");
+ (SELECT id FROM role WHERE name = "QUERY_ACCESS_ADMIN");
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
@@ -19,7 +19,7 @@
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
(SELECT id FROM user_group_member WHERE user_id="dory" AND group_id=1),
- (SELECT id FROM role WHERE name = "VC_ACCESS_ADMIN");
+ (SELECT id FROM role WHERE name = "QUERY_ACCESS_ADMIN");
-- dory group
@@ -31,7 +31,7 @@
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
(SELECT id FROM user_group_member WHERE user_id="dory" AND group_id=2),
- (SELECT id FROM role WHERE name = "VC_ACCESS_ADMIN");
+ (SELECT id FROM role WHERE name = "QUERY_ACCESS_ADMIN");
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
@@ -41,12 +41,12 @@
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
(SELECT id FROM user_group_member WHERE user_id="nemo" AND group_id=2),
- (SELECT id FROM role WHERE name = "VC_ACCESS_MEMBER");
+ (SELECT id FROM role WHERE name = "QUERY_ACCESS_MEMBER");
-- auto group
INSERT INTO group_member_role(group_member_id,role_id)
SELECT
(SELECT id FROM user_group_member WHERE user_id="pearl" AND group_id=3),
- (SELECT id FROM role WHERE name = "VC_ACCESS_MEMBER");
+ (SELECT id FROM role WHERE name = "QUERY_ACCESS_MEMBER");
diff --git a/full/src/main/resources/db/test/V3.7__insert_query_references.sql b/full/src/main/resources/db/test/V3.7__insert_query_references.sql
index a1ec5fb..0507380 100644
--- a/full/src/main/resources/db/test/V3.7__insert_query_references.sql
+++ b/full/src/main/resources/db/test/V3.7__insert_query_references.sql
@@ -1,10 +1,10 @@
-- query references
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status,
- corpus_query, query, query_language)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status,
+ koral_query, query, query_language)
VALUES ("dory-q", "PRIVATE", "QUERY", "FREE", "dory", "test query", "experimental",
'{ "@type": "koral:token" }', "[]", "poliqarp");
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status,
- corpus_query, query, query_language)
+INSERT INTO query(name, type, query_type, required_access, created_by, description, status,
+ koral_query, query, query_language)
VALUES ("system-q", "SYSTEM", "QUERY", "FREE", "system", '"system" query', "experimental",
'{ "@type": "koral:token" }', "[]", "poliqarp");
diff --git a/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java b/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
index 7e3736a..ef57687 100644
--- a/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
@@ -12,8 +12,8 @@
import de.ids_mannheim.korap.collection.CachedVCData;
import de.ids_mannheim.korap.config.NamedVCLoader;
import de.ids_mannheim.korap.config.SpringJerseyTest;
-import de.ids_mannheim.korap.dao.VirtualCorpusDao;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.dao.QueryDao;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.util.QueryException;
import net.sf.ehcache.CacheManager;
@@ -24,7 +24,7 @@
@Autowired
private NamedVCLoader vcLoader;
@Autowired
- private VirtualCorpusDao dao;
+ private QueryDao dao;
@Test
public void testNamedVCLoader ()
@@ -41,7 +41,7 @@
assertTrue(cachedData.getDocIdMap().size() > 0);
KrillCollection.cache.removeAll();
- VirtualCorpus vc = dao.retrieveVCByName("named-vc1", "system");
- dao.deleteVirtualCorpus(vc);
+ QueryDO vc = dao.retrieveQueryByName("named-vc1", "system");
+ dao.deleteQuery(vc);
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java b/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
index cbb6977..ac11283 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
@@ -76,7 +76,8 @@
socket.close();
}
catch (IOException e) {
- e.printStackTrace();
+// e.printStackTrace();
+ System.out.println("[WARNING] " + e.getMessage());
port = getPort(port);
}
return port;
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
index 3df8c24..e81ed11 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
@@ -20,12 +20,12 @@
import de.ids_mannheim.korap.constant.PredefinedRole;
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.UserGroupStatus;
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
import de.ids_mannheim.korap.constant.ResourceType;
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.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.user.User.CorpusAccess;
import edu.emory.mathcs.backport.java.util.Collections;
@@ -37,7 +37,7 @@
@Autowired
private UserGroupDao userGroupDao;
@Autowired
- private VirtualCorpusDao virtualCorpusDao;
+ private QueryDao virtualCorpusDao;
@Autowired
private RoleDao roleDao;
@Autowired
@@ -78,11 +78,11 @@
Collections.sort(roleList);
assertEquals(PredefinedRole.USER_GROUP_ADMIN.getId(),
roleList.get(0).getId());
- assertEquals(PredefinedRole.VC_ACCESS_ADMIN.getId(),
+ assertEquals(PredefinedRole.QUERY_ACCESS_ADMIN.getId(),
roleList.get(1).getId());
//retrieve VC by group
- List<VirtualCorpus> vc = virtualCorpusDao.retrieveVCByGroup(groupId);
+ List<QueryDO> vc = virtualCorpusDao.retrieveQueryByGroup(groupId);
assertEquals(0, vc.size());
// soft delete group
@@ -113,7 +113,7 @@
assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(),
sortedRoles.get(0).getName());
- assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(),
+ assertEquals(PredefinedRole.QUERY_ACCESS_MEMBER.name(),
sortedRoles.get(1).getName());
}
@@ -134,26 +134,26 @@
UserGroup group = userGroupDao.retrieveGroupById(groupId);
String createdBy = "dory";
String name = "dory new vc";
- int id = virtualCorpusDao.createVirtualCorpus(name,
+ int id = virtualCorpusDao.createQuery(name,
ResourceType.PROJECT, QueryType.VIRTUAL_CORPUS,
CorpusAccess.PUB, "corpusSigle=WPD15", "", "", "", false,
createdBy, null, null);
- VirtualCorpus virtualCorpus = virtualCorpusDao.retrieveVCById(id);
- userGroupDao.addVCToGroup(virtualCorpus, createdBy,
- VirtualCorpusAccessStatus.ACTIVE, group);
+ QueryDO virtualCorpus = virtualCorpusDao.retrieveQueryById(id);
+ userGroupDao.addQueryToGroup(virtualCorpus, createdBy,
+ QueryAccessStatus.ACTIVE, group);
- List<VirtualCorpus> vc = virtualCorpusDao.retrieveVCByGroup(groupId);
+ List<QueryDO> vc = virtualCorpusDao.retrieveQueryByGroup(groupId);
assertEquals(2, vc.size());
assertEquals(name, vc.get(1).getName());
// delete vc from group
- userGroupDao.deleteVCFromGroup(virtualCorpus.getId(), groupId);
+ userGroupDao.deleteQueryFromGroup(virtualCorpus.getId(), groupId);
- vc = virtualCorpusDao.retrieveVCByGroup(groupId);
+ vc = virtualCorpusDao.retrieveQueryByGroup(groupId);
assertEquals(1, vc.size());
// delete vc
- virtualCorpusDao.deleteVirtualCorpus(virtualCorpus);
+ virtualCorpusDao.deleteQuery(virtualCorpus);
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
index 8b38d7b..6059e2b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
@@ -30,7 +30,7 @@
public void testRetrieveMemberByRole () throws KustvaktException {
// dory group
List<UserGroupMember> vcaAdmins = dao.retrieveMemberByRole(2,
- PredefinedRole.VC_ACCESS_ADMIN.getId());
+ PredefinedRole.QUERY_ACCESS_ADMIN.getId());
// System.out.println(vcaAdmins);
assertEquals(1, vcaAdmins.size());
assertEquals("dory", vcaAdmins.get(0).getUserId());
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
index 006ca9c..bfdb84c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
@@ -12,9 +12,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.QueryAccessStatus;
import de.ids_mannheim.korap.entity.UserGroup;
-import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
+import de.ids_mannheim.korap.entity.QueryAccess;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -22,16 +22,16 @@
public class VirtualCorpusAccessDaoTest {
@Autowired
- private VirtualCorpusAccessDao dao;
+ private QueryAccessDao dao;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void getAccessByVC () throws KustvaktException {
- List<VirtualCorpusAccess> vcaList = dao.retrieveActiveAccessByVC(2);
- VirtualCorpusAccess access = vcaList.get(0);
- assertEquals(VirtualCorpusAccessStatus.ACTIVE, access.getStatus());
+ List<QueryAccess> vcaList = dao.retrieveActiveAccessByQuery(2);
+ QueryAccess access = vcaList.get(0);
+ assertEquals(QueryAccessStatus.ACTIVE, access.getStatus());
assertEquals("dory", access.getCreatedBy());
UserGroup group = access.getUserGroup();
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
index 3294099..10b3eb2 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
@@ -15,25 +15,25 @@
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.user.User;
public class VirtualCorpusDaoTest extends SpringJerseyTest {
@Autowired
- private VirtualCorpusDao dao;
+ private QueryDao dao;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testListVCByType () throws KustvaktException {
- List<VirtualCorpus> vcList =
- dao.retrieveVCByType(ResourceType.PUBLISHED, null, QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> vcList =
+ dao.retrieveQueryByType(ResourceType.PUBLISHED, null, QueryType.VIRTUAL_CORPUS);
assertEquals(1, vcList.size());
- VirtualCorpus vc = vcList.get(0);
+ QueryDO vc = vcList.get(0);
assertEquals(4, vc.getId());
assertEquals("published-vc", vc.getName());
assertEquals("marlin", vc.getCreatedBy());
@@ -42,23 +42,23 @@
@Test
public void testSystemVC () throws KustvaktException {
// insert vc
- int id = dao.createVirtualCorpus("system-vc", ResourceType.SYSTEM,
+ int id = dao.createQuery("system-vc", ResourceType.SYSTEM,
QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
"corpusSigle=GOE", "definition", "description", "experimental",
false, "test class", null, null);
// select vc
- List<VirtualCorpus> vcList =
- dao.retrieveVCByType(ResourceType.SYSTEM, null, QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> vcList =
+ dao.retrieveQueryByType(ResourceType.SYSTEM, null, QueryType.VIRTUAL_CORPUS);
assertEquals(2, vcList.size());
- VirtualCorpus vc = dao.retrieveVCById(id);
+ QueryDO vc = dao.retrieveQueryById(id);
// delete vc
- dao.deleteVirtualCorpus(vc);
+ dao.deleteQuery(vc);
// check if vc has been deleted
thrown.expect(KustvaktException.class);
- dao.retrieveVCById(id);
+ dao.retrieveQueryById(id);
}
@Test
@@ -66,7 +66,7 @@
thrown.expect(PersistenceException.class);
thrown.expectMessage("could not execute statement");
- dao.createVirtualCorpus("system-vc", ResourceType.SYSTEM,
+ dao.createQuery("system-vc", ResourceType.SYSTEM,
QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
"corpusSigle=GOE", "definition", "description", "experimental",
false, "system", null, null);
@@ -74,8 +74,8 @@
@Test
public void retrieveSystemVC () throws KustvaktException {
- List<VirtualCorpus> vc =
- dao.retrieveVCByType(ResourceType.SYSTEM, null, QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> vc =
+ dao.retrieveQueryByType(ResourceType.SYSTEM, null, QueryType.VIRTUAL_CORPUS);
assertEquals(1, vc.size());
}
@@ -86,12 +86,12 @@
*/
@Test
public void retrieveVCByUserDory () throws KustvaktException {
- List<VirtualCorpus> virtualCorpora =
- dao.retrieveVCByUser("dory", QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> virtualCorpora =
+ dao.retrieveQueryByUser("dory", QueryType.VIRTUAL_CORPUS);
// System.out.println(virtualCorpora);
assertEquals(4, virtualCorpora.size());
// ordered by id
- Iterator<VirtualCorpus> i = virtualCorpora.iterator();
+ Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals("dory-vc", i.next().getName());
assertEquals("group-vc", i.next().getName());
assertEquals("system-vc", i.next().getName());
@@ -106,10 +106,10 @@
*/
@Test
public void retrieveVCByUserNemo () throws KustvaktException {
- List<VirtualCorpus> virtualCorpora =
- dao.retrieveVCByUser("nemo", QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> virtualCorpora =
+ dao.retrieveQueryByUser("nemo", QueryType.VIRTUAL_CORPUS);
assertEquals(3, virtualCorpora.size());
- Iterator<VirtualCorpus> i = virtualCorpora.iterator();
+ Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals("group-vc", i.next().getName());
assertEquals("system-vc", i.next().getName());
assertEquals("nemo-vc", i.next().getName());
@@ -123,10 +123,10 @@
*/
@Test
public void retrieveVCByUserMarlin () throws KustvaktException {
- List<VirtualCorpus> virtualCorpora =
- dao.retrieveVCByUser("marlin", QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> virtualCorpora =
+ dao.retrieveQueryByUser("marlin", QueryType.VIRTUAL_CORPUS);
assertEquals(3, virtualCorpora.size());
- Iterator<VirtualCorpus> i = virtualCorpora.iterator();
+ Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals("system-vc", i.next().getName());
assertEquals("published-vc", i.next().getName());
assertEquals("marlin-vc", i.next().getName());
@@ -140,10 +140,10 @@
*/
@Test
public void retrieveVCByUserPearl () throws KustvaktException {
- List<VirtualCorpus> virtualCorpora =
- dao.retrieveVCByUser("pearl", QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> virtualCorpora =
+ dao.retrieveQueryByUser("pearl", QueryType.VIRTUAL_CORPUS);
assertEquals(2, virtualCorpora.size());
- Iterator<VirtualCorpus> i = virtualCorpora.iterator();
+ Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals("system-vc", i.next().getName());
assertEquals("published-vc", i.next().getName());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
index b911877..d019dd2 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
@@ -17,8 +17,8 @@
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.NamedVCLoader;
import de.ids_mannheim.korap.config.SpringJerseyTest;
-import de.ids_mannheim.korap.dao.VirtualCorpusDao;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.dao.QueryDao;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.util.QueryException;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -33,7 +33,7 @@
@Autowired
private NamedVCLoader vcLoader;
@Autowired
- private VirtualCorpusDao dao;
+ private QueryDao dao;
@Test
public void testCachedVCRef ()
@@ -56,8 +56,8 @@
testCachedVCRefWithUsername();
KrillCollection.cache.removeAll();
- VirtualCorpus vc = dao.retrieveVCByName("named-vc1", "system");
- dao.deleteVirtualCorpus(vc);
+ QueryDO vc = dao.retrieveQueryByName("named-vc1", "system");
+ dao.deleteQuery(vc);
}
private void testCachedVCRefWithUsername ()
diff --git a/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java
deleted file mode 100644
index 9590209..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package de.ids_mannheim.korap.service;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-
-@Ignore
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration("classpath:test-config.xml")
-public class QueryReferenceServiceTest {
-
- @Autowired
- private QueryReferenceService qService;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void createQuery () throws KustvaktException {
- qService.storeQuery("{\"@type\":\"koral:token\"}", "new-query", "me" );
- JsonNode json = qService.searchQueryByName("me", "new-query", "me");
- assertEquals("koral:token", json.at("/@type").asText());
- qService.deleteQueryByName("me", "new-query", "me");
- };
-
- @Test
- public void testCreateNonUniqueQuery () throws KustvaktException {
- qService.storeQuery("{\"@type\":\"koral:token\"}", "new-query", "me" );
- thrown.expect(KustvaktException.class);
- qService.storeQuery("{\"@type\":\"koral:token\"}", "new-query", "me" );
- qService.deleteQueryByName("me", "new-query", "me");
- };
-};
diff --git a/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
index 7d1e2f6..529efbd 100644
--- a/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
@@ -16,10 +16,10 @@
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.UserGroupStatus;
import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.dto.VirtualCorpusAccessDto;
-import de.ids_mannheim.korap.dto.VirtualCorpusDto;
+import de.ids_mannheim.korap.dto.QueryAccessDto;
+import de.ids_mannheim.korap.dto.QueryDto;
import de.ids_mannheim.korap.entity.UserGroup;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.web.input.QueryJson;
@@ -28,7 +28,7 @@
public class VirtualCorpusServiceTest {
@Autowired
- private VirtualCorpusService vcService;
+ private QueryService vcService;
@Autowired
private UserGroupService groupService;
@@ -62,12 +62,12 @@
String username = "VirtualCorpusServiceTest";
vcService.storeQuery(vc, vcName, username );
- List<VirtualCorpusAccessDto> accesses =
- vcService.listVCAccessByUsername("admin");
+ List<QueryAccessDto> accesses =
+ vcService.listQueryAccessByUsername("admin");
int size = accesses.size();
- VirtualCorpusAccessDto dto = accesses.get(accesses.size() - 1);
- assertEquals(vcName, dto.getVcName());
+ QueryAccessDto dto = accesses.get(accesses.size() - 1);
+ assertEquals(vcName, dto.getQueryName());
assertEquals("system", dto.getCreatedBy());
assertTrue(dto.getUserGroupName().startsWith("auto"));
@@ -77,10 +77,10 @@
assertEquals(UserGroupStatus.HIDDEN, group.getStatus());
//delete vc
- vcService.deleteVCByName(username, vcName, username);
+ vcService.deleteQueryByName(username, vcName, username);
// check hidden access
- accesses = vcService.listVCAccessByUsername("admin");
+ accesses = vcService.listQueryAccessByUsername("admin");
assertEquals(size-1, accesses.size());
// check hidden group
@@ -95,25 +95,25 @@
int vcId = 2;
String vcName = "group-vc";
- VirtualCorpus existingVC =
- vcService.searchVCByName(username, vcName, username, QueryType.VIRTUAL_CORPUS);
+ QueryDO existingVC =
+ vcService.searchQueryByName(username, vcName, username, QueryType.VIRTUAL_CORPUS);
QueryJson vcJson = new QueryJson();
vcJson.setType(ResourceType.PUBLISHED);
- vcService.editVC(existingVC, vcJson, vcName, username);
+ vcService.editQuery(existingVC, vcJson, vcName, username);
// check VC
- VirtualCorpusDto vcDto = vcService.searchVCById("dory", vcId);
+ QueryDto vcDto = vcService.searchQueryById("dory", vcId);
assertEquals(vcName, vcDto.getName());
assertEquals(ResourceType.PUBLISHED.displayName(),
vcDto.getType());
// check access
- List<VirtualCorpusAccessDto> accesses =
- vcService.listVCAccessByUsername("admin");
+ List<QueryAccessDto> accesses =
+ vcService.listQueryAccessByUsername("admin");
int size = accesses.size();
- VirtualCorpusAccessDto dto = accesses.get(accesses.size() - 1);
- assertEquals(vcName, dto.getVcName());
+ QueryAccessDto dto = accesses.get(accesses.size() - 1);
+ assertEquals(vcName, dto.getQueryName());
assertEquals("system", dto.getCreatedBy());
assertTrue(dto.getUserGroupName().startsWith("auto"));
@@ -127,15 +127,15 @@
vcJson = new QueryJson();
vcJson.setType(ResourceType.PROJECT);
- vcService.editVC(existingVC, vcJson, vcName, username);
+ vcService.editQuery(existingVC, vcJson, vcName, username);
// check VC
- vcDto = vcService.searchVCById("dory", vcId);
+ vcDto = vcService.searchQueryById("dory", vcId);
assertEquals("group-vc", vcDto.getName());
assertEquals(ResourceType.PROJECT.displayName(), vcDto.getType());
// check access
- accesses = vcService.listVCAccessByUsername("admin");
+ accesses = vcService.listQueryAccessByUsername("admin");
assertEquals(size - 1, accesses.size());
thrown.expect(KustvaktException.class);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
index bf78727..059ceee 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
@@ -214,7 +214,7 @@
if (member.at("/userId").asText().equals(memberUsername)) {
assertEquals(3, member.at("/roles").size());
assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(),
- member.at("/roles/0").asText());
+ member.at("/roles/1").asText());
break;
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index a03110d..b5623d6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -244,9 +244,9 @@
assertEquals(username, node.at("/members/0/userId").asText());
assertEquals(GroupMemberStatus.ACTIVE.name(),
node.at("/members/0/status").asText());
- assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(),
+ assertEquals(PredefinedRole.QUERY_ACCESS_ADMIN.name(),
node.at("/members/0/roles/0").asText());
- assertEquals(PredefinedRole.VC_ACCESS_ADMIN.name(),
+ assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(),
node.at("/members/0/roles/1").asText());
testUpdateUserGroup(groupName);
@@ -647,9 +647,9 @@
assertEquals(0, group.at("/members").size());
assertEquals(GroupMemberStatus.ACTIVE.name(),
group.at("/userMemberStatus").asText());
- assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(),
+ assertEquals(PredefinedRole.QUERY_ACCESS_MEMBER.name(),
group.at("/userRoles/0").asText());
- assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(),
+ assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(),
group.at("/userRoles/1").asText());
// unsubscribe marlin from dory-group
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
index e74105c..dbeecf1 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
@@ -18,8 +18,8 @@
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.NamedVCLoader;
import de.ids_mannheim.korap.config.SpringJerseyTest;
-import de.ids_mannheim.korap.dao.VirtualCorpusDao;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
+import de.ids_mannheim.korap.dao.QueryDao;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.util.QueryException;
@@ -31,7 +31,7 @@
@Autowired
private NamedVCLoader vcLoader;
@Autowired
- private VirtualCorpusDao dao;
+ private QueryDao dao;
@Test
public void testRefPredefinedVC ()
@@ -52,10 +52,10 @@
testSearchWithVCRefNotEqual();
KrillCollection.cache.removeAll();
- VirtualCorpus vc = dao.retrieveVCByName("named-vc1", "system");
- dao.deleteVirtualCorpus(vc);
- vc = dao.retrieveVCByName("named-vc2", "system");
- dao.deleteVirtualCorpus(vc);
+ QueryDO vc = dao.retrieveQueryByName("named-vc1", "system");
+ dao.deleteQuery(vc);
+ vc = dao.retrieveQueryByName("named-vc2", "system");
+ dao.deleteQuery(vc);
}
private void testSearchWithoutVCRefOr () throws KustvaktException {
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 666cac3..4b85b4b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -349,9 +349,9 @@
node = testlistAccessByGroup("admin", "");
node = node.get(node.size() - 1);
assertEquals("system", node.at("/createdBy").asText());
- assertEquals(vcName, node.at("/vcName").asText());
+ assertEquals(vcName, node.at("/queryName").asText());
assertTrue(node.at("/userGroupName").asText().startsWith("auto"));
- assertEquals(vcName, node.at("/vcName").asText());
+ assertEquals(vcName, node.at("/queryName").asText());
String groupName = node.at("/userGroupName").asText();
@@ -763,7 +763,7 @@
node = testlistAccessByGroup("admin", "");
assertEquals(4, node.size());
node = node.get(node.size() - 1);
- assertEquals(vcName, node.at("/vcName").asText());
+ assertEquals(vcName, node.at("/queryName").asText());
assertEquals("system", node.at("/createdBy").asText());
assertTrue(node.at("/userGroupName").asText().startsWith("auto"));
@@ -831,8 +831,8 @@
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(1, node.at("/0/accessId").asInt());
- assertEquals(2, node.at("/0/vcId").asInt());
- assertEquals("group-vc", node.at("/0/vcName").asText());
+ assertEquals(2, node.at("/0/queryId").asInt());
+ assertEquals("group-vc", node.at("/0/queryName").asText());
assertEquals(2, node.at("/0/userGroupId").asInt());
assertEquals("dory-group", node.at("/0/userGroupName").asText());
@@ -862,8 +862,8 @@
node = testlistAccessByGroup("marlin", groupName);
assertEquals(2, node.size());
node = node.get(1);
- assertEquals(5, node.at("/vcId").asInt());
- assertEquals(vcName, node.at("/vcName").asText());
+ assertEquals(5, node.at("/queryId").asInt());
+ assertEquals(vcName, node.at("/queryName").asText());
assertEquals(1, node.at("/userGroupId").asInt());
assertEquals(groupName, node.at("/userGroupName").asText());