Implemented custom namedVC path.

Change-Id: I3a2074e9b155a080971b58bd9aeb0432765dfd64
diff --git a/Changes b/Changes
index 57ecbbd..74f0474 100644
--- a/Changes
+++ b/Changes
@@ -1,11 +1,12 @@
-0.58.0 2018-08-02
+0.58.0 2018-08-13
     - Implemented referencing cached collection (margaretha)
     - Implemented deserialization of collection with array values and cache option (margaretha)
     - Implemented caching collection (margaretha)
     - Implemented KrillCollection cache clearing (margaretha)
     - Implemented auto-caching (margaretha)
     - Implemented serializable doc bits vector for caching on disk (margaretha)
-    - Added check for non-existing doc bit vector in the cache (margaretha) 
+    - Added check for non-existing doc bit vector in the cache (margaretha)
+    - Implemented custom namedVC path (margaretha)
 
 0.57 2018-04-05
     - [feature] Support text queries in metadata
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index ea0abb3..6e384a1 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -7,6 +7,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.lucene.index.DocsAndPositionsEnum;
@@ -33,6 +34,7 @@
 import de.ids_mannheim.korap.collection.CollectionBuilder;
 import de.ids_mannheim.korap.collection.DocBits;
 import de.ids_mannheim.korap.response.Notifications;
+import de.ids_mannheim.korap.util.KrillProperties;
 import de.ids_mannheim.korap.util.QueryException;
 import de.ids_mannheim.korap.util.StatusCodes;
 import net.sf.ehcache.Cache;
@@ -397,7 +399,19 @@
 
     
     private String loadVCFile (String ref) {
-        File file = new File("vc/"+ref+".jsonld");
+        Properties prop = KrillProperties.loadDefaultProperties();
+        if (prop == null){
+            this.addError(StatusCodes.MISSING_KRILL_PROPERTIES,
+                    "krill.properties is not found.");
+            return null;
+        }
+        
+        String namedVCPath = prop.getProperty("krill.namedVC");
+        if (!namedVCPath.endsWith("/")){
+            namedVCPath += "/";
+        }
+        File file = new File(namedVCPath+ref+".jsonld");
+        
         String json = null;
         try {
             FileInputStream fis = new FileInputStream(file);
diff --git a/src/main/java/de/ids_mannheim/korap/collection/DocBits.java b/src/main/java/de/ids_mannheim/korap/collection/DocBits.java
index 59044ab..9b63751 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/DocBits.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/DocBits.java
@@ -13,19 +13,17 @@
 public class DocBits implements Serializable {
 
     /**
-     * 
+     * Auto generated
      */
     private static final long serialVersionUID = -3505650918983180852L;
     final long[] bits;
-    final int numBits;
 
     public DocBits (long[] bits) {
         this.bits = bits;
-        this.numBits = bits.length;
     }
 
     public BitDocIdSet createBitDocIdSet () {
-        FixedBitSet bitset = new FixedBitSet(bits, numBits);
+        FixedBitSet bitset = new FixedBitSet(bits, bits.length);
         BitDocIdSet docIdSet = new BitDocIdSet(bitset);
         return docIdSet;
     }
@@ -36,7 +34,7 @@
         int i = 1;
         for (long b : bits) {
             sb.append(b);
-            if (i < numBits) {
+            if (i < bits.length) {
                 sb.append(",");
             }
             i++;
diff --git a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
index b0f3b59..981d0ed 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
@@ -60,8 +60,6 @@
                 bitset.flip(0, maxDoc);
             }
         }
-        
-        
 
         docIdMap.put(context.hashCode(), new DocBits(bitset.getBits()));
         CachedVCData cachedVCData = new CachedVCData(new HashMap<>(docIdMap));
diff --git a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
index 1ba261c..e9a38e6 100644
--- a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
+++ b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
@@ -91,4 +91,8 @@
         };
         return info;
     };
+    
+    public static void setProp (Properties prop) {
+        KrillProperties.prop = prop;
+    }
 };
diff --git a/src/main/java/de/ids_mannheim/korap/util/StatusCodes.java b/src/main/java/de/ids_mannheim/korap/util/StatusCodes.java
index b9067ae..a9c9adf 100644
--- a/src/main/java/de/ids_mannheim/korap/util/StatusCodes.java
+++ b/src/main/java/de/ids_mannheim/korap/util/StatusCodes.java
@@ -7,6 +7,7 @@
     public static final int UNABLE_TO_ADD_DOC_TO_INDEX = 602;
     public static final int UNABLE_TP_COMMIT_STAGED_DATA_TO_INDEX = 603;
     public static final int UNABLE_TO_CONNECT_TO_DB = 604;
+    public static final int MISSING_KRILL_PROPERTIES = 605;
     public static final int MISSING_REQUEST_PARAMETER = 610;
     public static final int ARBITRARY_DESERIALIZATION_ERROR = 613;
     public static final int UNABLE_TO_GENERATE_JSON = 620;
diff --git a/src/test/resources/krill.properties b/src/test/resources/krill.properties
index e14926b..a6302b6 100644
--- a/src/test/resources/krill.properties
+++ b/src/test/resources/krill.properties
@@ -1,3 +1,4 @@
 krill.version = ${project.version}
 krill.name = ${project.name}
-krill.indexDir = test-output
\ No newline at end of file
+krill.indexDir = test-output
+krill.namedVC = vc
\ No newline at end of file