Added create, edit, retrieve user default setting controllers

Change-Id: Iba5d6d4868aafe5cf5787f86cad61cf48d0eda3e
diff --git a/core/Changes b/core/Changes
index 4b47cb8..29195ff 100644
--- a/core/Changes
+++ b/core/Changes
@@ -12,6 +12,11 @@
    - Added comments (margaretha)
    - Updated code structure (margaretha)
    - Removed spring security libraries and ManagerInterface (margaretha)
+21/01/2019
+   - Removed codes related to user registration & password management (margaretha)  
+22/01/2019
+   - Added create, edit, retrieve user default setting controllers (margaretha)
+
 
 version 0.61.4
 14/11/2018
diff --git a/core/src/main/java/de/ids_mannheim/korap/authentication/AuthenticationManager.java b/core/src/main/java/de/ids_mannheim/korap/authentication/AuthenticationManager.java
index e782ea6..2fcc4e9 100644
--- a/core/src/main/java/de/ids_mannheim/korap/authentication/AuthenticationManager.java
+++ b/core/src/main/java/de/ids_mannheim/korap/authentication/AuthenticationManager.java
@@ -78,9 +78,11 @@
 
     public abstract boolean deleteAccount (User user) throws KustvaktException;
 
+    @Deprecated
     public abstract <T extends Userdata> T getUserData (User user,
             Class<T> clazz) throws KustvaktException;
 
+    @Deprecated
     public abstract void updateUserData (Userdata data)
             throws KustvaktException;
 
diff --git a/core/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java b/core/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java
index dea8ca7..0d1b280 100644
--- a/core/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java
+++ b/core/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java
@@ -42,7 +42,10 @@
     
     SHARE_VC, 
     DELETE_VC_ACCESS, 
-    VC_ACCESS_INFO;
+    VC_ACCESS_INFO, 
+    
+    CREATE_DEFAULT_SETTING, 
+    SETTING_INFO;
 
     @Override
     public String toString () {
diff --git a/core/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeService.java b/core/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeService.java
index da12bfd..53bfaf0 100644
--- a/core/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeService.java
+++ b/core/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeService.java
@@ -4,9 +4,20 @@
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.security.context.TokenContext;
 
+/**
+ * @author margaretha
+ *
+ */
 public interface OAuth2ScopeService {
 
-    
+    /**
+     * Verifies whether the given token context contains the required
+     * scope
+     * 
+     * @param context a token context containing authorized scopes
+     * @param requiredScope the required scope
+     * @throws KustvaktException
+     */
     void verifyScope (TokenContext context, OAuth2Scope requiredScope)
             throws KustvaktException;
 
diff --git a/core/src/main/java/de/ids_mannheim/korap/user/DataFactory.java b/core/src/main/java/de/ids_mannheim/korap/user/DataFactory.java
index bb86cb2..5ddf187 100644
--- a/core/src/main/java/de/ids_mannheim/korap/user/DataFactory.java
+++ b/core/src/main/java/de/ids_mannheim/korap/user/DataFactory.java
@@ -17,17 +17,15 @@
 import de.ids_mannheim.korap.utils.JsonUtils;
 
 /**
- * @author hanl
+ * @author hanl, margaretha
  * @date 27/01/2016
  */
 public abstract class DataFactory {
 
     private static DataFactory factory;
 
-
     private DataFactory () {}
 
-
     public static DataFactory getFactory () {
         if (factory == null)
             factory = new DefaultFactory();
@@ -116,7 +114,7 @@
         public Set<String> keys (Object data) {
             Set<String> keys = new HashSet<>();
             if (checkDataType(data) && ((JsonNode) data).isObject()) {
-                Iterator it = ((JsonNode) data).fieldNames();
+                Iterator<String> it = ((JsonNode) data).fieldNames();
                 while (it.hasNext())
                     keys.add((String) it.next());
             }
@@ -133,7 +131,8 @@
         public Object validate(Object data, ValidatorIface validator) throws KustvaktException {
             if (checkDataType(data) && ((JsonNode) data).isObject()) {
                 try {
-                    Map mdata = JsonUtils.read(toStringValue(data), HashMap.class);
+                    @SuppressWarnings("unchecked")
+                    Map<String, Object> mdata = JsonUtils.read(toStringValue(data), HashMap.class);
                     return validator.validateMap(mdata);
                 } catch (IOException e) {
                     // do nothing
@@ -182,7 +181,16 @@
                     if (value instanceof Integer)
                         node.put(field, (Integer) value);
                     if (value instanceof JsonNode)
-                        node.put(field, (JsonNode) value);
+                        node.set(field, (JsonNode) value);
+                    // EM: added
+                    if (value instanceof Collection<?>){
+                        Collection<?> list = (Collection<?>) value;
+                        ArrayNode arrayNode = JsonUtils.createArrayNode();
+                        for (Object o : list){
+                            addValue(arrayNode, null, o);
+                        }
+                        node.set(field,arrayNode);
+                    }
                     return true;
                 }
                 else if (((JsonNode) data).isArray()) {
@@ -241,7 +249,7 @@
             if (checkDataType(data1) && checkDataType(data2)) {
                 if (((JsonNode) data1).isObject()
                         && ((JsonNode) data2).isObject()) {
-                    ((ObjectNode) data1).putAll((ObjectNode) data2);
+                    ((ObjectNode) data1).setAll((ObjectNode) data2);
                 }
                 else if (((JsonNode) data1).isArray()
                         && ((JsonNode) data2).isArray()) {
diff --git a/core/src/main/java/de/ids_mannheim/korap/user/UserSettings.java b/core/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
index 5ab7c7e..9bc145d 100644
--- a/core/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
+++ b/core/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
@@ -3,7 +3,7 @@
 import de.ids_mannheim.korap.config.Attributes;
 
 /**
- * @author hanl
+ * @author hanl, margaretha
  * @date 28/01/2016
  */
 public class UserSettings extends Userdata {
@@ -12,10 +12,15 @@
 
     }
 
+    @Deprecated
     public UserSettings(Integer userid) {
         super(userid);
     }
 
+    // EM: added
+    public UserSettings(String username) {
+        super(username);
+    }
 
     @Override
     public String[] requiredFields () {
diff --git a/core/src/main/java/de/ids_mannheim/korap/user/Userdata.java b/core/src/main/java/de/ids_mannheim/korap/user/Userdata.java
index 3b8fb0e..d0135c8 100644
--- a/core/src/main/java/de/ids_mannheim/korap/user/Userdata.java
+++ b/core/src/main/java/de/ids_mannheim/korap/user/Userdata.java
@@ -10,44 +10,58 @@
 import java.util.*;
 
 /**
- * @author hanl
+ * @author hanl, margaretha
  * @date 22/01/2016
+ * 
  */
 public abstract class Userdata {
 
+    public static DataFactory dataFactory = DataFactory.getFactory();
+    
     @Getter
     @Setter
     private Integer id;
     @Getter(AccessLevel.PRIVATE)
-    @Setter(AccessLevel.PRIVATE)
     private Object data;
     @Getter
     @Setter
     private Integer userId;
-
-
+    
+    // EM: new
+    @Getter
+    @Setter
+    private String username;
+    
     public Userdata () {
         this(-1);
     }
 
+    // EM: replace with username
+    @Deprecated
     public Userdata(Integer userid) {
         this.userId = userid;
         this.id = -1;
-        this.data = DataFactory.getFactory().convertData(null);
+        this.data = dataFactory.convertData(null);
     }
 
+    // EM: new
+    public Userdata (String username) {
+        this.username = username;
+        this.id = -1;
+        this.data = dataFactory.convertData(null);
+    }
 
     public int size () {
-        return DataFactory.getFactory().size(this.data);
+        return dataFactory.size(this.data);
     }
 
 
     public Object get (String key) {
-        return DataFactory.getFactory().getValue(this.data, key);
+        return dataFactory.getValue(this.data, key);
     }
 
     public Object filter(String ... keys) {
-        return DataFactory.getFactory().filter(this.data, keys);
+        return dataFactory.filter(this.data, keys);
     }
 
 
@@ -56,13 +70,13 @@
      * @return
      */
     public boolean isValid () {
-        return missing().length == 0;
+        return findMissingFields().length == 0;
     }
 
 
-    public String[] missing () {
+    public String[] findMissingFields () {
         Set<String> missing = new HashSet<>();
-        Set<String> keys = DataFactory.getFactory().keys(this.data);
+        Set<String> keys = dataFactory.keys(this.data);
         for (String key : requiredFields()) {
             if (!keys.contains(key))
                 missing.add(key);
@@ -72,8 +86,8 @@
 
 
     public void checkRequired () throws KustvaktException {
-        String[] fields = missing();
-        if (missing().length != 0) {
+        String[] fields = findMissingFields();
+        if (findMissingFields().length != 0) {
             throw new KustvaktException(userId, StatusCodes.MISSING_PARAMETER,
                     "User data object not valid. Object has missing fields!",
                     Arrays.asList(fields).toString());
@@ -83,40 +97,41 @@
 
     //fixme: if data array, return empty?!
     public Set<String> keys () {
-        return DataFactory.getFactory().keys(this.data);
+        return dataFactory.keys(this.data);
     }
 
 
     public Collection<Object> values () {
-        return DataFactory.getFactory().values(this.data);
+        return dataFactory.values(this.data);
     }
 
 
     public void setData (String data) {
-        this.data = DataFactory.getFactory().convertData(data);
+        this.data = dataFactory.convertData(data);
     }
 
 
     public void update (Userdata other) {
         if (other != null && this.getClass().equals(other.getClass()))
-            this.data = DataFactory.getFactory().merge(this.data, other.data);
+            this.data = dataFactory.merge(this.data, other.data);
     }
 
 
     public String serialize () throws KustvaktException {
         // to have consistency with required fields --> updates/deletion may cause required fields to be missing.
         this.checkRequired();
-        return DataFactory.getFactory().toStringValue(this.data);
+        return dataFactory.toStringValue(this.data);
     }
 
 
     public void setField (String key, Object value) {
-        DataFactory.getFactory().addValue(this.data, key, value);
+        dataFactory.addValue(this.data, key, value);
     }
 
+    // EM: not reliable
     // todo: test
     public void validate (ValidatorIface validator) throws KustvaktException {
-        DataFactory.getFactory().validate(this.data, validator);
+        dataFactory.validate(this.data, validator);
     }
 
 
@@ -128,17 +143,19 @@
 
 
     public void readQuietly (Map<String, Object> map, boolean defaults_only) {
-        if (defaults_only) {
-            for (String k : defaultFields()) {
-                Object o = map.get(k);
-                if (o != null) {
-                    DataFactory.getFactory().addValue(this.data, k, o);
+        if (map != null){
+            if (defaults_only) {
+                for (String k : defaultFields()) {
+                    Object o = map.get(k);
+                    if (o != null) {
+                        dataFactory.addValue(this.data, k, o);
+                    }
                 }
             }
-        }
-        else {
-            for (String key : map.keySet())
-                DataFactory.getFactory().addValue(this.data, key, map.get(key));
+            else {
+                for (String key : map.keySet())
+                    dataFactory.addValue(this.data, key, map.get(key));
+            }
         }
     }