comparison 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
comparison
equal deleted inserted replaced
167:91f6dd655a01 168:54d68cda84c4
297 either = editor.success(); 297 either = editor.success();
298 } while (either.isA()); 298 } while (either.isA());
299 299
300 } 300 }
301 301
302 public void editMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) { 302 public void editMessage(String _board, String _nodeNum, final String _author, final String _message, final String _editKey) {
303 requestCounter.incrementAndGet(); 303 requestCounter.incrementAndGet();
304 final long timestamp = System.currentTimeMillis(); 304 final long timestamp = System.currentTimeMillis();
305 final ByteBuffer tBuffer = ByteBuffer.allocate(16); 305 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
306 tBuffer.putLong(timestamp); 306 tBuffer.putLong(timestamp);
307 JungleTree tree = jungle.getTreeByName(_board); 307 JungleTree tree = jungle.getTreeByName(_board);
308 Either<Error, JungleTreeEditor> either = null; 308 Either<Error, JungleTreeEditor> either = null;
309 309
310 do { 310 do {
311 DefaultNodePath path = new DefaultNodePath(); 311 DefaultNodePath path = new DefaultNodePath();
312 path = path.add(Integer.parseInt(_uuid)); 312 try {
313 313 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) {
314 if (!_nodeNum.substring(count, count + 1).equals("/"))
315 path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1)));
316 }
317 } catch (Exception _e) {
318 }
314 JungleTreeEditor editor = tree.getTreeEditor(); 319 JungleTreeEditor editor = tree.getTreeEditor();
315 NodeEditor e = new NodeEditor() { 320 NodeEditor e = new NodeEditor() {
316 public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { 321 public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
317 _e = _e.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); 322 _e = _e.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
318 _e = _e.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); 323 _e = _e.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
354 // EnableNodeWrapper<T> node = _e.getWrap(); 359 // EnableNodeWrapper<T> node = _e.getWrap();
355 String str = "0"; 360 String str = "0";
356 int count = 0; 361 int count = 0;
357 for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { 362 for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) {
358 } 363 }
359 str = String.valueOf(count); 364 str = String.valueOf(count);
360 _e = _e.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b(); 365 _e = _e.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b();
361 _e = _e.getAttributes().put("timestamp" + str, tBuffer).b(); 366 _e = _e.getAttributes().put("timestamp" + str, tBuffer).b();
362 return DefaultEither.newB(_e); 367 return DefaultEither.newB(_e);
363 } 368 }
364 }; 369 };
369 editor = either.b(); 374 editor = either.b();
370 either = editor.success(); 375 either = editor.success();
371 } while (either.isA()); 376 } while (either.isA());
372 } 377 }
373 378
379 public void editAttribute(String boardName, String _path, String id, String _message) {
380 requestCounter.incrementAndGet();
381 final long timestamp = System.currentTimeMillis();
382 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
383 tBuffer.putLong(timestamp);
384 JungleTree tree = jungle.getTreeByName(boardName);
385 Either<Error, JungleTreeEditor> either = null;
386 DefaultNodePath path = new DefaultNodePath();
387 do {
388 try {
389 for (int count = 0; _path.substring(count, count + 1) != null; count++) {
390 if (!_path.substring(count, count + 1).equals("/"))
391 path = path.add(Integer.parseInt(_path.substring(count, count + 1)));
392 }
393 } catch (Exception _e) {
394 }
395
396 JungleTreeEditor editor = tree.getTreeEditor();
397 NodeEditor e = new NodeEditor() {
398 public <T extends EditableNode<T>> Either<Error, T> edit(T _e) {
399 // EnableNodeWrapper<T> node = _e.getWrap();
400 _e = _e.getAttributes().put("mes" + id, ByteBuffer.wrap(_message.getBytes())).b();
401 _e = _e.getAttributes().put("timestamp" + id, tBuffer).b();
402 return DefaultEither.newB(_e);
403 }
404 };
405 either = editor.edit(path, e);
406 if (either.isA()) {
407 throw new IllegalStateException();
408 }
409 editor = either.b();
410 either = editor.success();
411 } while (either.isA());
412 }
413
414
374 public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) { 415 public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) {
375 requestCounter.incrementAndGet(); 416 requestCounter.incrementAndGet();
376 final long timestamp = System.currentTimeMillis(); 417 final long timestamp = System.currentTimeMillis();
377 final ByteBuffer tBuffer = ByteBuffer.allocate(16); 418 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
378 tBuffer.putLong(timestamp); 419 tBuffer.putLong(timestamp);
513 return uuid; 554 return uuid;
514 } 555 }
515 556
516 } 557 }
517 558
559
560
518 } 561 }