Added service layer to SearchController, added OAuth2 scope handling,
fixed bugs.

Change-Id: Id6cfb5c264472d106314dbd4a485681460e67288
diff --git a/core/Changes b/core/Changes
index 687adb1..409fd0d 100644
--- a/core/Changes
+++ b/core/Changes
@@ -1,8 +1,13 @@
+version 0.60.5
+09/07/2018
+	- Fixed status codes (margaretha)
+	- Added KustvaktException for wrapping another exception (margaretha)
+	
 version 0.60.4
 25/06/2018
 	- added the redirect URI property in KustvaktException (margaretha)
 	- added openid related status codes (margaretha)
-	
+
 version 0.60.3
 30/05/2018
 	- added parameter checker for collection (margaretha)
diff --git a/core/pom.xml b/core/pom.xml
index 2525eff..0fa8b97 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -3,7 +3,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>de.ids_mannheim.korap</groupId>
 	<artifactId>Kustvakt-core</artifactId>
-	<version>0.60.4</version>
+	<version>0.60.5</version>
 
 	<properties>
 		<java.version>1.8</java.version>
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/Attributes.java b/core/src/main/java/de/ids_mannheim/korap/config/Attributes.java
index 51e4dab..dd54f28 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/Attributes.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/Attributes.java
@@ -20,7 +20,7 @@
     
     public static final String CLIENT_ID = "client_id";
     public static final String CLIENT_SECRET = "client_secret";
-    public static final String SCOPES = "scopes";
+    public static final String SCOPE = "scope";
 
     public static final String PUBLIC_GROUP = "public";
 
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/Scopes.java b/core/src/main/java/de/ids_mannheim/korap/config/Scopes.java
index 1cc07cf..20e5627 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/Scopes.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/Scopes.java
@@ -68,7 +68,7 @@
             }
             if (scopes.contains(Scope.profile.toString()))
                 m.values.putAll(Scopes.getProfileScopes(details).values);
-            m.values.put(Attributes.SCOPES, scopes);
+            m.values.put(Attributes.SCOPE, scopes);
         }
         return m;
     }
diff --git a/core/src/main/java/de/ids_mannheim/korap/exceptions/KustvaktException.java b/core/src/main/java/de/ids_mannheim/korap/exceptions/KustvaktException.java
index 9a76e74..9123a5b 100644
--- a/core/src/main/java/de/ids_mannheim/korap/exceptions/KustvaktException.java
+++ b/core/src/main/java/de/ids_mannheim/korap/exceptions/KustvaktException.java
@@ -107,6 +107,11 @@
 
 
 
+    public KustvaktException (String notification) {
+        this.notification = notification;
+        isNotification = true;
+    }
+
     public String string () {
         return "Excpt{" + "status=" + getStatusCode() + ", message="
                 + getMessage() + ", args=" + getEntity() + ", userid=" + userid
diff --git a/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java b/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
index 5bd0a8d..2166813 100644
--- a/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -26,17 +26,23 @@
     public static final int HTTPS_REQUIRED = 110;
 
     /**
+     * 200 status codes general JSON serialization error
+     */
+
+    public static final int SERIALIZATION_FAILED = 200;
+    public static final int DESERIALIZATION_FAILED = 201;
+    public static final int MISSING_ATTRIBUTE = 202;
+    public static final int INVALID_ATTRIBUTE = 203;
+    public static final int UNSUPPORTED_VALUE = 204;
+
+    /**
      * 300 status codes for query language and serialization
      */
 
     public static final int NO_QUERY = 301;
-    //    public static final int INVALID_TYPE = 302;
-    public static final int MISSING_ATTRIBUTE = 303;
-    public static final int INVALID_ATTRIBUTE = 304;
-    public static final int UNSUPPORTED_VALUE = 305;
-    public static final int SERIALIZATION_FAILED = 306;
-    public static final int DESERIALIZATION_FAILED = 307;
-
+//    public static final int INVALID_TYPE = 302;
+//    public static final int SERIALIZATION_FAILED = 300;
+    
     /**
      *  400 status codes for authorization and rewrite functions
      */
@@ -83,15 +89,6 @@
     public static final int DB_ENTRY_EXISTS = 508;
 
 
-    // User group and member 
-    public static final int GROUP_MEMBER_EXISTS = 601;
-    public static final int GROUP_MEMBER_INACTIVE = 602;
-    public static final int GROUP_MEMBER_DELETED = 603;
-    public static final int GROUP_MEMBER_NOT_FOUND = 604;
-    public static final int INVITATION_EXPIRED = 605;
-    public static final int GROUP_NOT_FOUND = 606;
-    public static final int GROUP_DELETED = 607;
-
     //    public static final int ARGUMENT_VALIDATION_FAILURE = 700;
     // public static final int ARGUMENT_VALIDATION_FAILURE = 701;
 
@@ -112,6 +109,16 @@
     public static final int REQUEST_INVALID = 1002;
     public static final int ACCESS_DENIED = 1003;
 
+    
+    // User group and member 
+    public static final int GROUP_MEMBER_EXISTS = 1601;
+    public static final int GROUP_MEMBER_INACTIVE = 1602;
+    public static final int GROUP_MEMBER_DELETED = 1603;
+    public static final int GROUP_MEMBER_NOT_FOUND = 1604;
+    public static final int INVITATION_EXPIRED = 1605;
+    public static final int GROUP_NOT_FOUND = 1606;
+    public static final int GROUP_DELETED = 1607;
+    
     /**
      * 1800 Oauth2 and OpenID
      */
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java b/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
index d118ac2..2a398e7 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
@@ -19,11 +19,11 @@
 public class CoreResponseHandler {
 
     private AuditingIface auditing;
-    
+
     public CoreResponseHandler (AuditingIface iface) {
         this.auditing = iface;
     }
-    
+
     private void register (List<AuditRecord> records) {
         if (auditing != null && !records.isEmpty())
             auditing.audit(records);
@@ -34,11 +34,18 @@
 
     public WebApplicationException throwit (KustvaktException e) {
         Response s;
-        if (e.hasNotification()){
-            s = Response.status(getStatus(e.getStatusCode()))
-                    .entity(e.getNotification()).build();
+        if (e.hasNotification()) {
+            if (e.getStatusCode() != null) {
+                s = Response.status(getStatus(e.getStatusCode()))
+                        .entity(e.getNotification()).build();
+            }
+            // KustvaktException just wraps another exception 
+            else {
+                s=Response.status(Response.Status.BAD_REQUEST)
+                        .entity(e.getNotification()).build();
+            }
         }
-        else{
+        else {
             s = Response.status(getStatus(e.getStatusCode()))
                     .entity(buildNotification(e)).build();
         }
@@ -58,10 +65,10 @@
     }
 
     public WebApplicationException throwit (int code, String notification) {
-        return new WebApplicationException(Response.status(getStatus(code))
-                .entity(notification).build());
+        return new WebApplicationException(
+                Response.status(getStatus(code)).entity(notification).build());
     }
-    
+
     protected String buildNotification (KustvaktException e) {
         register(e.getRecords());
         return buildNotification(e.getStatusCode(), e.getMessage(),
@@ -78,9 +85,9 @@
     protected Response.Status getStatus (int code) {
         Response.Status status = Response.Status.BAD_REQUEST;
         switch (code) {
-//            case StatusCodes.NO_VALUE_FOUND:
-//                status = Response.Status.NO_CONTENT;
-//                break;
+            // case StatusCodes.NO_VALUE_FOUND:
+            // status = Response.Status.NO_CONTENT;
+            // break;
             case StatusCodes.ILLEGAL_ARGUMENT:
                 status = Response.Status.NOT_ACCEPTABLE;
                 break;