Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d2ac590f

Přidáno uživatelem Tomáš Šimandl před asi 6 roky(ů)

Added remove diagram servlet + minor fixes

Zobrazit rozdíly:

sources/src/main/java/cz/zcu/kiv/offscreen/servlets/LoadGraphData.java
50 50
        }
51 51
    }
52 52

  
53
    /**
54
     * Return json of file which was uploaded and is stored in session.
55
     */
53 56
    private String getDiagramFromSession(HttpServletRequest request) throws IOException {
54 57

  
55 58
        String jsonToDisplay = (String)request.getSession().getAttribute("json_graph");
......
68 71
        return "";
69 72
    }
70 73

  
74
    /**
75
     * Return json of diagram which is taken from database. Permissions of user to this diagram is checked.
76
     */
71 77
    private String getDiagramById(HttpServletRequest request, int diagramId){
72 78

  
73 79
        DB db = new DB(getServletContext());
......
85 91
        return diagram.getJsonDiagram();
86 92
    }
87 93

  
94
    /**
95
     * Return demo diagram from file system.
96
     */
88 97
    private String getDemoDiagram(HttpServletRequest request){
89 98
        String demoId = request.getSession().getAttribute("demo_id").toString();
90 99
        String path = "/WEB-INF" + File.separator + "demoDiagram" + File.separator + demoId + ".json";
sources/src/main/java/cz/zcu/kiv/offscreen/servlets/actions/RemoveDiagram.java
1
package cz.zcu.kiv.offscreen.servlets.actions;
2

  
3
import com.google.common.base.Strings;
4
import cz.zcu.kiv.offscreen.user.DB;
5
import cz.zcu.kiv.offscreen.user.Diagram;
6
import org.apache.commons.lang.StringUtils;
7

  
8
import javax.servlet.ServletException;
9
import javax.servlet.http.HttpServlet;
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletResponse;
12
import java.io.IOException;
13

  
14
public class RemoveDiagram extends HttpServlet {
15

  
16
    @Override
17
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
18

  
19
        if (request.getSession().getAttribute("logged_user_id") == null) {
20
            response.sendError(response.SC_UNAUTHORIZED);
21
            return;
22
        }
23

  
24
        if(request.getParameter("diagram_id") == null){
25
            response.sendError(response.SC_BAD_REQUEST);
26
            return;
27
        }
28

  
29
        Integer loggedUserId = Integer.parseInt(request.getSession().getAttribute("logged_user_id").toString());
30
        Integer diagramId = Integer.parseInt(request.getParameter("diagram_id"));
31

  
32
        DB db = new DB(getServletContext());
33
        Diagram diagram = new Diagram(db, diagramId);
34

  
35
        if(diagram.getUserId() != loggedUserId){
36
            response.sendError(response.SC_UNAUTHORIZED);
37
            return;
38
        }
39

  
40
        diagram.delete();
41
        response.sendRedirect("/");
42
    }
43
}
sources/src/main/webapp/logged_user_menu.jsp
10 10
				<a href="/graph?diagramId=${diagramName.id}">${diagramName.name}</a><a href="#" onclick="return deleteDiagram(${diagramName.id});"><img src="images/button_cancel.png" alt="odstranit" class="imgDelete"/></a>
11 11
			</li>
12 12
		</c:forEach>
13
		<li id="diagram_id_new">
14
			<a href="<%= getServletContext().getInitParameter("HOME_URL") %>">New diagram</a>
15
		</li>
16 13
	</ul>
17 14
<% } %>
18 15

  

Také k dispozici: Unified diff