Changed loading external kustvakt.conf and jdbc.properties

to use /data folder (#598)

Change-Id: I0431d6fa76e68a90821234f90a626d999b150aac
diff --git a/Changes b/Changes
index a34b4b2..3eb7fa4 100644
--- a/Changes
+++ b/Changes
@@ -5,6 +5,9 @@
 - Moved service.properties to src/main/resources/properties 
 - Moved free-resources.json to src/main/resources/json
 - Enables inputting free-resources.json from data folder
+- Changed loading external kustvakt.conf and jdbc.properties 
+  to use /data folder (#598)
+
 
 
 # version 0.73
diff --git a/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java b/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
index d13517c..9ad1334 100644
--- a/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
+++ b/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
@@ -1,13 +1,18 @@
 package de.ids_mannheim.korap.server;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.nio.charset.StandardCharsets;
 import java.security.NoSuchAlgorithmException;
+import java.util.Properties;
 import java.util.Scanner;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.HttpConnectionFactory;
 import org.eclipse.jetty.server.Server;
@@ -22,17 +27,20 @@
 import org.springframework.web.context.support.XmlWebApplicationContext;
 
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.dao.AnnotationDao;
 import de.ids_mannheim.korap.encryption.RandomCodeGenerator;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import lombok.Getter;
 import lombok.Setter;
 
 /**
- * @author hanl
- * @date 01/06/2015
+ * @author hanl, margaretha
+ * 
  */
 public abstract class KustvaktBaseServer {
 
+    private Logger log = LogManager.getLogger(KustvaktBaseServer.class);
+    
     protected static KustvaktConfiguration config;
     protected static String springConfig = "default-config.xml";
 
@@ -76,6 +84,28 @@
         return kargs;
     }
 
+    protected void loadProperties (String path, String defaultPath) throws IOException {
+        File f = new File(path);
+        Properties properties = new Properties();
+
+        InputStream in = null;
+        if (!f.exists()) {
+            log.info("Loading kustvakt configuration from "+defaultPath);
+            in = KustvaktServer.class.getClassLoader()
+                    .getResourceAsStream(defaultPath);
+        }
+        else {
+            log.info("Loading kustvakt configuration from "+path);
+            in = new FileInputStream(f);
+        }
+
+        properties.load(in);
+        in.close();
+        
+        config = new KustvaktConfiguration();
+        config.loadBasicProperties(properties);
+    }
+    
     protected void start ()
             throws KustvaktException, IOException, NoSuchAlgorithmException {
 
diff --git a/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java b/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
index d6b1c80..173a424 100644
--- a/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
+++ b/src/main/java/de/ids_mannheim/korap/server/KustvaktLiteServer.java
@@ -1,12 +1,5 @@
 package de.ids_mannheim.korap.server;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.Properties;
-
-import de.ids_mannheim.korap.config.KustvaktConfiguration;
-
 public class KustvaktLiteServer extends KustvaktBaseServer {
 
     public static void main (String[] args) throws Exception {
@@ -16,22 +9,7 @@
         if (kargs == null)
             System.exit(0);
 
-        File f = new File("kustvakt-lite.conf");
-        Properties properties = new Properties();
-        InputStream in = null;
-
-        if (!f.exists()) {
-            in = KustvaktLiteServer.class.getClassLoader()
-                    .getResourceAsStream("kustvakt-lite.conf");
-        }
-        else {
-            in = new FileInputStream(f);
-        }
-
-        properties.load(in);
-        in.close();
-        config = new KustvaktConfiguration();
-        config.loadBasicProperties(properties);
+        server.loadProperties("data/kustvakt-lite.conf", "kustvakt-lite.conf");
 
         springConfig = "default-lite-config.xml";
 
diff --git a/src/main/java/de/ids_mannheim/korap/server/KustvaktServer.java b/src/main/java/de/ids_mannheim/korap/server/KustvaktServer.java
index 392190e..2dd0ae9 100644
--- a/src/main/java/de/ids_mannheim/korap/server/KustvaktServer.java
+++ b/src/main/java/de/ids_mannheim/korap/server/KustvaktServer.java
@@ -1,12 +1,5 @@
 package de.ids_mannheim.korap.server;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.Properties;
-
-import de.ids_mannheim.korap.config.FullConfiguration;
-
 /**
  * pu
  * 
@@ -19,27 +12,11 @@
         KustvaktServer server = new KustvaktServer();
         kargs = server.readAttributes(args);
 
-        File f = new File("kustvakt.conf");
-        Properties properties = new Properties();
-
-        InputStream in = null;
-        if (!f.exists()) {
-            in = KustvaktServer.class.getClassLoader()
-                    .getResourceAsStream("kustvakt.conf");
-        }
-        else {
-            in = new FileInputStream(f);
-        }
-
-        properties.load(in);
-        in.close();
-
-        config = new FullConfiguration();
-        config.loadBasicProperties(properties);
-
+        // EM: why is this necessary?
         if (kargs == null)
             System.exit(0);
 
+        server.loadProperties("data/kustvakt.conf", "kustvakt.conf");
         server.start();
     }
 }
diff --git a/src/main/resources/default-config.xml b/src/main/resources/default-config.xml
index 291271c..57e2f8d 100644
--- a/src/main/resources/default-config.xml
+++ b/src/main/resources/default-config.xml
@@ -29,6 +29,7 @@
 			<array>
 				<value>classpath:kustvakt.conf</value>
 				<value>file:./kustvakt.conf</value>
+				<value>file:./data/kustvakt.conf</value>
 			</array>
 		</property>
 	</bean>
@@ -40,12 +41,14 @@
 			<array>
 				<value>classpath:properties/jdbc.properties</value>
 				<value>file:./jdbc.properties</value>
+				<value>file:./data/jdbc.properties</value>
 				<value>classpath:properties/mail.properties</value>
 				<value>file:./mail.properties</value>
 				<value>classpath:properties/hibernate.properties</value>
 
 				<value>classpath:kustvakt.conf</value>
 				<value>file:./kustvakt.conf</value>
+				<value>file:./data/kustvakt.conf</value>
 			</array>
 		</property>
 	</bean>