Fixed KustvaktResponseHandler and missing exceptions in JsonUtils.
Change-Id: I3a95361659cebf91dc9175d08891dd67815b1851
diff --git a/full/pom.xml b/full/pom.xml
index 7d476e4..1bfb4af 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -154,12 +154,13 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
- <version>0.59.8</version>
+ <version>0.59.9</version>
+ <type>jar</type>
</dependency>
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
- <version>0.59.8</version>
+ <version>0.59.9</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
diff --git a/full/src/main/java/de/ids_mannheim/korap/filter/AuthFilter.java b/full/src/main/java/de/ids_mannheim/korap/filter/AuthFilter.java
index 79d5511..146879d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/filter/AuthFilter.java
+++ b/full/src/main/java/de/ids_mannheim/korap/filter/AuthFilter.java
@@ -27,6 +27,8 @@
@Autowired
private AuthenticationManagerIface userController;
+ @Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
// public AuthFilter () {
// this.userController = BeansFactory.getKustvaktContext()
@@ -48,7 +50,7 @@
ua);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwAuthenticationException(authentication);
+ throw kustvaktResponseHandler.throwAuthenticationException(authentication);
}
// fixme: give reason why access is not granted?
if (context != null
@@ -57,7 +59,7 @@
.isSecureRequired()))
request.setSecurityContext(new KustvaktContext(context));
else
- throw KustvaktResponseHandler.throwAuthenticationException("");
+ throw kustvaktResponseHandler.throwAuthenticationException("");
}
return request;
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java b/full/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
index 5520ffc..9cdc277 100644
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
@@ -29,6 +29,7 @@
* @date 05/11/2014
*/
// todo: error handling
+@Deprecated
public class DocumentDao implements ResourceOperationIface<Document> {
private NamedParameterJdbcTemplate jdbcTemplate;
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java b/full/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java
index 164887b..c913e51 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java
@@ -24,6 +24,9 @@
LoggerFactory.getLogger(AnnotationService.class);
@Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
+
+ @Autowired
private AnnotationDao annotationDao;
@Autowired
@@ -59,7 +62,7 @@
}
else {
jlog.error("Annotation code is wrong: " + annotationCode);
- throw KustvaktResponseHandler.throwit(
+ kustvaktResponseHandler.throwit(
new KustvaktException(StatusCodes.INVALID_ATTRIBUTE,
"Bad attribute:", code));
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/AdminController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/AdminController.java
index c9e8a4b..53f0acf 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/AdminController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/AdminController.java
@@ -16,17 +16,16 @@
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
import com.sun.jersey.api.core.HttpContext;
import com.sun.jersey.spi.container.ResourceFilters;
import de.ids_mannheim.korap.auditing.AuditRecord;
-import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.handlers.DocumentDao;
import de.ids_mannheim.korap.interfaces.db.AuditingIface;
-import de.ids_mannheim.korap.resources.Document;
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.resources.Permissions;
import de.ids_mannheim.korap.resources.ResourceFactory;
@@ -43,25 +42,22 @@
/**
* @author hanl, margaretha
* Created date 6/11/14.
- * Last update: 04/2017
+ * Last update: 08/11/2017
+ * Last changes:
+ * removed DocumentDao (EM)
*/
+@Controller
@Path(KustvaktServer.API_VERSION + "/admin")
@ResourceFilters({ AdminFilter.class, PiwikFilter.class })
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public class AdminController {
private static Logger jlog = LoggerFactory.getLogger(AdminController.class);
-
+ @Autowired
private AuditingIface auditingController;
- private DocumentDao documentDao;
-
- public AdminController () {
- this.auditingController = BeansFactory.getKustvaktContext()
- .getAuditingProvider();
- this.documentDao = new DocumentDao(
- BeansFactory.getKustvaktContext().getPersistenceClient());
- }
+ @Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
// EM: not documented and tested, not sure what the purpose of the service is
@GET
@@ -87,7 +83,7 @@
integer_limit = Integer.valueOf(limit);
}
catch (NumberFormatException | NullPointerException e) {
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT);
+ throw kustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT);
}
String result = JsonUtils.toJSON(auditingController.retrieveRecords(
AuditRecord.CATEGORY.valueOf(type.toUpperCase()), from_date,
@@ -112,31 +108,31 @@
KustvaktException e = new KustvaktException(
StatusCodes.MISSING_ARGUMENT,
"The value of parameter type is missing.");
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
else if (name == null | name.isEmpty()) {
KustvaktException e = new KustvaktException(
StatusCodes.MISSING_ARGUMENT,
"The value of parameter name is missing.");
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
else if (description == null | description.isEmpty()) {
KustvaktException e = new KustvaktException(
StatusCodes.MISSING_ARGUMENT,
"The value of parameter description is missing.");
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
else if (group == null | group.isEmpty()) {
KustvaktException e = new KustvaktException(
StatusCodes.MISSING_ARGUMENT,
"The value of parameter group is missing.");
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
else if (permissions == null | permissions.isEmpty()) {
KustvaktException e = new KustvaktException(
StatusCodes.MISSING_ARGUMENT,
"The value of parameter permissions is missing.");
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
@@ -167,25 +163,10 @@
pb.create();
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
-
- @POST
- @Path("doc/{id}/add")
- @Deprecated
- public Response addDocument (@PathParam("id") String id) {
- Document document = new Document(id);
- try {
- this.documentDao.storeResource(document, null);
- }
- catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
- }
- return Response.ok().build();
- }
-
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
index 331ed6f..ac4f69f 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
@@ -44,6 +44,9 @@
LoggerFactory.getLogger(AnnotationController.class);
@Autowired
+ KustvaktResponseHandler responseHandler;
+
+ @Autowired
private AnnotationService annotationService;
/**
@@ -73,12 +76,19 @@
@Path("description")
@Consumes(MediaType.APPLICATION_JSON)
public Response getFoundryDescriptions (String json) {
- JsonNode node = JsonUtils.readTree(json);
- if (node == null) {
- throw KustvaktResponseHandler
+ if (json == null || json.isEmpty()) {
+ throw responseHandler
.throwit(new KustvaktException(StatusCodes.MISSING_ARGUMENT,
"Missing a json string.", ""));
}
+
+ JsonNode node;
+ try {
+ node = JsonUtils.readTree(json);
+ }
+ catch (KustvaktException e1) {
+ throw responseHandler.throwit(e1);
+ }
String language;
if (!node.has("language")) {
@@ -90,7 +100,7 @@
language = "en";
}
else if (!(language.equals("en") || language.equals("de"))) {
- throw KustvaktResponseHandler.throwit(
+ throw responseHandler.throwit(
new KustvaktException(StatusCodes.UNSUPPORTED_VALUE,
"Unsupported value:", language));
}
@@ -101,16 +111,16 @@
codes = JsonUtils.convert(node.get("codes"), List.class);
}
catch (IOException | NullPointerException e) {
- throw KustvaktResponseHandler.throwit(new KustvaktException(
+ throw responseHandler.throwit(new KustvaktException(
StatusCodes.INVALID_ARGUMENT, "Bad argument:", json));
}
if (codes == null) {
- throw KustvaktResponseHandler.throwit(
+ throw responseHandler.throwit(
new KustvaktException(StatusCodes.MISSING_ATTRIBUTE,
"Missing attribute:", "codes"));
}
else if (codes.isEmpty()) {
- throw KustvaktResponseHandler
+ throw responseHandler
.throwit(new KustvaktException(StatusCodes.NO_RESULT_FOUND,
"No result found.", "codes:[]"));
}
@@ -121,7 +131,7 @@
.toJSON(annotationService.getFoundryDtos(codes, language));
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
return Response.ok(result).build();
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java
index b475c9c..f772224 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java
@@ -1,5 +1,29 @@
package de.ids_mannheim.korap.web.controller;
+import java.util.HashMap;
+import java.util.Iterator; // 07.02.17/FB
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ResourceFilters;
@@ -10,62 +34,42 @@
import de.ids_mannheim.korap.filter.AuthFilter;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
-import de.ids_mannheim.korap.server.KustvaktServer;
-import de.ids_mannheim.korap.user.*;
+import de.ids_mannheim.korap.user.TokenContext;
+import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.KustvaktLogger;
import de.ids_mannheim.korap.utils.ServiceInfo;
-import de.ids_mannheim.korap.web.filter.*;
+import de.ids_mannheim.korap.web.filter.BlockingFilter;
+import de.ids_mannheim.korap.web.filter.DemoUserFilter;
+import de.ids_mannheim.korap.web.filter.PiwikFilter;
import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
-import org.eclipse.jetty.util.log.Log;
-import org.slf4j.Logger;
-
-import javax.servlet.http.HttpServletRequest; // FB
-import javax.ws.rs.*;
-import javax.ws.rs.core.*;
-import javax.xml.ws.WebServiceContext; // FB
-import javax.xml.ws.handler.MessageContext; // FB
-import javax.annotation.Resource; // FB
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ArrayList;
-import java.util.Iterator; // 07.02.17/FB
-
//import com.sun.xml.internal.messaging.saaj.util.Base64;
/**
* @author hanl
* @date 24/01/2014
*/
+@Controller
@Path("/auth")
@ResourceFilters({ PiwikFilter.class })
@Produces(MediaType.TEXT_HTML + ";charset=utf-8")
public class AuthenticationController {
+ @Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
+
private static Boolean DEBUG_LOG = true;
//todo: bootstrap function to transmit certain default configuration settings and examples (example user queries,
// default usersettings, etc.)
private static Logger jlog = KustvaktLogger.getLogger(AuthenticationController.class);
+ @Autowired
private AuthenticationManagerIface controller;
-
// private SendMail mail;
- public AuthenticationController () {
- this.controller =
- BeansFactory.getKustvaktContext().getAuthenticationManager();
- //todo: replace with real property values
- // this.mail = new SendMail(ExtConfiguration.getMailProperties());
- }
-
-
/**
* represents json string with data. All GUI clients can access
* this method to get certain default values
@@ -117,7 +121,7 @@
List<String> auth =
headers.getRequestHeader(ContainerRequest.AUTHORIZATION);
if (auth == null || auth.isEmpty()) {
- throw KustvaktResponseHandler
+ throw kustvaktResponseHandler
.throwit(new KustvaktException(StatusCodes.MISSING_ARGUMENT,
"Authorization header is missing.",
"Authorization header"));
@@ -163,12 +167,12 @@
// "Invalid syntax for username and password"
if (values == null)
- throw KustvaktResponseHandler.throwit(StatusCodes.ACCESS_DENIED);
+ throw kustvaktResponseHandler.throwit(StatusCodes.ACCESS_DENIED);
if (values[0].equalsIgnoreCase("null")
| values[1].equalsIgnoreCase("null"))
// is actual an invalid request
- throw KustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
+ throw kustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
Map<String, Object> attr = new HashMap<>();
if (scopes != null && !scopes.isEmpty())
@@ -193,7 +197,7 @@
Attributes.API_AUTHENTICATION);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok(context.toJson()).build();
@@ -238,14 +242,14 @@
// "Invalid syntax for username and password"
if (values == null)
- throw KustvaktResponseHandler.throwit(StatusCodes.BAD_CREDENTIALS);
+ throw kustvaktResponseHandler.throwit(StatusCodes.BAD_CREDENTIALS);
// Implementation Hanl mit '|'. 16.02.17/FB
//if (values[0].equalsIgnoreCase("null")
// | values[1].equalsIgnoreCase("null"))
if (values[0].equalsIgnoreCase("null")
|| values[1].equalsIgnoreCase("null"))
- throw KustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
+ throw kustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
Map<String, Object> attr = new HashMap<>();
attr.put(Attributes.HOST, host);
@@ -260,7 +264,7 @@
jlog.debug(contextJson);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().entity(contextJson).build();
}
@@ -293,7 +297,7 @@
context = controller.createTokenContext(user, attr, null);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().entity(context.toJson()).build();
}
@@ -312,7 +316,7 @@
}
catch (KustvaktException e) {
jlog.error("Logout Exception: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/DocumentController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/DocumentController.java
index c23db52..f60a91e 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/DocumentController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/DocumentController.java
@@ -12,6 +12,8 @@
import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@@ -24,23 +26,21 @@
* @author hanl
* @date 19/11/2014
*/
+@Deprecated
+@Controller
@Path(KustvaktServer.API_VERSION + "/doc")
@ResourceFilters({ AdminFilter.class })
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public class DocumentController {
+ @Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
+
private static Logger jlog =
LoggerFactory.getLogger(DocumentController.class);
private DocumentDao documentDao;
- // todo: error handling
- public DocumentController () {
- this.documentDao = new DocumentDao(
- BeansFactory.getKustvaktContext().getPersistenceClient());
- }
-
-
@POST
@Path("{doc}")
public Response store (@PathParam("doc") String docid,
@@ -51,7 +51,7 @@
this.documentDao.storeResource(doc, null);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -72,7 +72,7 @@
return Response.ok(JsonUtils.toJSON(docs)).build();
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuthController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuthController.java
index 7192e3e..c21c406 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuthController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuthController.java
@@ -33,6 +33,7 @@
import org.apache.oltu.oauth2.common.message.types.ResponseType;
import org.apache.oltu.oauth2.common.message.types.TokenType;
import org.apache.oltu.oauth2.common.utils.OAuthUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -54,7 +55,11 @@
@Path(KustvaktServer.API_VERSION + "/oauth2")
public class OAuthController {
+ @Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
+
private OAuth2Handler handler;
+ @Autowired
private AuthenticationManagerIface controller;
private EncryptionIface crypto;
private KustvaktConfiguration config;
@@ -85,7 +90,7 @@
this.controller.getUser(ctx.getUsername()));
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -101,7 +106,7 @@
crypto.createToken());
info.setUrl(host);
if (rurl == null)
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw kustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"Missing parameter!", "redirect_url");
info.setRedirect_uri(rurl);
TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -110,7 +115,7 @@
this.handler.getPersistenceHandler().registerClient(info, user);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok(info.toJSON()).build();
}
@@ -131,7 +136,7 @@
scopes = StringUtils.toString(base_scope);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
// json format with scope callback parameter
// todo: add other scopes as well!
@@ -157,7 +162,7 @@
return Response.ok(JsonUtils.toJSON(auths)).build();
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
}
@@ -205,7 +210,7 @@
// user.addUserData(data);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
// register response according to response_type
@@ -281,7 +286,7 @@
this.handler.authorize(codeInfo, user);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
builder.setParam(OAuth.OAUTH_RESPONSE_TYPE,
ResponseType.CODE.toString());
@@ -316,7 +321,7 @@
new_context.getToken());
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
}
response = builder.buildBodyMessage();
@@ -501,7 +506,7 @@
}
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
// todo: errors for invalid scopes or different scopes then during authorization request?
//todo ??
@@ -530,7 +535,7 @@
oauthRequest.getPassword(), attr);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
try {
@@ -552,7 +557,7 @@
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
}
@@ -575,7 +580,7 @@
builder.setParam(c.getTokenType(), c.getToken());
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
index 363477a..5e37692 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.web.controller;// package
// de.ids_mannheim.korap.ext.web;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -31,6 +32,8 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import com.sun.jersey.spi.container.ResourceFilters;
@@ -66,7 +69,9 @@
import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
/**
- * EM: To Do: restructure codes regarding service and controller layers
+ * EM: To Do: restructure codes regarding service and controller
+ * layers
+ *
* @author hanl, margaretha
* @date 29/01/2014
* @lastUpdate 06/2017
@@ -82,6 +87,8 @@
LoggerFactory.getLogger(SearchController.class);
@Autowired
+ KustvaktResponseHandler responseHandler;
+ @Autowired
private SearchKrill searchKrill;
private ResourceHandler resourceHandler;
@Autowired
@@ -104,106 +111,6 @@
this.processor.defaultRewriteConstraints();
}
- /**
- * retrieve resources dependent by type. determines based on the
- * user's
- * permission or resource owner if the user can access the
- * resource.
- *
- * @param locale
- * @param context
- * @param type
- * @return valid resources in json format
- */
- @Deprecated
- @GET
- @Path("{type}")
- public Response getResources (@Context Locale locale,
- @Context SecurityContext context, @PathParam("type") String type) {
- TokenContext ctx = (TokenContext) context.getUserPrincipal();
- Set<KustvaktResource> resources = new HashSet<>();
- type = StringUtils.normalize(type);
-
- try {
- Class cl_type = ResourceFactory.getResourceClass(type);
- if (cl_type == null) throw KustvaktResponseHandler.throwit(
- StatusCodes.MISSING_ARGUMENT,
- "Resource type not available!", "");
-
- User user = controller.getUser(ctx.getUsername());
-
- resources = ResourceFinder.search(user,
- ResourceFactory.getResourceClass(type));
- }
- catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
- }
-
- Set values = new HashSet();
- for (KustvaktResource resource : resources)
- values.add(resource.toMap());
- return Response.ok(JsonUtils.toJSON(values)).build();
- }
-
-
- @Deprecated
- @GET
- @Path("{type}/{id}/{child}")
- public Response getResource (@Context SecurityContext context,
- @Context Locale locale, @PathParam("type") String type,
- @PathParam("id") String id, @PathParam("child") String child) {
- return getResource(context, locale, type,
- StringUtils.joinResources(id, child));
- }
-
-
- /**
- * @param context
- * @param locale
- * @param id
- * @param type
- * @return
- */
- @Deprecated
- @GET
- @Path("{type}/{id}")
- public Response getResource (@Context SecurityContext context,
- @Context Locale locale, @PathParam("type") String type,
- @PathParam("id") String id) {
- TokenContext ctx = (TokenContext) context.getUserPrincipal();
- type = StringUtils.normalize(type);
- KustvaktResource resource;
- try {
- Class cl_type = ResourceFactory.getResourceClass(type);
-
- if (ctx.isDemo()) {
- Set set = ResourceFinder.searchPublicFiltered(cl_type, id);
- resource = (KustvaktResource) set.toArray()[0];
- }
- else {
- User user = controller.getUser(ctx.getUsername());
- if (StringUtils.isInteger(id))
- resource = resourceHandler.findbyIntId(Integer.valueOf(id),
- user);
- else
- resource = resourceHandler.findbyStrId(id, user, cl_type);
- }
- }
- catch (KustvaktException e) {
- // if (e.getStatusCode() != StatusCodes.ACCESS_DENIED)
- throw KustvaktResponseHandler.throwit(e);
-
- // try {
- // Set set = ResourceFinder.searchPublicFiltered(cl_type, id);
- // resource = (KustvaktResource) set.toArray()[0];
- // }
- // catch (KustvaktException e1) {
- // throw KustvaktResponseHandler.throwit(e);
- // }
- }
- return Response.ok(JsonUtils.toJSON(resource.toMap())).build();
- }
-
// @GET
// @Path("colloc")
// public Response getCollocationsAll(@Context SecurityContext ctx,
@@ -313,7 +220,7 @@
result = graphDBhandler.getResponse("distCollo", "q", query);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
return Response.ok(result).build();
}
@@ -418,7 +325,12 @@
ss.setMeta(meta.raw());
KoralCollectionQueryBuilder cquery = new KoralCollectionQueryBuilder();
- cquery.setBaseQuery(ss.toJSON());
+ try {
+ cquery.setBaseQuery(ss.toJSON());
+ }
+ catch (KustvaktException e1) {
+ throw responseHandler.throwit(e1);
+ }
String query = "";
// EM: is this necessary at all?
@@ -431,7 +343,12 @@
else if (resource instanceof Corpus) {
cquery.and().with(Attributes.CORPUS_SIGLE, "=",
resource.getPersistentID());
- query = cquery.toJSON();
+ try {
+ query = cquery.toJSON();
+ }
+ catch (KustvaktException e) {
+ throw responseHandler.throwit(e);
+ }
}
}
@@ -487,7 +404,7 @@
// jsonld = this.processor.processQuery(jsonld, user);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
jlog.info("Serialized search: {}", jsonld);
@@ -522,7 +439,7 @@
catch (KustvaktException e) {
jlog.error("Failed retrieving user in the search service: {}",
e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
QuerySerializer serializer = new QuerySerializer();
@@ -539,7 +456,7 @@
jlog.info("the serialized query {}", query);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
String result = doSearch(eng, query, pageLength, meta);
@@ -584,7 +501,7 @@
MetaQueryBuilder meta, boolean raw) {
if (raw) {
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw responseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"raw not supported!", null);
}
@@ -598,7 +515,7 @@
}
catch (KustvaktException e) {
jlog.error("Failed searching in Neo4J: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
}
@@ -636,7 +553,7 @@
}
catch (KustvaktException e) {
jlog.error("Failed retrieving resource: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
if (resource instanceof VirtualCollection) {
@@ -648,10 +565,15 @@
else if (resource instanceof Corpus) {
builder.and().with(Attributes.CORPUS_SIGLE, "=",
resource.getPersistentID());
- return builder.toJSON();
+ try {
+ return builder.toJSON();
+ }
+ catch (KustvaktException e) {
+ throw responseHandler.throwit(e);
+ }
}
else {
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw responseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"Type parameter not supported", type);
}
}
@@ -675,7 +597,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
VirtualCollection tmp = resourceHandler.getCache(cache.getId(),
@@ -684,12 +606,12 @@
String query;
try {
query = this.processor.processQuery(cache.getData(), user);
+ String stats = searchKrill.getStatistics(query);
+ cache.setStats(JsonUtils.convertToClass(stats, Map.class));
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
- String stats = searchKrill.getStatistics(query);
- cache.setStats(JsonUtils.readSimple(stats, Map.class));
resourceHandler.cache(cache);
}
else
@@ -762,7 +684,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -793,24 +715,29 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
if (VirtualCollection.class.equals(ctype)) {
VirtualCollection cachetmp, collection;
- JsonNode base;
+ JsonNode base = null;
if (reference != null && !reference.equals("null")) {
try {
base = resourceHandler.findbyStrId(reference, user,
VirtualCollection.class).getData();
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
}
else if (query != null)
- base = JsonUtils.readTree(query);
+ try {
+ base = JsonUtils.readTree(query);
+ }
+ catch (KustvaktException e) {
+ responseHandler.throwit(e);
+ }
else
// todo: throw exception response for no resource to save!
return null;
@@ -828,7 +755,8 @@
// if not cached, fill with stats values
if (tmp == null) {
String stats = searchKrill.getStatistics(cquery.toJSON());
- cachetmp.setStats(JsonUtils.readSimple(stats, Map.class));
+ cachetmp.setStats(
+ JsonUtils.convertToClass(stats, Map.class));
}
if (!cache) {
@@ -844,7 +772,7 @@
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
}
return Response.ok(JsonUtils.toJSON(vals)).build();
@@ -889,7 +817,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
if (VirtualCollection.class.equals(ctype)) {
@@ -904,7 +832,7 @@
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
}
if (query != null && !query.isEmpty()) cquery.with(query);
@@ -918,7 +846,7 @@
// if not cached, fill with stats values
if (tmp == null) {
String stats = searchKrill.getStatistics(cquery.toJSON());
- cachetmp.setStats(JsonUtils.readSimple(stats, Map.class));
+ cachetmp.setStats(JsonUtils.convertToClass(stats, Map.class));
if (query != null && !query.isEmpty())
cachetmp.setFields(cquery.toJSON());
}
@@ -932,7 +860,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
}
else {
@@ -941,7 +869,7 @@
}
}
else {
- throw KustvaktResponseHandler.throwit(
+ throw responseHandler.throwit(
new KustvaktException(StatusCodes.UNSUPPORTED_RESOURCE,
"Unsupported operation for the given resource type.",
type));
@@ -977,7 +905,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
return Response.ok().build();
@@ -1015,7 +943,7 @@
catch (KustvaktException e) {
jlog.error("Failed getting user in the matchInfo service: {}",
e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
CorpusAccess corpusAccess = user.getCorpusAccess();
@@ -1058,7 +986,7 @@
}
catch (Exception e) {
jlog.error("Exception in the MatchInfo service encountered!", e);
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw responseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
e.getMessage(), "");
}
jlog.debug("MatchInfo results: " + results);
@@ -1114,7 +1042,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw responseHandler.throwit(e);
}
return Response.ok().build();
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
index d9d0cd2..cfe46ce 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
@@ -31,7 +31,7 @@
* @author hanl
* @author margaretha
*
- * @date 27/09/2017
+ * @date 08/11/2017
*
*/
@Controller
@@ -43,7 +43,8 @@
private static Logger jlog =
LoggerFactory.getLogger(StatisticController.class);
-
+ @Autowired
+ private KustvaktResponseHandler kustvaktResponseHandler;
@Autowired
private SearchKrill searchKrill;
@@ -67,7 +68,7 @@
@QueryParam("collectionQuery") String collectionQuery) {
if (collectionQuery == null || collectionQuery.isEmpty()) {
- throw KustvaktResponseHandler
+ throw kustvaktResponseHandler
.throwit(new KustvaktException(StatusCodes.MISSING_ARGUMENT,
"Parameter collectionQuery is missing.",
"collectionQuery"));
@@ -76,11 +77,17 @@
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
builder.with(collectionQuery);
- String json = builder.toJSON();
+ String json = null;
+ try {
+ json = builder.toJSON();
+ }
+ catch (KustvaktException e) {
+ throw kustvaktResponseHandler.throwit(e);
+ }
String stats = searchKrill.getStatistics(json);
if (stats.contains("-1"))
- throw KustvaktResponseHandler.throwit(StatusCodes.NO_RESULT_FOUND);
+ throw kustvaktResponseHandler.throwit(StatusCodes.NO_RESULT_FOUND);
jlog.debug("Stats: " + stats);
return Response.ok(stats).build();
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/UserController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/UserController.java
index 1399c5c..ff8ccf9 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/UserController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/UserController.java
@@ -1,19 +1,55 @@
package de.ids_mannheim.korap.web.controller;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ResourceFilters;
+
import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.Scopes;
import de.ids_mannheim.korap.config.URIParam;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.filter.AuthFilter;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
-import de.ids_mannheim.korap.server.KustvaktServer;
-import de.ids_mannheim.korap.user.*;
+import de.ids_mannheim.korap.user.KorAPUser;
+import de.ids_mannheim.korap.user.TokenContext;
+import de.ids_mannheim.korap.user.User;
+import de.ids_mannheim.korap.user.UserDetails;
+import de.ids_mannheim.korap.user.UserQuery;
+import de.ids_mannheim.korap.user.UserSettings;
+import de.ids_mannheim.korap.user.Userdata;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.StringUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
@@ -21,34 +57,27 @@
import de.ids_mannheim.korap.web.filter.DemoUserFilter;
import de.ids_mannheim.korap.web.filter.PiwikFilter;
import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.*;
-import java.util.*;
/**
* @author hanl, margaretha
- * @lastUpdate 04/2017
+ * @lastUpdate 11/2017
*/
+@Controller
@Path("/user")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
@ResourceFilters({ PiwikFilter.class })
public class UserController {
+ @Autowired
+ KustvaktResponseHandler kustvaktResponseHandler;
+
private static Logger jlog = LoggerFactory.getLogger(UserController.class);
+ @Autowired
private AuthenticationManagerIface controller;
private @Context UriInfo info;
- public UserController () {
- this.controller = BeansFactory.getKustvaktContext()
- .getAuthenticationManager();
- }
-
-
// fixme: json contains password in clear text. Encrypt request?
// EM: no encryption is needed for communications over https.
// It should not be necessary in IDS internal network.
@@ -72,7 +101,7 @@
user = controller.createUserAccount(values, true);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
URIParam uri = user.getField(URIParam.class);
if (uri.hasValues()) {
@@ -92,7 +121,7 @@
else {
jlog.error("Failed creating confirmation and expiry tokens.");
// EM: why illegal argument when uri fragment/param is self-generated
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw kustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"failed to validate uri parameter", "confirmation fragment");
}
@@ -119,7 +148,7 @@
// controller.updateAccount(user);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -131,10 +160,10 @@
public Response confirmRegistration (@QueryParam("uri") String uritoken,
@Context Locale locale, @QueryParam("user") String username) {
if (uritoken == null || uritoken.isEmpty())
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw kustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"parameter missing", "uri parameter");
if (username == null || username.isEmpty())
- throw KustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
+ throw kustvaktResponseHandler.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"parameter missing", "Username");
try {
@@ -142,7 +171,7 @@
}
catch (KustvaktException e) {
e.printStackTrace();
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -155,7 +184,13 @@
@Consumes({ MediaType.APPLICATION_JSON,
MediaType.APPLICATION_FORM_URLENCODED })
public Response requestPasswordReset (@Context Locale locale, String json) {
- JsonNode node = JsonUtils.readTree(json);
+ JsonNode node;
+ try {
+ node = JsonUtils.readTree(json);
+ }
+ catch (KustvaktException e1) {
+ throw kustvaktResponseHandler.throwit(e1);
+ }
StringBuilder builder = new StringBuilder();
String username, email;
username = node.path(Attributes.USERNAME).asText();
@@ -183,7 +218,7 @@
}
catch (KustvaktException e) {
jlog.error("Eoxception encountered!", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
ObjectNode obj = JsonUtils.createObjectNode();
@@ -233,7 +268,7 @@
m = Scopes.mapScopes(scopes, data);
}
catch (KustvaktException e) {
- throw KustvaktResponseHandler
+ throw kustvaktResponseHandler
.throwAuthenticationException(ctx.getUsername());
}
return Response.ok(m.toEntity()).build();
@@ -256,7 +291,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok(result).build();
}
@@ -293,7 +328,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
@@ -319,7 +354,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered: {}", e.string());
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok(result).build();
}
@@ -351,7 +386,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -407,7 +442,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok(JsonUtils.toJSON(add)).build();
}
@@ -425,7 +460,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok().build();
}
@@ -449,7 +484,7 @@
}
catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ throw kustvaktResponseHandler.throwit(e);
}
return Response.ok(queryStr).build();
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java b/full/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
new file mode 100644
index 0000000..ee8ee15
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
@@ -0,0 +1,152 @@
+package de.ids_mannheim.korap.web.filter;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.client.filter.LoggingFilter;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import com.sun.jersey.spi.container.ContainerRequest;
+import com.sun.jersey.spi.container.ContainerRequestFilter;
+import com.sun.jersey.spi.container.ContainerResponseFilter;
+import com.sun.jersey.spi.container.ResourceFilter;
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.BeansFactory;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
+import de.ids_mannheim.korap.user.*;
+import net.minidev.json.JSONArray;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.ext.Provider;
+import java.security.SecureRandom;
+import java.util.*;
+
+/**
+ * @author hanl
+ * @date 13/05/2014
+ */
+@Component
+@Provider
+public class PiwikFilter implements ContainerRequestFilter, ResourceFilter {
+
+ private WebResource service;
+ // private static final String SERVICE = "http://localhost:8888";
+ private static final String SERVICE = "http://10.0.10.13";
+ private static Logger jlog = LoggerFactory.getLogger(PiwikFilter.class);
+ public static boolean ENABLED = false;
+ private Map<String, String> customVars;
+ @Autowired
+ private AuthenticationManagerIface controller;
+
+
+ public PiwikFilter () {
+// controller = BeansFactory.getKustvaktContext()
+// .getAuthenticationManager();
+ ClientConfig config = new DefaultClientConfig();
+ Client client = Client.create(config);
+ if (jlog.isDebugEnabled())
+ client.addFilter(new LoggingFilter());
+ UriBuilder b = UriBuilder.fromUri(SERVICE);
+ service = client.resource(b.build());
+ this.customVars = new HashMap<>();
+ }
+
+
+ private void send (ContainerRequest request) {
+ Random random = new SecureRandom();
+ MultivaluedMap<String, String> params = new MultivaluedMapImpl();
+ params.add("idsite", "2");
+ params.add("rec", "1");
+ if (!customVars.isEmpty())
+ params.add("_cvar", translateCustomData());
+ params.add("cip", request.getHeaderValue("Host"));
+ params.add("cookie", "false");
+ params.add("r", String.valueOf(random.nextDouble()));
+ params.add("action_name", request.getRequestUri().toASCIIString());
+
+ Locale l = null;
+ if (request.getAcceptableLanguages() != null)
+ l = request.getAcceptableLanguages().get(0);
+ try {
+ service.path("piwik/piwik.php")
+ .queryParam("idsite", "2")
+ .queryParam("rec", "1")
+ //todo check for empty container
+ .queryParam("_cvar", translateCustomData())
+ .queryParam("cip", request.getHeaderValue("Host"))
+ .queryParam("cookie", "false")
+ .queryParam("r", String.valueOf(random.nextDouble()))
+ .queryParam("action_name",
+ request.getRequestUri().toASCIIString())
+ .queryParams(params).accept("text/html")
+ .header("Host", request.getHeaderValue("Host"))
+ .header("User-Agent", request.getHeaderValue("User-Agent"))
+ .acceptLanguage(l).method("GET");
+ }
+ catch (Exception e) {
+ // do nothing if piwik not available!
+ }
+ }
+
+
+ private String translateCustomData () {
+ final Map<String, List<String>> customVariables = new HashMap<String, List<String>>();
+ int i = 0;
+ for (final Map.Entry<String, String> entry : this.customVars.entrySet()) {
+ i++;
+ final List<String> list = new ArrayList<String>();
+ list.add(entry.getKey());
+ list.add(entry.getValue());
+ customVariables.put(Integer.toString(i), list);
+ }
+
+ final JSONArray json = new JSONArray();
+ json.add(customVariables);
+
+ // remove unnecessary parent square brackets from JSON-string
+ String jsonString = json.toString().substring(1,
+ json.toString().length() - 1);
+ customVars.clear();
+ return jsonString;
+ }
+
+
+ @Override
+ public ContainerRequest filter (ContainerRequest request) {
+ if (ENABLED) {
+ try {
+ TokenContext context = (TokenContext) request
+ .getUserPrincipal();
+ // since this is cached, not very expensive!
+ User user = controller.getUser(context.getUsername());
+ Userdata data = controller
+ .getUserData(user, UserSettings.class);
+ if ((Boolean) data.get(Attributes.COLLECT_AUDITING_DATA))
+ customVars.put("username", context.getUsername());
+ }
+ catch (KustvaktException | UnsupportedOperationException e) {
+ //do nothing
+ }
+ send(request);
+ }
+ return request;
+ }
+
+
+ @Override
+ public ContainerRequestFilter getRequestFilter () {
+ return this;
+ }
+
+
+ @Override
+ public ContainerResponseFilter getResponseFilter () {
+ return null;
+ }
+}
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index 869059b..cae9cdc 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -101,8 +101,8 @@
<!-- <property name="validateOnMigrate" value="false" /> -->
<!-- <property name="cleanOnValidationError" value="true" /> -->
<property name="locations" value="${jdbc.schemaPath}" />
- <property name="dataSource" ref="dataSource" />
- <!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+ <!-- <property name="dataSource" ref="dataSource" /> -->
+ <property name="dataSource" ref="sqliteDataSource" />
</bean>
@@ -114,7 +114,9 @@
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="dataSource" />
+ <!-- <property name="dataSource" ref="dataSource" /> -->
+ <property name="dataSource" ref="sqliteDataSource" />
+
<property name="packagesToScan" value="de.ids_mannheim.korap.entity" />
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
@@ -139,6 +141,7 @@
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />
+
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
@@ -161,6 +164,11 @@
<constructor-arg ref="kustvakt_db" />
</bean>
+ <bean id="kustvakt_response"
+ class="de.ids_mannheim.korap.web.utils.KustvaktResponseHandler">
+ <constructor-arg index="0" name="iface" ref="kustvakt_auditing"/>
+ </bean>
+
<bean id="kustvakt_userdb" class="de.ids_mannheim.korap.handlers.EntityDao">
<constructor-arg ref="kustvakt_db" />
</bean>
@@ -283,7 +291,8 @@
<!-- similarly, don't forget the PlatformTransactionManager -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
+ <!-- <property name="dataSource" ref="dataSource" /> -->
+ <property name="dataSource" ref="sqliteDataSource" />
</bean>
</beans>
\ No newline at end of file
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java
index 0656c02..3142330 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java
@@ -1,5 +1,7 @@
package de.ids_mannheim.korap.misc;
import com.fasterxml.jackson.databind.JsonNode;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.resources.VirtualCollection;
@@ -19,7 +21,7 @@
public class CollectionQueryBuilderTest {
@Test
- public void testsimpleAdd () {
+ public void testsimpleAdd () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("corpusSigle=WPD");
@@ -32,7 +34,7 @@
@Test
- public void testSimpleConjunction () {
+ public void testSimpleConjunction () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("corpusSigle=WPD & textClass=freizeit");
JsonNode node = JsonUtils.readTree(b.toJSON());
@@ -49,7 +51,7 @@
@Test
- public void testSimpleDisjunction () {
+ public void testSimpleDisjunction () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("corpusSigle=WPD | textClass=freizeit");
JsonNode node = JsonUtils.readTree(b.toJSON());
@@ -64,7 +66,7 @@
@Test
- public void testComplexSubQuery () {
+ public void testComplexSubQuery () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(corpusSigle=WPD) | (textClass=freizeit & corpusSigle=BRZ13)");
JsonNode node = JsonUtils.readTree(b.toJSON());
@@ -80,7 +82,7 @@
@Test
- public void testAddResourceQueryAfter () {
+ public void testAddResourceQueryAfter () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(textClass=politik & title=\"random title\") | textClass=wissenschaft");
@@ -109,7 +111,7 @@
@Test
- public void testAddComplexResourceQueryAfter () {
+ public void testAddComplexResourceQueryAfter () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(title=\"random title\") | (textClass=wissenschaft)");
@@ -135,7 +137,7 @@
@Test
- public void testBuildQuery () {
+ public void testBuildQuery () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -171,7 +173,7 @@
@Test
- public void testBaseQueryBuild () {
+ public void testBaseQueryBuild () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(corpusSigle=ADF) | (textClass=freizeit & corpusSigle=WPD)");
@@ -192,7 +194,7 @@
@Test
- public void testNodeMergeWithBase () {
+ public void testNodeMergeWithBase () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -214,7 +216,7 @@
@Test
- public void testNodeMergeWithoutBase () {
+ public void testNodeMergeWithoutBase () throws KustvaktException {
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
check.setQuery(query, "poliqarp");
@@ -235,7 +237,7 @@
@Test
- public void testNodeMergeWithoutBaseWrongOperator () {
+ public void testNodeMergeWithoutBaseWrongOperator () throws KustvaktException {
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
check.setQuery(query, "poliqarp");
@@ -263,7 +265,7 @@
@Test
- public void testAddOROperator () {
+ public void testAddOROperator () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -282,7 +284,7 @@
@Test
- public void testAddANDOperator () {
+ public void testAddANDOperator () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -301,7 +303,7 @@
@Test
- public void testAddDefaultOperator () {
+ public void testAddDefaultOperator () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -320,7 +322,7 @@
@Test
- public void testCollectionMergeWithFromResource () {
+ public void testCollectionMergeWithFromResource () throws KustvaktException {
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
builder.with("textClass=politik & corpusSigle=WPD");
KustvaktResource resource = new VirtualCollection();
@@ -339,7 +341,7 @@
@Test
- public void testCollectionMergeWithFromResourceNoCollection () {
+ public void testCollectionMergeWithFromResourceNoCollection () throws KustvaktException {
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
builder.with("textClass=politik & corpusSigle=WPD");
KustvaktResource resource = new VirtualCollection();
@@ -358,7 +360,7 @@
@Test
- public void testCollectionMergeFromQuerySerializer () {
+ public void testCollectionMergeFromQuerySerializer () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
KoralCollectionQueryBuilder total = new KoralCollectionQueryBuilder();
@@ -384,7 +386,7 @@
@Test
- public void testBaseCollectionNull () {
+ public void testBaseCollectionNull () throws KustvaktException {
// base is missing collection segment
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
@@ -412,7 +414,7 @@
@Test
- public void testMergeCollectionNull () {
+ public void testMergeCollectionNull () throws KustvaktException {
// merge json is missing collection segment
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java
index e5020f9..ff8df15 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java
@@ -37,7 +37,7 @@
@Test
- public void testQuery () {
+ public void testQuery () throws KustvaktException {
SearchKrill krill = new SearchKrill(index);
KoralCollectionQueryBuilder coll = new KoralCollectionQueryBuilder();
coll.with(qstring);
diff --git a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
index 43ff936..439462a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
@@ -131,7 +131,7 @@
@Test
- public void testDataFactoryAdd () {
+ public void testDataFactoryAdd () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
@@ -153,7 +153,7 @@
@Test
- public void testDataFactoryGet () {
+ public void testDataFactoryGet () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
@@ -203,7 +203,7 @@
@Test
- public void testDataFactoryEmbeddedProperty () {
+ public void testDataFactoryEmbeddedProperty () throws KustvaktException {
String data = "{}";
JsonNode node = JsonUtils.readTree(data);
@@ -247,7 +247,7 @@
@Test
- public void testDataFactoryMerge () {
+ public void testDataFactoryMerge () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
@@ -277,7 +277,7 @@
@Test
@Ignore
- public void testDataFactoryRemove () {
+ public void testDataFactoryRemove () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
@@ -382,7 +382,7 @@
@Test
- public void testDataFactoryKeys () {
+ public void testDataFactoryKeys () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java
index 4e06330..f8e664a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/SearchKrillTest.java
@@ -65,7 +65,7 @@
}
@Test
- public void testSearch () {
+ public void testSearch () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=der]", "poliqarp");
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
index 77eeb10..58d3ad6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
@@ -53,7 +53,7 @@
}
@Test
- public void testSessionToken() {
+ public void testSessionToken() throws KustvaktException {
String auth = BasicHttpAuth.encode(credentials[0], credentials[1]);
ClientResponse response = resource().path("auth")
.path("sessionToken").header(Attributes.AUTHORIZATION, auth)
@@ -89,7 +89,7 @@
}
@Test
- public void testSessionTokenExpire() {
+ public void testSessionTokenExpire() throws KustvaktException {
String auth = BasicHttpAuth.encode(credentials[0], credentials[1]);
ClientResponse response = resource().path("auth")
.path("sessionToken").header(Attributes.AUTHORIZATION, auth)
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
index 374f9fc..3b575d4 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
@@ -20,7 +20,7 @@
public class MatchInfoServiceTest extends FastJerseyTest {
@Test
- public void testGetMatchInfoPublicCorpus () {
+ public void testGetMatchInfoPublicCorpus () throws KustvaktException {
ClientResponse response = resource()
.path("corpus").path("GOE").path("AGA").path("01784")
@@ -46,7 +46,7 @@
}
@Test
- public void testGetMatchInfoNotAllowed () {
+ public void testGetMatchInfoNotAllowed () throws KustvaktException {
ClientResponse response = resource()
.path("corpus").path("GOE").path("AGI").path("04846")
@@ -67,7 +67,7 @@
}
@Test
- public void testGetMatchInfoWithAuthentication () {
+ public void testGetMatchInfoWithAuthentication () throws KustvaktException {
ClientResponse response = resource()
.path("corpus").path("GOE").path("AGI").path("04846")
.path("p36875-36876").path("matchInfo")
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
index f4d0144..807ee1f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
@@ -8,7 +8,9 @@
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.TestHelper;
@@ -32,7 +34,7 @@
@Test
- public void testAuthorizeClient () {
+ public void testAuthorizeClient () throws ClientHandlerException, UniformInterfaceException, KustvaktException {
String auth = BasicHttpAuth.encode(helper().getUser().getUsername(),
(String) TestHelper.getUserCredentials().get(Attributes.PASSWORD));
ClientResponse response = resource().path(getAPIVersion()).path("oauth2")
@@ -53,7 +55,7 @@
@Test
@Ignore
- public void testRevokeClient () {
+ public void testRevokeClient () throws ClientHandlerException, UniformInterfaceException, KustvaktException {
ClientResponse response = resource().path(getAPIVersion()).path("oauth2")
.path("register")
.queryParam("redirect_url", "korap.ids-mannheim.de/redirect")
@@ -68,7 +70,7 @@
@Test
@Ignore
- public void authenticate () {
+ public void authenticate () throws KustvaktException {
Map<String, Object> cred = TestHelper.getUserCredentials();
String enc = BasicHttpAuth.encode((String) cred.get(Attributes.USERNAME), (String) cred.get(Attributes.PASSWORD));
ClientResponse response = resource().path(getAPIVersion()).path("oauth2")
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
index eed1024..88fd598 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
@@ -37,7 +37,7 @@
@Test
- public void testQuerySerializationFilteredPublic () {
+ public void testQuerySerializationFilteredPublic () throws KustvaktException {
ClientResponse response = resource()
.path("corpus/WPD13/query").queryParam("q", "[orth=der]")
@@ -55,7 +55,7 @@
@Test
- public void testQuerySerializationUnexistingResource () {
+ public void testQuerySerializationUnexistingResource () throws KustvaktException {
ClientResponse response = resource()
.path("corpus/ZUW19/query").queryParam("q", "[orth=der]")
@@ -72,7 +72,7 @@
@Test
- public void testQuerySerializationWithNonPublicCorpus () {
+ public void testQuerySerializationWithNonPublicCorpus () throws KustvaktException {
ClientResponse response = resource()
.path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
@@ -89,7 +89,7 @@
@Test
- public void testQuerySerializationWithAuthentication () {
+ public void testQuerySerializationWithAuthentication () throws KustvaktException {
ClientResponse response = resource()
.path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
@@ -109,7 +109,7 @@
@Test
- public void testQuerySerializationWithNewCollection () {
+ public void testQuerySerializationWithNewCollection () throws KustvaktException {
// Add Virtual Collection
ClientResponse response = resource()
@@ -191,7 +191,7 @@
@Test
- public void testQuerySerializationOfVirtualCollection () {
+ public void testQuerySerializationOfVirtualCollection () throws KustvaktException {
ClientResponse response = resource()
.path("collection/GOE-VC/query").queryParam("q", "[orth=der]")
@@ -218,7 +218,7 @@
@Test
- public void testMetaQuerySerialization () {
+ public void testMetaQuerySerialization () throws KustvaktException {
ClientResponse response = resource()
.path("query").queryParam("context", "sentence")
@@ -245,7 +245,7 @@
@Test
- public void testMetaQuerySerializationWithOffset () {
+ public void testMetaQuerySerializationWithOffset () throws KustvaktException{
ClientResponse response = resource()
.path("query").queryParam("context", "sentence")
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
index 2ef3fd1..06741be 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
@@ -31,7 +31,7 @@
}
@Test
- public void testGetPublicVirtualCollectionInfo () {
+ public void testGetPublicVirtualCollectionInfo () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("collection").get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -44,7 +44,7 @@
@Test
- public void testGetVirtualCollectionInfoWithAuthentication () {
+ public void testGetVirtualCollectionInfoWithAuthentication () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("collection")
.header(Attributes.AUTHORIZATION,
@@ -61,7 +61,7 @@
@Test
- public void testGetVirtualCollectionInfoById () {
+ public void testGetVirtualCollectionInfoById () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("collection").path("GOE-VC").get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -77,7 +77,7 @@
}
@Test
- public void testGetVirtualCollectionInfoByIdUnauthorized () {
+ public void testGetVirtualCollectionInfoByIdUnauthorized () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("collection").path("WPD15-VC").get(ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
@@ -92,7 +92,7 @@
}
@Test
- public void testGetPublicCorporaInfo () {
+ public void testGetPublicCorporaInfo () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -106,7 +106,7 @@
@Test
- public void testGetCorpusInfoById () {
+ public void testGetCorpusInfoById () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").path("WPD13").get(ClientResponse.class);
@@ -122,7 +122,7 @@
@Test
- public void testGetCorpusInfoById2 () {
+ public void testGetCorpusInfoById2 () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").path("GOE").get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -136,7 +136,7 @@
@Test
- public void testGetPublicFoundriesInfo () {
+ public void testGetPublicFoundriesInfo () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("foundry").get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -150,7 +150,7 @@
@Test
- public void testGetFoundryInfoById () {
+ public void testGetFoundryInfoById () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("foundry").path("tt").get(ClientResponse.class);
String ent = response.getEntity(String.class);
@@ -164,7 +164,7 @@
@Test
- public void testGetUnexistingCorpusInfo () {
+ public void testGetUnexistingCorpusInfo () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").path("ZUW19").get(ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
@@ -182,7 +182,7 @@
// EM: queries for an unauthorized corpus get the same responses / treatment as
// asking for an unexisting corpus info. Does it need a specific exception instead?
@Test
- public void testGetUnauthorizedCorpusInfo () {
+ public void testGetUnauthorizedCorpusInfo () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").path("BRZ10").get(ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
index 0ccc272..3b6850b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
@@ -39,7 +39,7 @@
// create a simple test collection for user kustvakt, otherwise test fails
@Test
@Ignore
- public void testStats () {
+ public void testStats () throws KustvaktException{
ClientResponse response = resource().path(getAPIVersion())
.path("collection")
.header(Attributes.AUTHORIZATION,
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
index 1362f33..f40ba1b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
@@ -46,7 +46,7 @@
@Test
- public void testSearchQueryPublicCorpora () {
+ public void testSearchQueryPublicCorpora () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
@@ -68,7 +68,7 @@
@Test
- public void testSearchQueryWithMeta () {
+ public void testSearchQueryWithMeta () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp").queryParam("cutoff", "true")
@@ -89,7 +89,7 @@
}
@Test
- public void testSearchQueryFreeExtern () {
+ public void testSearchQueryFreeExtern () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
@@ -111,7 +111,7 @@
}
@Test
- public void testSearchQueryFreeIntern () {
+ public void testSearchQueryFreeIntern () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
@@ -134,7 +134,7 @@
@Test
- public void testSearchQueryExternAuthorized () {
+ public void testSearchQueryExternAuthorized () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
@@ -160,7 +160,7 @@
}
@Test
- public void testSearchQueryInternAuthorized () {
+ public void testSearchQueryInternAuthorized () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
@@ -191,7 +191,7 @@
// EM: shouldn't this case gets CorpusAccess.PUB ?
@Test
@Ignore
- public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP () {
+ public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp")
@@ -221,7 +221,7 @@
@Test
@Ignore
- public void testSearchQueryAuthorizedWithoutIP () {
+ public void testSearchQueryAuthorizedWithoutIP () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
@@ -247,7 +247,7 @@
@Test
@Ignore
- public void testSearchForPublicCorpusWithStringId () {
+ public void testSearchForPublicCorpusWithStringId () throws KustvaktException {
ClientResponse response = resource()
.path("corpus").path("GOE").path("search")
.queryParam("q", "blau").queryParam("ql", "poliqarp")
@@ -273,7 +273,7 @@
@Test
@Ignore
- public void testSearchForVirtualCollectionWithStringId () {
+ public void testSearchForVirtualCollectionWithStringId () throws KustvaktException{
ClientResponse response = resource()
.path("collection").path("GOE-VC").path("search")
.queryParam("q", "blau").queryParam("ql", "poliqarp")
@@ -338,7 +338,7 @@
@Test
@Ignore
- public void testSearchForCorpusWithStringIdUnauthorized () {
+ public void testSearchForCorpusWithStringIdUnauthorized () throws KustvaktException {
ClientResponse response = resource()
.path("corpus").path("WPD15").path("search")
.queryParam("q", "blau").queryParam("ql", "poliqarp")
@@ -355,7 +355,7 @@
@Test
@Ignore
- public void testSearchForSpecificCorpus () {
+ public void testSearchForSpecificCorpus () throws KustvaktException{
ClientResponse response = resource()
.path("corpus").path("GOE").path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
@@ -423,7 +423,7 @@
@Test
- public void testSearchSentenceMeta () {
+ public void testSearchSentenceMeta () throws KustvaktException{
ClientResponse response = resource()
.path("search").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp").queryParam("context", "sentence")
@@ -439,7 +439,7 @@
@Test
- public void testSearchSimpleCQL () {
+ public void testSearchSimpleCQL () throws KustvaktException{
QuerySerializer s = new QuerySerializer();
s.setQuery("(der) or (das)", "CQL");
@@ -457,7 +457,7 @@
@Test
- public void testSearchRawQuery () {
+ public void testSearchRawQuery () throws KustvaktException{
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=der]", "poliqarp");
s.setCollection("corpusSigle=GOE");
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
index 5427fd0..cbf1b3e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
@@ -22,7 +22,7 @@
// helper().runBootInterfaces();
}
- private void checkAndFree (String json) {
+ private void checkAndFree (String json) throws KustvaktException{
JsonNode node = JsonUtils.readTree(json);
assertEquals("availability",
node.at("/collection/operands/0/key").asText());
@@ -35,7 +35,7 @@
}
- private void checkAndPublic (String json) {
+ private void checkAndPublic (String json) throws KustvaktException{
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("operation:and",
@@ -58,7 +58,7 @@
node.at("/collection/rewrites/0/scope").asText());
}
- private void checkAndPublicWithoutACA (String json) {
+ private void checkAndPublicWithoutACA (String json) throws KustvaktException{
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("operation:and",
@@ -87,7 +87,7 @@
node.at("/collection/rewrites/0/scope").asText());
}
- private void checkAndAll (String json) {
+ private void checkAndAll (String json) throws KustvaktException{
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("availability(ALL)",
@@ -127,7 +127,7 @@
}
- private void checkAndAllWithoutACA (String json) {
+ private void checkAndAllWithoutACA (String json) throws KustvaktException{
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("operation:and",
@@ -172,7 +172,7 @@
@Test
- public void testAvailabilityFreeAuthorized () {
+ public void testAvailabilityFreeAuthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability = CC-BY-SA");
@@ -184,7 +184,7 @@
@Test
- public void testAvailabilityRegexFreeAuthorized () {
+ public void testAvailabilityRegexFreeAuthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability = /.*BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -195,7 +195,7 @@
@Test
- public void testAvailabilityFreeUnauthorized () {
+ public void testAvailabilityFreeUnauthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability = ACA-NC");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -206,7 +206,7 @@
@Test
- public void testAvailabilityRegexFreeUnauthorized () {
+ public void testAvailabilityRegexFreeUnauthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability = /ACA.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -216,7 +216,7 @@
}
@Test
- public void testAvailabilityRegexNoRewrite () {
+ public void testAvailabilityRegexNoRewrite () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability = /CC-BY.*/ & availability = /ACA.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -242,7 +242,7 @@
@Test
- public void testAvailabilityRegexFreeUnauthorized3 () {
+ public void testAvailabilityRegexFreeUnauthorized3 () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability = /.*NC.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -254,7 +254,7 @@
@Test
- public void testNegationAvailabilityFreeUnauthorized () {
+ public void testNegationAvailabilityFreeUnauthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability != /CC-BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -265,7 +265,7 @@
@Test
- public void testNegationAvailabilityFreeUnauthorized2 () {
+ public void testNegationAvailabilityFreeUnauthorized2 () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"availability != /.*BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -276,7 +276,7 @@
@Test
- public void testComplexNegationAvailabilityFreeUnauthorized () {
+ public void testComplexNegationAvailabilityFreeUnauthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"textClass=politik & availability != /CC-BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -287,7 +287,7 @@
@Test
- public void testComplexAvailabilityFreeUnauthorized () {
+ public void testComplexAvailabilityFreeUnauthorized () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"textClass=politik & availability=ACA-NC");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -298,7 +298,7 @@
@Test
- public void testComplexAvailabilityFreeUnauthorized3 () {
+ public void testComplexAvailabilityFreeUnauthorized3 () throws KustvaktException{
ClientResponse response = builtSimpleClientResponse(
"textClass=politik & availability=/.*NC.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -309,7 +309,7 @@
@Test
- public void testAvailabilityPublicAuthorized () {
+ public void testAvailabilityPublicAuthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"availability=ACA-NC", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -320,7 +320,7 @@
@Test
- public void testAvailabilityPublicUnauthorized () {
+ public void testAvailabilityPublicUnauthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"availability=QAO-NC-LOC:ids", "149.27.0.32");
@@ -332,7 +332,7 @@
@Test
- public void testAvailabilityRegexPublicAuthorized () {
+ public void testAvailabilityRegexPublicAuthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"availability= /ACA.*/", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -343,7 +343,7 @@
@Test
- public void testNegationAvailabilityPublicUnauthorized () {
+ public void testNegationAvailabilityPublicUnauthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"availability != ACA-NC", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -354,7 +354,7 @@
@Test
- public void testNegationAvailabilityRegexPublicUnauthorized () {
+ public void testNegationAvailabilityRegexPublicUnauthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"availability != /ACA.*/", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -365,7 +365,7 @@
@Test
- public void testComplexAvailabilityPublicUnauthorized () {
+ public void testComplexAvailabilityPublicUnauthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"textClass=politik & availability=QAO-NC-LOC:ids",
"149.27.0.32");
@@ -378,7 +378,7 @@
@Test
- public void testNegationComplexAvailabilityPublicUnauthorized () {
+ public void testNegationComplexAvailabilityPublicUnauthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"textClass=politik & availability!=QAO-NC-LOC:ids",
"149.27.0.32");
@@ -390,7 +390,7 @@
}
@Test
- public void testAvailabilityRegexAllAuthorized () {
+ public void testAvailabilityRegexAllAuthorized () throws KustvaktException{
ClientResponse response = builtClientResponseWithIP(
"availability= /ACA.*/", "10.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
index 4c84a67..b754d26 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
@@ -60,7 +60,7 @@
}
@Test
- public void testRegisterMissingFields() {
+ public void testRegisterMissingFields() throws KustvaktException{
MultivaluedMap map = new MultivaluedMapImpl();
map.putSingle("username", "testuser"); // bodmer funktioniert noch nicht
@@ -114,7 +114,7 @@
// should be run over https, since password is transmitted in plain text
@Test
- public void testRegisterAndConfirm() {
+ public void testRegisterAndConfirm() throws KustvaktException{
MultivaluedMap map = new MultivaluedMapImpl();
map.putSingle("username", "testuser");
map.putSingle("email", "hanl@ids-mannheim.de");
@@ -154,7 +154,7 @@
// EM: This test require VPN / IDS Intranet
@Test
@Ignore
- public void loginJWT() {
+ public void loginJWT() throws KustvaktException{
String en = BasicHttpAuth.encode(credentials[0], credentials[1]);
/* lauffähige Version von Hanl: */
ClientResponse response = resource().path("auth").path("apiToken")
@@ -238,7 +238,7 @@
}
@Test
- public void testUpdateUserDetailsMerge() {
+ public void testUpdateUserDetailsMerge() throws KustvaktException{
String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
Map m = new LinkedMap();
m.put("test", "test value 1");
@@ -294,7 +294,7 @@
}
@Test
- public void testUpdateUserDetailsJson() {
+ public void testUpdateUserDetailsJson() throws KustvaktException{
String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
Map m = new LinkedMap();
m.put("firstName", "newName");
@@ -329,7 +329,7 @@
@Test
@Ignore
- public void testUpdateUserSettingsForm() throws IOException {
+ public void testUpdateUserSettingsForm() throws IOException, KustvaktException{
String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
MultivaluedMap m = new MultivaluedMapImpl();
m.putSingle("queryLanguage", "poliqarp_test");
@@ -367,7 +367,7 @@
}
@Test
- public void testUpdateUserSettingsJson() throws IOException {
+ public void testUpdateUserSettingsJson() throws IOException, KustvaktException {
String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
Map m = new HashMap<>();
m.put("queryLanguage", "poliqarp_test");
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index c5c47af..43cc494 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -160,6 +160,11 @@
<bean id="kustvakt_auditing" class="de.ids_mannheim.korap.handlers.JDBCAuditing">
<constructor-arg ref="kustvakt_db" />
</bean>
+
+ <bean id="kustvakt_response"
+ class="de.ids_mannheim.korap.web.utils.KustvaktResponseHandler">
+ <constructor-arg index="0" name="iface" ref="kustvakt_auditing"/>
+ </bean>
<bean id="kustvakt_userdb" class="de.ids_mannheim.korap.handlers.EntityDao">
<constructor-arg ref="kustvakt_db" />