changeset 170:df063cf6f3b5

add Delete Node Method
author tatsuki
date Wed, 30 Jul 2014 10:57:19 +0900
parents 2403b9a4416f
children 00c3cca1903c
files src/main/java/app/bbs/NetworkBulletinBoard.java src/main/java/app/bbs/NetworkJungleBulletinBoard.java src/main/java/app/bbs/thinks/CreateNode.java src/main/java/app/bbs/thinks/ShowMatrix.java src/main/java/app/bbs/thinks/deleteNodeServlet.java
diffstat 5 files changed, 54 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/app/bbs/NetworkBulletinBoard.java	Wed Jul 30 10:20:01 2014 +0900
+++ b/src/main/java/app/bbs/NetworkBulletinBoard.java	Wed Jul 30 10:57:19 2014 +0900
@@ -16,4 +16,5 @@
 	public getAttributeImp getAttribute(String _bname, String nodeNum);
 	public void editAttribute(String boardName, String path, String id, String message);
 	public void deleteAttribute(String _board, String _path , String id);
+	public void deleteNode(String _board, String _path, String id);
 }
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java	Wed Jul 30 10:20:01 2014 +0900
+++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java	Wed Jul 30 10:57:19 2014 +0900
@@ -409,7 +409,37 @@
 			either = editor.success();
 		} while (either.isA());
 	}
+	
+	
+	public void deleteNode(String _board, String _path, String _id) {
+		requestCounter.incrementAndGet();
+		int id = Integer.parseInt(_id);
+		final long timestamp = System.currentTimeMillis();
+		final ByteBuffer tBuffer = ByteBuffer.allocate(16);
+		tBuffer.putLong(timestamp);
+		JungleTree tree = jungle.getTreeByName(_board);
+		Either<Error, JungleTreeEditor> either = null;
+		DefaultNodePath path = new DefaultNodePath();
+		do {
+			try {
+				for (int count = 0; _path.substring(count, count + 1) != null; count++) {
+					if (!_path.substring(count, count + 1).equals("/"))
+						path = path.add(Integer.parseInt(_path.substring(count,	count + 1)));
+				}
+			} catch (Exception _e) {
+			}
+			
+			JungleTreeEditor editor = tree.getTreeEditor();
 
+			either = editor.deleteChildAt(path, id);
+			if (either.isA()) {
+				throw new IllegalStateException();
+			}
+			editor = either.b();
+			either = editor.success();
+		} while (either.isA());
+		
+	}
 	public void deleteAttribute(String _board, String _path ,final String id) {
 		requestCounter.incrementAndGet();
 		final long timestamp = System.currentTimeMillis();
@@ -597,4 +627,5 @@
 
 	}
 
+
 }
--- a/src/main/java/app/bbs/thinks/CreateNode.java	Wed Jul 30 10:20:01 2014 +0900
+++ b/src/main/java/app/bbs/thinks/CreateNode.java	Wed Jul 30 10:57:19 2014 +0900
@@ -14,7 +14,7 @@
 	private static final String PARAM_BOARD_AUTHOR = "author";
 	private static final String PARAM_BOARD_INITMESSAGE = "msg";
 	private static final String PARAM_BOARD_EDITKEY = "key";
-
+	private static final String PARAM_BOARD_UUID = "uuid";
 	private static final long serialVersionUID = 1L;
 
 	public CreateNode(NetworkBulletinBoard _bbs) {
@@ -26,7 +26,7 @@
 		String author = _req.getParameter(PARAM_BOARD_AUTHOR);
 		String msg = _req.getParameter(PARAM_BOARD_INITMESSAGE);
 		String key = _req.getParameter(PARAM_BOARD_EDITKEY);
-		String nodeNum = _req.getParameter("uuid");
+		String nodeNum = _req.getParameter(PARAM_BOARD_UUID);
 
 		try {
 			bbs.createFolder(boardName, author, msg, key, nodeNum);
--- a/src/main/java/app/bbs/thinks/ShowMatrix.java	Wed Jul 30 10:20:01 2014 +0900
+++ b/src/main/java/app/bbs/thinks/ShowMatrix.java	Wed Jul 30 10:57:19 2014 +0900
@@ -13,21 +13,21 @@
 
 public class ShowMatrix extends HttpServlet {
 	/**
-	 * 
-	 */
+	 * edit Node Path is rename editNodePath
+	 **/
 	private static final long serialVersionUID = 1L;
 	private final NetworkBulletinBoard bbs;
 	private final String createBoardMessagePath;
-	private final String editMessagePath;
+	private final String editNodePath;
 	private final String showMatrixPath;
 	private final String createAttributePath;
 	private final String editAttributePath;
 	private final String  deleteAttributePath;
 	private final String  deleteNodePath;
 	private static final String PARAM_BOARD_NAME = "bname";
-
+	private static final String PARAM_BOARD_UUID = "uuid";
 	public ShowMatrix(NetworkBulletinBoard _bbs,
-			String _createBoardMessagePath, String _editMessagePath,
+			String _createBoardMessagePath, String _editNodePath,
 			String _showMatrixPath, String _createAttributePath, String _editAttributePath, String _deleteAttributePath, String _deleteNodePath, ThreadPool thp) {
 		bbs = _bbs;
 		deleteAttributePath = _deleteAttributePath;
@@ -36,12 +36,12 @@
 		editAttributePath = _editAttributePath;
 		showMatrixPath = _showMatrixPath;
 		createBoardMessagePath = _createBoardMessagePath;
-		editMessagePath = _editMessagePath;
+		editNodePath = _editNodePath;
 	}
 
 	public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
 		final String bname = _req.getParameter(PARAM_BOARD_NAME);
-		String nodeNum = _req.getParameter("uuid");
+		String nodeNum = _req.getParameter(PARAM_BOARD_UUID);
 		String nodeName = _req.getParameter("nodeName");
 		try {
 			printBoard(bname, nodeNum, nodeName, _res.getWriter());
@@ -80,7 +80,9 @@
 		for (BoardMessage msg : bbs.getFolder(_bname, nodeNum)) {
 			_pw.write("<small><a href=" + showMatrixPath + "?bname=" + _bname + "&uuid=" + nodeNum + "/" + msg.getUUID() + "&nodeName=" + msg.getMessage() + ">" + msg.getMessage() + "</a></small>");
 			_pw.write("   ");
-			_pw.write("<small><a href='" + editMessagePath + "?bname=" + _bname + "&uuid=" + nodeNum  + "/"+ msg.getUUID() + "'>edit</a><br><br></small>");
+			_pw.write("<small><a href='" + editNodePath + "?bname=" + _bname + "&uuid=" + nodeNum  + "/"+ msg.getUUID() + "'>edit</a></small>");
+			_pw.write("   ");
+			_pw.write("<small><a href='" + deleteNodePath + "?bname=" + _bname + "&path=" + nodeNum  + "&id=" + msg.getUUID() + "'>delete</a><br><br></small>");
 		}
 		
 		
--- a/src/main/java/app/bbs/thinks/deleteNodeServlet.java	Wed Jul 30 10:20:01 2014 +0900
+++ b/src/main/java/app/bbs/thinks/deleteNodeServlet.java	Wed Jul 30 10:57:19 2014 +0900
@@ -13,9 +13,8 @@
 {
 	private final NetworkBulletinBoard bbs;
 	private static final String PARAM_BOARD_NAME = "bname";
-	private static final String PARAM_BOARD_MSGID = "uuid";
-	private static final String PARAM_BOARD_MESSAGE= "msg";
-	private static final String PARAM_BOARD_EDITKEY = "key";
+	private static final String PARAM_BOARD_PATH = "path";
+	private static final String PARAM_NODE_ID = "id";
 
 	private static final long serialVersionUID = 1L;
 	
@@ -27,17 +26,16 @@
 	public void doGet(HttpServletRequest _req,HttpServletResponse _res)
 	{
 		String bname = _req.getParameter(PARAM_BOARD_NAME);
-		String path = _req.getParameter("path");
-		String id = _req.getParameter("count");
-		
+		String path = _req.getParameter(PARAM_BOARD_PATH );
+		String id = _req.getParameter(PARAM_NODE_ID);
 		
 		try{
 			PrintWriter pw = _res.getWriter();
 			pw.write("<html><body><h1>本当に削除しますか?message</h1>");
 			pw.write("<form method='POST'\n");
-			pw.write("<p><input type='hidden' name='path' value='"+path+"'/>" +
-					"<input type='hidden' name='id' value='"+id+"'/>" +
-					"<input type='hidden' name='bname' value='"+bname+"'</p>\n");
+			pw.write("<p><input type='hidden' name='path' value='" + path + "'/>" +
+					"<input type='hidden' name='id' value='" + id +"'/>" +
+					"<input type='hidden' name='bname' value='" + bname + "'</p>\n");
 			pw.write("<p><input type='submit' value='submit'/></p>\n");
 			pw.write("</body></html>");
 			pw.flush();
@@ -49,11 +47,10 @@
 	public void doPost(HttpServletRequest _req,HttpServletResponse _res)
 	{
 		String boardName = _req.getParameter(PARAM_BOARD_NAME);
-		String path = _req.getParameter("path");
-		String id = _req.getParameter("id");
-		
+		String path = _req.getParameter(PARAM_BOARD_PATH);
+		String id = _req.getParameter(PARAM_NODE_ID);
 		try{
-			bbs.deleteAttribute(boardName, path,id);
+			bbs.deleteNode(boardName, path, id);
 			PrintWriter pw = _res.getWriter();
 			pw.write("successfully written");
 			pw.flush();