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

Task #3805: Major changes related to Task #3805

* Added session controller with method to get session by id
* Created session class to be used as entity object
* Created session service class and interface
* Added content negotiation view resolver to map entity objects to JSON
parent 90261b3f
Branches
Tags
No related merge requests found
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;
}
}
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) {}
}
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
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;
}
}
......@@ -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>
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
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