diff src/main/java/app/bbs/NetworkJungleBulletinBoard.java @ 168:54d68cda84c4

create edit Attribute & Folder Method
author tatsuki
date Tue, 29 Jul 2014 18:51:44 +0900
parents 91f6dd655a01
children 2403b9a4416f
line wrap: on
line diff
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java	Tue Jul 29 10:58:11 2014 +0900
+++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java	Tue Jul 29 18:51:44 2014 +0900
@@ -299,7 +299,7 @@
 
 	}
 
-	public void editMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) {
+	public void editMessage(String _board, String _nodeNum, final String _author, final String _message, final String _editKey) {
 		requestCounter.incrementAndGet();
 		final long timestamp = System.currentTimeMillis();
 		final ByteBuffer tBuffer = ByteBuffer.allocate(16);
@@ -309,8 +309,13 @@
 	
 		do {
 			DefaultNodePath path = new DefaultNodePath();
-			path = path.add(Integer.parseInt(_uuid));
-
+			try {
+				for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) {
+					if (!_nodeNum.substring(count, count + 1).equals("/"))
+						path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1)));
+				}
+			} catch (Exception _e) {
+			}
 			JungleTreeEditor editor = tree.getTreeEditor();
 			NodeEditor e = new NodeEditor() {
 				public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
@@ -356,7 +361,7 @@
 					int count = 0;
 						for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) {
 						}
-						str = String.valueOf(count);
+					str = String.valueOf(count);
 					_e = _e.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b();
 					_e = _e.getAttributes().put("timestamp" + str, tBuffer).b();
 					return DefaultEither.newB(_e);
@@ -371,6 +376,42 @@
 		} while (either.isA());
 	}
 
+	public void editAttribute(String boardName, String _path, String id, String _message) {
+		requestCounter.incrementAndGet();
+		final long timestamp = System.currentTimeMillis();
+		final ByteBuffer tBuffer = ByteBuffer.allocate(16);
+		tBuffer.putLong(timestamp);
+		JungleTree tree = jungle.getTreeByName(boardName);
+		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();
+			NodeEditor e = new NodeEditor() {
+				public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
+					// EnableNodeWrapper<T> node = _e.getWrap();
+					_e = _e.getAttributes().put("mes" + id, ByteBuffer.wrap(_message.getBytes())).b();
+					_e = _e.getAttributes().put("timestamp" + id, tBuffer).b();
+					return DefaultEither.newB(_e);
+				}
+			};
+			either = editor.edit(path, e);
+			if (either.isA()) {
+				throw new IllegalStateException();
+			}
+			editor = either.b();
+			either = editor.success();
+		} while (either.isA());
+	}
+
+	
 	public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) {
 		requestCounter.incrementAndGet();
 		final long timestamp = System.currentTimeMillis();
@@ -515,4 +556,6 @@
 
 	}
 
+
+
 }