Commit e1770a86 authored by Zacharie Bugaud's avatar Zacharie Bugaud
Browse files

add some msg

parent d5510b7a
......@@ -101,6 +101,10 @@ public class AddChoice extends HttpServlet {
if (session == null || session.getAttribute("username") == null) {
PrintWriter out = response.getWriter();
out.println("you are not authentified");
request.setAttribute("action", "Add choice");
request.setAttribute("status", "Failed! You are not authentified");
request.getRequestDispatcher("response.jsp").forward(request, response);
return;//TODO
} else if (!storyDAO.isLegitim((String) session.getAttribute("username"), story_id)) {
PrintWriter out = response.getWriter();
......@@ -116,11 +120,18 @@ public class AddChoice extends HttpServlet {
try (PrintWriter out = response.getWriter()) {
out.println(e);
}
request.setAttribute("action", "Add choice");
request.setAttribute("status", "Failed! Unable to add this choice");
request.getRequestDispatcher("response.jsp").forward(request, response);
return ;//TODO
}
if (choiceID == -1) {
PrintWriter out = response.getWriter();
out.println("you are not allowed to add choice");
request.setAttribute("action", "Add choice");
request.setAttribute("status", "Failed! Choice not found");
request.getRequestDispatcher("response.jsp").forward(request, response);
return; //TODO failure
}
try (PrintWriter out = response.getWriter()) {
......
......@@ -105,6 +105,9 @@ public class AssociateParagraphChoice extends HttpServlet {
throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute("username") == null) {
request.setAttribute("action", "Associate");
request.setAttribute("status", "Failed! Your are not logged");
request.getRequestDispatcher("response.jsp").forward(request, response);
return;//TODO
}
//TODO verify user is associated to this story
......
......@@ -118,6 +118,10 @@ public class CreateStory extends HttpServlet {
int idFirstParagraph = paraDAO.createParagraph(textfirstParagraph, author, false, true);
if (idFirstParagraph == -1) {
//TODO failure
request.setAttribute("action", "Create story");
request.setAttribute("status", "Failed! Internal error");
request.getRequestDispatcher("response.jsp").forward(request, response);
return;
}
ChoixDAO choixDAO = new ChoixDAO(ds);
choixDAO.addChoice(idFirstParagraph, firstChoice);
......@@ -130,6 +134,9 @@ public class CreateStory extends HttpServlet {
paraDAO.associateStoryParagraph(idStory, idFirstParagraph);
} catch (DAOException e) {
System.out.println("database error");//TODO
request.setAttribute("action", "Create story");
request.setAttribute("status", "Failed! Internal error");
request.getRequestDispatcher("response.jsp").forward(request, response);
}
}
}
......
......@@ -58,6 +58,7 @@ public class LookupStory extends HttpServlet {
actionGetAllPublishedStories(request, response, new StoryDAO(ds));
break;
case "1":
actionGetStory(request, response, new StoryDAO(ds));
break;
case "2":
......@@ -73,6 +74,8 @@ public class LookupStory extends HttpServlet {
throw new IllegalStateException("Unexpected value: " + request.getParameter("code"));
}
} catch (Exception e) {
PrintWriter out = response.getWriter();
out.println("iciiiiiiiiiii");
e.printStackTrace();
/*
PrintWriter out = response.getWriter();
......@@ -144,6 +147,9 @@ public class LookupStory extends HttpServlet {
throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute("username") == null) {
request.setAttribute("action", "Get my stories");
request.setAttribute("status", "Failed! Your are not logged");
request.getRequestDispatcher("response.jsp").forward(request, response);
return;//TODO
}
ArrayList<Story> stories = histoireDAO.getUserStories((String) session.getAttribute("username"));
......@@ -171,6 +177,7 @@ public class LookupStory extends HttpServlet {
throws ServletException, IOException {
HttpSession session = request.getSession(true);
System.out.println("ici");
boolean published = histoireDAO.isPublished(Integer.parseInt(request.getParameter("story_id")));
if (published) {
......@@ -200,7 +207,14 @@ public class LookupStory extends HttpServlet {
request.setAttribute("action", "1");
System.out.println("looking up history...");
this.getServletContext().getRequestDispatcher("/LookupHistory").include(request, response);
System.out.println(session);
System.out.println((HashMap<Integer, History>)session);
System.out.println((HashMap<Integer, History>)session.getAttribute("history"));
System.out.println(story.getId());
System.out.println(((HashMap<Integer, History>)session.getAttribute("history")).get(story.getId()));
System.out.println(((HashMap<Integer, History>)session.getAttribute("history")).get(story.getId()).size());
request.setAttribute("history", session.getAttribute("history"));
request.setAttribute("publicStory", publicStory);
request.setAttribute("invitedList",invitedList);
......@@ -274,6 +288,9 @@ public class LookupStory extends HttpServlet {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute("username") == null) {
request.setAttribute("action", "Get Inviter Stories");
request.setAttribute("status", "Failed! Your are not logged");
request.getRequestDispatcher("response.jsp").forward(request, response);
return;//TODO
}
ArrayList<Story> stories = histoireDAO.getInviterStories((String) session.getAttribute("username"));
......
......@@ -189,6 +189,10 @@ public class ManageParagraph extends HttpServlet {
throws ServletException, IOException {
if (!isLegitim(request, paragraphDAO)) {
request.setAttribute("action", "Validate paragraph");
request.setAttribute("status", "Failed! You are not legitimate");
request.getRequestDispatcher("response.jsp").forward(request, response);
return; //TODO
}
int id = Integer.parseInt(request.getParameter("paragraph_id"));
......@@ -223,6 +227,9 @@ public class ManageParagraph extends HttpServlet {
throws ServletException, IOException {
if (!isLegitim(request, paragraphDAO)) {
request.setAttribute("action", "Write paragraph");
request.setAttribute("status", "Failed! You are not legitimate");
request.getRequestDispatcher("response.jsp").forward(request, response);
return; //TODO
}
int id = Integer.parseInt(request.getParameter("paragraph_id"));
......@@ -231,11 +238,20 @@ public class ManageParagraph extends HttpServlet {
paragraphDAO.alterText(id, text);
} catch (DAOException e) {
//TODO
request.setAttribute("action", "Write paragraph");
request.setAttribute("status", "Failed! Internal error");
request.getRequestDispatcher("response.jsp").forward(request, response);
}
}
private void actionSetReadBefore(HttpServletRequest request, HttpServletResponse response, ParagraphDAO paragraphDAO) {
private void actionSetReadBefore(HttpServletRequest request, HttpServletResponse response, ParagraphDAO paragraphDAO) throws IOException, ServletException {
if (!isLegitim(request, paragraphDAO)) {
request.setAttribute("action", "Set read before");
request.setAttribute("status", "Failed! You are not legitimate");
request.getRequestDispatcher("response.jsp").forward(request, response);
return; //TODO
}
int id = Integer.parseInt(request.getParameter("paragraph_id"));
......@@ -273,6 +289,11 @@ public class ManageParagraph extends HttpServlet {
out.print(1);
} catch (DAOException e) {
//TODO
request.setAttribute("action", "Delete paragraph");
request.setAttribute("status", "Failed! Internal error");
request.getRequestDispatcher("response.jsp").forward(request, response);
}
}
......@@ -344,7 +365,10 @@ public class ManageParagraph extends HttpServlet {
throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute("username") == null) {
if (session == null || session.getAttribute("username") == null) {
request.setAttribute("action", "Lock");
request.setAttribute("status", "Failed! You are not logged in");
request.getRequestDispatcher("response.jsp").forward(request, response);
return;//TODO
}
String username = (String)session.getAttribute("username");
......@@ -363,7 +387,11 @@ public class ManageParagraph extends HttpServlet {
}
} catch (DAOException e) {
//TODO
request.setAttribute("action", "Lock");
request.setAttribute("status", "Failed! Internal error");
request.getRequestDispatcher("response.jsp").forward(request, response);
}
}
}
......@@ -5,6 +5,7 @@
*/
package modele;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
......@@ -61,6 +62,7 @@ public class Choix {
this.texte = texte;
this.id =id;
this.published=published;
this.required=new ArrayList<Integer>();
}
public void addParagraphe() {
......@@ -71,4 +73,4 @@ public class Choix {
return null;
}
}
}
\ No newline at end of file
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