diff --git a/src/main/java/de/thm/arsnova/SessionController.java b/src/main/java/de/thm/arsnova/SessionController.java new file mode 100644 index 0000000000000000000000000000000000000000..334969898030b2a05b45f39ee4bca1165771d3b8 --- /dev/null +++ b/src/main/java/de/thm/arsnova/SessionController.java @@ -0,0 +1,28 @@ +package de.thm.arsnova; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +import de.thm.arsnova.entities.Session; +import de.thm.arsnova.services.ISessionService; + +@Controller +public class SessionController { + + @Autowired + ISessionService sessionService; + + @RequestMapping("/session/{sessionkey}") + public Session getSession(@PathVariable String sessionkey, HttpServletResponse response) { + Session session = sessionService.getSession(sessionkey); + if (session != null) return session; + + response.setStatus(HttpStatus.NOT_FOUND.value()); + return null; + } +} diff --git a/src/main/java/de/thm/arsnova/entities/Session.java b/src/main/java/de/thm/arsnova/entities/Session.java new file mode 100644 index 0000000000000000000000000000000000000000..431b221372fb1cbd52ab88837a79e79967938fed --- /dev/null +++ b/src/main/java/de/thm/arsnova/entities/Session.java @@ -0,0 +1,55 @@ +package de.thm.arsnova.entities; + + +public class Session { + + private String type; + private String name; + private String shortName; + private String keyword; + private String creator; + private boolean active; + private String _id; + private String _rev; + + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getShortName() { + return shortName; + } + public void setShortName(String shortName) { + this.shortName = shortName; + } + public String getKeyword() { + return keyword; + } + public void setKeyword(String keyword) { + this.keyword = keyword; + } + public String getCreator() { + return creator; + } + public void setCreator(String creator) { + this.creator = creator; + } + public boolean isActive() { + return active; + } + public void setActive(boolean active) { + this.active = active; + } + + public void set_id(String id) {} + public void set_rev(String rev) {} + +} diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java new file mode 100644 index 0000000000000000000000000000000000000000..a40d08b1efa284c5631a7bab0495f476ef4e8814 --- /dev/null +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -0,0 +1,10 @@ +package de.thm.arsnova.services; + +import de.thm.arsnova.entities.Session; + + +public interface ISessionService { + + public Session getSession(String keyword); + +} \ No newline at end of file diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java new file mode 100644 index 0000000000000000000000000000000000000000..b4737211843dd94b1c4d646279333e03e82d3f0c --- /dev/null +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -0,0 +1,37 @@ +package de.thm.arsnova.services; + +import java.net.URLEncoder; + +import net.sf.json.JSONObject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.fourspaces.couchdb.Database; +import com.fourspaces.couchdb.View; +import com.fourspaces.couchdb.ViewResults; + +import de.thm.arsnova.entities.Session; + +@Service +public class SessionService implements ISessionService { + + private final com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session("localhost", 5984); + public static final Logger logger = LoggerFactory + .getLogger(SessionService.class); + + @Override + public Session getSession(String keyword) { + Database db = session.getDatabase("arsnova"); + View view = new View("session/by_keyword"); + view.setKey(URLEncoder.encode("\""+keyword+"\"")); + ViewResults results = db.view(view); + + if (results.getJSONArray("rows").optJSONObject(0) == null) return null; + + Session result = (Session)JSONObject.toBean(results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"), Session.class); + return result; + } + +} diff --git a/src/main/webapp/WEB-INF/arsnova-servlet.xml b/src/main/webapp/WEB-INF/arsnova-servlet.xml index 32eddb27c9697e9dcde9fd3b9cb9d92ad84a2360..9b8f48148edefa06733b6ac328d3b08b76415baf 100644 --- a/src/main/webapp/WEB-INF/arsnova-servlet.xml +++ b/src/main/webapp/WEB-INF/arsnova-servlet.xml @@ -12,28 +12,48 @@ <context:annotation-config /> <mvc:resources mapping="/**.html" location="/" /> - <mvc:resources mapping="/**.png" location="/"/> - <mvc:resources mapping="/**.manifest" location="/"/> - <mvc:resources mapping="/**.json" location="/"/> - <mvc:resources mapping="/**.xml" location="/"/> - <mvc:resources mapping="/dojo/**" location="/dojo/"/> - <mvc:resources mapping="/dijit/**" location="/dijit/"/> - <mvc:resources mapping="/dojox/**" location="/dojox/"/> - <mvc:resources mapping="/app/**" location="/app/"/> - <mvc:resources mapping="/views/**" location="/views/"/> - <mvc:resources mapping="/lib/**" location="/lib/"/> - <mvc:resources mapping="/resources/**" location="/resources/"/> - <mvc:resources mapping="/screenshots/**" location="/screenshots/"/> - <mvc:resources mapping="/templates/**" location="/templates/"/> - + <mvc:resources mapping="/**.png" location="/" /> + <mvc:resources mapping="/**.manifest" location="/" /> + <mvc:resources mapping="/**.json" location="/" /> + <mvc:resources mapping="/**.xml" location="/" /> + <mvc:resources mapping="/dojo/**" location="/dojo/" /> + <mvc:resources mapping="/dijit/**" location="/dijit/" /> + <mvc:resources mapping="/dojox/**" location="/dojox/" /> + <mvc:resources mapping="/app/**" location="/app/" /> + <mvc:resources mapping="/views/**" location="/views/" /> + <mvc:resources mapping="/lib/**" location="/lib/" /> + <mvc:resources mapping="/resources/**" location="/resources/" /> + <mvc:resources mapping="/screenshots/**" location="/screenshots/" /> + <mvc:resources mapping="/templates/**" location="/templates/" /> + <mvc:annotation-driven /> - <bean id="viewResolver" - class="org.springframework.web.servlet.view.InternalResourceViewResolver"> - <property name="viewClass" - value="org.springframework.web.servlet.view.JstlView" /> - <property name="prefix" value="/WEB-INF/views/" /> - <property name="suffix" value=".jsp" /> + <bean + class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> + <bean + class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> + <property name="messageConverters"> + <list> + <bean + class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> + </list> + </property> + </bean> + + <bean + class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> + <property name="mediaTypes"> + <map> + <entry key="json" value="application/json" /> + </map> + </property> + + <property name="defaultViews"> + <list> + <bean + class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> + </list> + </property> </bean> </beans> diff --git a/src/main/webapp/config.properties.example b/src/main/webapp/config.properties.example index f781cbac1be52df84fa361816bd0947c1b39b718..280d47dae5a9fa5b895a069ecb65afdf5597dce7 100644 --- a/src/main/webapp/config.properties.example +++ b/src/main/webapp/config.properties.example @@ -1,3 +1,7 @@ security.openid-target-url=http://localhost:8080/arsnova-war/doOpenIdLogin security.cas-check-url=http://localhost:8080/arsnova-war/j_spring_cas_security_check -security.cas-service-url=https://cas.thm.de/cas \ No newline at end of file +security.cas-service-url=https://cas.thm.de/cas + +couchdb.host=localhost +couchdb.port=5984 +couchdb.name=arsnova \ No newline at end of file