diff --git a/src/main/java/de/thm/arsnova/config/PersistanceConfig.java b/src/main/java/de/thm/arsnova/config/PersistanceConfig.java index 1b9cf5ad867d62c64b4a4711728307d9f27d3fc5..8955777066a7a0fb8bffdb00931c513edb952b0c 100644 --- a/src/main/java/de/thm/arsnova/config/PersistanceConfig.java +++ b/src/main/java/de/thm/arsnova/config/PersistanceConfig.java @@ -17,6 +17,8 @@ public class PersistanceConfig { @Value("${couchdb.name}") private String couchDbName; @Value("${couchdb.host}") private String couchDbHost; @Value("${couchdb.port}") private int couchDbPort; + @Value("${couchdb.username:}") private String couchDbUsername; + @Value("${couchdb.password:}") private String couchDbPassword; @Bean public CouchDbConnector couchDbConnector() throws Exception { @@ -33,6 +35,10 @@ public class PersistanceConfig { final HttpClientFactoryBean factory = new HttpClientFactoryBean(); factory.setHost(couchDbHost); factory.setPort(couchDbPort); + if (!couchDbUsername.isEmpty()) { + factory.setUsername(couchDbUsername); + factory.setPassword(couchDbPassword); + } return factory; } diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/InitializingCouchDbConnector.java b/src/main/java/de/thm/arsnova/persistance/couchdb/InitializingCouchDbConnector.java index b6675a48d380aa840ab07440b3d39d65fb4c6511..d968a7ae030dd6e207d29287efeac3a2bf59f929 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/InitializingCouchDbConnector.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/InitializingCouchDbConnector.java @@ -2,6 +2,7 @@ package de.thm.arsnova.persistance.couchdb; import com.fasterxml.jackson.core.JsonProcessingException; import org.ektorp.CouchDbInstance; +import org.ektorp.DocumentNotFoundException; import org.ektorp.impl.ObjectMapperFactory; import org.ektorp.impl.StdCouchDbConnector; import org.slf4j.Logger; @@ -62,12 +63,12 @@ public class InitializingCouchDbConnector extends StdCouchDbConnector implements logger.warn("Failed to serialize design doc.", e); } } - String rev = getCurrentRevision((String) doc.get("_id")); - if (rev == null) { - create(doc); - } else { + try { + String rev = getCurrentRevision((String) doc.get("_id")); doc.put("_rev", rev); update(doc); + } catch (DocumentNotFoundException e) { + create(doc); } }); }