Implemented publish VC task.
Change-Id: I87ef9042d77036b3640aa2687377d94a99ddb9f5
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedUserGroup.java b/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedUserGroup.java
index 78b39cf..f218ac4 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedUserGroup.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedUserGroup.java
@@ -1,15 +1,21 @@
package de.ids_mannheim.korap.constant;
public enum PredefinedUserGroup {
- ALL("all users");
+ ALL("all users", 1);
private String value;
+ private int id;
- PredefinedUserGroup (String value) {
+ PredefinedUserGroup (String value, int id) {
this.value = value;
+ this.id = id;
}
public String getValue () {
return value;
}
+
+ public int getId () {
+ return id;
+ }
}
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 a1f74e6..cb04594 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
@@ -20,6 +20,7 @@
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PredefinedUserGroup;
import de.ids_mannheim.korap.constant.UserGroupStatus;
import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
import de.ids_mannheim.korap.entity.Role;
@@ -39,8 +40,6 @@
@Repository
public class UserGroupDao {
- public static final String USER_GROUP_ALL = "all";
-
@PersistenceContext
private EntityManager entityManager;
@@ -104,7 +103,20 @@
throws KustvaktException {
UserGroup group = retrieveGroupById(groupId);
group.setName(name);
- entityManager.persist(group);
+ entityManager.merge(group);
+ }
+
+ public UserGroup retrieveAllUserGroup () {
+ CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
+ CriteriaQuery<UserGroup> query =
+ criteriaBuilder.createQuery(UserGroup.class);
+
+ Root<UserGroup> root = query.from(UserGroup.class);
+ query.select(root);
+ query.where(criteriaBuilder.equal(root.get(UserGroup_.id),
+ PredefinedUserGroup.ALL.getId()));
+ Query q = entityManager.createQuery(query);
+ return (UserGroup) q.getSingleResult();
}
/** Retrieves the UserGroup by the given group id. This methods does not
@@ -128,9 +140,8 @@
query.where(criteriaBuilder.equal(root.get(UserGroup_.id), groupId));
Query q = entityManager.createQuery(query);
- UserGroup userGroup;
try {
- userGroup = (UserGroup) q.getSingleResult();
+ return (UserGroup) q.getSingleResult();
}
catch (NoResultException e) {
throw new KustvaktException(StatusCodes.NO_RESULT_FOUND,
@@ -138,7 +149,6 @@
+ groupId,
String.valueOf(groupId), e);
}
- return userGroup;
}
public UserGroup retrieveGroupWithMemberById (int groupId)
@@ -156,9 +166,8 @@
query.where(criteriaBuilder.equal(root.get(UserGroup_.id), groupId));
Query q = entityManager.createQuery(query);
- UserGroup userGroup;
try {
- userGroup = (UserGroup) q.getSingleResult();
+ return (UserGroup) q.getSingleResult();
}
catch (NoResultException e) {
throw new KustvaktException(StatusCodes.NO_RESULT_FOUND,
@@ -166,7 +175,6 @@
+ groupId,
String.valueOf(groupId), e);
}
- return userGroup;
}
/** Retrieves only user-groups that are active (not hidden or deleted).
@@ -199,7 +207,18 @@
query.select(root);
query.where(restrictions);
Query q = entityManager.createQuery(query);
- return q.getResultList();
+
+ try {
+ return q.getResultList();
+ }
+ catch (NoResultException e) {
+ throw new KustvaktException(StatusCodes.NO_RESULT_FOUND,
+ "No result found for query: retrieve group by used id "
+ + userId,
+ userId, e);
+ }
+
+
}
public UserGroup retrieveGroupByName (String groupName)
@@ -216,9 +235,8 @@
criteriaBuilder.equal(root.get(UserGroup_.name), groupName));
Query q = entityManager.createQuery(query);
- UserGroup userGroup;
try {
- userGroup = (UserGroup) q.getSingleResult();
+ return (UserGroup) q.getSingleResult();
}
catch (NoResultException e) {
throw new KustvaktException(StatusCodes.NO_RESULT_FOUND,
@@ -226,7 +244,6 @@
+ groupName,
groupName, e);
}
- return userGroup;
}
// public void retrieveGroupByVCId (String vcId) {
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
new file mode 100644
index 0000000..98e7990
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java
@@ -0,0 +1,106 @@
+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.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.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.utils.ParameterChecker;
+
+@Transactional
+@Repository
+public class VirtualCorpusAccessDao {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ public List<VirtualCorpusAccess> retrieveAccessByVC (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);
+
+ query.select(access);
+ query.where(builder.equal(accessVC.get(VirtualCorpus_.id), vcId));
+ Query 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 boolean hasHiddenAccess (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);
+ List<VirtualCorpusAccess> resultList = q.getResultList();
+ if (resultList.isEmpty()) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ catch (NoResultException e) {
+ return false;
+ }
+ }
+
+ public void addAccessToVC (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);
+ }
+}
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
index 936c56f..a7690d7 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
@@ -11,7 +11,6 @@
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
-import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
@@ -49,7 +48,7 @@
private EntityManager entityManager;
public int createVirtualCorpus (String name, VirtualCorpusType type,
- CorpusAccess requiredAccess, String collectionQuery,
+ CorpusAccess requiredAccess, String corpusQuery,
String definition, String description, String status,
String createdBy) throws KustvaktException {
@@ -57,7 +56,7 @@
vc.setName(name);
vc.setType(type);
vc.setRequiredAccess(requiredAccess);
- vc.setCollectionQuery(collectionQuery);
+ vc.setCorpusQuery(corpusQuery);
vc.setDefinition(definition);
vc.setDescription(description);
vc.setStatus(status);
@@ -69,7 +68,7 @@
public void editVirtualCorpus (VirtualCorpus vc, String name,
VirtualCorpusType type, CorpusAccess requiredAccess,
- String collectionQuery, String definition, String description,
+ String corpusQuery, String definition, String description,
String status) throws KustvaktException {
if (name != null && !name.isEmpty()) {
@@ -81,8 +80,8 @@
if (requiredAccess != null) {
vc.setRequiredAccess(requiredAccess);
}
- if (collectionQuery != null) {
- vc.setCollectionQuery(collectionQuery);
+ if (corpusQuery != null) {
+ vc.setCorpusQuery(corpusQuery);
}
if (definition != null && !definition.isEmpty()) {
vc.setDefinition(definition);
@@ -101,6 +100,7 @@
entityManager.remove(vc);
}
+ // for admins
public List<VirtualCorpus> retrieveVCByType (VirtualCorpusType type)
throws KustvaktException {
ParameterChecker.checkObjectValue(type, "type");
@@ -116,7 +116,6 @@
return q.getResultList();
}
-
public VirtualCorpus retrieveVCById (int id) throws KustvaktException {
ParameterChecker.checkIntegerValue(id, "id");
@@ -142,8 +141,7 @@
return vc;
}
-
- public List<VirtualCorpus> retrievePrivateVC (String userId)
+ public List<VirtualCorpus> retrieveOwnerVC (String userId)
throws KustvaktException {
ParameterChecker.checkStringValue(userId, "userId");
@@ -159,7 +157,29 @@
Query q = entityManager.createQuery(query);
return q.getResultList();
}
+
+ public List<VirtualCorpus> retrieveOwnerVCByType (String userId, VirtualCorpusType 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();
+ }
public List<VirtualCorpus> retrieveGroupVCByUser (String userId)
throws KustvaktException {
@@ -199,7 +219,6 @@
return q.getResultList();
}
-
public Set<VirtualCorpus> retrieveVCByUser (String userId)
throws KustvaktException {
ParameterChecker.checkStringValue(userId, "userId");
@@ -229,6 +248,7 @@
return vcSet;
}
+ // for admins
public List<VirtualCorpus> retrieveVCByGroup (int groupId)
throws KustvaktException {
ParameterChecker.checkIntegerValue(groupId, "groupId");
@@ -238,7 +258,7 @@
builder.createQuery(VirtualCorpus.class);
Root<VirtualCorpus> virtualCorpus = query.from(VirtualCorpus.class);
- ListJoin<VirtualCorpus, VirtualCorpusAccess> corpusAccess =
+ Join<VirtualCorpus, VirtualCorpusAccess> corpusAccess =
virtualCorpus.join(VirtualCorpus_.virtualCorpusAccess);
Join<VirtualCorpusAccess, UserGroup> accessGroup =
corpusAccess.join(VirtualCorpusAccess_.userGroup);
@@ -249,11 +269,4 @@
return q.getResultList();
}
- // EM: what is needed for admin?
- public List<VirtualCorpus> retrieveVirtualCorpusByAdmin () {
- return null;
-
- }
-
-
}
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
index e05f203..66a74a5 100644
--- 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
@@ -23,7 +23,7 @@
dto.setStatus(vc.getStatus());
dto.setDescription(vc.getDescription());
dto.setType(vc.getType().displayName());
- dto.setKoralQuery(vc.getCollectionQuery());
+ dto.setKoralQuery(vc.getCorpusQuery());
JsonNode node = JsonUtils.readTree(statistics);
int numberOfDoc = node.at("/documents").asInt();
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java b/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
index 8413c24..e62af0c 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
@@ -46,8 +46,8 @@
@Enumerated(EnumType.STRING)
@Column(name = "required_access")
private CorpusAccess requiredAccess;
- @Column(name = "collection_query")
- private String collectionQuery;
+ @Column(name = "corpus_query")
+ private String corpusQuery;
private String definition;
@Column(name = "created_by")
private String createdBy;
@@ -59,7 +59,7 @@
public String toString () {
return "id=" + id + ", name= " + name + ", type= " + type + ", status= "
+ status + ", description=" + description + ", requiredAccess="
- + requiredAccess + ", collectionQuery= " + collectionQuery
+ + requiredAccess + ", corpusQuery= " + corpusQuery
+ ", definition= " + definition + ", createdBy= " + createdBy;
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java b/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java
index 873aac7..c3bba6e 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpusAccess.java
@@ -43,12 +43,12 @@
@Enumerated(EnumType.STRING)
private VirtualCorpusAccessStatus status;
- @ManyToOne(fetch=FetchType.LAZY)
+ @ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "virtual_corpus_id",
referencedColumnName = "id")
private VirtualCorpus virtualCorpus;
- @ManyToOne(fetch=FetchType.LAZY)
+ @ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "user_group_id", referencedColumnName = "id")
private UserGroup userGroup;
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 7751988..77c6554 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
@@ -77,7 +77,15 @@
return dtos;
}
-
+
+ public UserGroup retrieveUserGroupById (int groupId)
+ throws KustvaktException {
+ return userGroupDao.retrieveGroupById(groupId);
+ }
+
+ public UserGroup retrieveAllUserGroup () {
+ return userGroupDao.retrieveAllUserGroup();
+ }
/** Group owner is automatically added when creating a group.
* Do not include owners in group members.
@@ -131,7 +139,7 @@
}
public int createAutoHiddenGroup (int vcId) throws KustvaktException {
- String groupName = "auto-group-VC" + vcId;
+ String groupName = "auto-published-group";
int groupId = userGroupDao.createGroup(groupName, "system",
UserGroupStatus.HIDDEN);
@@ -162,4 +170,5 @@
throws KustvaktException {
groupMemberDao.deleteMember(username, groupId, true);
}
+
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
index dee1da7..5f8bed0 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.service;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -14,12 +16,15 @@
import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.constant.PredefinedUserGroup;
+import de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
import de.ids_mannheim.korap.constant.VirtualCorpusType;
+import de.ids_mannheim.korap.dao.VirtualCorpusAccessDao;
import de.ids_mannheim.korap.dao.VirtualCorpusDao;
import de.ids_mannheim.korap.dto.VirtualCorpusDto;
import de.ids_mannheim.korap.dto.converter.VirtualCorpusConverter;
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.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
@@ -34,8 +39,8 @@
import de.ids_mannheim.korap.web.input.VirtualCorpusJson;
/** VirtualCorpusService handles the logic behind {@link VirtualCorpusController}.
- * It communicates with {@link VirtualCorpusDao} and returns DTO to
- * {@link VirtualCorpusController}.
+ * It communicates with {@link VirtualCorpusDao} and returns
+ * {@link VirtualCorpusDto} to {@link VirtualCorpusController}.
*
* @author margaretha
*
@@ -47,7 +52,9 @@
LoggerFactory.getLogger(VirtualCorpusService.class);
@Autowired
- private VirtualCorpusDao dao;
+ private VirtualCorpusDao vcDao;
+ @Autowired
+ private VirtualCorpusAccessDao accessDao;
@Autowired
private UserGroupService userGroupService;
@Autowired
@@ -59,13 +66,12 @@
@Autowired
private VirtualCorpusConverter converter;
- public void storeVC (VirtualCorpusJson vc, String username)
+ public int storeVC (VirtualCorpusJson vc, String username)
throws KustvaktException {
ParameterChecker.checkStringValue(vc.getName(), "name");
ParameterChecker.checkObjectValue(vc.getType(), "type");
- ParameterChecker.checkStringValue(vc.getCollectionQuery(),
- "collectionQuery");
+ ParameterChecker.checkStringValue(vc.getCorpusQuery(), "corpusQuery");
ParameterChecker.checkStringValue(vc.getCreatedBy(), "createdBy");
User user = authManager.getUser(username);
@@ -76,31 +82,25 @@
"Unauthorized operation for user: " + username, username);
}
- String koralQuery = serializeCollectionQuery(vc.getCollectionQuery());
+ String koralQuery = serializeCorpusQuery(vc.getCorpusQuery());
CorpusAccess requiredAccess = determineRequiredAccess(koralQuery);
- int vcId = dao.createVirtualCorpus(vc.getName(), vc.getType(),
+ int vcId = vcDao.createVirtualCorpus(vc.getName(), vc.getType(),
requiredAccess, koralQuery, vc.getDefinition(),
vc.getDescription(), vc.getStatus(), vc.getCreatedBy());
- // EM: how about VirtualCorpusType.PUBLISHED?
- // if (vc.getType() != null
- // && vc.getType().equals(VirtualCorpusType.PUBLISHED)) {
- // int groupId = userGroupService.createAutoHiddenGroup(vcId);
- // UserGroup allUserGroup = userGroupDao
- // .retrieveGroupByName(PredefinedUserGroup.ALL.getValue());
- // int allUserGroupId = allUserGroup.getId();
- // // add access to VC for all and auto-group
- // }
-
+ if (vc.getType().equals(VirtualCorpusType.PUBLISHED)) {
+ publishVC(vcId);
+ }
// EM: should this return anything?
+ return vcId;
}
public void editVC (VirtualCorpusJson vcJson, String username)
throws KustvaktException {
ParameterChecker.checkIntegerValue(vcJson.getId(), "id");
- VirtualCorpus vc = dao.retrieveVCById(vcJson.getId());
+ VirtualCorpus vc = vcDao.retrieveVCById(vcJson.getId());
User user = authManager.getUser(username);
@@ -111,31 +111,57 @@
String koralQuery = null;
CorpusAccess requiredAccess = null;
- if (vcJson.getCollectionQuery() != null
- && vcJson.getCollectionQuery().isEmpty()) {
- koralQuery = serializeCollectionQuery(vcJson.getCollectionQuery());
+ if (vcJson.getCorpusQuery() != null
+ && vcJson.getCorpusQuery().isEmpty()) {
+ koralQuery = serializeCorpusQuery(vcJson.getCorpusQuery());
requiredAccess = determineRequiredAccess(koralQuery);
}
- dao.editVirtualCorpus(vc, vcJson.getName(), vcJson.getType(), requiredAccess,
- koralQuery, vcJson.getDefinition(), vcJson.getDescription(),
- vcJson.getStatus());
-
- vc = dao.retrieveVCById(vcJson.getId());
+ vcDao.editVirtualCorpus(vc, vcJson.getName(), vcJson.getType(),
+ requiredAccess, koralQuery, vcJson.getDefinition(),
+ vcJson.getDescription(), vcJson.getStatus());
+ if (!vc.getType().equals(VirtualCorpusType.PUBLISHED)
+ && vcJson.getType() != null
+ && vcJson.getType().equals(VirtualCorpusType.PUBLISHED)) {
+ publishVC(vcJson.getId());
+ }
}
- private String serializeCollectionQuery (String collectionQuery)
+ private void publishVC (int vcId) throws KustvaktException {
+
+ // check if hidden access exists
+ if (!accessDao.hasHiddenAccess(vcId)) {
+ // assign hidden access for all users
+ VirtualCorpus vc = vcDao.retrieveVCById(vcId);
+ UserGroup all = userGroupService.retrieveAllUserGroup();
+ accessDao.addAccessToVC(vc, all, "system",
+ VirtualCorpusAccessStatus.HIDDEN);
+
+ // create and assign a hidden group
+ int groupId = userGroupService.createAutoHiddenGroup(vcId);
+ UserGroup autoHidden =
+ userGroupService.retrieveUserGroupById(groupId);
+ accessDao.addAccessToVC(vc, autoHidden, "system",
+ VirtualCorpusAccessStatus.HIDDEN);
+ }
+ else {
+ jlog.error("Cannot publish VC with id: " + vcId
+ + ". There have been hidden accesses for the VC already.");
+ }
+ }
+
+ private String serializeCorpusQuery (String corpusQuery)
throws KustvaktException {
QuerySerializer serializer = new QuerySerializer();
- serializer.setCollection(collectionQuery);
+ serializer.setCollection(corpusQuery);
String koralQuery;
try {
koralQuery = serializer.convertCollectionToJson();
}
catch (JsonProcessingException e) {
throw new KustvaktException(StatusCodes.INVALID_ARGUMENT,
- "Invalid argument: " + collectionQuery, collectionQuery);
+ "Invalid argument: " + corpusQuery, corpusQuery);
}
jlog.debug(koralQuery);
return koralQuery;
@@ -169,14 +195,26 @@
return (numberOfDoc > 0) ? true : false;
}
- public List<VirtualCorpusDto> retrieveUserVC (String username)
+ public List<VirtualCorpusDto> listOwnerVC (String username)
throws KustvaktException {
+ List<VirtualCorpus> vcList = vcDao.retrieveOwnerVC(username);
+ return createVCDtos(vcList);
+ }
- Set<VirtualCorpus> vcs = dao.retrieveVCByUser(username);
- ArrayList<VirtualCorpusDto> dtos = new ArrayList<>(vcs.size());
+ public List<VirtualCorpusDto> listVCByUser (String username)
+ throws KustvaktException {
+ Set<VirtualCorpus> vcSet = vcDao.retrieveVCByUser(username);
+ return createVCDtos(vcSet);
+ }
- for (VirtualCorpus vc : vcs) {
- String json = vc.getCollectionQuery();
+ private ArrayList<VirtualCorpusDto> createVCDtos (
+ Collection<VirtualCorpus> vcList) throws KustvaktException {
+ ArrayList<VirtualCorpusDto> dtos = new ArrayList<>(vcList.size());
+ VirtualCorpus vc;
+ Iterator<VirtualCorpus> i = vcList.iterator();
+ while (i.hasNext()) {
+ vc = i.next();
+ String json = vc.getCorpusQuery();
String statistics = krill.getStatistics(json);
VirtualCorpusDto vcDto =
converter.createVirtualCorpusDto(vc, statistics);
@@ -188,8 +226,6 @@
/** Only admin and the owner of the virtual corpus are allowed to
* delete a virtual corpus.
*
- * EM: are VC-access admins also allowed to delete?
- *
* @param username username
* @param vcId virtual corpus id
* @throws KustvaktException
@@ -197,14 +233,19 @@
public void deleteVC (String username, int vcId) throws KustvaktException {
User user = authManager.getUser(username);
- VirtualCorpus vc = dao.retrieveVCById(vcId);
+ VirtualCorpus vc = vcDao.retrieveVCById(vcId);
if (user.isAdmin() || vc.getCreatedBy().equals(username)) {
- dao.deleteVirtualCorpus(vcId);
+ vcDao.deleteVirtualCorpus(vcId);
}
else {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
"Unauthorized operation for user: " + username, username);
}
}
+
+ public List<VirtualCorpusAccess> retrieveVCAccess (int vcId)
+ throws KustvaktException {
+ return accessDao.retrieveAccessByVC(vcId);
+ }
}
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 ada1c8f..2e018fe 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
@@ -112,13 +112,35 @@
*/
@GET
@Path("list")
- public Response getUserVC (@Context SecurityContext securityContext) {
+ public Response listVCByUser (@Context SecurityContext securityContext) {
String result;
TokenContext context =
(TokenContext) securityContext.getUserPrincipal();
try {
List<VirtualCorpusDto> dtos =
- service.retrieveUserVC(context.getUsername());
+ service.listVCByUser(context.getUsername());
+ result = JsonUtils.toJSON(dtos);
+ }
+ catch (KustvaktException e) {
+ throw responseHandler.throwit(e);
+ }
+ return Response.ok(result).build();
+ }
+
+ /** Lists all VCs created by a user
+ *
+ * @param securityContext
+ * @return a list of VCs created by the user in the security context.
+ */
+ @GET
+ @Path("list/user")
+ public Response listUserVC (@Context SecurityContext securityContext) {
+ String result;
+ TokenContext context =
+ (TokenContext) securityContext.getUserPrincipal();
+ try {
+ List<VirtualCorpusDto> dtos =
+ service.listOwnerVC(context.getUsername());
result = JsonUtils.toJSON(dtos);
}
catch (KustvaktException e) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java b/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java
index 7038690..2c8b35a 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java
@@ -4,7 +4,6 @@
import de.ids_mannheim.korap.constant.VirtualCorpusType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.service.VirtualCorpusService;
-import de.ids_mannheim.korap.utils.ParameterChecker;
import de.ids_mannheim.korap.web.controller.VirtualCorpusController;
import lombok.Getter;
import lombok.Setter;
@@ -23,7 +22,7 @@
// required in creating VCs
private String name;
private VirtualCorpusType type;
- private String collectionQuery;
+ private String corpusQuery;
private String createdBy;
// required in editing VCs
@@ -35,9 +34,9 @@
private String status;
- public void setCollectionQuery (String collectionQuery)
+ public void setCorpusQuery (String corpusQuery)
throws KustvaktException {
- this.collectionQuery = collectionQuery;
+ this.corpusQuery = corpusQuery;
}
}
\ No newline at end of file
diff --git a/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql b/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql
index d613460..82ee835 100644
--- a/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql
+++ b/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql
@@ -43,19 +43,19 @@
-- virtual corpora
-INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, collection_query)
+INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, corpus_query)
VALUES ("dory VC", "PRIVATE", "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, required_access, created_by, description, status, collection_query)
+INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, corpus_query)
VALUES ("group VC", "PROJECT", "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, required_access, created_by, description, status, collection_query)
+INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, corpus_query)
VALUES ("system VC", "PREDEFINED", "ALL", "system", "test vc", "experimental",
'{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
-INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, collection_query)
+INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, corpus_query)
VALUES ("published VC", "PUBLISHED", "ALL", "marlin", "test vc", "experimental",
'{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
diff --git a/full/src/main/resources/db/new-mysql/V1.1__create_virtual_corpus_tables.sql b/full/src/main/resources/db/new-mysql/V1.1__create_virtual_corpus_tables.sql
index 328e13e..a8df972 100644
--- a/full/src/main/resources/db/new-mysql/V1.1__create_virtual_corpus_tables.sql
+++ b/full/src/main/resources/db/new-mysql/V1.1__create_virtual_corpus_tables.sql
@@ -60,7 +60,7 @@
created_by varchar(100) NOT NULL,
description varchar(255) DEFAULT NULL,
status varchar(100) DEFAULT NULL,
- collection_query varchar(2000) NOT NULL,
+ corpus_query varchar(2000) NOT NULL,
definition varchar(255) DEFAULT NULL,
INDEX owner_index (created_by),
INDEX type_index (type)
diff --git a/full/src/main/resources/db/new-sqlite/V1.1__create_virtual_corpus_tables.sql b/full/src/main/resources/db/new-sqlite/V1.1__create_virtual_corpus_tables.sql
index 91b01a7..8476535 100644
--- a/full/src/main/resources/db/new-sqlite/V1.1__create_virtual_corpus_tables.sql
+++ b/full/src/main/resources/db/new-sqlite/V1.1__create_virtual_corpus_tables.sql
@@ -69,7 +69,7 @@
created_by varchar(100) NOT NULL,
description varchar(255) DEFAULT NULL,
status varchar(100) DEFAULT NULL,
- collection_query varchar(2000) NOT NULL,
+ corpus_query varchar(2000) NOT NULL,
definition varchar(255) DEFAULT NULL
);
diff --git a/full/src/main/resources/db/predefined/V3.0__insert_predefined_user_groups.sql b/full/src/main/resources/db/predefined/V3.0__insert_predefined_user_groups.sql
index ba34c4e..9dc9e52 100644
--- a/full/src/main/resources/db/predefined/V3.0__insert_predefined_user_groups.sql
+++ b/full/src/main/resources/db/predefined/V3.0__insert_predefined_user_groups.sql
@@ -1,3 +1,3 @@
-INSERT INTO user_group(name,status,created_by)
- VALUES ("all users","HIDDEN","system");
\ No newline at end of file
+INSERT INTO user_group(id,name,status,created_by)
+ VALUES (1,"all users","HIDDEN","system");
\ No newline at end of file
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
new file mode 100644
index 0000000..3d538af
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
@@ -0,0 +1,40 @@
+package de.ids_mannheim.korap.dao;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+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 de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.entity.UserGroup;
+import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:test-config.xml")
+public class VirtualCorpusAccessDaoTest {
+
+ @Autowired
+ private VirtualCorpusAccessDao dao;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void getAccessByVC () throws KustvaktException {
+ List<VirtualCorpusAccess> vcaList = dao.retrieveAccessByVC(2);
+ VirtualCorpusAccess access = vcaList.get(0);
+ assertEquals(VirtualCorpusAccessStatus.ACTIVE, access.getStatus());
+ assertEquals("dory", access.getCreatedBy());
+
+ UserGroup group = access.getUserGroup();
+ assertEquals(2, group.getId());
+ }
+}
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 4ec7314..199753a 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
@@ -34,7 +34,7 @@
List<VirtualCorpus> vcList =
dao.retrieveVCByType(VirtualCorpusType.PUBLISHED);
assertEquals(1, vcList.size());
-
+
VirtualCorpus vc = vcList.get(0);
assertEquals(4, vc.getId());
assertEquals("published VC", vc.getName());
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java
index 90ff26d..b3d134c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/DemoUserTest.java
@@ -6,7 +6,7 @@
import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* EM: DemoUser is not saved in the new DB
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/PublicAPITest.java b/full/src/test/java/de/ids_mannheim/korap/misc/PublicAPITest.java
index 784d755..2e895aa 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/PublicAPITest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/PublicAPITest.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.misc;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
+
import org.junit.BeforeClass;
import org.junit.Test;
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
new file mode 100644
index 0000000..ed585f1
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
@@ -0,0 +1,44 @@
+package de.ids_mannheim.korap.service;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+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 de.ids_mannheim.korap.constant.VirtualCorpusAccessStatus;
+import de.ids_mannheim.korap.constant.VirtualCorpusType;
+import de.ids_mannheim.korap.dto.UserGroupDto;
+import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.web.input.VirtualCorpusJson;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:test-config.xml")
+public class VirtualCorpusServiceTest {
+
+ @Autowired
+ private VirtualCorpusService vcService;
+
+ @Test
+ public void createPublishVC () throws KustvaktException {
+
+ VirtualCorpusJson vc = new VirtualCorpusJson();
+ vc.setCorpusQuery("corpusSigle=GOE");
+ vc.setCreatedBy("VirtualCorpusServiceTest");
+ vc.setName("new published vc");
+ vc.setType(VirtualCorpusType.PUBLISHED);
+ int vcId = vcService.storeVC(vc, "VirtualCorpusServiceTest");
+
+ List<VirtualCorpusAccess> accesses = vcService.retrieveVCAccess(vcId);
+ assertEquals(2, accesses.size());
+ for (VirtualCorpusAccess access : accesses) {
+ assertEquals(VirtualCorpusAccessStatus.HIDDEN, access.getStatus());
+ }
+ }
+
+}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java b/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
similarity index 92%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
index c1a187e..aa7657a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/FastJerseyTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service;
+package de.ids_mannheim.korap.web;
import java.util.concurrent.ThreadLocalRandom;
@@ -6,6 +6,7 @@
import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.web.service.FastJerseyBaseTest;
public abstract class FastJerseyTest extends FastJerseyBaseTest {
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java b/full/src/test/java/de/ids_mannheim/korap/web/FilterTest.java
similarity index 95%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/FilterTest.java
index 7f3b33b..7dcfa32 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/FilterTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web;
import static org.junit.Assert.assertEquals;
@@ -16,7 +16,6 @@
import de.ids_mannheim.korap.config.TokenType;
import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
/** EM: fix tests. new DB does not save users.
* @author hanl
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java
index 9d8fa86..52c266e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service;
+package de.ids_mannheim.korap.web;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java b/full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java
index c08c247..34dd3be 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service;
+package de.ids_mannheim.korap.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
similarity index 96%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
index 26bbfa5..79aa8fe 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AuthenticationControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -24,7 +24,7 @@
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* EM: fix tests. New DB does not save users.
@@ -32,7 +32,7 @@
* @date 24/09/2015
*/
@Ignore
-public class AuthServiceTest extends FastJerseyTest {
+public class AuthenticationControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/KustvaktCoreRestTest.java
similarity index 96%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/KustvaktCoreRestTest.java
index ca0adf2..324ed0e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/KustvaktCoreRestTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import org.junit.Ignore;
import org.junit.Test;
@@ -7,7 +7,7 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author hanl
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
similarity index 95%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
index 6d997b7..11a3193 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -16,9 +16,9 @@
import de.ids_mannheim.korap.config.TokenType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
-public class MatchInfoServiceTest extends FastJerseyTest {
+public class MatchInfoControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2EndpointTest.java
similarity index 97%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2EndpointTest.java
index 9d9f735..4cf05dc 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2EndpointTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
@@ -20,7 +20,7 @@
import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author hanl
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/PolicyServiceTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/PolicyServiceTest.java
index 1714ae1..708259a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/PolicyServiceTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
@@ -27,7 +27,7 @@
import de.ids_mannheim.korap.security.SecurityPolicy;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.user.User.UserFactory;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/** Not in the new DB
* @author margaretha
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
similarity index 97%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
index ea6ace6..138ca08 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
/**
* @author hanl, margaretha
@@ -24,12 +24,12 @@
import de.ids_mannheim.korap.config.TokenType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/* EM: potentially an unused service! */
@Ignore
-public class QuerySerializationServiceTest extends FastJerseyTest {
+public class QuerySerializationControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceControllerTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceControllerTest.java
index ec5657e..ef47198 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -25,7 +25,7 @@
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author hanl, margaretha
@@ -34,7 +34,7 @@
*/
@Ignore
@Deprecated
-public class ResourceServiceTest extends FastJerseyTest {
+public class ResourceControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
similarity index 97%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
index c2ac7bb..2a43ec4 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -17,14 +17,14 @@
import de.ids_mannheim.korap.config.TokenType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author hanl, margaretha
* @lastUpdate 19/04/2017
* EM: FIX ME: Database restructure
*/
@Ignore
-public class ResourceInfoServiceTest extends FastJerseyTest {
+public class ResourceInfoControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceRemoteApiTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceRemoteApiTest.java
similarity index 78%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceRemoteApiTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceRemoteApiTest.java
index 95d7470..4fc436f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceRemoteApiTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceRemoteApiTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import org.junit.Test;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index 0ede615..2f2eb57 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -29,14 +29,14 @@
import de.ids_mannheim.korap.security.ac.ResourceFinder;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author hanl, margaretha
* @lastUpdate 30/05/2017
*
*/
-public class SearchServiceTest extends FastJerseyTest {
+public class SearchControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
@@ -150,6 +150,7 @@
response.getStatus());
String entity = response.getEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
+ System.out.println(entity);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
assertEquals("koral:docGroup", node.at("/collection/@type").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchWithAvailabilityTest.java
similarity index 99%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/SearchWithAvailabilityTest.java
index dad8f99..73e6880 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchWithAvailabilityTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -17,7 +17,7 @@
import de.ids_mannheim.korap.config.TokenType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
public class SearchWithAvailabilityTest extends FastJerseyTest {
@Autowired
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
similarity index 96%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
index 4dd4fb9..eee4016 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import java.io.IOException;
@@ -11,14 +11,14 @@
import com.sun.jersey.api.client.ClientResponse;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/**
* @author margaretha
* @date 27/09/2017
*
*/
-public class StatisticsServiceTest extends FastJerseyTest {
+public class StatisticsControllerTest extends FastJerseyTest {
private ObjectMapper mapper = new ObjectMapper();
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
index 9fbf0be..3cb66f2 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -34,7 +34,7 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import de.ids_mannheim.korap.web.FastJerseyTest;
/** EM: To do: not implemented in the new DB yet
* @author hanl
@@ -44,7 +44,7 @@
// todo: do benchmarks for simple request to check access_token check and user
// retrieval!
@Ignore
-public class UserServiceTest extends FastJerseyTest {
+public class UserControllerTest extends FastJerseyTest {
@Autowired
HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserGroupServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
similarity index 98%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/UserGroupServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index 5a975a6..e59e6b5 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserGroupServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
@@ -21,7 +21,7 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
-public class UserGroupServiceTest extends SpringJerseyTest {
+public class UserGroupControllerTest extends SpringJerseyTest {
@Autowired
private HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
similarity index 85%
rename from full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 0e02f2b..32fa94a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service.full;
+package de.ids_mannheim.korap.web.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -27,13 +27,11 @@
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.AuthenticationScheme;
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.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
-public class VirtualCorpusServiceTest extends SpringJerseyTest {
+public class VirtualCorpusControllerTest extends SpringJerseyTest {
@Autowired
private HttpAuthorizationHandler handler;
@@ -94,10 +92,53 @@
}
@Test
+ public void testCreatePublishVC () throws KustvaktException {
+ String json =
+ "{\"name\": \"new published vc\",\"type\": \"PUBLISHED\",\"createdBy\": "
+ + "\"test class\",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ ClientResponse response = resource().path("vc").path("create")
+ .header(Attributes.AUTHORIZATION,
+ handler.createBasicAuthorizationHeaderValue(
+ "test class", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .post(ClientResponse.class, json);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ // test list owner vc
+ response = resource().path("vc").path("list").path("user")
+ .header(Attributes.AUTHORIZATION,
+ handler.createBasicAuthorizationHeaderValue(
+ "test class", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+
+ .get(ClientResponse.class);
+
+ String entity = response.getEntity(String.class);
+ System.out.println(entity);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(1, node.size());
+ assertEquals("new published vc", node.get(0).get("name").asText());
+ // cannot explicitly checked hidden groups here
+
+ String vcId = node.get(0).get("id").asText();
+
+ // delete vc
+ resource().path("vc").path("delete").queryParam("vcId", vcId)
+ .header(Attributes.AUTHORIZATION,
+ handler.createBasicAuthorizationHeaderValue(
+ "test class", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+
+ .delete(ClientResponse.class);
+ }
+
+ @Test
public void testCreateDeleteVC () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"corpusSigle=GOE\"}";
+ + "\"test class\",\"corpusQuery\": \"corpusSigle=GOE\"}";
ClientResponse response = resource().path("vc").path("create")
.header(Attributes.AUTHORIZATION,
@@ -158,7 +199,7 @@
throws IOException, KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"corpusSigle=GOE\"}";
+ + "\"test class\",\"corpusQuery\": \"corpusSigle=GOE\"}";
InputStream is = getClass().getClassLoader()
.getResourceAsStream("test-user.token");
@@ -189,7 +230,7 @@
public void testCreateVCUnauthorized () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"creationDate since 1820\"}";
+ + "\"test class\",\"corpusQuery\": \"creationDate since 1820\"}";
ClientResponse response = resource().path("vc").path("create")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
@@ -208,7 +249,7 @@
}
@Test
- public void testCreateVCWithoutCollectionQuery () throws KustvaktException {
+ public void testCreateVCWithoutcorpusQuery () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
+ "\"test class\"}";
@@ -226,14 +267,14 @@
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
- assertEquals("collectionQuery", node.at("/errors/0/1").asText());
+ assertEquals("corpusQuery", node.at("/errors/0/1").asText());
assertEquals("null", node.at("/errors/0/2").asText());
}
@Test
public void testCreateVCWithoutType () throws KustvaktException {
String json = "{\"name\": \"new vc\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"creationDate since 1820\"}";
+ + "\"test class\",\"corpusQuery\": \"creationDate since 1820\"}";
ClientResponse response = resource().path("vc").path("create")
.header(Attributes.AUTHORIZATION,
@@ -256,7 +297,7 @@
public void testCreateVCWithWrongType () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVAT\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"creationDate since 1820\"}";
+ + "\"test class\",\"corpusQuery\": \"creationDate since 1820\"}";
ClientResponse response = resource().path("vc").path("create")
.header(Attributes.AUTHORIZATION,
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
deleted file mode 100644
index 1466056..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
+++ /dev/null
@@ -1,371 +0,0 @@
-package de.ids_mannheim.korap.web.service.full;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.UUID;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClients;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.BeanConfigTest;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.handlers.ResourceDao;
-import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.resources.Permissions.Permission;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.utils.JsonUtils;
-
-/**
- * This class tests services of a running Kustvakt server with a MySQL
- * database.
- * Please check the database configuration in
- * src/main/resources/jdbc.properties
- * and run the server before running the tests.
- *
- * See {@link ResourceServiceTest} for tests using an in-memory
- * database.
- *
- * @author margaretha
- *
- */
-@Ignore
-@Deprecated
-public class KustvaktServerTest extends BeanConfigTest {
- private static ObjectMapper mapper = new ObjectMapper();
- @Autowired
- private HttpAuthorizationHandler handler;
-
-
- @Test
- public void testRegisterBadPassword ()
- throws URISyntaxException, ClientProtocolException, IOException, KustvaktException {
- HttpClient httpClient = HttpClients.createDefault();
-
- MultivaluedMap<String, String> map = new MultivaluedMapImpl();
- map.putSingle("username", "kusvakt");
- map.putSingle("email", "kustvakt@ids-mannheim.de");
- map.putSingle("password", "password");
- map.putSingle("firstName", "kustvakt");
- map.putSingle("lastName", "user");
- map.putSingle("address", "Mannheim");
-
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/user/register");
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
- StringEntity entity = new StringEntity(JsonUtils.toJSON(map));
- httppost.setEntity(entity);
- httppost.addHeader(HttpHeaders.CONTENT_TYPE,
- MediaType.APPLICATION_JSON);
- httppost.addHeader(HttpHeaders.USER_AGENT, "Apache HTTP Client");
- httppost.addHeader(HttpHeaders.HOST, "localhost");
-
- HttpResponse response = httpClient.execute(httppost);
- assertEquals(ClientResponse.Status.NOT_ACCEPTABLE.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- HttpEntity responseEntity = response.getEntity();
- JsonNode errorNode = mapper.readTree(responseEntity.getContent());
- assertEquals(
- "[The value for the parameter password is not valid or acceptable.]",
- errorNode.get("errors").get(0).get(2).asText());
-
- }
-
-
- @Test
- public void testRegisterExistingUsername ()
- throws URISyntaxException, ClientProtocolException, IOException, KustvaktException {
- HttpClient httpClient = HttpClients.createDefault();
-
- MultivaluedMap<String, String> map = new MultivaluedMapImpl();
- map.putSingle("username", "kustvakt");
- map.putSingle("email", "kustvakt@ids-mannheim.de");
- map.putSingle("password", "password1234");
- map.putSingle("firstName", "kustvakt");
- map.putSingle("lastName", "user");
- map.putSingle("address", "Mannheim");
-
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/user/register");
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
- StringEntity entity = new StringEntity(JsonUtils.toJSON(map));
- httppost.setEntity(entity);
- httppost.addHeader(HttpHeaders.CONTENT_TYPE,
- MediaType.APPLICATION_JSON);
- httppost.addHeader(HttpHeaders.USER_AGENT, "Apache HTTP Client");
- httppost.addHeader(HttpHeaders.HOST, "localhost");
-
- HttpResponse response = httpClient.execute(httppost);
- assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- HttpEntity responseEntity = response.getEntity();
- JsonNode errorNode = mapper.readTree(responseEntity.getContent());
- assertEquals(
- "[The value for the parameter password is not valid or acceptable.]",
- errorNode.get("errors").asText());
- }
-
-
- @Test
- public void testRegisterUser ()
- throws URISyntaxException, ClientProtocolException, IOException, KustvaktException {
- HttpClient httpClient = HttpClients.createDefault();
-
- MultivaluedMap<String, String> map = new MultivaluedMapImpl();
- map.putSingle("username", "testUser");
- map.putSingle("email", "testUser@ids-mannheim.de");
- map.putSingle("password", "testPassword1234");
- map.putSingle("firstName", "test");
- map.putSingle("lastName", "user");
- map.putSingle("address", "Mannheim");
-
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/user/register");
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
- StringEntity entity = new StringEntity(JsonUtils.toJSON(map));
- httppost.setEntity(entity);
- httppost.addHeader(HttpHeaders.CONTENT_TYPE,
- MediaType.APPLICATION_JSON);
- httppost.addHeader(HttpHeaders.USER_AGENT, "Apache HTTP Client");
- httppost.addHeader(HttpHeaders.HOST, "localhost");
-
- HttpResponse response = httpClient.execute(httppost);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- }
-
-
- @Test
- public void testCreatePolicy () throws IOException, URISyntaxException, KustvaktException {
-
- HttpClient httpClient = HttpClients.createDefault();
-
- String id = UUID.randomUUID().toString();
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/admin/createPolicies/" + id)
- .setParameter("type", "virtualcollection")
- .setParameter("name", "Goethe VC")
- .setParameter("description", "Goethe corpus")
- .setParameter("group", "public")
- .setParameter("perm", Permission.READ.name())
- .setParameter("loc", "").setParameter("expire", "");
-
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
-
- httppost.addHeader(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"));
- HttpResponse response = httpClient.execute(httppost);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- }
-
-
- @Test
- public void testCreatePolicyForFoundry ()
- throws IOException, URISyntaxException, KustvaktException {
-
- HttpClient httpClient = HttpClients.createDefault();
-
- String id = UUID.randomUUID().toString();
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/admin/createPolicies/" + id)
- .setParameter("type", "foundry")
- .setParameter("name", "stanford")
- .setParameter("description", "stanford parser")
- .setParameter("group", "public")
- .setParameter("perm", Permission.READ.name())
- .setParameter("loc", "255.255.255.0")
- .setParameter("expire", "30D");
-
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
-
- httppost.addHeader(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"));
- HttpResponse response = httpClient.execute(httppost);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- }
-
-
- @Test
- public void testCreatePolicyWithMultiplePermissions ()
- throws IOException, URISyntaxException, KustvaktException {
-
- HttpClient httpClient = HttpClients.createDefault();
-
- String id = UUID.randomUUID().toString();
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/admin/createPolicies/" + id)
- .setParameter("type", "corpus").setParameter("name", "Brown")
- .setParameter("description", "Brown corpus")
- .setParameter("group", "public")
- .setParameter("perm", Permission.READ.name())
- .setParameter("perm", Permission.WRITE.name())
- .setParameter("perm", Permission.DELETE.name())
- .setParameter("loc", "255.255.255.0")
- .setParameter("expire", "30D");
-
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
-
- httppost.addHeader(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"));
- HttpResponse response = httpClient.execute(httppost);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- }
-
-
- @Test
- public void testWrongAuthorization ()
- throws IOException, URISyntaxException, KustvaktException {
- HttpResponse response = testResourceStore("wezrowerowj");
- assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
- response.getStatusLine().getStatusCode());
- }
-
-
- @Test
- public void testCorrectAuthorization ()
- throws IOException, URISyntaxException, KustvaktException {
-
- HttpResponse response = testResourceStore("kustvakt2015");
- HttpEntity entity = response.getEntity();
- String content = null;
-
- if (entity != null) {
- InputStream is = entity.getContent();
- try {
- content = IOUtils.toString(is, "UTF-8");
- }
- finally {
- is.close();
- }
- }
-
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
- JsonNode node = JsonUtils.readTree(content);
- assertNotNull(node);
- assertTrue(node.isObject());
- assertEquals("Goethe", node.path("name").asText());
- assertEquals("Goethe corpus", node.path("description").asText());
- }
-
-
- public HttpResponse testResourceStore (String password)
- throws IOException, URISyntaxException, KustvaktException {
-
- HttpClient httpclient = HttpClients.createDefault();
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- .setPath("/api/v0.1/virtualcollection")
- .setParameter("filter", "httpclient")
- .setParameter("name", "Goethe")
- .setParameter("description", "Goethe corpus");
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
- httppost.addHeader(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", password));
- return httpclient.execute(httppost);
-
- }
-
- @Test
- public void testResourceUpdate ()
- throws IOException, URISyntaxException, KustvaktException {
-
- HttpClient httpclient = HttpClients.createDefault();
- URIBuilder builder = new URIBuilder();
- builder.setScheme("http").setHost("localhost").setPort(8089)
- //.setPath("/api/v0.1/virtualcollection/00df953b-2227-4c23-84c1-5532c07bf8ce")
- .setPath("/api/v0.1/virtualcollection/GOE-VC")
- .setParameter("name", "Goethe collection")
- .setParameter("description", "Goethe collection");
- URI uri = builder.build();
- HttpPost httppost = new HttpPost(uri);
- httppost.addHeader(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"));
- HttpResponse response = httpclient.execute(httppost);
-
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatusLine().getStatusCode());
-
-// assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
-// response.getStatusLine().getStatusCode());
-
-// JsonNode errorNode = mapper.readTree(response.getEntity().getContent());
-// assertEquals(
-// "Resource not found!",
-// errorNode.get("errors").get(0).get(1).asText());
-
- }
-
-
- private void checkResourceInDB (String id) throws KustvaktException {
-
- ResourceDao<?> dao = new ResourceDao<>(
- helper().getContext().getPersistenceClient());
- assertEquals("sqlite",
- helper().getContext().getPersistenceClient().getDatabase());
-
- assertNotEquals(0, dao.size());
- KustvaktResource res = dao.findbyId(id, User.UserFactory.getDemoUser());
- assertNotNull(res);
- Assert.assertEquals(true,
- res.getField("testVar").toString().startsWith("testVal_"));
- }
-
-
- @Override
- public void initMethod () throws KustvaktException {
- // TODO Auto-generated method stub
-
- }
-}