Merge branch 'master' of ssh://korap.ids-mannheim.de:29418/private/Kustvakt-core
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index 7976ad5..90437df 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -4,7 +4,7 @@
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
<name>Kustvakt core</name>
- <version>0.56</version>
+ <version>0.58</version>
<description>Kustvakt core, basic rest api for testing purposes and default
interfaces</description>
<build>
@@ -70,7 +70,7 @@
<exclude>**/*APITest.java</exclude>
</excludes>
<includes>
- <include>**/*.java</include>
+ <include>de.ids_mannheim.korap.**/*.java</include>
</includes>
</configuration>
</plugin>
diff --git a/pom.xml b/pom.xml
index 52043a2..4876e67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
- <version>0.56</version>
+ <version>0.58</version>
<packaging>jar</packaging>
<name>Kustvakt core</name>
<description>Kustvakt core, basic rest api for testing purposes and default
@@ -149,7 +149,7 @@
<exclude>**/*APITest.java</exclude>
</excludes>
<includes>
- <include>**/*.java</include>
+ <include>de/ids_mannheim/korap/**/*.java</include>
</includes>
</configuration>
</plugin>
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java
new file mode 100644
index 0000000..8d826ee
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java
@@ -0,0 +1,37 @@
+package de.ids_mannheim.korap.config;
+
+import net.sf.ehcache.CacheManager;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * @author hanl
+ * @date 03/02/2016
+ */
+public class KustvaktCacheManager {
+
+ private static boolean loaded = false;
+
+ public static void init() {
+ if (!loaded) {
+ System.out.println("LOADING EHCACHE CONFIG FROM FILE");
+ InputStream in = null;
+ try {
+ in = new FileInputStream(new File("./ehcache.xml"));
+ }catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ if (in == null) {
+ System.out.println("LOADING EHCACHE FROM CLASSPATH");
+ in = KustvaktCacheManager.class
+ .getResourceAsStream("ehcache.xml");
+ }
+ CacheManager.newInstance(in);
+ loaded = true;
+ }
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index ba271f0..d59c23e 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -34,6 +34,7 @@
KUSTVAKT_USER.put(Attributes.PASSWORD, "kustvakt2015");
KUSTVAKT_USER.put(Attributes.EMAIL, "kustvakt@ids-mannheim.de");
KUSTVAKT_USER.put(Attributes.COUNTRY, "Germany");
+ KUSTVAKT_USER.put(Attributes.ADDRESS, "Mannheim");
KUSTVAKT_USER.put(Attributes.FIRSTNAME, "Kustvakt");
KUSTVAKT_USER.put(Attributes.LASTNAME, "KorAP");
KUSTVAKT_USER.put(Attributes.INSTITUTION, "IDS Mannheim");
diff --git a/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java b/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
index a854bc5..f510ac5 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
@@ -12,7 +12,7 @@
}
public EmptyResultException(String entity) {
- super(StatusCodes.EMPTY_RESULTS, "", entity);
+ super(StatusCodes.EMPTY_RESULTS, "No entity found for id", entity);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
index 34aa013..4c40304 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -9,96 +9,96 @@
/**
* 100 status codes for standard system errors
*/
- public static final Integer EMPTY_RESULTS = 100;
- public static final Integer REQUEST_INVALID = 101;
+ public static final int EMPTY_RESULTS = 100;
+ public static final int REQUEST_INVALID = 101;
//fixme: redundancy?!
- public static final Integer ENTRY_EXISTS = 102;
- public static final Integer STATUS_OK = 103;
- public static final Integer UNSUPPORTED_OPERATION = 104;
- public static final Integer ILLEGAL_ARGUMENT = 105;
- public static final Integer CONNECTION_ERROR = 106;
- public static final Integer NOTHING_CHANGED = 107;
- public static final Integer PARAMETER_VALIDATION_ERROR = 108;
- public static final Integer DEFAULT_ERROR = 109;
- public static final Integer NOT_SUPPORTED = 110;
+ public static final int ENTRY_EXISTS = 102;
+ public static final int STATUS_OK = 103;
+ public static final int UNSUPPORTED_OPERATION = 104;
+ public static final int ILLEGAL_ARGUMENT = 105;
+ public static final int CONNECTION_ERROR = 106;
+ public static final int NOTHING_CHANGED = 107;
+ public static final int PARAMETER_VALIDATION_ERROR = 108;
+ public static final int DEFAULT_ERROR = 109;
+ public static final int NOT_SUPPORTED = 110;
/**
* 400 status codes for account/authentication relevant components
*/
- public static final Integer ACCOUNT_DEACTIVATED = 200;
- public static final Integer ACCOUNT_CONFIRMATION_FAILED = 201;
- public static final Integer ALREADY_LOGGED_IN = 202;
- public static final Integer EXPIRED = 204;
- public static final Integer BAD_CREDENTIALS = 205;
- public static final Integer UNCONFIRMED_ACCOUNT = 206;
- public static final Integer NAME_EXISTS = 207;
- public static final Integer PASSWORD_RESET_FAILED = 208;
+ public static final int ACCOUNT_DEACTIVATED = 200;
+ public static final int ACCOUNT_CONFIRMATION_FAILED = 201;
+ public static final int ALREADY_LOGGED_IN = 202;
+ public static final int EXPIRED = 204;
+ public static final int BAD_CREDENTIALS = 205;
+ public static final int UNCONFIRMED_ACCOUNT = 206;
+ public static final int NAME_EXISTS = 207;
+ public static final int PASSWORD_RESET_FAILED = 208;
// fixme: ?!
@Deprecated
- public static final Integer AUTHENTICATION_DENIED = 209;
+ public static final int AUTHENTICATION_DENIED = 209;
- public static final Integer LOGIN_SUCCESSFUL = 210;
- public static final Integer LOGIN_FAILED = 211;
- public static final Integer LOGOUT_SUCCESSFUL = 212;
- public static final Integer LOGOUT_FAILED = 213;
+ public static final int LOGIN_SUCCESSFUL = 210;
+ public static final int LOGIN_FAILED = 211;
+ public static final int LOGOUT_SUCCESSFUL = 212;
+ public static final int LOGOUT_FAILED = 213;
- public static final Integer CLIENT_REGISTRATION_FAILURE = 214;
- public static final Integer CLIENT_REMOVAL_FAILURE = 215;
- public static final Integer CLIENT_AUTHORIZATION_FAILURE = 216;
+ public static final int CLIENT_REGISTRATION_FAILURE = 214;
+ public static final int CLIENT_REMOVAL_FAILURE = 215;
+ public static final int CLIENT_AUTHORIZATION_FAILURE = 216;
/**
* 500 status codes for access control related components (also policy rewrite)
*/
- public static final Integer PERMISSION_DENIED = 401;
- public static final Integer UNSUPPORTED_RESOURCE = 402;
- public static final Integer UNSUPPORTED_FOUNDRY = 403;
- public static final Integer UNSUPPORTED_CORPUS = 404;
- public static final Integer UNSUPPORTED_LAYER = 405;
+ public static final int PERMISSION_DENIED = 401;
+ public static final int UNSUPPORTED_RESOURCE = 402;
+ public static final int UNSUPPORTED_FOUNDRY = 403;
+ public static final int UNSUPPORTED_CORPUS = 404;
+ public static final int UNSUPPORTED_LAYER = 405;
// make a distinction between no and invalid vc?
- public static final Integer UNSUPPORTED_COLLECTION = 406;
- public static final Integer CORPUS_REWRITE = 407;
- public static final Integer FOUNDRY_REWRITE = 408;
- public static final Integer FOUNDRY_INJECTION = 409;
- public static final Integer MISSING_ARGUMENTS = 410;
- public static final Integer MISSING_VIRTUALCOLLECTION = 411;
- public static final Integer MISSING_POLICY_TARGET = 412;
- public static final Integer MISSING_POLICY_CONDITIONS = 413;
- public static final Integer MISSING_POLICY_PERMISSION = 414;
- public static final Integer RESOURCE_NOT_FOUND = 415;
+ public static final int UNSUPPORTED_COLLECTION = 406;
+ public static final int CORPUS_REWRITE = 407;
+ public static final int FOUNDRY_REWRITE = 408;
+ public static final int FOUNDRY_INJECTION = 409;
+ public static final int MISSING_ARGUMENTS = 410;
+ public static final int MISSING_VIRTUALCOLLECTION = 411;
+ public static final int MISSING_POLICY_TARGET = 412;
+ public static final int MISSING_POLICY_CONDITIONS = 413;
+ public static final int MISSING_POLICY_PERMISSION = 414;
+ public static final int RESOURCE_NOT_FOUND = 415;
// todo: extend according to policy rewrite possible!
// policy errors
- public static final Integer POLICY_ERROR_DEFAULT = 500;
- public static final Integer POLICY_CREATE_ERROR = 501;
- public static final Integer NO_POLICIES = 502;
+ public static final int POLICY_ERROR_DEFAULT = 500;
+ public static final int POLICY_CREATE_ERROR = 501;
+ public static final int NO_POLICIES = 502;
// database codes
- public static final Integer DB_GET_FAILED = 601;
- public static final Integer DB_INSERT_FAILED = 602;
- public static final Integer DB_DELETE_FAILED = 603;
- public static final Integer DB_UPDATE_FAILED = 604;
+ public static final int DB_GET_FAILED = 601;
+ public static final int DB_INSERT_FAILED = 602;
+ public static final int DB_DELETE_FAILED = 603;
+ public static final int DB_UPDATE_FAILED = 604;
- public static final Integer DB_GET_SUCCESSFUL = 605;
- public static final Integer DB_INSERT_SUCCESSFUL = 606;
- public static final Integer DB_DELETE_SUCCESSFUL = 607;
- public static final Integer DB_UPDATE_SUCCESSFUL = 608;
+ public static final int DB_GET_SUCCESSFUL = 605;
+ public static final int DB_INSERT_SUCCESSFUL = 606;
+ public static final int DB_DELETE_SUCCESSFUL = 607;
+ public static final int DB_UPDATE_SUCCESSFUL = 608;
// service status codes
- public static final Integer CREATE_ACCOUNT_SUCCESSFUL = 700;
- public static final Integer CREATE_ACCOUNT_FAILED = 701;
- public static final Integer DELETE_ACCOUNT_SUCCESSFUL = 702;
- public static final Integer DELETE_ACCOUNT_FAILED = 703;
- public static final Integer UPDATE_ACCOUNT_SUCCESSFUL = 704;
- public static final Integer UPDATE_ACCOUNT_FAILED = 705;
+ public static final int CREATE_ACCOUNT_SUCCESSFUL = 700;
+ public static final int CREATE_ACCOUNT_FAILED = 701;
+ public static final int DELETE_ACCOUNT_SUCCESSFUL = 702;
+ public static final int DELETE_ACCOUNT_FAILED = 703;
+ public static final int UPDATE_ACCOUNT_SUCCESSFUL = 704;
+ public static final int UPDATE_ACCOUNT_FAILED = 705;
- public static final Integer GET_ACCOUNT_SUCCESSFUL = 706;
- public static final Integer GET_ACCOUNT_FAILED = 707;
+ public static final int GET_ACCOUNT_SUCCESSFUL = 706;
+ public static final int GET_ACCOUNT_FAILED = 707;
/**
* 300 status codes for query language and serialization
*/
- public static final Integer NO_QUERY = 301;
+ public static final int NO_QUERY = 301;
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
index e87b62d..497b23c 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -73,20 +73,21 @@
np.addValue("alo", k.isAccountLocked());
if (k.getPassword() != null)
np.addValue("ps", k.getPassword());
- URIParam param = k.getField(URIParam.class);
- if (param != null) {
- np.addValue("frag", param.getUriFragment());
- np.addValue("exp", new Date(param.getUriExpiration()));
- }else {
- np.addValue("frag", null);
- np.addValue("exp", null);
- }
+ // URIParam param = k.getField(URIParam.class);
+ // if (param != null) {
+ // np.addValue("frag", param.getUriFragment());
+ // np.addValue("exp", new Date(param.getUriExpiration()));
+ // }else {
+ // np.addValue("frag", null);
+ // np.addValue("exp", null);
+ // }
np.addValue("id", k.getId());
query = "UPDATE korap_users SET account_lock=:alo," +
- "account_link=:ali, password=:ps," +
- "uri_fragment=:frag," +
- "uri_expiration=:exp WHERE id=:id";
+ "account_link=:ali, password=:ps "
+ // "uri_fragment=:frag," +
+ // "uri_expiration=:exp "
+ + "WHERE id=:id";
}else if (user instanceof ShibUser) {
ShibUser s = (ShibUser) user;
//todo:
@@ -138,6 +139,7 @@
np.addValue("acr", System.currentTimeMillis());
np.addValue("id", k.getId());
+ System.out.println("query map " + np.getValues());
if (user.getId() != -1)
query = "INSERT INTO korap_users (id, username, account_lock, "
+
@@ -278,6 +280,7 @@
}
}
+ @Override
public int size() {
final String query = "SELECT COUNT(*) FROM korap_users;";
return this.jdbcTemplate
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
index 06c952f..0869236 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -116,7 +116,9 @@
return (T) this.jdbcTemplate.queryForObject(sql, source,
new RowMapperFactory.ResourceMapper());
}catch (DataAccessException e) {
- e.printStackTrace();
+ if (e instanceof IncorrectResultSizeDataAccessException)
+ throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT,
+ "invalid request id given!", String.valueOf(id));
return null;
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
index 060578c..22c600c 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
@@ -111,7 +111,7 @@
r.setFields(rs.getString("data"));
r.setDescription(rs.getString("description"));
- r.setCreated(rs.getTimestamp("created").getTime());
+ r.setCreated(rs.getLong("created"));
r.setPath(rs.getString("name_path"));
r.setPersistentID(rs.getString("persistent_id"));
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java b/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
index e05386b..e301ff5 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
@@ -1,10 +1,13 @@
package de.ids_mannheim.korap.handlers;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.exceptions.dbException;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.user.UserDetails;
import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -60,7 +63,7 @@
}
@Override
- public UserDetails get(Integer id) {
+ public UserDetails get(Integer id) throws dbException {
String sql = "SELECT * FROM user_details WHERE id=:id;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("id", id);
@@ -80,13 +83,16 @@
}
});
- }catch (DataAccessException e) {
+ }catch (EmptyResultDataAccessException ex) {
return null;
+ }catch (DataAccessException e) {
+ throw new dbException(-1, "userDetails",
+ StatusCodes.REQUEST_INVALID, String.valueOf(id));
}
}
@Override
- public UserDetails get(User user) {
+ public UserDetails get(User user) throws dbException {
String sql = "SELECT * FROM user_details WHERE user_id=:userid;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("userid", user.getId());
@@ -105,10 +111,11 @@
return details;
}
});
-
- }catch (DataAccessException e) {
- e.printStackTrace();
+ }catch (EmptyResultDataAccessException ex) {
return null;
+ }catch (DataAccessException e) {
+ throw new dbException(user.getId(), "userDetails",
+ StatusCodes.REQUEST_INVALID);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java b/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
index d343dca..6b9300f 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
@@ -1,10 +1,13 @@
package de.ids_mannheim.korap.handlers;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.exceptions.dbException;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.user.UserSettings;
import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -25,6 +28,7 @@
public UserSettingsDao(PersistenceClient client) {
this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
}
+
@Override
public int store(UserSettings data) {
String sql = "INSERT INTO user_settings (user_id, data) VALUES (:userid, :data);";
@@ -59,7 +63,7 @@
}
@Override
- public UserSettings get(Integer id) {
+ public UserSettings get(Integer id) throws dbException {
String sql = "SELECT * FROM user_settings WHERE id=:id;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("id", id);
@@ -79,13 +83,16 @@
}
});
- }catch (DataAccessException e) {
+ }catch (EmptyResultDataAccessException ex) {
return null;
+ }catch (DataAccessException e) {
+ throw new dbException(-1, "userSettings",
+ StatusCodes.REQUEST_INVALID, String.valueOf(id));
}
}
@Override
- public UserSettings get(User user) {
+ public UserSettings get(User user) throws dbException {
String sql = "SELECT * FROM user_settings WHERE user_id=:userid;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("userid", user.getId());
@@ -105,9 +112,11 @@
}
});
- }catch (DataAccessException e) {
- e.printStackTrace();
+ }catch (EmptyResultDataAccessException ex) {
return null;
+ }catch (DataAccessException e) {
+ throw new dbException(-1, "userSettings",
+ StatusCodes.REQUEST_INVALID);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
index c83f60d..932c069 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
@@ -26,4 +26,5 @@
int activateAccount(String username, String uriToken)
throws KustvaktException;
+ int size();
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java b/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java
index 7c0bc50..3eb7f38 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/LayerMapper.java
@@ -33,7 +33,6 @@
//todo: make mapping configurable!
public String findFoundry(String layer) {
if (settings != null) {
-
switch (translateLayer(layer.toLowerCase().trim())) {
case "d":
return (String) settings
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java
index 06af664..1922433 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java
@@ -11,8 +11,6 @@
import de.ids_mannheim.korap.security.SecurityPolicy;
import de.ids_mannheim.korap.user.User;
-import java.util.Arrays;
-
/**
* @author hanl
* @date 14/04/2014
@@ -130,15 +128,10 @@
if (this.rel == null)
this.rel = Relation.AND;
- System.out.println("CREATING RESOURCES " + Arrays.asList(resources));
- System.out.println("RESOURCES LENGTH " + resources.length);
for (int idx = 0; idx < this.resources.length; idx++) {
try {
- System.out.println("ITERATING OVER ARRAY " + idx);
if (parents[idx] != null)
resources[idx].setParentID(parents[idx].getPersistentID());
- System.out.println("RUNNING REGISTERING SERVICE ON RESOURCE "
- + resources[idx]);
SecurityManager manager = SecurityManager
.register(resources[idx], user);
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
index 57c6fe2..e006d87 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
@@ -602,10 +602,9 @@
}
}
- private Integer createCondition(PolicyCondition condition, User user)
+ private void createCondition(PolicyCondition condition, User user)
throws KustvaktException {
MapSqlParameterSource param = new MapSqlParameterSource();
- KeyHolder key = new GeneratedKeyHolder();
param.addValue("name", condition.getSpecifier());
param.addValue("ex", condition.getFlags().get(Attributes.EXPORT));
param.addValue("qo", condition.getFlags().get(Attributes.QUERY_ONLY));
@@ -615,8 +614,7 @@
try {
this.jdbcTemplate
.update("INSERT INTO group_store (name, sym_use, export, commercial) "
- + "VALUES (:name, :sy, :ex, :com);", param, key);
- return key.getKey().intValue();
+ + "VALUES (:name, :sy, :ex, :com);", param);
}catch (DataAccessException e) {
jlog.error("Operation (INSERT) not possible for '{}'",
condition.toString());
@@ -625,7 +623,7 @@
}
}
- //
+ //todo: check for unique constraint exception and exclude from throw!
@Override
public int addToCondition(String username, PolicyCondition condition,
boolean admin) throws KustvaktException {
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java
index 0b33e68..4dedb30 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java
@@ -14,7 +14,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Timestamp;
import java.util.*;
/**
@@ -34,12 +33,12 @@
PolicyContext context = new PolicyContext();
context.setIPMask(rs.getString("iprange"));
- Timestamp date = rs.getTimestamp("enable");
- Timestamp date2 = rs.getTimestamp("expire");
- if (date != null)
- context.setEnableTime(date.getTime());
- if (date2 != null)
- context.setExpirationTime(date2.getTime());
+ long enable = rs.getLong("enable");
+ long expire = rs.getLong("expire");
+ if (enable != -1)
+ context.setEnableTime(enable);
+ if (expire != -1)
+ context.setExpirationTime(expire);
// context.addFlag("export", rs.getBoolean("export"));
// context.addFlag("sym_use", rs.getInt("sym_use"));
p.setContext(context);
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java b/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
index e97ea53..aa7b28b 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
@@ -50,15 +50,16 @@
EncryptionIface crypto = BeanConfiguration.getBeans().getEncryption();
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
- TokenContext c = new TokenContext();
String[] values = decode(authToken);
if (values != null) {
+ TokenContext c = new TokenContext();
User user = dao.getAccount(values[0]);
if (user instanceof KorAPUser) {
boolean check = crypto
.checkHash(values[1], ((KorAPUser) user).getPassword());
+
if (!check)
- return c;
+ return null;
}
c.setUsername(values[0]);
c.setTokenType(Attributes.BASIC_AUTHENTICATION);
@@ -68,8 +69,9 @@
// fixme: you can make queries, but user sensitive data is off limits?!
c.addContextParameter(Attributes.SCOPES,
Scopes.Scope.search.toString());
+ return c;
}
- return c;
+ return null;
}
// not supported!
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
index adcb263..680f67d 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
@@ -89,14 +89,9 @@
Map map = (Map) e.getObjectValue();
user = User.UserFactory.toUser(map);
}else {
- try {
- user = entHandler.getAccount(username);
- user_cache.put(new Element(key, user.toCache()));
- // todo: not valid. for the duration of the session, the host should not change!
- }catch (EmptyResultException e1) {
- // do nothing
- return null;
- }
+ user = entHandler.getAccount(username);
+ user_cache.put(new Element(key, user.toCache()));
+ // todo: not valid. for the duration of the session, the host should not change!
}
//todo:
// user.addField(Attributes.HOST, context.getHostAddress());
@@ -486,8 +481,9 @@
}
KorAPUser user = User.UserFactory.getUser(username);
+ user.setAccountLocked(confirmation_required);
+
if (confirmation_required) {
- user.setAccountLocked(true);
URIParam param = new URIParam(crypto.createToken(),
TimeUtils.plusSeconds(config.getExpiration()).getMillis());
user.addField(param);
@@ -506,6 +502,7 @@
UserdataFactory.getDaoInstance(UserDetails.class).store(details);
UserdataFactory.getDaoInstance(UserSettings.class).store(settings);
}catch (KustvaktException e) {
+ e.printStackTrace();
throw new WrappedException(e, StatusCodes.CREATE_ACCOUNT_FAILED,
user.toString());
}
@@ -679,7 +676,12 @@
try {
UserDataDbIface<T> dao = UserdataFactory.getDaoInstance(clazz);
- return dao.get(user);
+ T data = dao.get(user);
+ if (data == null)
+ throw new WrappedException(user.getId(),
+ StatusCodes.EMPTY_RESULTS, clazz.getSimpleName());
+
+ return data;
}catch (KustvaktException e) {
jlog.error("Error ", e);
throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java b/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
index 426d594..8004e31 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
@@ -25,6 +25,7 @@
*
* @author hanl
*/
+//todo: use simple ehcache!
public class SessionFactory implements Runnable {
private static Logger jlog = LoggerFactory.getLogger(SessionFactory.class);
@@ -48,10 +49,8 @@
public boolean hasSession(TokenContext context) {
if (context.getUsername().equalsIgnoreCase(DemoUser.DEMOUSER_NAME))
return false;
- if (loggedInRecord.containsKey(context.getUsername()) && !loggedInRecord
- .get(context.getUsername()).isEmpty())
- return true;
- return false;
+ return loggedInRecord.containsKey(context.getUsername())
+ && !loggedInRecord.get(context.getUsername()).isEmpty();
}
@Cacheable("session")
@@ -118,8 +117,9 @@
*/
private boolean isUserSessionValid(String token) {
if (timeCheck.containsKey(token)) {
- if (TimeUtils.plusSeconds(timeCheck.get(token).getMillis(),
- inactive).isAfterNow()) {
+ if (TimeUtils
+ .plusSeconds(timeCheck.get(token).getMillis(), inactive)
+ .isAfterNow()) {
jlog.debug("user has session");
return true;
}else
@@ -144,19 +144,10 @@
removeSession(entry.getKey());
}
}
+ // fixme: not doing anything!
if (inactive.size() > 0)
jlog.debug("removing inactive user session for users '{}' ",
inactive);
-
- // keys:
- // for (String key : failedLogins.getKeySet()) {
- // DateTime d = new DateTime(failedLogins.get(key).get(1));
- // if (d.isBeforeNow()) {
- // failedLogins.remove(key);
- // jlog.info("removed failed login counts due to expiration for user {}", key);
- // continue keys;
- // }
- // }
}
/**
@@ -165,7 +156,7 @@
@Override
public void run() {
timeoutMaintenance();
- jlog.debug("logged users: {}", loggedInRecord.toString());
-
+ if (loggedInRecord.size() > 0)
+ jlog.debug("logged users: {}", loggedInRecord.toString());
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
index 22da0e8..b1ceef1 100644
--- a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
+++ b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
@@ -18,7 +18,6 @@
protected DemoUser() {
super(DEMOUSER_NAME, 2);
this.setAccountCreation(ACCOUNT_CREATED);
-// this.setQueries(UserQuery.demoUserQueries());
}
protected User clone() {
diff --git a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
index a31beab..bdc2d36 100644
--- a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
+++ b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
@@ -109,6 +109,12 @@
return c;
}
+ public boolean isValid() {
+ return (this.username != null && !this.username.isEmpty()) && (
+ this.token != null && !this.token.isEmpty()) && (
+ this.tokenType != null && !this.tokenType.isEmpty());
+ }
+
public String getToken() {
return token;
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/User.java b/src/main/java/de/ids_mannheim/korap/user/User.java
index 95330b1..79df7cb 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -177,6 +177,24 @@
return u;
}
+ public static KorAPUser toKorAPUser(Map<String, Object> map) {
+ KorAPUser user = UserFactory
+ .getUser((String) map.get(Attributes.USERNAME));
+ user.setPassword((String) map.get(Attributes.PASSWORD));
+ int id = map.get(Attributes.ID) == null ?
+ -1 :
+ (int) map.get(Attributes.ID);
+ if (id != -1)
+ user.setId(id);
+ long cr = map.get(Attributes.ACCOUNT_CREATION) == null ?
+ -1 :
+ (long) map.get(Attributes.ACCOUNT_CREATION);
+ if (cr != -1)
+ user.setAccountCreation(
+ (Long) map.get(Attributes.ACCOUNT_CREATION));
+ return user;
+ }
+
public static User toUser(Map<String, Object> map) {
KustvaktMap kmap = new KustvaktMap(map);
int type = map.get(Attributes.TYPE) == null ?
@@ -184,14 +202,19 @@
(Integer) kmap.get(Attributes.TYPE, Integer.class);
User user;
long created = -1;
+ int id = kmap.get(Attributes.ID, Integer.class) == null ?
+ -1 :
+ (Integer) kmap.get(Attributes.ID, Integer.class);
+
if (map.get(Attributes.ACCOUNT_CREATION) != null)
created = DateTime.parse(kmap.get(Attributes.ACCOUNT_CREATION))
.getMillis();
switch (type) {
case 0:
user = UserFactory.getUser(kmap.get(Attributes.USERNAME));
- user.setId(
- (Integer) kmap.get(Attributes.ID, Integer.class));
+ if (id != -1)
+ user.setId((Integer) kmap
+ .get(Attributes.ID, Integer.class));
user.setAccountLocked(
map.get(Attributes.ACCOUNTLOCK) == null ?
false :
@@ -200,8 +223,7 @@
user.setAccountCreation(created);
break;
default:
- user = UserFactory.getDemoUser(
- (Integer) kmap.get(Attributes.ID, Integer.class));
+ user = UserFactory.getDemoUser();
user.setAccountCreation(created);
}
return user;
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettings.java b/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
index 1d0c758..077c869 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
@@ -6,20 +6,22 @@
*/
public class UserSettings extends Userdata {
-
public UserSettings(Integer userid) {
super(userid);
}
@Override
public String[] requiredFields() {
- return new String[0];
+ return new String[] {};
}
-
//todo: define default fields and values --> so they can never be null!
@Override
public String[] defaultFields() {
- return new String[0];
+ return new String[] { Attributes.DEFAULT_REL_FOUNDRY,
+ Attributes.DEFAULT_POS_FOUNDRY,
+ Attributes.DEFAULT_CONST_FOUNDRY,
+ Attributes.DEFAULT_LEMMA_FOUNDRY, Attributes.QUERY_LANGUAGE,
+ Attributes.PAGE_LENGTH };
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java b/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
index 353915f..85e8046 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
@@ -59,7 +59,7 @@
}
}
throw new KustvaktException(StatusCodes.NOT_SUPPORTED,
- "No database class found for type " + data.getSimpleName());
+ "No database handler found for type " + data.getSimpleName());
}else
return instances.get(data);
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
index 8bdfb7d..2a8e430 100644
--- a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
+++ b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
@@ -4,6 +4,7 @@
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer;
import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.KustvaktCacheManager;
import de.ids_mannheim.korap.config.KustvaktClassLoader;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -39,6 +40,8 @@
else
BeanConfiguration.loadClasspathContext();
+ KustvaktCacheManager.init();
+
kargs.setRootPackages(
new String[] { "de.ids_mannheim.korap.web.service.light" });
@@ -107,6 +110,7 @@
iface.load();
}catch (KustvaktException e) {
// don't do anything!
+ System.out.println("An error occurred! " + e);
}
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
index 60a2891..cb419fd 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
@@ -40,11 +40,10 @@
context = userController
.getTokenStatus(authentication, host, ua);
}catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw KustvaktResponseHandler.throwAuthenticationException();
}
-
// fixme: give reason why access is not granted?
- if (context != null && (
+ if (context != null && context.isValid() && (
(context.isSecureRequired() && request.isSecure())
| !context.isSecureRequired()))
request.setSecurityContext(new KorAPContext(context));
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index 7a6b249..d9fec47 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -29,6 +29,7 @@
import de.ids_mannheim.korap.web.SearchKrill;
import de.ids_mannheim.korap.web.TRACE;
import de.ids_mannheim.korap.web.filter.AuthFilter;
+import de.ids_mannheim.korap.web.filter.BlockingFilter;
import de.ids_mannheim.korap.web.filter.DefaultFilter;
import de.ids_mannheim.korap.web.filter.PiwikFilter;
import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
@@ -44,7 +45,8 @@
* @date 29/01/2014
*/
@Path(KustvaktServer.API_VERSION + "/")
-@ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class })
+@ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public class ResourceService {
@@ -869,8 +871,8 @@
CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
if (reference != null && !reference.equals("null")) {
try {
- cquery.addQuery(
- (String) resourceHandler.findbyStrId(reference, user,
+ cquery.addQuery((String) resourceHandler
+ .findbyStrId(reference, user,
VirtualCollection.class).getData());
}catch (KustvaktException e) {
throw KustvaktResponseHandler.throwit(e);
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
index b7a5e5e..2f4e4de 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
@@ -101,8 +101,8 @@
@POST
@Path("update")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response updateAccount(@Context SecurityContext ctx, String json) {
TokenContext context = (TokenContext) ctx.getUserPrincipal();
try {
@@ -206,7 +206,7 @@
@GET
@Path("info")
@ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
- BlockingFilter.class })
+ BlockingFilter.class, BlockingFilter.class })
public Response getStatus(@Context SecurityContext context,
@QueryParam("scopes") String scopes) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -228,8 +228,8 @@
@GET
@Path("settings")
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response getUserSettings(@Context SecurityContext context,
@Context Locale locale) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -250,8 +250,8 @@
@POST
@Path("settings")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response updateSettings(@Context SecurityContext context,
@Context Locale locale, MultivaluedMap form) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -284,8 +284,8 @@
@GET
@Path("details")
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response getDetails(@Context SecurityContext context,
@Context Locale locale) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -305,8 +305,8 @@
@POST
@Path("details")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response updateDetails(@Context SecurityContext context,
@Context Locale locale, MultivaluedMap form) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -336,8 +336,8 @@
@POST
@Path("queries")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response updateQueries(@Context SecurityContext context,
String json) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -387,8 +387,8 @@
}
@DELETE
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response deleteUser(@Context SecurityContext context) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
try {
@@ -405,8 +405,8 @@
@GET
@Path("queries")
- @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
- PiwikFilter.class })
+ @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+ BlockingFilter.class })
public Response getQueries(@Context SecurityContext context,
@Context Locale locale) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
index 89ad245..80cd425 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
@@ -32,19 +32,19 @@
}
public static WebApplicationException throwit(KustvaktException e) {
- return new WebApplicationException(
- Response.status(Response.Status.BAD_REQUEST)
- .entity(buildNotification(e)).build());
+ Response s = Response.status(getStatus(e.getStatusCode()))
+ .entity(buildNotification(e)).build();
+ return new WebApplicationException(s);
}
public static WebApplicationException throwit(int code) {
- return new WebApplicationException(Response.status(Response.Status.OK)
+ return new WebApplicationException(Response.status(getStatus(code))
.entity(buildNotification(code, "", "")).build());
}
public static WebApplicationException throwit(int code, String message,
String entity) {
- return new WebApplicationException(Response.status(Response.Status.OK)
+ return new WebApplicationException(Response.status(getStatus(code))
.entity(buildNotification(code, message, entity)).build());
}
@@ -62,12 +62,24 @@
}
public static WebApplicationException throwAuthenticationException() {
- KustvaktException e = new KustvaktException(
- StatusCodes.BAD_CREDENTIALS);
return new WebApplicationException(
Response.status(Response.Status.UNAUTHORIZED)
.header(HttpHeaders.WWW_AUTHENTICATE,
"Basic realm=Kustvakt Authentication Service")
- .entity(buildNotification(e)).build());
+ .entity(buildNotification(StatusCodes.BAD_CREDENTIALS,
+ "Unauthorized access", "")).build());
+ }
+
+ private static Response.Status getStatus(int code) {
+ Response.Status status = Response.Status.BAD_REQUEST;
+ switch (code) {
+ case StatusCodes.EMPTY_RESULTS:
+ status = Response.Status.NO_CONTENT;
+ break;
+ case StatusCodes.ILLEGAL_ARGUMENT:
+ status = Response.Status.NOT_ACCEPTABLE;
+ break;
+ }
+ return status;
}
}
diff --git a/src/main/resources/db/mysql/V0.1__userdatabase.sql b/src/main/resources/db/mysql/V0.1__userdatabase.sql
index 6444651..cfe31a1 100644
--- a/src/main/resources/db/mysql/V0.1__userdatabase.sql
+++ b/src/main/resources/db/mysql/V0.1__userdatabase.sql
@@ -23,53 +23,17 @@
account_link VARCHAR(100)
);
+
CREATE TABLE IF NOT EXISTS user_details (
- Id INTEGER PRIMARY KEY AUTO_INCREMENT,
- user_id INTEGER NOT NULL UNIQUE,
- firstName VARCHAR(100),
- lastName VARCHAR(100),
- gender VARCHAR(100),
- phone VARCHAR(100),
- institution VARCHAR(100),
- email VARCHAR(100),
- address VARCHAR(100),
- country VARCHAR(100),
- privateUsage BOOLEAN,
- foreign key (user_id)
- references korap_users (id)
- on delete cascade
+id INTEGER PRIMARY KEY AUTO_INCREMENT,
+user_id INTEGER UNIQUE NOT NULL,
+data BLOB NOT NULL
);
CREATE TABLE IF NOT EXISTS user_settings (
- Id INTEGER PRIMARY KEY AUTO_INCREMENT,
- user_id INTEGER NOT NULL UNIQUE,
- fileNameForExport VARCHAR(100),
- itemForSimpleAnnotation INTEGER,
- leftContextItemForExport VARCHAR(100),
- leftContextSizeForExport INTEGER,
- locale VARCHAR(100),
- leftContextItem VARCHAR(100),
- leftContextSize INTEGER,
- rightContextItem VARCHAR(100),
- rightContextItemForExport VARCHAR(100),
- rightContextSize INTEGER,
- rightContextSizeForExport INTEGER,
- selectedCollection VARCHAR(100),
- queryLanguage VARCHAR(100),
- pageLength INTEGER,
- metadataQueryExpertModus BOOLEAN,
- searchSettingsTab INTEGER,
- selectedGraphType INTEGER,
- selectedSortType VARCHAR(100),
- selectedViewForSearchResults VARCHAR(100),
- POSFoundry VARCHAR(100),
- lemmaFoundry VARCHAR(100),
- constFoundry VARCHAR(100),
- relFoundry VARCHAR(100),
- collectData BOOLEAN,
- foreign key (user_id)
- references korap_users (id)
- on delete cascade
+id INTEGER PRIMARY KEY AUTO_INCREMENT,
+user_id INTEGER UNIQUE NOT NULL,
+data BLOB NOT NULL
);
-- deprecated
diff --git a/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql b/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql
index 01b8c26..cc2afa3 100644
--- a/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql
+++ b/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql
@@ -5,7 +5,8 @@
name VARCHAR(100),
description VARCHAR(300),
parent_id Integer unsigned null,
-created BIGINT NOT NULL,
+created BIGINT null,
+data BLOB,
type INTEGER NOT NULL,
creator INTEGER NOT NULL
);
@@ -24,7 +25,7 @@
on delete cascade
);
-
+-- deprecated
CREATE TABLE IF NOT EXISTS user_queries (
id INTEGER PRIMARY KEY,
queryLanguage VARCHAR(100),
diff --git a/src/main/resources/db/mysql/V0.3__securitydatabase.sql b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
index b7d826b..e74b114 100644
--- a/src/main/resources/db/mysql/V0.3__securitydatabase.sql
+++ b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
@@ -5,8 +5,8 @@
created TIMESTAMP,
creator INTEGER NOT NULL,
posix SMALLINT NOT NULL,
- expire TIMESTAMP NULL,
- enable TIMESTAMP NULL,
+ expire BIGINT NULL,
+ enable BIGINT NULL,
iprange VARCHAR(200)
);
diff --git a/src/main/resources/db/sqlite/V1__Initial_version.sql b/src/main/resources/db/sqlite/V1__Initial_version.sql
index 69fd635..46eff5e 100644
--- a/src/main/resources/db/sqlite/V1__Initial_version.sql
+++ b/src/main/resources/db/sqlite/V1__Initial_version.sql
@@ -45,19 +45,6 @@
on delete cascade
);
-CREATE TABLE IF NOT EXISTS coll_store (
-id INTEGER PRIMARY KEY AUTOINCREMENT,
-persistent_id VARCHAR(150) UNIQUE,
-name VARCHAR(150),
-description VARCHAR(200),
-query VARCHAR(500),
-created BIGINT NOT NULL,
-user_id INTEGER,
-foreign key(user_id)
-references korap_users(id)
-on delete cascade
-);
-
CREATE TABLE IF NOT EXISTS audit_records (
aud_id INTEGER PRIMARY KEY AUTOINCREMENT,
aud_category VARCHAR(100),
@@ -161,7 +148,7 @@
name VARCHAR(100),
description VARCHAR(300),
parent_id INTEGER unsigned null,
-created TIMESTAMP default current_timestamp,
+created BIGINT null,
data BLOB,
type INTEGER NOT NULL,
creator INTEGER NOT NULL
diff --git a/src/main/resources/default-config.xml b/src/main/resources/default-config.xml
index cb62910..89f4bb9 100644
--- a/src/main/resources/default-config.xml
+++ b/src/main/resources/default-config.xml
@@ -10,18 +10,14 @@
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
-
-
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
-
-
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
- <cache:annotation-driven/>
+ <!--<cache:annotation-driven/>-->
<bean id="props"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
@@ -45,14 +41,14 @@
</property>
</bean>
- <bean id='cacheManager'
- class='org.springframework.cache.ehcache.EhCacheCacheManager'
- p:cacheManager-ref='ehcache'/>
+ <!--<bean id='cacheManager'-->
+ <!--class='org.springframework.cache.ehcache.EhCacheCacheManager'-->
+ <!--p:cacheManager-ref='ehcache'/>-->
- <bean id='ehcache'
- class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
- p:configLocation='classpath:ehcache.xml'
- p:shared='true'/>
+ <!--<bean id='ehcache'-->
+ <!--class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'-->
+ <!--p:configLocation='classpath:ehcache.xml'-->
+ <!--p:shared='true'/>-->
<!-- props are injected from default-config.xml -->
<bean id="kustvakt_config"
diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml
index 4259339..1bbb213 100644
--- a/src/main/resources/ehcache.xml
+++ b/src/main/resources/ehcache.xml
@@ -17,20 +17,25 @@
maxEntriesLocalHeap="50"
overflowToDisk='false'/>
<cache name='id_tokens'
- timeToIdleSeconds="172800"
eternal='true'
maxElementsOnDisk="10000000"
memoryStoreEvictionPolicy="LRU"
maxEntriesLocalHeap="50"
overflowToDisk='true'/>
<cache name='id_tokens_inv'
- timeToIdleSeconds="322800"
eternal='true'
maxElementsOnDisk="10000000"
memoryStoreEvictionPolicy="LRU"
maxEntriesLocalHeap="50"
overflowToDisk='true'/>
+ <cache name='auth_sessions'
+ timeToIdleSeconds="172800"
+ eternal='false'
+ memoryStoreEvictionPolicy="LRU"
+ maxEntriesLocalHeap="100"
+ overflowToDisk='false'/>
+
<cache name='auth_codes'
timeToIdleSeconds="600"
eternal='false'
diff --git a/src/test/java/UserdataTest.java b/src/test/java/UserdataTest.java
index c3cc6b8..e5b598f 100644
--- a/src/test/java/UserdataTest.java
+++ b/src/test/java/UserdataTest.java
@@ -1,5 +1,6 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.dbException;
import de.ids_mannheim.korap.handlers.UserDetailsDao;
import de.ids_mannheim.korap.handlers.UserSettingsDao;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
@@ -47,7 +48,7 @@
}
@Test
- public void testDataGet() {
+ public void testDataGet() throws dbException {
User user = new KorAPUser();
user.setId(1);
UserDetailsDao dao = new UserDetailsDao(
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index c1e2cd1..cc180f3 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -10,6 +10,8 @@
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
@@ -25,9 +27,9 @@
private static final String[] credentials = new String[] { "test1",
"testPass2015" };
- public static boolean setupUser() {
+ public static boolean setupAccount() {
boolean r = BeanConfiguration.hasContext();
- if (r) {
+ if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
Map m = new HashMap<>();
@@ -45,7 +47,6 @@
.createUserAccount(m, false);
}catch (KustvaktException e) {
// do nothing
- System.out.println("THE EXCEPTION...");
e.printStackTrace();
Assert.assertNull("Test user could not be set up", true);
return false;
@@ -54,6 +55,37 @@
return r;
}
+ public static boolean setupSimpleAccount(String username, String password) {
+ boolean r = BeanConfiguration.hasContext();
+ if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
+ EntityHandlerIface dao = BeanConfiguration.getBeans()
+ .getUserDBHandler();
+ Map m = new HashMap<>();
+ m.put(Attributes.USERNAME, username);
+
+ try {
+ String hash = BeanConfiguration.getBeans().getEncryption()
+ .produceSecureHash(password);
+ m.put(Attributes.PASSWORD, hash);
+ }catch (NoSuchAlgorithmException | UnsupportedEncodingException | KustvaktException e) {
+
+ }
+ Assert.assertNotNull("userdatabase handler must not be null", dao);
+
+ try {
+ int i = dao.createAccount(User.UserFactory.toKorAPUser(m));
+ assert BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount(credentials[0]) != null;
+ assert i == 1;
+ }catch (KustvaktException e) {
+ // do nothing
+ Assert.assertNull("Test user could not be set up", true);
+ return false;
+ }
+ }
+ return r;
+ }
+
public static User getUser() {
if (BeanConfiguration.hasContext()) {
try {
@@ -65,22 +97,39 @@
throw new RuntimeException("User could not be retrieved!");
}
- public static boolean dropUser() {
- boolean r = BeanConfiguration.hasContext();
- if (r) {
- EntityHandlerIface dao = BeanConfiguration.getBeans()
- .getUserDBHandler();
- try {
- User us = dao.getAccount(credentials[0]);
- dao.deleteAccount(us.getId());
- }catch (KustvaktException e) {
- // do nothing
- }
+ public static boolean dropUser(String... usernames) {
+ if (usernames == null || usernames.length == 0)
+ usernames = new String[] { credentials[0] };
+ if (BeanConfiguration.hasContext()) {
+ for (String name : usernames)
+ remove(name);
}
- return r;
+ return BeanConfiguration.hasContext();
}
- public static boolean truncateAllUsers() {
+ private static void remove(String username) {
+ EntityHandlerIface dao = BeanConfiguration.getBeans()
+ .getUserDBHandler();
+ try {
+ User us = dao.getAccount(username);
+ dao.deleteAccount(us.getId());
+ }catch (KustvaktException e) {
+ // do nothing
+ }
+ }
+
+ public static void drop() {
+ if (BeanConfiguration.hasContext()) {
+ PersistenceClient cl = BeanConfiguration.getBeans()
+ .getPersistenceClient();
+ String sql = "drop database " + cl.getDatabase() + ";";
+ NamedParameterJdbcTemplate jdbc = (NamedParameterJdbcTemplate) cl
+ .getSource();
+ jdbc.update(sql, new HashMap<String, Object>());
+ }
+ }
+
+ public static boolean truncateAll() {
boolean r = BeanConfiguration.hasContext();
if (r) {
String sql = "SELECT Concat('TRUNCATE TABLE ', TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES";
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/DocumentDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/DocumentDaoTest.java
new file mode 100644
index 0000000..603aa53
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/handlers/DocumentDaoTest.java
@@ -0,0 +1,112 @@
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.handlers.DocumentDao;
+import de.ids_mannheim.korap.resources.Document;
+import org.junit.*;
+
+import java.util.List;
+
+/**
+ * @author hanl
+ * @date 12/11/2015
+ */
+public class DocumentDaoTest {
+
+ private static DocumentDao dao;
+
+ @BeforeClass
+ public static void setup() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ dao = new DocumentDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ }
+
+ @AfterClass
+ public static void close() {
+ BeanConfiguration.closeApplication();
+ }
+
+ @After
+ public void clear() {
+ try {
+ dao.deleteAll();
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testSet() throws KustvaktException {
+ Document doc = new Document("BRZ13_APR.00001");
+ doc.setDisabled(true);
+ dao.storeResource(doc, null);
+ }
+
+ @Test
+ public void testGet() {
+ Document doc = new Document("BRZ13_APR.00002");
+ doc.setDisabled(true);
+ try {
+ dao.storeResource(doc, null);
+ Document doc1 = dao.findbyId(doc.getPersistentID(), null);
+ assert doc1 != null && doc.isDisabled();
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testRemove() {
+ Document doc = new Document("BRZ13_APR.00003");
+ doc.setDisabled(true);
+ try {
+ dao.storeResource(doc, null);
+ Document doc1 = dao.findbyId(doc.getPersistentID(), null);
+ assert dao.deleteResource(doc.getPersistentID(), null) == 1;
+ doc1 = dao.findbyId(doc.getPersistentID(), null);
+ assert doc1 == null;
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+
+ }
+ }
+
+ @Test
+ public void testEmptyFind() {
+ List<String> dc = null;
+ try {
+ dc = dao.findbyCorpus("WPD", true);
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertNotNull(dc);
+ Assert.assertEquals("should be empty", 0, dc.size());
+ }
+
+ @Test
+ public void testFind() {
+ int length = 10;
+ for (int i = 0; i < length; i++) {
+ Document doc = new Document("WPD_APR.0000" + i);
+ doc.setDisabled(true);
+ try {
+ dao.storeResource(doc, null);
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ break;
+ }
+ }
+
+ List<String> dc = null;
+ try {
+ dc = dao.findbyCorpus("WPD", true);
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertNotNull(dc);
+ Assert.assertNotSame("should not be empty", 0, dc.size());
+ Assert.assertEquals("not all found", length, dc.size());
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
new file mode 100644
index 0000000..0b11863
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
@@ -0,0 +1,84 @@
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.TestHelper;
+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.ResourceFactory;
+import de.ids_mannheim.korap.resources.VirtualCollection;
+import de.ids_mannheim.korap.user.User;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 26/01/2016
+ */
+public class ResourceDaoTest {
+
+ @BeforeClass
+ public static void init() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ TestHelper.setupAccount();
+ }
+
+ @AfterClass
+ public static void drop() {
+// TestHelper.dropUser();
+ BeanConfiguration.closeApplication();
+ }
+
+ @After
+ public void clear() throws KustvaktException {
+ new ResourceDao<>(BeanConfiguration.getBeans().getPersistenceClient())
+ .deleteAll();
+ }
+
+ @Test
+ public void createCollection() throws KustvaktException {
+ ResourceDao dao = new ResourceDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ VirtualCollection c = ResourceFactory.createCollection("testColl", 1);
+ c.addField("key_1", "this is a test");
+ c.addField("key_2", 2);
+
+ User user = User.UserFactory
+ .getUser(TestHelper.getUserCredentials()[0]);
+
+ int id = dao.storeResource(c, user);
+
+ KustvaktResource r = dao.findbyId(id, user);
+ assert dao.size() > 0;
+ assert r != null;
+ assert r.getField("key_1") instanceof String;
+ assert r.getField("key_2") instanceof Integer;
+ }
+
+ @Test
+ public void ResourceDataUpdate() throws KustvaktException {
+ ResourceDao dao = new ResourceDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ VirtualCollection c = ResourceFactory.createCollection("testColl", 1);
+ c.addField("key_1", "this is a test");
+ c.addField("key_2", 2);
+
+ User user = User.UserFactory
+ .getUser(TestHelper.getUserCredentials()[0]);
+
+ int id = dao.storeResource(c, user);
+
+ c.setId(id);
+ c.addField("key_3", -1);
+ int row_update = dao.updateResource(c, user);
+ assert row_update > 0;
+
+ KustvaktResource r = dao.findbyId(id, user);
+ assert dao.size() > 0;
+ assert r != null;
+ assert r.getField("key_1") instanceof String;
+ assert r.getField("key_2") instanceof Integer;
+ assert r.getField("key_3") instanceof Integer;
+
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
new file mode 100644
index 0000000..94abd81
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
@@ -0,0 +1,95 @@
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
+import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
+import de.ids_mannheim.korap.user.*;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+;
+
+/**
+ * @author hanl
+ * @date 13/02/2015
+ */
+public class UserDaoTest {
+
+ @BeforeClass
+ public static void create() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ TestHelper.setupAccount();
+ TestHelper.runBootInterfaces();
+ }
+
+ @AfterClass
+ public static void close() {
+ assert TestHelper.dropUser();
+ BeanConfiguration.closeApplication();
+ }
+
+ @Test
+ public void userput() throws KustvaktException {
+ User user1 = BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount(TestHelper.getUserCredentials()[0]);
+ Assert.assertEquals("user creation failed", true, user1.getId() != -1);
+ }
+
+ @Test
+ public void userget() throws KustvaktException {
+ User user1 = BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount(TestHelper.getUserCredentials()[0]);
+ Assert.assertEquals("User Retrieval does not work",
+ TestHelper.getUserCredentials()[0], user1.getUsername());
+ }
+
+ // @Test
+ public void testUserdetailsGetNonExistent() throws KustvaktException {
+ TestHelper.setupSimpleAccount("userdbtest", "userdbTest");
+ User user = BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount("userdbtest");
+ UserDataDbIface dao = UserdataFactory.getDaoInstance(UserDetails.class);
+ Userdata data = dao.get(user);
+ assert data == null;
+ TestHelper.dropUser("userdbtest");
+ }
+
+ // @Test
+ public void testUserSettingsGetNonExistent() throws KustvaktException {
+ TestHelper.setupSimpleAccount("userdbtest", "userdbTest");
+ User user = BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount("userdbtest");
+ UserDataDbIface dao = UserdataFactory
+ .getDaoInstance(UserSettings.class);
+ Userdata data = dao.get(user);
+ assert data == null;
+ TestHelper.dropUser("userdbtest");
+
+ }
+
+ // username cannot currently be changed
+ // @Test
+ public void updateUsername() throws KustvaktException {
+ User user1 = BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount(TestHelper.getUserCredentials()[0]);
+ user1.setUsername("new_user");
+ BeanConfiguration.getBeans().getUserDBHandler().updateAccount(user1);
+ User u2 = BeanConfiguration.getBeans().getUserDBHandler()
+ .getAccount("new_user");
+ Assert.assertEquals("not found", user1.getUsername(), u2.getUsername());
+ }
+
+ @Test
+ public void userupdate() throws KustvaktException {
+ EntityHandlerIface dao = BeanConfiguration.getBeans()
+ .getUserDBHandler();
+ User user1 = dao.getAccount(TestHelper.getUserCredentials()[0]);
+ user1.setAccountLocked(true);
+ dao.updateAccount(user1);
+ Assert.assertEquals("not valid", true,
+ dao.getAccount(user1.getUsername()).isAccountLocked());
+ }
+
+}
diff --git a/src/test/java/CollectionRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
similarity index 100%
rename from src/test/java/CollectionRewriteTest.java
rename to src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
diff --git a/src/test/java/FoundryRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
similarity index 100%
rename from src/test/java/FoundryRewriteTest.java
rename to src/test/java/de/ids_mannheim/korap/resource/rewrite/FoundryRewriteTest.java
diff --git a/src/test/java/IdRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/IdRewriteTest.java
similarity index 100%
rename from src/test/java/IdRewriteTest.java
rename to src/test/java/de/ids_mannheim/korap/resource/rewrite/IdRewriteTest.java
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
new file mode 100644
index 0000000..2771a06
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/PostRewriteTest.java
@@ -0,0 +1,469 @@
+import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.handlers.DocumentDao;
+import de.ids_mannheim.korap.resource.rewrite.DocMatchRewrite;
+import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
+import de.ids_mannheim.korap.resources.Document;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import net.sf.ehcache.CacheManager;
+import org.junit.*;
+
+/**
+ * @author hanl
+ * @date 12/11/2015
+ */
+//fixme: tests only work with singleconnection data sources
+public class PostRewriteTest {
+
+ @BeforeClass
+ public static void setup() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ }
+
+ @AfterClass
+ public static void close() {
+ BeanConfiguration.closeApplication();
+ }
+
+ // otherwise cache will maintain values not relevant for other tests
+ @Before
+ public void before() {
+ CacheManager.getInstance().getCache("documents").removeAll();
+ }
+
+ @Test
+ public void testPostRewriteNothingToDo() {
+ RewriteHandler ha = new RewriteHandler(null);
+ Assert.assertEquals("Handler could not be added to rewriter instance!",
+ true, ha.add(DocMatchRewrite.class));
+
+ DocumentDao dao = new DocumentDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ try {
+ Document d = dao.findbyId("BRZ13_APR.00014", null);
+ Assert.assertNull(d);
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ }
+
+ String v = ha.postProcess(RESULT, null);
+ Assert.assertEquals("results do not match", JsonUtils.readTree(RESULT),
+ JsonUtils.readTree(v));
+ }
+
+ @Test
+ public void testPostRewriteRemoveDoc() {
+ DocumentDao dao = new DocumentDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+
+ Document doc = new Document("BRZ13_APR.00014");
+ doc.setDisabled(true);
+ try {
+ dao.storeResource(doc, null);
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ RewriteHandler ha = new RewriteHandler(null);
+ Assert.assertEquals("Handler could not be added to rewriter instance!",
+ true, ha.add(DocMatchRewrite.class));
+
+ String v = ha.postProcess(RESULT, null);
+
+ JsonNode node = JsonUtils.readTree(v);
+
+ Assert.assertNotEquals("Wrong DocID", "BRZ13_APR.00014",
+ node.at("/matches/1/docID"));
+
+ try {
+ dao.deleteResource(doc.getPersistentID(), null);
+ Document d = dao.findbyId(doc.getPersistentID(), null);
+ if (d != null)
+ System.out.println("IS SUPPOSED TO BE NULL! " + d);
+ }catch (KustvaktException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ }
+
+ @Test
+ public void testPath() {
+ String v = "{\n" + " \"meta\": {\n" + " \"count\": 25,\n"
+ + " \"startIndex\": 0,\n"
+ + " \"timeout\": 120000,\n" + " \"context\": {\n"
+ + " \"left\": [\n" + " \"token\",\n"
+ + " 6\n" + " ],\n"
+ + " \"right\": [\n" + " \"token\",\n"
+ + " 6\n" + " ]\n" + " }}}";
+ JsonNode n = JsonUtils.readTree(v);
+
+ }
+
+ private static final String RESULT =
+ "{\n" + " \"meta\": {\n" + " \"count\": 25,\n"
+ + " \"startIndex\": 0,\n"
+ + " \"timeout\": 120000,\n"
+ + " \"context\": {\n" + " \"left\": [\n"
+ + " \"token\",\n" + " 6\n"
+ + " ],\n" + " \"right\": [\n"
+ + " \"token\",\n" + " 6\n"
+ + " ]\n" + " },\n"
+ + " \"fields\": [\n" + " \"textSigle\",\n"
+ + " \"author\",\n"
+ + " \"docSigle\",\n" + " \"title\",\n"
+ + " \"pubDate\",\n" + " \"UID\",\n"
+ + " \"corpusID\",\n"
+ + " \"textClass\",\n"
+ + " \"subTitle\",\n"
+ + " \"layerInfos\",\n" + " \"ID\",\n"
+ + " \"pubPlace\",\n"
+ + " \"corpusSigle\"\n" + " ],\n"
+ + " \"version\": \"unknown\",\n"
+ + " \"benchmark\": \"0.204314141 s\",\n"
+ + " \"totalResults\": 1755,\n"
+ + " \"serialQuery\": \"tokens:tt/l:Wort\",\n"
+ + " \"itemsPerPage\": 25\n" + " },\n"
+ + " \"query\": {\n"
+ + " \"@type\": \"koral:token\",\n"
+ + " \"wrap\": {\n"
+ + " \"@type\": \"koral:term\",\n"
+ + " \"key\": \"Wort\",\n"
+ + " \"layer\": \"lemma\",\n"
+ + " \"match\": \"match:eq\",\n"
+ + " \"foundry\": \"tt\",\n"
+ + " \"rewrites\": [\n" + " {\n"
+ + " \"@type\": \"koral:rewrite\",\n"
+ + " \"src\": \"Kustvakt\",\n"
+ + " \"operation\": \"operation:injection\"\n"
+ + " }\n" + " ]\n" + " }\n"
+ + " },\n" + " \"matches\": [\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"staat-gesellschaft familie-geschlecht\",\n"
+ + " \"title\": \"Sexueller Missbrauch –„Das schreiende Kind steckt noch tief in mir“\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>in ihrer Stimme schwingt bei diesem </span><mark>Wort</mark><span class=\\\"context-right\\\"> Sarkasmus mit. Bis man einen passenden<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00001-p454-455\",\n"
+ + " \"docID\": \"BRZ13_APR.00001\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"freizeit-unterhaltung reisen\",\n"
+ + " \"title\": \"Leben dick und prall\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>der DLRG, ausgelassene Partys und markige </span><mark>Worte</mark><span class=\\\"context-right\\\"> des Dompredigers: „Ostern ist kein goethischer<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00014-p96-97\",\n"
+ + " \"docID\": \"BRZ13_APR.00014\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"staat-gesellschaft biographien-interviews kultur musik\",\n"
+ + " \"title\": \"So wird es gemacht:\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>derfehlende Buchstabe.Gelingt es dir,das </span><mark>Wort</mark><span class=\\\"context-right\\\"> vervollständigen? Tipp: Probiere auch mal rückwärts<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00055-p19-20\",\n"
+ + " \"docID\": \"BRZ13_APR.00055\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik ausland\",\n"
+ + " \"title\": \"Südkorea droht mit Angriffen – USA rüsten auf\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>der Stunde. „Aus einem Krieg der </span><mark>Worte</mark><span class=\\\"context-right\\\"> darf kein echter Krieg werden“, sagte<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00076-p238-239\",\n"
+ + " \"docID\": \"BRZ13_APR.00076\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland freizeit-unterhaltung reisen\",\n"
+ + " \"title\": \"Dauercamper kämpfen für ihren Platz\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>„Initiative Campingplatz Räbke“. „Als ich das </span><mark>Wort</mark><span class=\\\"context-right\\\"> Schließung gelesen habe, war ich richtig<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00200-p255-256\",\n"
+ + " \"docID\": \"BRZ13_APR.00200\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"freizeit-unterhaltung reisen\",\n"
+ + " \"title\": \"Neue Aktionen lockten Besucher\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Jan Waldheim (CWG) unter den aufmunternden </span><mark>Worten</mark><span class=\\\"context-right\\\"> eines augenzwinkernden Axel Schnalke („Ein bisschen<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00210-p142-143\",\n"
+ + " \"docID\": \"BRZ13_APR.00210\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"kultur musik\",\n"
+ + " \"title\": \"Travestie – Helden in Strumpfhosen\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>trotzdem nicht. Selten wurden so viele </span><mark>Worte</mark><span class=\\\"context-right\\\">, die der Autor hier lieber verschweigt<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00253-p166-167\",\n"
+ + " \"docID\": \"BRZ13_APR.00253\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"kultur musik\",\n"
+ + " \"title\": \"Travestie – Helden in Strumpfhosen\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>zudem nicht immer nur bei den </span><mark>Worten</mark><span class=\\\"context-right\\\"> geblieben) und dabei gleichzeitig soviel Charme<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00253-p191-192\",\n"
+ + " \"docID\": \"BRZ13_APR.00253\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"kultur musik\",\n"
+ + " \"title\": \"Travestie – Helden in Strumpfhosen\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>bedeutet Travestie sich zu verkleiden, das </span><mark>Wort</mark><span class=\\\"context-right\\\"> stammt aus dem Französischen. Traditionell belegten<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00253-p371-372\",\n"
+ + " \"docID\": \"BRZ13_APR.00253\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"sport fussball\",\n"
+ + " \"title\": \"VfL kommt nicht vom Fleck\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>am internationalen Geschäft berechtigt. Mit anderen </span><mark>Worten</mark><span class=\\\"context-right\\\">: Die „Wölfe“ stecken im grauen Mittelmaß<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00260-p93-94\",\n"
+ + " \"docID\": \"BRZ13_APR.00260\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"sport fussball\",\n"
+ + " \"title\": \"Mensch, Mayer! Super Tor\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>bekommst, ist das unbezahlbar – ein Bonus.“ </span><mark>Worte</mark><span class=\\\"context-right\\\">, die dem Torschützen weiteres Selbstvertrauen geben<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00275-p271-272\",\n"
+ + " \"docID\": \"BRZ13_APR.00275\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"sport fussball\",\n"
+ + " \"title\": \"Nur Gerücht? KHL-Klub will „Dshuni“\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>und hakt das Thema ab.cb Kein </span><mark>Wort</mark><span class=\\\"context-right\\\"> zum Interesse aus Astana: Daniar Dshunussow.Foto<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00277-p163-164\",\n"
+ + " \"docID\": \"BRZ13_APR.00277\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-02\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"staat-gesellschaft biographien-interviews\",\n"
+ + " \"title\": \"Das Leben ist nicht auf diese Erde beschränkt\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>1. Korinther 1,18 denken: Denn das </span><mark>Wort</mark><span class=\\\"context-right\\\"> vom Kreuz ist eine Torheit denen<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00520-p32-33\",\n"
+ + " \"docID\": \"BRZ13_APR.00520\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-03\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"sport fussball\",\n"
+ + " \"title\": \"Allofs und Hecking knöpfensich die VfL-Profis vor\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>für die Profis am Dienstag klare </span><mark>Worte</mark><span class=\\\"context-right\\\"> vom Führungsduo. Von Thorsten Grunow Wolfsburg<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00557-p17-18\",\n"
+ + " \"docID\": \"BRZ13_APR.00557\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-03\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"sport fussball\",\n"
+ + " \"title\": \"Allofs und Hecking knöpfensich die VfL-Profis vor\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Minuten setzte es am Dienstagnachmittag klare </span><mark>Worte</mark><span class=\\\"context-right\\\"> für die kickende Belegschaft, die durchaus<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00557-p60-61\",\n"
+ + " \"docID\": \"BRZ13_APR.00557\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-03\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"sport fussball\",\n"
+ + " \"title\": \"Allofs und Hecking knöpfensich die VfL-Profis vor\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Manager ist überzeugt, dass die klaren </span><mark>Worte</mark><span class=\\\"context-right\\\"> auf fruchtbaren Boden gefallen sind. „Ich<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_APR.00557-p235-236\",\n"
+ + " \"docID\": \"BRZ13_APR.00557\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-04-03\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland politik ausland\",\n"
+ + " \"title\": \"Zeitungsartikelzufällig deponiert?\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>erspart“, lautete die Schlagzeile – wobei das </span><mark>Wort</mark><span class=\\\"context-right\\\"> „erspart“ abgeschnitten war. Ein plumper Versuch<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07616-p31-32\",\n"
+ + " \"docID\": \"BRZ13_JAN.07616\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland\",\n"
+ + " \"title\": \"„Philipp Rösler wackelt nicht“\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Vizekanzler bei all dem Jubel zu </span><mark>Wort</mark><span class=\\\"context-right\\\"> kommt. „Ein großartiger Tag“, sagt er<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07617-p177-178\",\n"
+ + " \"docID\": \"BRZ13_JAN.07617\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"freizeit-unterhaltung reisen\",\n"
+ + " \"title\": \"Lanz gibt den charmanten, zurückhaltenden Gastgeber\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>er, als seine Assistentin ihm ins </span><mark>Wort</mark><span class=\\\"context-right\\\"> fiel. Dennoch holte das ungleiche Duo<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07621-p261-262\",\n"
+ + " \"docID\": \"BRZ13_JAN.07621\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland\",\n"
+ + " \"title\": \"Mundlos denkt über Rücktritt nach\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>räumte selbst ein, wie sarkastisch diese </span><mark>Worte</mark><span class=\\\"context-right\\\"> nach einer solchen Wahlnacht klingen mussten<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07694-p192-193\",\n"
+ + " \"docID\": \"BRZ13_JAN.07694\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland\",\n"
+ + " \"title\": \"BraunschweigGold – Hannover Blech\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>im Volksfreundhaus hört man kein schlechtes </span><mark>Wort</mark><span class=\\\"context-right\\\"> über den Kanzlerkandidaten Peer Steinbrück – und<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07695-p169-170\",\n"
+ + " \"docID\": \"BRZ13_JAN.07695\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland\",\n"
+ + " \"title\": \"BraunschweigGold – Hannover Blech\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Volksfreundhaus merklich steigen. Hier hat das </span><mark>Wort</mark><span class=\\\"context-right\\\"> von der Wahlparty bei Bier, Bockwurst<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07695-p266-267\",\n"
+ + " \"docID\": \"BRZ13_JAN.07695\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"staat-gesellschaft kirche\",\n"
+ + " \"title\": \"Fernsehen überträgt Gottesdienst\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>schon mal von der Sendung „Das </span><mark>Wort</mark><span class=\\\"context-right\\\"> zum Sonntag“ gehört. Das sind Predigten<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07840-p37-38\",\n"
+ + " \"docID\": \"BRZ13_JAN.07840\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland\",\n"
+ + " \"title\": \"Wahlkrimi im Ratssaal\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>ihre Konkurrentin Glosemeyer hatte sie warme </span><mark>Worte</mark><span class=\\\"context-right\\\"> übrig. „Für den ersten Anlauf eine<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07848-p147-148\",\n"
+ + " \"docID\": \"BRZ13_JAN.07848\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " },\n" + " {\n"
+ + " \"field\": \"tokens\",\n"
+ + " \"textClass\": \"politik inland\",\n"
+ + " \"title\": \"Warme Worte nach eiskaltem Wahlkampf\",\n"
+ + " \"author\": \"\",\n"
+ + " \"startMore\": true,\n"
+ + " \"endMore\": true,\n"
+ + " \"corpusID\": \"BRZ13\",\n"
+ + " \"snippet\": \"<span class=\\\"context-left\\\">Warme </span><mark>Worte</mark><span class=\\\"context-right\\\"> nach eiskaltem Wahlkampf Die SPD feierte<span class=\\\"more\\\"></span></span>\",\n"
+ + " \"matchID\": \"match-BRZ13!BRZ13_JAN.07850-p1-2\",\n"
+ + " \"docID\": \"BRZ13_JAN.07850\",\n"
+ + " \"UID\": 0,\n"
+ + " \"pubDate\": \"2013-01-21\"\n"
+ + " }\n" + " ]\n" + "}";
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java b/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
new file mode 100644
index 0000000..a46282c
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandlerTest.java
@@ -0,0 +1,38 @@
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.resource.rewrite.*;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 21/10/2015
+ */
+public class RewriteHandlerTest {
+
+ @BeforeClass
+ public static void setup() {
+ BeanConfiguration.loadClasspathContext();
+ }
+
+ @Test
+ public void initHandler() {
+ RewriteHandler handler = new RewriteHandler(null);
+ handler.add(FoundryInject.class);
+ }
+
+ @Test
+ public void testRewriteTastAdd() {
+ RewriteHandler handler = new RewriteHandler(null);
+ handler.add(FoundryInject.class);
+ handler.add(DocMatchRewrite.class);
+ handler.add(CollectionCleanupFilter.class);
+ handler.add(IdWriter.class);
+ }
+
+ @AfterClass
+ public static void close() {
+ BeanConfiguration.closeApplication();
+ }
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
new file mode 100644
index 0000000..efcf6c0
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
@@ -0,0 +1,106 @@
+package de.ids_mannheim.korap.security.auth;
+
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
+import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
+import de.ids_mannheim.korap.user.*;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 04/02/2016
+ */
+public class KustvaktAuthenticationManagerTest {
+
+ @BeforeClass
+ public static void create() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ assert TestHelper.setupAccount();
+ }
+
+ @AfterClass
+ public static void close() {
+ assert TestHelper.dropUser();
+ BeanConfiguration.closeApplication();
+ }
+
+ @After
+ public void after() throws KustvaktException {
+ User user = BeanConfiguration.getBeans().getAuthenticationManager()
+ .getUser((String) KustvaktConfiguration.KUSTVAKT_USER
+ .get(Attributes.USERNAME));
+ BeanConfiguration.getBeans().getAuthenticationManager()
+ .deleteAccount(user);
+ }
+
+ @Test
+ public void testCreateUser() throws KustvaktException {
+ User user = BeanConfiguration.getBeans().getAuthenticationManager()
+ .createUserAccount(KustvaktConfiguration.KUSTVAKT_USER, false);
+
+ EntityHandlerIface dao = BeanConfiguration.getBeans()
+ .getUserDBHandler();
+
+ assert dao.size() > 0;
+ User check = dao.getAccount(user.getUsername());
+ assert check != null;
+ }
+
+ @Test
+ public void testUserdetailsGet() throws KustvaktException {
+ testCreateUser();
+ AuthenticationManagerIface manager = BeanConfiguration.getBeans()
+ .getAuthenticationManager();
+
+ User user = manager.getUser((String) KustvaktConfiguration.KUSTVAKT_USER
+ .get(Attributes.USERNAME));
+
+ Userdata data = manager.getUserData(user, UserDetails.class);
+
+ assert data != null;
+ }
+
+ @Test
+ public void testUsersettingsGet() throws KustvaktException {
+ testCreateUser();
+ AuthenticationManagerIface manager = BeanConfiguration.getBeans()
+ .getAuthenticationManager();
+
+ User user = manager.getUser((String) KustvaktConfiguration.KUSTVAKT_USER
+ .get(Attributes.USERNAME));
+
+ Userdata data = manager.getUserData(user, UserSettings.class);
+ assert data != null;
+ }
+
+ @Test(expected = KustvaktException.class)
+ public void testUserDetailsGetNonExistent() throws KustvaktException {
+ testCreateUser();
+ AuthenticationManagerIface manager = BeanConfiguration.getBeans()
+ .getAuthenticationManager();
+
+ User user = new KorAPUser(10, "random");
+
+ Userdata data = manager.getUserData(user, UserDetails.class);
+ assert data != null;
+ }
+
+ @Test(expected = KustvaktException.class)
+ public void testUserSettingsGetNonExistent() throws KustvaktException {
+ testCreateUser();
+ AuthenticationManagerIface manager = BeanConfiguration.getBeans()
+ .getAuthenticationManager();
+
+ User user = new KorAPUser(10, "random");
+
+ Userdata data = manager.getUserData(user, UserSettings.class);
+ assert data != null;
+ }
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java
deleted file mode 100644
index af4ebdd..0000000
--- a/src/test/java/de/ids_mannheim/korap/web/service/AuthServiceTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package de.ids_mannheim.korap.web.service;
-
-/**
- * @author hanl
- * @date 24/09/2015
- */
-public class AuthServiceTest extends FastJerseyTest {
-
- //todo: test basicauth via secure connection
-
-
-
-
-
-}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
index a804d69..4cf5ecb 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
@@ -39,7 +39,7 @@
info.setUrl("http://localhost:8080/api/v0.1");
info.setRedirect_uri("testwebsite/login");
- TestHelper.setupUser();
+ TestHelper.setupAccount();
user = TestHelper.getUser();
handler.registerClient(info, user);
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
new file mode 100644
index 0000000..2b3667a
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
@@ -0,0 +1,17 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+
+/**
+ * @author hanl
+ * @date 24/09/2015
+ */
+public class AuthServiceTest extends FastJerseyTest {
+
+ //todo: test basicauth via secure connection
+
+
+
+
+
+}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
similarity index 85%
rename from src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
rename to src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
index d42a446..f297953 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktCoreRestTest.java
@@ -1,10 +1,11 @@
-package de.ids_mannheim.korap.web.service;
+package de.ids_mannheim.korap.web.service.full;
import com.sun.jersey.api.client.ClientResponse;
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -22,7 +23,7 @@
@BeforeClass
public static void configure() {
BeanConfiguration.loadClasspathContext();
- setPackages("de.ids_mannheim.korap.web.service.light",
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.light",
"de.ids_mannheim.korap.web.filter",
"de.ids_mannheim.korap.web.utils");
}
@@ -45,8 +46,8 @@
ClientResponse response = resource().path(getAPIVersion())
.path("search").queryParam("q", "[base=Wort]")
.queryParam("ql", "poliqarp").get(ClientResponse.class);
-// System.out.println("_______________________________________________");
-// System.out.println(response.getEntity(String.class));
+ // System.out.println("_______________________________________________");
+ // System.out.println(response.getEntity(String.class));
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
}
@@ -57,14 +58,14 @@
ClientResponse response = resource().path(getAPIVersion())
.path("search").post(ClientResponse.class, s.toJSON());
-// System.out.println("_______________________________________________ RAW");
-// System.out.println(response.getEntity(String.class));
+ // System.out.println("_______________________________________________ RAW");
+ // System.out.println(response.getEntity(String.class));
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
}
// in case no index is there, this will throw an error
- @Ignore
@Test
+ @Ignore
public void testGetMatchInfoThrowsNoException() {
ClientResponse response = resource().path(getAPIVersion())
.get(ClientResponse.class);
@@ -88,9 +89,9 @@
.post(ClientResponse.class, "creationDate in 1787");
String ent = response.getEntity(String.class);
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
-// System.out
-// .println("___________________________________________________");
-// System.out.println("STATS ENTITY " + ent);
+ // System.out
+ // .println("___________________________________________________");
+ // System.out.println("STATS ENTITY " + ent);
}
// @Test
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java
similarity index 90%
rename from src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
rename to src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java
index 62beae8..377b4e8 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java
@@ -1,12 +1,14 @@
-package de.ids_mannheim.korap.web.service;
+package de.ids_mannheim.korap.web.service.full;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -20,14 +22,15 @@
@BeforeClass
public static void configure() {
BeanConfiguration.loadClasspathContext("default-config.xml");
- setPackages("de.ids_mannheim.korap.web.service.full",
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
"de.ids_mannheim.korap.web.filter",
"de.ids_mannheim.korap.web.utils");
TestHelper.runBootInterfaces();
}
@AfterClass
- public static void close() {
+ public static void close() throws KustvaktException {
+ BeanConfiguration.getBeans().getResourceProvider().deleteAll();
BeanConfiguration.closeApplication();
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
similarity index 94%
rename from src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
rename to src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
index f0865b6..b94be84 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.web.service;
+package de.ids_mannheim.korap.web.service.full;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
@@ -7,6 +7,7 @@
import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -31,11 +32,11 @@
@BeforeClass
public static void configure() {
BeanConfiguration.loadClasspathContext("default-config.xml");
- setPackages("de.ids_mannheim.korap.web.service",
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service",
"de.ids_mannheim.korap.web.filter",
"de.ids_mannheim.korap.web.utils");
- TestHelper.setupUser();
+ TestHelper.setupAccount();
credentials = TestHelper.getUserCredentials();
}