diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java index 06bd24d75edced5f007ff2db5a58b1bbcd6b30ab..2fb7b840289b1b9056c7da73329bb2bbef6de38d 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/project/Project.java @@ -122,5 +122,18 @@ public class Project { return timecreated; } - + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("Project{"); + sb.append("id='").append(id).append('\''); + sb.append(", password='").append(password).append('\''); + sb.append(", active=").append(active); + sb.append(", timecreated=").append(timecreated); + sb.append(", author='").append(author).append('\''); + sb.append(", adminPassword='").append(adminPassword).append('\''); + sb.append(", token='").append(token).append('\''); + sb.append(", phase='").append(phase).append('\''); + sb.append('}'); + return sb.toString(); + } } \ No newline at end of file diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/ContextTag.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/ContextTag.java new file mode 100644 index 0000000000000000000000000000000000000000..741d3eb28a69d4a2ebef9f63b9749e7d8a9204ec --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/ContextTag.java @@ -0,0 +1,27 @@ +package unipotsdam.gf.core.session; + +import unipotsdam.gf.core.management.project.Project; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import java.io.IOException; + +public class ContextTag extends SimpleTagSupport { + public void doTag() throws IOException { + PageContext pageContext = (PageContext) getJspContext(); + HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); + // sessionID is created with first call and persisted throughout the user's session< + JspWriter out = getJspContext().getOut(); + // lets add some context to the site + + /** + * We assume that the project context is added to the session, when a project is selected + * in the view, then the project is loaded from db and added via setAttribute like below + */ + GFContext gfContext = (GFContext) request.getSession().getAttribute("gf_context"); + out.println("<p>project:"+gfContext.getProject().toString()+"</p>"); + + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/GFContext.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/GFContext.java new file mode 100644 index 0000000000000000000000000000000000000000..bdbac9ae7b6b1171b82063e4d34f320fadf242fd --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/GFContext.java @@ -0,0 +1,77 @@ +package unipotsdam.gf.core.session; + +import unipotsdam.gf.core.management.project.Project; +import unipotsdam.gf.core.management.user.User; +import unipotsdam.gf.core.states.ProjectPhase; +import unipotsdam.gf.modules.assessment.controller.model.Quiz; +import unipotsdam.gf.modules.communication.model.chat.ChatRoom; + +public class GFContext { + Project project; + User user; + ProjectPhase projectPhase; + ChatRoom chatRoom; + // could be quizState .... + Quiz quiz; + + public GFContext( + Project project, User user, ProjectPhase projectPhase, ChatRoom chatRoom, Quiz quiz) { + this.project = project; + this.user = user; + this.projectPhase = projectPhase; + this.chatRoom = chatRoom; + this.quiz = quiz; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public ProjectPhase getProjectPhase() { + return projectPhase; + } + + public void setProjectPhase(ProjectPhase projectPhase) { + this.projectPhase = projectPhase; + } + + public ChatRoom getChatRoom() { + return chatRoom; + } + + public void setChatRoom(ChatRoom chatRoom) { + this.chatRoom = chatRoom; + } + + public Quiz getQuiz() { + return quiz; + } + + public void setQuiz(Quiz quiz) { + this.quiz = quiz; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("GFContext{"); + sb.append("project=").append(project); + sb.append(", user=").append(user); + sb.append(", projectPhase=").append(projectPhase); + sb.append(", chatRoom=").append(chatRoom); + sb.append(", quiz=").append(quiz); + sb.append('}'); + return sb.toString(); + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/SessionTag.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/SessionTag.java new file mode 100644 index 0000000000000000000000000000000000000000..eae3f549fe2061b4533e4092dbcd1e0d52632edb --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/session/SessionTag.java @@ -0,0 +1,51 @@ +package unipotsdam.gf.core.session; + +import uk.co.jemos.podam.api.PodamFactory; +import uk.co.jemos.podam.api.PodamFactoryImpl; +import unipotsdam.gf.core.management.ManagementImpl; +import unipotsdam.gf.core.management.project.Project; +import unipotsdam.gf.core.management.user.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import java.io.IOException; + +public class SessionTag extends SimpleTagSupport { + + /** + * Utility to creaty dummy data for students + */ + PodamFactory factory = new PodamFactoryImpl(); + + + public void doTag() throws IOException { + PageContext pageContext = (PageContext) getJspContext(); + HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); + // sessionID is created with first call and persisted throughout the user's session< + JspWriter out = getJspContext().getOut(); + out.println("<p id=\"sessionId\"> SessionId:"+request.getSession().getId()+"</p>"); + + // lets add some context to the site + + /** + * We assume that the project context is added to the session, when a project is selected + * in the view, then the project is loaded from db and added via setAttribute like below + * this is only done here for the purpose of example + */ + + // create dummy context + String context1 = factory.manufacturePojo(GFContext.class).toString(); + // set dummy context in sessions + request.getSession().setAttribute("gf_context", context1); + + // you can update it + Project project = factory.manufacturePojo(Project.class); + GFContext context2 = (GFContext) request.getSession().getAttribute("gf_context"); + context2.setProject(project); + // updated context set in session + request.getSession().setAttribute("gf_context", context2); + + } +} diff --git a/gemeinsamforschen/src/main/webapp/core/pages/gemeinsamForschen.tld b/gemeinsamforschen/src/main/webapp/core/pages/gemeinsamForschen.tld index 3704c718e3338de67f5165d78f3d5785f983b11a..63ab26a6b00b0ad200ba5a3a73ccf4a0da13a1b5 100644 --- a/gemeinsamforschen/src/main/webapp/core/pages/gemeinsamForschen.tld +++ b/gemeinsamforschen/src/main/webapp/core/pages/gemeinsamForschen.tld @@ -15,4 +15,16 @@ <body-content>empty</body-content> </tag> + <tag> + <name>session</name> + <tag-class>unipotsdam.gf.core.session.SessionTag</tag-class> + <body-content>empty</body-content> + </tag> + + <tag> + <name>context</name> + <tag-class>unipotsdam.gf.core.session.ContextTag</tag-class> + <body-content>empty</body-content> + </tag> + </taglib> \ No newline at end of file diff --git a/gemeinsamforschen/src/main/webapp/session/session_example_1.jsp b/gemeinsamforschen/src/main/webapp/session/session_example_1.jsp new file mode 100644 index 0000000000000000000000000000000000000000..4f2ddf97366c1617b8aad74c34fe72937b36fea1 --- /dev/null +++ b/gemeinsamforschen/src/main/webapp/session/session_example_1.jsp @@ -0,0 +1,18 @@ +<%-- + Created by IntelliJ IDEA. + User: dehne + Date: 23.07.2018 + Time: 13:51 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="gf" uri="../core/pages/gemeinsamForschen.tld" %> +<html> +<head> + <title>Title</title> +</head> +<body> + <gf:session></gf:session> + <a href="session_example_2.jsp">click mich</a> +</body> +</html> diff --git a/gemeinsamforschen/src/main/webapp/session/session_example_2.jsp b/gemeinsamforschen/src/main/webapp/session/session_example_2.jsp new file mode 100644 index 0000000000000000000000000000000000000000..a6e570bc3814fac53418a447f95854fe729a2224 --- /dev/null +++ b/gemeinsamforschen/src/main/webapp/session/session_example_2.jsp @@ -0,0 +1,17 @@ +<%-- + Created by IntelliJ IDEA. + User: dehne + Date: 23.07.2018 + Time: 13:51 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="gf" uri="../core/pages/gemeinsamForschen.tld" %> +<html> +<head> + <title>Big Deal</title> +</head> +<body> + <gf:context/> +</body> +</html>