GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit dc06e767 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Merge branch 'fix-designdoc-creation' into 'master'

Fix design doc creation

See merge request !69
parents 136134c1 6836d3dd
...@@ -17,6 +17,8 @@ public class PersistanceConfig { ...@@ -17,6 +17,8 @@ public class PersistanceConfig {
@Value("${couchdb.name}") private String couchDbName; @Value("${couchdb.name}") private String couchDbName;
@Value("${couchdb.host}") private String couchDbHost; @Value("${couchdb.host}") private String couchDbHost;
@Value("${couchdb.port}") private int couchDbPort; @Value("${couchdb.port}") private int couchDbPort;
@Value("${couchdb.username:}") private String couchDbUsername;
@Value("${couchdb.password:}") private String couchDbPassword;
@Bean @Bean
public CouchDbConnector couchDbConnector() throws Exception { public CouchDbConnector couchDbConnector() throws Exception {
...@@ -33,6 +35,10 @@ public class PersistanceConfig { ...@@ -33,6 +35,10 @@ public class PersistanceConfig {
final HttpClientFactoryBean factory = new HttpClientFactoryBean(); final HttpClientFactoryBean factory = new HttpClientFactoryBean();
factory.setHost(couchDbHost); factory.setHost(couchDbHost);
factory.setPort(couchDbPort); factory.setPort(couchDbPort);
if (!couchDbUsername.isEmpty()) {
factory.setUsername(couchDbUsername);
factory.setPassword(couchDbPassword);
}
return factory; return factory;
} }
......
...@@ -2,6 +2,7 @@ package de.thm.arsnova.persistance.couchdb; ...@@ -2,6 +2,7 @@ package de.thm.arsnova.persistance.couchdb;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import org.ektorp.CouchDbInstance; import org.ektorp.CouchDbInstance;
import org.ektorp.DocumentNotFoundException;
import org.ektorp.impl.ObjectMapperFactory; import org.ektorp.impl.ObjectMapperFactory;
import org.ektorp.impl.StdCouchDbConnector; import org.ektorp.impl.StdCouchDbConnector;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -62,12 +63,12 @@ public class InitializingCouchDbConnector extends StdCouchDbConnector implements ...@@ -62,12 +63,12 @@ public class InitializingCouchDbConnector extends StdCouchDbConnector implements
logger.warn("Failed to serialize design doc.", e); logger.warn("Failed to serialize design doc.", e);
} }
} }
String rev = getCurrentRevision((String) doc.get("_id")); try {
if (rev == null) { String rev = getCurrentRevision((String) doc.get("_id"));
create(doc);
} else {
doc.put("_rev", rev); doc.put("_rev", rev);
update(doc); update(doc);
} catch (DocumentNotFoundException e) {
create(doc);
} }
}); });
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment