nullpointer in specific user constructor bug fix
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index 5241316..9ebc5a9 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -10,6 +10,17 @@
<build>
<plugins>
<plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
@@ -34,7 +45,7 @@
<configuration>
<transformers>
<transformer>
- <mainClass>de.ids_mannheim.korap.web.Kustvakt</mainClass>
+ <mainClass>de.ids_mannheim.korap.web.KustvaktServer</mainClass>
</transformer>
<transformer>
<resource>META-INF/spring.handlers</resource>
@@ -77,6 +88,44 @@
</repositories>
<dependencies>
<dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>javax.servlet-api</artifactId>
+ <groupId>javax.servlet</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jersey-client</artifactId>
+ <groupId>com.sun.jersey</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-grizzly</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>grizzly-servlet-webserver</artifactId>
+ <groupId>com.sun.grizzly</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>jersey-grizzly</artifactId>
+ <groupId>com.sun.jersey</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.restfuse</groupId>
<artifactId>com.eclipsesource.restfuse</artifactId>
<version>1.0.0</version>
diff --git a/pom.xml b/pom.xml
index 2e28fb8..ec963a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,19 @@
</properties>
<build>
<plugins>
+ <!-- build tests jar, so extensions can use fastjerseytest class to build rest tests -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -48,7 +61,7 @@
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>
- de.ids_mannheim.korap.web.Kustvakt
+ de.ids_mannheim.korap.web.KustvaktServer
</mainClass>
</transformer>
<transformer
@@ -108,11 +121,13 @@
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>1.19</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly</artifactId>
<version>1.19</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -138,11 +153,13 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.8</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
@@ -160,16 +177,18 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-grizzly2</artifactId>
- <version>1.8</version>
- </dependency>
- <dependency>
- <groupId>com.sun.grizzly</groupId>
- <artifactId>grizzly-servlet-webserver</artifactId>
- <version>1.9.18-i</version>
- </dependency>
+ <!--
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-grizzly2</artifactId>
+ <version>1.8</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.grizzly</groupId>
+ <artifactId>grizzly-servlet-webserver</artifactId>
+ <version>1.9.18-i</version>
+ </dependency>
+ -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
@@ -179,7 +198,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Krill</artifactId>
- <version>0.52</version>
+ <version>0.53</version>
<exclusions>
<exclusion>
<groupId>org.xerial</groupId>
@@ -192,6 +211,7 @@
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
+ <!-- deprecated? -->
<dependency>
<groupId>com.restfuse</groupId>
<artifactId>com.eclipsesource.restfuse</artifactId>
@@ -238,6 +258,16 @@
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>8.1.8.v20121106</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>8.1.8.v20121106</version>
+ </dependency>
<!--
not part of public release
<dependency>
diff --git a/src/main/java/de/ids_mannheim/korap/auditing/AuditRecord.java b/src/main/java/de/ids_mannheim/korap/auditing/AuditRecord.java
index 28f915d..8e7169c 100644
--- a/src/main/java/de/ids_mannheim/korap/auditing/AuditRecord.java
+++ b/src/main/java/de/ids_mannheim/korap/auditing/AuditRecord.java
@@ -8,6 +8,7 @@
import lombok.Setter;
import java.util.Arrays;
+import java.util.Date;
/**
* @author hanl
@@ -18,7 +19,7 @@
@Setter
public class AuditRecord {
- // fixme: handle via status codes
+ // todo: handle via status codes
@Deprecated
public enum Operation {
GET, INSERT, UPDATE, DELETE, CREATE
@@ -100,16 +101,19 @@
return userAgent + "@" + IP;
}
+ // fixme: add id, useragent
@Override
public String toString() {
- return "Record{" +
- "account='" + userid + '\'' +
- ", category=" + category +
- ", loc='" + loc + '\'' +
- ", timestamp=" + timestamp +
- ", status='" + status + '\'' +
- ", field_1='" + field_1 + '\'' +
- '}';
+ StringBuilder b = new StringBuilder();
+ b.append(category.toString().toLowerCase() + " audit : ")
+ .append(userid + "@" + new Date(timestamp)).append("\n")
+ .append("Status " + status).append("; ");
+
+ if (this.args != null)
+ b.append("Args " + field_1).append("; ");
+ if (this.loc != null)
+ b.append("Location " + loc).append("; ");
+ return b.toString();
}
@Override
diff --git a/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
index df461e9..42aa8c7 100644
--- a/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
@@ -24,18 +24,19 @@
public static final String KUSTVAKT_AUDITING = "kustvakt_auditing";
public static final String KUSTVAKT_CONFIG = "kustvakt_config";
- private static BeanHolder beans;
+ private static BeanHolderHelper beans;
- public static void setCustomBeansHolder(BeanHolder holder) {
+ public static void setCustomBeansHolder(BeanHolderHelper holder) {
ApplicationContext context = beans.context;
holder.context = context;
BeanConfiguration.beans = holder;
}
- public static BeanHolder getBeans() {
+ public static BeanHolderHelper getBeans() {
return BeanConfiguration.beans;
}
+ @Deprecated
public static void loadAuthenticationProviders() {
Set<Class<? extends AuthenticationIface>> set = KustvaktClassLoader
.loadSubTypes(AuthenticationIface.class);
@@ -54,6 +55,10 @@
}
}
+ public static boolean hasContext() {
+ return beans != null;
+ }
+
public static void loadClasspathContext(String... files) {
if (beans == null) {
ApplicationContext context;
@@ -61,7 +66,7 @@
context = new ClassPathXmlApplicationContext(config_file);
else
context = new ClassPathXmlApplicationContext(files);
- BeanConfiguration.beans = new BeanHolder(context);
+ BeanConfiguration.beans = new BeanHolderHelper(context);
}
}
@@ -69,42 +74,54 @@
if (beans == null) {
ApplicationContext context = new FileSystemXmlApplicationContext(
"file:" + filepath);
- BeanConfiguration.beans = new BeanHolder(context);
+ BeanConfiguration.beans = new BeanHolderHelper(context);
}
}
+
+ public static void closeApplication() {
+ beans.finish();
+ }
+
//todo: set response handler
+ @Deprecated
public static KustvaktResponseHandler getResponseHandler() {
return null;
}
- public static class BeanHolder {
+ public static class BeanHolderHelper {
private ApplicationContext context = null;
- private PluginHandler handler;
+ private DefaultHandler handler;
- public BeanHolder() {
- this.handler = new PluginHandler();
+ public BeanHolderHelper() {
+ this.handler = new DefaultHandler();
}
- private BeanHolder(ApplicationContext context) {
+ private BeanHolderHelper(ApplicationContext context) {
this();
this.context = context;
}
protected <T> T getBean(Class<T> clazz) {
- try {
- return context.getBean(clazz);
- }catch (NoSuchBeanDefinitionException e) {
- return this.handler.getDefault(clazz);
+ if (context != null) {
+ try {
+ return context.getBean(clazz);
+ }catch (NoSuchBeanDefinitionException e) {
+ // do nothing
+ }
}
+ return this.handler.getDefault(clazz);
}
protected <T> T getBean(String name) {
- try {
- return (T) context.getBean(name);
- }catch (NoSuchBeanDefinitionException e) {
- return (T) this.handler.getDefault(name);
+ if (context != null) {
+ try {
+ return (T) context.getBean(name);
+ }catch (NoSuchBeanDefinitionException e) {
+ // do nothing
+ }
}
+ return (T) this.handler.getDefault(name);
}
public AuditingIface getAuditingProvider() {
@@ -131,5 +148,10 @@
return getBean(KUSTVAKT_ENCRYPTION);
}
+ public void finish() {
+ this.getAuditingProvider().finish();
+ context = null;
+ }
+
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/config/PluginHandler.java b/src/main/java/de/ids_mannheim/korap/config/DefaultHandler.java
similarity index 95%
rename from src/main/java/de/ids_mannheim/korap/config/PluginHandler.java
rename to src/main/java/de/ids_mannheim/korap/config/DefaultHandler.java
index 47ddf59..38af9f3 100644
--- a/src/main/java/de/ids_mannheim/korap/config/PluginHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/config/DefaultHandler.java
@@ -8,11 +8,11 @@
* @author hanl
* @date 17/06/2015
*/
-public class PluginHandler {
+public class DefaultHandler {
private Map<String, Object> defaults;
- public PluginHandler() {
+ public DefaultHandler() {
this.defaults = new HashMap<>();
loadClasses();
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/AuditingIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/AuditingIface.java
index 410ecbd..18a616f 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/AuditingIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/AuditingIface.java
@@ -66,4 +66,6 @@
return this.records;
}
+
+ public abstract void finish();
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
index f44bdab..45e5143 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
@@ -76,4 +76,9 @@
public abstract void confirmRegistration(String uriFragment,
String username) throws KorAPException;
+
+ @Override
+ public String toString() {
+ return "provider list: " + this.providers.toString();
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
index 01cab35..fb8048b 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
@@ -12,33 +12,33 @@
* Time: 11:04 AM
*/
public interface EntityHandlerIface {
- public UserSettings getUserSettings(Integer userid) throws KorAPException;
+ UserSettings getUserSettings(Integer userid) throws KorAPException;
- public int updateSettings(UserSettings settings) throws KorAPException;
+ int updateSettings(UserSettings settings) throws KorAPException;
- public UserDetails getUserDetails(Integer userid) throws KorAPException;
+ UserDetails getUserDetails(Integer userid) throws KorAPException;
- public int updateUserDetails(UserDetails details) throws KorAPException;
+ int updateUserDetails(UserDetails details) throws KorAPException;
- // public List<UserQuery> getUserQueries(User user) throws KorAPException;
+ // List<UserQuery> getUserQueries(User user) throws KorAPException;
- // public UserQuery getUserQuery(String id) throws KorAPException;
+ // UserQuery getUserQuery(String id) throws KorAPException;
- // public void updateUserQueries(User user, List<UserQuery> newOnes) throws KorAPException;
+ // void updateUserQueries(User user, List<UserQuery> newOnes) throws KorAPException;
- public User getAccount(String username) throws
+ User getAccount(String username) throws
EmptyResultException, KorAPException;
- public int updateAccount(User user) throws KorAPException;
+ int updateAccount(User user) throws KorAPException;
- public int createAccount(User user) throws KorAPException;
+ int createAccount(User user) throws KorAPException;
- public int deleteAccount(Integer userid) throws KorAPException;
+ int deleteAccount(Integer userid) throws KorAPException;
- public int resetPassphrase(String username, String uriToken,
+ int resetPassphrase(String username, String uriToken,
String passphrase) throws KorAPException;
- public int activateAccount(String username, String uriToken)
+ int activateAccount(String username, String uriToken)
throws KorAPException;
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/PersistenceClient.java b/src/main/java/de/ids_mannheim/korap/interfaces/PersistenceClient.java
index 43e0faa..07d53c7 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/PersistenceClient.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/PersistenceClient.java
@@ -9,6 +9,7 @@
private SOURCE source;
private TYPE type;
+ @Deprecated
protected String database;
private InputStream schema;
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java
index 24bc445..9f5a453 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java
@@ -27,7 +27,7 @@
try {
File f = new File("logs");
f.mkdirs();
- stream = new FileOutputStream(new File(f, "audit.log"));
+ stream = new FileOutputStream(new File(f, "default_audit.log"));
}catch (FileNotFoundException e) {
e.printStackTrace();
}
@@ -37,33 +37,43 @@
public <T extends AuditRecord> List<T> retrieveRecords(
AuditRecord.CATEGORY category, DateTime day, DateTime until,
boolean exact, int limit) {
- throw new UnsupportedOperationException("operation not supported!");
+ throw new UnsupportedOperationException("Operation not supported!");
}
@Override
public <T extends AuditRecord> List<T> retrieveRecords(
AuditRecord.CATEGORY category, User user, int limit) {
- throw new UnsupportedOperationException("operation not supported!");
+ throw new UnsupportedOperationException("Operation not supported!");
}
@Override
public <T extends AuditRecord> List<T> retrieveRecords(LocalDate day,
int hitMax) {
- throw new UnsupportedOperationException("operation not supported!");
+ throw new UnsupportedOperationException("Operation not supported!");
}
@Override
public <T extends AuditRecord> List<T> retrieveRecords(String userID,
LocalDate start, LocalDate end, int hitMax) {
- throw new UnsupportedOperationException("operation not supported!");
+ throw new UnsupportedOperationException("Operation not supported!");
}
@Override
public void apply() {
+ List<AuditRecord> rcs = getRecordsToSave();
try {
- for (AuditRecord r : getRecordsToSave())
+ for (AuditRecord r : rcs)
stream.write((r.toString() + "\n").getBytes());
+ }catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void finish() {
+ try {
stream.flush();
+ stream.close();
}catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/Attributes.java b/src/main/java/de/ids_mannheim/korap/user/Attributes.java
index 13303e6..55110f8 100644
--- a/src/main/java/de/ids_mannheim/korap/user/Attributes.java
+++ b/src/main/java/de/ids_mannheim/korap/user/Attributes.java
@@ -43,8 +43,8 @@
public static final String ACCOUNTLOCK = "accountLock";
public static final String ACCOUNTLINK = "accountLink";
public static final String URI = "uri";
- public static final String URI_FRAGMENT = "URIFragment";
- public static final String URI_EXPIRATION = "uriExpiration";
+ public static final String URI_FRAGMENT = "uri_fragment";
+ public static final String URI_EXPIRATION = "uri_expiration";
public static final String PRIVATE_USAGE = "privateUsage";
/**
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 32af973..7de02b4 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -30,6 +30,7 @@
private List<UserQuery> queries;
protected User() {
+ this.fields = new ParamFields();
this.accountCreation = TimeUtils.getNow().getMillis();
this.isAccountLocked = false;
this.username = "";
diff --git a/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java b/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java
index da6f630..4d012b2 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/CollectionQueryBuilder3.java
@@ -3,10 +3,7 @@
import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* convenience builder class for collection query
@@ -14,7 +11,6 @@
* @author hanl
* @date 16/09/2014
*/
-@Deprecated
public class CollectionQueryBuilder3 {
private boolean verbose;
@@ -31,14 +27,21 @@
this.rq = new LinkedList<>();
}
-
public CollectionQueryBuilder3 addSegment(String field, String value) {
String f = field + "=" + value;
this.builder.append(f);
return this;
}
- public CollectionQueryBuilder3 add(String query) {
+ /**
+ * element can be a more complex sub query like (textClass=freizeit & corpusID=WPD)
+ *
+ * @param query will be parenthised in order to make sub query element
+ * @return
+ */
+ public CollectionQueryBuilder3 addSub(String query) {
+ if (!query.startsWith("(") && !query.endsWith(")"))
+ query = "(" + query + ")";
this.builder.append(query);
return this;
}
@@ -53,29 +56,33 @@
return this;
}
- public CollectionQueryBuilder3 addResource(String collection) {
+ public CollectionQueryBuilder3 addRaw(String collection) {
try {
- List v = JsonUtils.read(collection, LinkedList.class);
- this.rq.addAll(v);
- } catch (IOException e) {
+ Map v = JsonUtils.read(collection, HashMap.class);
+ v.get("collection");
+ }catch (IOException e) {
throw new IllegalArgumentException("Conversion went wrong!");
}
return this;
}
- public List getRequest() {
- List list = new ArrayList();
- if (!this.rq.isEmpty())
- list.addAll(this.rq);
- CollectionQueryProcessor tree = new CollectionQueryProcessor(this.verbose);
+ public Map getRequest() {
+ //todo: adding another resource query doesnt work
+
+ CollectionQueryProcessor tree = new CollectionQueryProcessor(
+ this.verbose);
tree.process(this.builder.toString());
- list.add(tree.getRequestMap());
- return list;
+
+ Map request = tree.getRequestMap();
+ if (!this.rq.isEmpty()) {
+ List coll = (List) request.get("collection");
+ coll.addAll(this.rq);
+ }
+ return request;
}
public String toJSON() {
return JsonUtils.toJSON(getRequest());
}
-
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/Kustvakt.java b/src/main/java/de/ids_mannheim/korap/web/Kustvakt.java
deleted file mode 100644
index 72e8200..0000000
--- a/src/main/java/de/ids_mannheim/korap/web/Kustvakt.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package de.ids_mannheim.korap.web;
-
-import com.sun.grizzly.http.embed.GrizzlyWebServer;
-import com.sun.grizzly.http.servlet.ServletAdapter;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-import de.ids_mannheim.korap.config.BeanConfiguration;
-import de.ids_mannheim.korap.utils.KustvaktLogger;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-/**
- * @author hanl
- * @date 01/06/2015
- */
-public class Kustvakt {
-
- private static Integer PORT = -1;
- private static String CONFIG = null;
-
- public static void main(String[] args) throws Exception {
- attributes(args);
- BeanConfiguration.loadClasspathContext();
-
- if (CONFIG != null) {
- BeanConfiguration.getBeans().getConfiguration()
- .setPropertiesAsStream(new FileInputStream(new File(CONFIG)));
-
- }
- grizzlyServer(PORT);
- }
-
- public static void grizzlyServer(int port) throws IOException {
- if (port == -1)
- port = BeanConfiguration.getBeans().getConfiguration().getPort();
- System.out.println("Starting grizzly on port " + port + " ...");
- GrizzlyWebServer gws = new GrizzlyWebServer(port);
- ServletAdapter jerseyAdapter = new ServletAdapter();
- jerseyAdapter
- .addInitParameter("com.sun.jersey.config.property.packages",
- "de.ids_mannheim.korap.web.service");
- jerseyAdapter.setContextPath("/api");
- jerseyAdapter.setServletInstance(new ServletContainer());
-
- gws.addGrizzlyAdapter(jerseyAdapter, new String[] { "/api" });
- gws.start();
- }
-
- private static void attributes(String[] args) {
- for (int i = 0; i < args.length; i++) {
- switch ((args[i])) {
- case "--debug":
- KustvaktLogger.DEBUG = true;
- break;
- case "--config":
- CONFIG = args[i + 1];
- break;
- case "--port":
- PORT = Integer.valueOf(args[i + 1]);
- break;
- }
- }
- }
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 63605c9..2ac7979 100644
--- a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -1,14 +1,12 @@
// Connector to the Lucene Backend
package de.ids_mannheim.korap.web;
-import com.fasterxml.jackson.databind.JsonNode;
import de.ids_mannheim.korap.Krill;
import de.ids_mannheim.korap.KrillCollection;
import de.ids_mannheim.korap.KrillIndex;
import de.ids_mannheim.korap.response.Match;
import de.ids_mannheim.korap.response.Result;
import de.ids_mannheim.korap.util.QueryException;
-import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.KustvaktLogger;
import org.apache.lucene.store.MMapDirectory;
import org.slf4j.Logger;
@@ -171,54 +169,6 @@
return km.toJsonString();
};
- /**
- * Get statistics on (virtual) collections.
- *
- * @param json JSON-LD string with potential meta filters.
- */
- @Deprecated
- public String getStatisticsLegacy (JsonNode json) throws QueryException {
- qlog.trace(JsonUtils.toJSON(json));
- System.out.println("THE NODE BEFORE GETTING STATISTICS " + json);
-
- if (this.index == null) {
- return "{\"documents\" : -1, error\" : \"No index given\" }";
- }
-
- // Create Virtula VCollection from json search
- KrillCollection kc = new KrillCollection();
- kc.fromJsonLegacy(json);
-
- // Set index
- kc.setIndex(this.index);
-
- long docs = 0,
- tokens = 0,
- sentences = 0,
- paragraphs = 0;
-
- // Get numbers from index (currently slow)
- try {
- docs = kc.numberOf("documents");
- tokens = kc.numberOf("tokens");
- sentences = kc.numberOf("sentences");
- paragraphs = kc.numberOf("paragraphs");
- } catch (IOException e) {
- e.printStackTrace();
- }
-
-
- /*
- KorAPLogger.ERROR_LOGGER.error("Unable to retrieve statistics: {}", e.getMessage());
- */
-
- // Build json response
- StringBuilder sb = new StringBuilder("{");
- sb.append("\"documents\":").append(docs).append(",\"tokens\":")
- .append(tokens).append(",\"sentences\":").append(sentences)
- .append(",\"paragraphs\":").append(paragraphs).append("}");
- return sb.toString();
- }
/**
* Get statistics on (virtual) collections.
@@ -267,42 +217,6 @@
return sb.toString();
}
- /**
- * Get set relations on field terms of (virtual) collections.
- *
- * @param json JSON-LD string with potential meta filters.
- */
- @Deprecated
- public String getTermRelation (String json, String field) {
- qlog.trace(json);
-
- if (this.index == null) {
- return "{\"documents\" : -1, \"error\" : \"No index given\" }";
- }
-
- // Create Virtula VCollection from json search
- KrillCollection kc = new KrillCollection(json);
-
- // Set index
- kc.setIndex(this.index);
- long v = 0L;
- try {
- v = kc.numberOf("documents");
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- try {
- // Get term relations as a json string
- return kc.getTermRelationJSON(field);
- } catch (IOException e) {
- KustvaktLogger.ERROR_LOGGER
- .error("Unable to retrieve term relations: {}",
- e.getMessage());
- return "{\"documents\" : -1, \"error\" : \"IO error\" }";
- }
- }
-
public String getMatchId (String type, String docid, String tofrom) {
return new StringBuilder().append("match-").append(type).append("!")
.append(type).append("_").append(docid).append("-")
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 7a74506..c35ce5b 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
@@ -1,7 +1,6 @@
package de.ids_mannheim.korap.web.utils;
import de.ids_mannheim.korap.auditing.AuditRecord;
-import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.exceptions.BaseException;
import de.ids_mannheim.korap.exceptions.KorAPException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -19,12 +18,18 @@
*/
public class KustvaktResponseHandler {
- private static AuditingIface auditing = BeanConfiguration.getBeans()
- .getAuditingProvider();
+ private static AuditingIface auditing;
+
+ public static void init(AuditingIface iface) {
+ if (auditing == null)
+ auditing = iface;
+ }
private static void register(List<AuditRecord> records) {
if (auditing != null && !records.isEmpty())
auditing.audit(records);
+ else if (auditing == null)
+ throw new RuntimeException("Auditing handler must be set!");
}
public static WebApplicationException throwit(BaseException e) {
@@ -53,7 +58,7 @@
}
private static String buildNotification(BaseException e) {
- KustvaktResponseHandler.register(e.getRecords());
+ register(e.getRecords());
return buildNotification(e.getStatusCode(), e.getMessage(),
e.getEntity());
}
@@ -73,5 +78,4 @@
"Basic realm=Kustvakt Authentication Service")
.entity(buildNotification(e)).build());
}
-
}
diff --git a/src/test/java/ClassLoaderTest.java b/src/test/java/ClassLoaderTest.java
index 4f9e455..207ef81 100644
--- a/src/test/java/ClassLoaderTest.java
+++ b/src/test/java/ClassLoaderTest.java
@@ -1,5 +1,5 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
-import de.ids_mannheim.korap.config.PluginHandler;
+import de.ids_mannheim.korap.config.DefaultHandler;
import de.ids_mannheim.korap.interfaces.AuditingIface;
import de.ids_mannheim.korap.interfaces.defaults.DefaultAuditing;
import org.junit.Test;
@@ -18,9 +18,10 @@
@Test
public void testDefaultCreationThrowsNoException() {
- PluginHandler pl = new PluginHandler();
+ DefaultHandler pl = new DefaultHandler();
Object o = pl.getDefault(BeanConfiguration.KUSTVAKT_AUDITING);
assert o != null;
+ assert o instanceof AuditingIface;
}
@Test(expected = RuntimeException.class)
diff --git a/src/test/java/RewriteTest.java b/src/test/java/RewriteTest.java
index f06390e..7835ca1 100644
--- a/src/test/java/RewriteTest.java
+++ b/src/test/java/RewriteTest.java
@@ -4,7 +4,10 @@
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.resource.LayerMapper;
import de.ids_mannheim.korap.resource.RewriteProcessor;
-import de.ids_mannheim.korap.resource.rewrite.*;
+import de.ids_mannheim.korap.resource.rewrite.CollectionCleanupFilter;
+import de.ids_mannheim.korap.resource.rewrite.CollectionConstraint;
+import de.ids_mannheim.korap.resource.rewrite.FoundryInject;
+import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
import de.ids_mannheim.korap.utils.JsonUtils;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -37,6 +40,8 @@
s.setQuery(simple_add_query, "poliqarp");
String result = processor.process(s.toJSON());
JsonNode node = JsonUtils.readTree(result);
+
+ assert node != null;
assert !node.at("/query/wrap/foundry").isMissingNode();
}
@@ -59,6 +64,8 @@
handler.add(new FoundryInject(config));
String result = handler.apply(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
+
+ assert node != null;
assert !node.at("/query/wrap/foundry").isMissingNode();
assert !node.at("/query/wrap/rewrites").isMissingNode();
assert node.at("/query/wrap/rewrites/0/@type").asText()
@@ -73,6 +80,8 @@
handler.add(new FoundryInject(config));
String result = handler.apply(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
+
+ assert node != null;
assert node.at("/query/wrap/@type").asText().equals("koral:termGroup");
assert !node.at("/query/wrap/operands/0/foundry").isMissingNode();
assert !node.at("/query/wrap/operands/0/rewrites").isMissingNode();
@@ -89,6 +98,7 @@
String result = handler.apply(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
+ assert node != null;
assert node.at("/query/wrap/@type").asText().equals("koral:termGroup");
assert !node.at("/query/wrap/operands/0/operands/0/foundry")
.isMissingNode();
@@ -112,6 +122,7 @@
s.setCollection("textClass=politik & corpusID=WPD");
String result = s.toJSON();
JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ assert node != null;
assert node.at("/collection/operands").size() == 1;
}
@@ -124,6 +135,8 @@
s.setCollection("corpusID=BRZ13 & corpusID=WPD");
String result = s.toJSON();
JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+
+ assert node != null;
assert node.at("/collection/operands").size() == 0;
}
@@ -138,6 +151,7 @@
String result = s.toJSON();
JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ assert node != null;
assert node.at("/collection/operands/0/@type").asText()
.equals("koral:docGroup");
assert node.at("/collection/operands/0/operands/0/key").asText()
@@ -156,6 +170,7 @@
"(corpusID=BRZ13 & corpusID=WPD) & textClass=Wissenschaft & textClass=Sport");
String result = s.toJSON();
JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ assert node != null;
assert node.at("/collection/@type").asText().equals("koral:docGroup");
assert node.at("/collection/operands").size() == 2;
assert node.at("/collection/operands/0/key").asText()
@@ -174,6 +189,7 @@
s.setCollection("(corpusID=BRZ13 & textClass=Wissenschaft)");
String result = s.toJSON();
JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ assert node != null;
assert node.at("/collection/@type").asText().equals("koral:doc");
}
@@ -188,6 +204,7 @@
"(corpusID=BRZ13 & corpusID=WPD) & textClass=Wissenschaft");
String result = s.toJSON();
JsonNode node = JsonUtils.readTree(handler.apply(result, null));
+ assert node != null;
assert node.at("/collection/@type").asText().equals("koral:doc");
assert node.at("/collection/key").asText().equals("textClass");
}
diff --git a/src/test/java/FastJerseyTest.java b/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
similarity index 98%
rename from src/test/java/FastJerseyTest.java
rename to src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
index c51e62c..f3a0a04 100644
--- a/src/test/java/FastJerseyTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyTest.java
@@ -1,3 +1,5 @@
+package de.ids_mannheim.korap.web.service;
+
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.core.DefaultResourceConfig;
diff --git a/src/test/java/KustvaktCoreRestTest.java b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
similarity index 97%
rename from src/test/java/KustvaktCoreRestTest.java
rename to src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
index 11a935a..88ad2bf 100644
--- a/src/test/java/KustvaktCoreRestTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktCoreRestTest.java
@@ -1,8 +1,9 @@
+package de.ids_mannheim.korap.web.service;
+
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.utils.JsonUtils;
-import de.ids_mannheim.korap.web.service.LightService;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;