# HG changeset patch
# User tatsuki
# Date 1411802601 -32400
# Node ID f9b26747ef632d43dc4d142990492ab89c33c943
# Parent ef5045af0753358451919be0c0cc5b5364b223d5
add matrixBullet in board
diff -r ef5045af0753 -r f9b26747ef63 src/main/java/app/bbs/NetworkJungleBulletinBoard.java
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Tue Sep 16 07:49:14 2014 +0900
+++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Sat Sep 27 16:23:21 2014 +0900
@@ -3,6 +3,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
@@ -720,8 +722,6 @@
TreeNode node = tree.getRootNode();
DefaultTraverser traverser = new DefaultTraverser();
- // TraversableNodeWrapper traversable = new
- // TraversableNodeWrapper(node);
DefaultEvaluator evaluator = new DefaultEvaluator(path);
Either ret = traverser.traverse(node,
evaluator);
@@ -769,36 +769,86 @@
return false;
}
+
public String searchJungle(String requestName , String approvalName) {
JungleTree tree = jungle.getTreeByName("人物");
TreeNode searchNode = search(tree , requestName,"mes");
- if (searchNode == null)
+ if (searchNode == null){
+ fail(requestName,approvalName,"申請者がデータに無い人物です");
return "申請者がデータに無い人物です";
+ }
- if (!compare(searchNode, "河野研"))
+ if (!compare(searchNode, "河野研")){
+ fail(requestName,approvalName,"河野研以外に所属している人は、この申請をすることが出来ません");
return "河野研以外に所属している人は、この申請をすることが出来ません";
-
+ }
searchNode = search(tree , approvalName,"mes");
- if (searchNode == null)
+ if (searchNode == null){
+ fail(requestName,approvalName,"承認者がデータに無い人物です");
return "承認者がデータに無い人物です";
-
- if (!compare(searchNode, "上位申請権限"))
- return "権限がありません(この申請の承認は上位申請者である必要があります";
+ }
String position = searchNode.getAttributes().getString("mes1");
JungleTree grantTree = jungle.getTreeByName("役職");
searchNode = search(grantTree , position,"mes");
- if (!compare(searchNode, "准教授権限") || !!compare(searchNode, "教授権限"))
+ if (!compare(searchNode, "准教授権限") && !compare(searchNode, "教授権限")){
+ fail(requestName,approvalName,"権限がありません(この申請の承認は助教授か、教授である必要があります");
return "権限がありません(この申請の承認は助教授か、教授である必要があります";
+ }
- return "申請が受理されました";
+ searchNode = search(tree , approvalName,"mes");
+ if (searchNode == null){
+ fail(requestName,approvalName,"申請者がデータに無い人物です");
+ return "申請者がデータに無い人物です";
+ }
+
+ if (!compare(searchNode, "上位申請権限")){
+ fail(requestName,approvalName,"権限がありません(この申請の承認は上位申請者である必要があります");
+ return "権限がありません(この申請の承認は上位申請者である必要があります";
+ }
+ success(requestName,approvalName);
+
+ return "申請が受理されました";
}
+ public void fail(String requestName, String approvalName, String reason){
+ JungleTree contextTree = jungle.getTreeByName("申請");
+ JungleTreeEditor editor = contextTree.getTreeEditor();
+ editor = editor.putAttribute(new DefaultNodePath(),"mes0", ByteBuffer.wrap(("申請者名 = " + requestName).getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath(),"mes1", ByteBuffer.wrap(("申請内容".getBytes()))).b();
+ Date date = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+ String time = sdf.format(date);
+ editor = editor.putAttribute(new DefaultNodePath(),"mes2", ByteBuffer.wrap(("承認時間 = " + time).getBytes())).b();
+
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes", ByteBuffer.wrap("否認書".getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes0", ByteBuffer.wrap(("否認者名 = " + approvalName).getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes1", ByteBuffer.wrap(("否認理由 = " + reason).getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes2", ByteBuffer.wrap(("承認時間 = " + time).getBytes())).b();
+ editor.success();
+ }
+
+ public void success(String requestName, String approvalName){
+ JungleTree contextTree = jungle.getTreeByName("申請");
+ JungleTreeEditor editor = contextTree.getTreeEditor();
+ editor = editor.putAttribute(new DefaultNodePath(),"mes0", ByteBuffer.wrap(("申請者名 = " + requestName).getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath(),"mes1", ByteBuffer.wrap(("申請内容".getBytes()))).b();
+ Date date = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+ String time = sdf.format(date);
+ editor = editor.putAttribute(new DefaultNodePath(),"mes2", ByteBuffer.wrap(("承認時間" + time).getBytes())).b();
+
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes", ByteBuffer.wrap("承認書".getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes0", ByteBuffer.wrap(("承認者名 = " + approvalName).getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes1", ByteBuffer.wrap("承認理由 = 権限があってるので許可した".getBytes())).b();
+ editor = editor.putAttribute(new DefaultNodePath().add(0),"mes2", ByteBuffer.wrap(("承認時間" + time).getBytes())).b();
+ editor.success();
+ }
public int getRequestNum() {
return requestCounter.get();
diff -r ef5045af0753 -r f9b26747ef63 src/main/java/app/bbs/thinks/NetworkMatrixBulletinBoard.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/app/bbs/thinks/NetworkMatrixBulletinBoard.java Sat Sep 27 16:23:21 2014 +0900
@@ -0,0 +1,343 @@
+package app.bbs.thinks;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
+import alice.jungle.core.NetworkDefaultJungle;
+import alice.jungle.persistent.AliceJournal;
+import alice.jungle.persistent.NetworkJournal;
+import alice.jungle.persistent.PersistentJournal;
+import alice.jungle.transaction.JungleUpdater;
+import app.bbs.BulletinBoardJungleManager;
+import app.bbs.NetworkBulletinBoard;
+import app.bbs.NetworkJungleBulletinBoard;
+
+public class NetworkMatrixBulletinBoard implements NetworkBulletinBoard {
+
+ private final Jungle jungle;
+ private final NetworkJournal journal;
+ private final String LOG_DIR;
+ private Boolean persistentFlag;
+ private AtomicInteger requestCounter;
+ private long renewTime;
+
+ private NetworkMatrixBulletinBoard(String _uuid, NetworkJournal _journal) {
+ journal = _journal;
+ jungle = new NetworkDefaultJungle(journal, _uuid,
+ new DefaultTreeEditor(new DefaultTraverser()));
+ BulletinBoardJungleManager.setJungle(jungle);
+ persistentFlag = false;
+ requestCounter = BulletinBoardJungleManager.getRequestCounter();
+ LOG_DIR = "./log";
+ renewTime = 0;
+ }
+
+ public NetworkMatrixBulletinBoard(String _uuid) {
+ this(_uuid, new AliceJournal());
+ jungle.createNewTree("boards");
+ }
+
+ public static NetworkBulletinBoard NewPersistentJungle(String _uuid) {
+ NetworkMatrixBulletinBoard board = new NetworkMatrixBulletinBoard( _uuid, new PersistentJournal());
+ board.persistentFlag = true;
+ return board;
+ }
+
+ @Override
+ public void init() {
+ if (!persistentFlag) {
+ return;
+ }
+ checkAndCreateLogDirectory();
+ try {
+ commitLogRecover();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void checkAndCreateLogDirectory() {
+ File logFile = new File(LOG_DIR);
+ if (!logFile.exists()) {
+ logFile.mkdir();
+ return;
+ }
+ if (logFile.isFile()) {
+ logFile.delete();
+ logFile.mkdir();
+ }
+ }
+
+ public void commitLogRecover() throws IOException {
+ File[] logFiles = new File(LOG_DIR).listFiles();
+ for (File logFile : logFiles) {
+ commitLogRecover(logFile);
+ logFile.delete();
+ }
+ if (jungle.getTreeByName("boards") == null) {
+ jungle.createNewTree("boards");
+ }
+ }
+
+ private void commitLogRecover(File logFile) throws IOException {
+ journal.setInputFile(logFile);
+ ChangeListReader reader = journal.getReader();
+ if (reader == null)
+ return;
+ for (ChangeList chList : reader) {
+ String treeName = chList.getTreeName();
+ JungleTree tree = jungle.getTreeByName(treeName);
+ if (tree == null) {
+ tree = jungle.createNewTree(treeName);
+ }
+ JungleTreeEditor editor = tree.getLocalTreeEditor();
+ Either either = JungleUpdater.edit(editor,
+ chList);
+ editor = either.b();
+ if (either.isA()) {
+ throw new IOException("Failed commit log recovery");
+ }
+ editor.success();
+ }
+ }
+
+ @Override
+ public Iterable getBoards() {
+ JungleTree tree = jungle.getTreeByName("boards");
+ TreeNode node = tree.getRootNode();
+ Children chs = node.getChildren();
+
+ IterableConverter.Converter converter = new IterableConverter.Converter() {
+ public String conv(TreeNode _b) {
+ ByteBuffer e = _b.getAttributes().get("name");
+ System.out.println(new String(e.array()));
+ return new String(e.array());
+ }
+ };
+
+ return new IterableConverter(chs, converter);
+ }
+
+ @Override
+ public long getRenewTime(String _boardName) {
+ return renewTime;
+ }
+
+ @Override
+ public void createBoards(String _name, String _author, String _initMessage,
+ String _editKey) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void createBoardMessage(String _board, String _author,
+ String _message, String _editKey) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void editMessage(String _board, String _uuid, String _author,
+ String _message, String _editKey) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String sanitize(String str) {
+ if (str == null) {
+ return str;
+ }
+ str = str.replaceAll("&", "&");
+ str = str.replaceAll("<", "<");
+ str = str.replaceAll(">", ">");
+ str = str.replaceAll("\"", """);
+ str = str.replaceAll("'", "'");
+ return str;
+ }
+
+ @Override
+ public Iterable getMessages(String _boardName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getRequestNum() {
+ return requestCounter.get();
+ }
+
+ @Override
+ public Iterable getFolder(String _boardName, String nodeNum) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void createFolder(String boardName, String author, String msg,
+ String key, String _nodeNum) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void createAttribute(String boardName, String uuid, String author,
+ String msg, String key) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public getAttributeImp getAttribute(String _bname, String nodeNum) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void editAttribute(String boardName, String path, String id,
+ String message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void deleteAttribute(String _board, String _path, String id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void deleteNode(String _board, String _path, String id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void editMatrixMessage(String boardName, String path, String author,
+ String msg, String key) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ private static class BoardMessageImpl implements BoardMessage {
+ private final String author;
+ private final String message;
+ private final String uuid;
+
+ public BoardMessageImpl(String _author, String _message, String _uuid) {
+ author = _author;
+ message = _message;
+ uuid = _uuid;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getUUID() {
+ return uuid;
+ }
+
+ }
+
+ public TreeNode search(JungleTree tree ,String searchAttribute,String key){
+ InterfaceTraverser ifTraverser = tree.getTraverser();
+ Iterator> searchNode = ifTraverser.find(
+ (TreeNode node) -> {
+ ByteBuffer attribute = node.getAttributes().get(key);
+ if(attribute != null){
+ byte[] byteAttribute = attribute.array();
+ String str = new String(byteAttribute);
+ System.out.println(str);
+ return str.equals(searchAttribute);
+ }
+ return false;
+ }
+ );
+
+ if (!searchNode.hasNext())
+ return null;
+ return searchNode.next().left();
+
+ }
+
+ public boolean compare(TreeNode compareNode, String compareAttribute) {
+ String labName = compareNode.getAttributes().getString("mes");
+ if (labName.equals(compareAttribute))
+ return true;
+
+ int loopCount = 0;
+ for (loopCount = 0 ;compareNode.getAttributes().getString("mes" + loopCount) != null; loopCount++ ) {
+ labName = compareNode.getAttributes().getString("mes" + loopCount);
+ if (labName.equals(compareAttribute))
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public String searchJungle(String requestName , String approvalName) {
+ JungleTree tree = jungle.getTreeByName("人物");
+
+
+ TreeNode searchNode = search(tree , requestName,"mes");
+ if (searchNode == null)
+ return "申請者がデータに無い人物です";
+
+ if (!compare(searchNode, "河野研"))
+ return "河野研以外に所属している人は、この申請をすることが出来ません";
+
+
+ searchNode = search(tree , approvalName,"mes");
+ if (searchNode == null)
+ return "承認者がデータに無い人物です";
+
+ String position = searchNode.getAttributes().getString("mes1");
+
+ JungleTree grantTree = jungle.getTreeByName("役職");
+ searchNode = search(grantTree , position,"mes");
+
+ if (!compare(searchNode, "准教授権限") && !compare(searchNode, "教授権限"))
+ return "権限がありません(この申請の承認は助教授か、教授である必要があります";
+
+
+ searchNode = search(tree , approvalName,"mes");
+ if (searchNode == null)
+ return "申請者がデータに無い人物です";
+
+ if (!compare(searchNode, "上位申請権限"))
+ return "権限がありません(この申請の承認は上位申請者である必要があります";
+
+
+ }
+
+}
diff -r ef5045af0753 -r f9b26747ef63 src/main/java/app/bbs/thinks/permission.java
--- a/src/main/java/app/bbs/thinks/permission.java Tue Sep 16 07:49:14 2014 +0900
+++ b/src/main/java/app/bbs/thinks/permission.java Sat Sep 27 16:23:21 2014 +0900
@@ -37,8 +37,7 @@
try {
_res.setCharacterEncoding("UTF-8");
PrintWriter _pw = _res.getWriter();
- _pw.write("" + " 承認フォーム " + "
\n");
- _pw.write("edit message
");
+ _pw.write("承認フォーム
");
_pw.write("
\n");
_pw.write("承認者名
\n");
diff -r ef5045af0753 -r f9b26747ef63 src/test/java/alice/jungle/log/example/FindMatrixTest.java
--- a/src/test/java/alice/jungle/log/example/FindMatrixTest.java Tue Sep 16 07:49:14 2014 +0900
+++ b/src/test/java/alice/jungle/log/example/FindMatrixTest.java Sat Sep 27 16:23:21 2014 +0900
@@ -53,12 +53,10 @@
Iterator> searchNode = ifTraverser.find(
(TreeNode node) -> {
- ByteBuffer attribute = node.getAttributes().get("mes");
+ String attribute = node.getAttributes().getString("mes");
if(attribute != null){
- byte[] byteAttribute = attribute.array();
- String str = new String(byteAttribute);
- System.out.println(str);
- return str.equals("比嘉健太");
+ System.out.println(attribute);
+ return attribute.equals("比嘉健太");
}
return false;
}