Skip to content
Snippets Groups Projects
Commit fae0aa9b authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Merge branch 'master' of scm.thm.de:~pcvl72/arsnova/pcvolkmers-arsnova-war

parents 26785c05 0df046e4
No related merge requests found
...@@ -38,7 +38,7 @@ public class SessionController { ...@@ -38,7 +38,7 @@ public class SessionController {
@Autowired @Autowired
ISessionService sessionService; ISessionService sessionService;
@RequestMapping("/session/{sessionkey}") @RequestMapping(value="/session/{sessionkey}", method=RequestMethod.GET)
public Session getSession(@PathVariable String sessionkey, HttpServletResponse response) { public Session getSession(@PathVariable String sessionkey, HttpServletResponse response) {
Session session = sessionService.getSession(sessionkey); Session session = sessionService.getSession(sessionkey);
if (session != null) return session; if (session != null) return session;
......
...@@ -27,6 +27,7 @@ import net.sf.json.JSONObject; ...@@ -27,6 +27,7 @@ import net.sf.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
...@@ -45,18 +46,34 @@ import de.thm.arsnova.entities.Session; ...@@ -45,18 +46,34 @@ import de.thm.arsnova.entities.Session;
@Service @Service
public class SessionService implements ISessionService { public class SessionService implements ISessionService {
private final com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session( private String databaseHost;
"localhost", 5984); private int databasePort;
private final Database database = session.getDatabase("arsnova"); private String databaseName;
private Database database;
public static final Logger logger = LoggerFactory.getLogger(SessionService.class);
public static final Logger logger = LoggerFactory @Value("#{props['couchdb.host']}")
.getLogger(SessionService.class); public final void setDatabaseHost(String databaseHost) {
this.databaseHost = databaseHost;
}
@Value("#{props['couchdb.port']}")
public final void setDatabasePort(String databasePort) {
this.databasePort = Integer.parseInt(databasePort);
}
@Value("#{props['couchdb.name']}")
public final void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
@Override @Override
public Session getSession(String keyword) { public Session getSession(String keyword) {
View view = new View("session/by_keyword"); View view = new View("session/by_keyword");
view.setKey(URLEncoder.encode("\"" + keyword + "\"")); view.setKey(URLEncoder.encode("\"" + keyword + "\""));
ViewResults results = database.view(view); ViewResults results = this.getDatabase().view(view);
if (results.getJSONArray("rows").optJSONObject(0) == null) if (results.getJSONArray("rows").optJSONObject(0) == null)
return null; return null;
...@@ -103,7 +120,7 @@ public class SessionService implements ISessionService { ...@@ -103,7 +120,7 @@ public class SessionService implements ISessionService {
view.setGroup(true); view.setGroup(true);
view.setStartKey(URLEncoder.encode("[\"" + sessionId + "\"]")); view.setStartKey(URLEncoder.encode("[\"" + sessionId + "\"]"));
view.setEndKey(URLEncoder.encode("[\"" + sessionId + "\",{}]")); view.setEndKey(URLEncoder.encode("[\"" + sessionId + "\",{}]"));
ViewResults results = database.view(view); ViewResults results = this.getDatabase().view(view);
logger.info("Feedback: {}", results.getJSONArray("rows")); logger.info("Feedback: {}", results.getJSONArray("rows"));
...@@ -173,7 +190,7 @@ public class SessionService implements ISessionService { ...@@ -173,7 +190,7 @@ public class SessionService implements ISessionService {
} }
try { try {
database.saveDocument(feedback); this.getDatabase().saveDocument(feedback);
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} }
...@@ -185,7 +202,7 @@ public class SessionService implements ISessionService { ...@@ -185,7 +202,7 @@ public class SessionService implements ISessionService {
@Transactional(isolation=Isolation.READ_COMMITTED) @Transactional(isolation=Isolation.READ_COMMITTED)
public boolean sessionKeyAvailable(String keyword) { public boolean sessionKeyAvailable(String keyword) {
View view = new View("session/by_keyword"); View view = new View("session/by_keyword");
ViewResults results = database.view(view); ViewResults results = this.getDatabase().view(view);
return ! results.containsKey(keyword); return ! results.containsKey(keyword);
} }
...@@ -193,7 +210,7 @@ public class SessionService implements ISessionService { ...@@ -193,7 +210,7 @@ public class SessionService implements ISessionService {
private String getSessionId(String keyword) { private String getSessionId(String keyword) {
View view = new View("session/by_keyword"); View view = new View("session/by_keyword");
view.setKey(URLEncoder.encode("\"" + keyword + "\"")); view.setKey(URLEncoder.encode("\"" + keyword + "\""));
ViewResults results = database.view(view); ViewResults results = this.getDatabase().view(view);
if (results.getJSONArray("rows").optJSONObject(0) == null) if (results.getJSONArray("rows").optJSONObject(0) == null)
return null; return null;
...@@ -224,4 +241,28 @@ public class SessionService implements ISessionService { ...@@ -224,4 +241,28 @@ public class SessionService implements ISessionService {
if (this.sessionKeyAvailable(keyword)) return keyword; if (this.sessionKeyAvailable(keyword)) return keyword;
return generateKeyword(); return generateKeyword();
} }
private Database getDatabase() {
if (database == null) {
try {
com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session(
databaseHost,
databasePort
);
database = session.getDatabase(databaseName);
} catch (Exception e) {
logger.error(
"Cannot connect to CouchDB database '"
+ databaseName
+"' on host '"
+ databaseHost
+ "' using port "
+ databasePort
);
}
}
return database;
}
} }
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean id="propertyPlaceholderConfigurer" <bean id="propertyPlaceholderConfigurer"
...@@ -12,12 +14,13 @@ ...@@ -12,12 +14,13 @@
p:ignoreResourceNotFound="true"> p:ignoreResourceNotFound="true">
<property name="locations" > <property name="locations" >
<list> <list>
<value>config.properties.example</value>
<value>config.properties</value> <value>config.properties</value>
</list> </list>
</property> </property>
</bean> </bean>
<util:properties id="props" location="config.properties"/>
<import resource="spring-security.xml" /> <import resource="spring-security.xml" />
<context:component-scan base-package="de.thm.arsnova" /> <context:component-scan base-package="de.thm.arsnova" />
......
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