Set a default virtual collection from the config file.

Change-Id: I408e02b359c6705baa8e291a8f11e40e48375211
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index 1aed56c..f3e3d5c 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -83,6 +83,10 @@
     private String default_token;
     private String default_dep;
     private String default_const;
+    
+    private String defaultVirtualCollectionId;
+    private String defaultVirtualCollectionName;
+    private String defaultVirtualCollectionDescription;
 
     // deprec?!
     private final BACKENDS DEFAULT_ENGINE = BACKENDS.LUCENE;
@@ -154,6 +158,11 @@
 
         passcodeSaltField = properties.getProperty("security.passcode.salt",
                 "accountCreation");
+        
+        defaultVirtualCollectionId = properties.getProperty("virtual.collection.default.id");
+        defaultVirtualCollectionName = properties.getProperty("virtual.collection.default.name");
+        defaultVirtualCollectionDescription = properties.getProperty("virtual.collection.default.description");
+        
 
         return properties;
     }
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
index e0ba3c3..12193ca 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -102,7 +102,8 @@
         MapSqlParameterSource source = new MapSqlParameterSource();
         source.addValue("pid", id);
         String sql = "SELECT rs.*, rt.name_path FROM resource_store as rs inner join resource_tree as rt"
-                + " on rs.id=rt.child_id WHERE rs.persistent_id=:pid group by rs.id;";
+                + " on rs.id=rt.child_id WHERE rs.persistent_id=:pid";
+        //group by rs.id;";
         try {
             return (T) this.jdbcTemplate.queryForObject(sql, source,
                     new RowMapperFactory.ResourceMapper());
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
index 084a686..359643a 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
@@ -9,7 +9,6 @@
 import de.ids_mannheim.korap.security.ac.PolicyBuilder;
 import de.ids_mannheim.korap.security.ac.ResourceFinder;
 import de.ids_mannheim.korap.security.ac.SecurityManager;
-import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
 import de.ids_mannheim.korap.utils.JsonUtils;
@@ -28,35 +27,41 @@
         User user = User.UserFactory
                 .toUser(KustvaktConfiguration.KUSTVAKT_USER);
 
+        KustvaktConfiguration config = beans.getConfiguration();
+        
         KoralCollectionQueryBuilder bui = new KoralCollectionQueryBuilder();
-        bui.with("creationDate since 1775 & corpusSigle=GOE");
-
-        VirtualCollection c1 = new VirtualCollection();
-        c1.setName("Weimarer Werke");
-
-        c1.setFields(bui.toJSON());
-
-        c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
-
-        bui = new KoralCollectionQueryBuilder();
-        bui.with("textType=Aphorismus");
-
-        VirtualCollection c2 = new VirtualCollection();
-        c2.setName("Aphorismen");
-        c2.setFields(bui.toJSON());
-        c2.setDescription("Aphorismentexte Goethes");
-
-        bui = new KoralCollectionQueryBuilder();
-        bui.with("title ~ \"Werther\"");
-
-        VirtualCollection c3 = new VirtualCollection();
-        c3.setName("Werther");
-        c3.setFields(bui.toJSON());
-        c3.setDescription("Goethe - Die Leiden des jungen Werther");
+//        bui.with("creationDate since 1775 & corpusSigle=GOE");
+//
+//        VirtualCollection c1 = new VirtualCollection();
+//        c1.setName("Weimarer Werke");
+//
+//        c1.setFields(bui.toJSON());
+//
+//        c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
+//
+//        bui = new KoralCollectionQueryBuilder();
+//        bui.with("textType=Aphorismus");
+//
+//        VirtualCollection c2 = new VirtualCollection();
+//        c2.setName("Aphorismen");
+//        c2.setFields(bui.toJSON());
+//        c2.setDescription("Aphorismentexte Goethes");
+//
+//        bui = new KoralCollectionQueryBuilder();
+//        bui.with("title ~ \"Werther\"");
+//
+//        VirtualCollection c3 = new VirtualCollection();
+//        c3.setName("Werther");
+//        c3.setFields(bui.toJSON());
+//        c3.setDescription("Goethe - Die Leiden des jungen Werther");
+        
+        VirtualCollection c4 = new VirtualCollection();
+        c4.setName(config.getDefaultVirtualCollectionName());
+        c4.setDescription(config.getDefaultVirtualCollectionDescription());
 
         PolicyBuilder b = new PolicyBuilder(user);
         b.setPermissions(Permissions.Permission.READ);
-        b.setResources(c1, c2, c3);
+        b.setResources(c4);
         b.setConditions("public");
         String result = b.create();
 
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
index 5765778..c01fc66 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
@@ -4,8 +4,6 @@
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.resources.Corpus;
-import de.ids_mannheim.korap.resources.Foundry;
-import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.resources.Permissions;
 import de.ids_mannheim.korap.security.ac.PolicyBuilder;
 import de.ids_mannheim.korap.security.ac.ResourceFinder;
@@ -25,26 +23,27 @@
 
         User user = User.UserFactory
                 .toUser(KustvaktConfiguration.KUSTVAKT_USER);
+        KustvaktConfiguration config =beans.getConfiguration();
         PolicyBuilder builder = new PolicyBuilder(user);
-        builder.addCondition("public");
-        builder.setResources(new Corpus("GOE"));
-        builder.setPermissions(Permissions.Permission.READ);
-        builder.create();
+//        builder.addCondition("public");
+//        builder.setResources(new Corpus("GOE"));
+//        builder.setPermissions(Permissions.Permission.READ);
+//        builder.create();
 
         builder = new PolicyBuilder(user);
         builder.addCondition("public");
-        builder.setResources(new Corpus("WPD"));
+        builder.setResources(new Corpus(config.getDefaultVirtualCollectionId()));
         builder.setPermissions(Permissions.Permission.READ);
         builder.create();
 
-        KustvaktResource tt = new Foundry("tt");
-        tt.setName("TreeTagger");
-        tt.setDescription("todo ...");
-        builder = new PolicyBuilder(user);
-        builder.addCondition("public");
-        builder.setResources(tt);
-        builder.setPermissions(Permissions.Permission.READ);
-        builder.create();
+//        KustvaktResource tt = new Foundry("tt");
+//        tt.setName("TreeTagger");
+//        tt.setDescription("todo ...");
+//        builder = new PolicyBuilder(user);
+//        builder.addCondition("public");
+//        builder.setResources(tt);
+//        builder.setPermissions(Permissions.Permission.READ);
+//        builder.create();
     }
 
 
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
index 25d110b..02bfe4a 100644
--- a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
@@ -88,7 +88,7 @@
         KustvaktResource res = dao.findbyId(ids.get(0),
                 User.UserFactory.getDemoUser());
         assertNotNull(res);
-        Assert.assertEquals("testVal_0", res.getField("testVar"));
+        Assert.assertEquals(true,res.getField("testVar").toString().startsWith("testVal_"));
     }