Mercurial > hg > Database > jungle-network
changeset 186:ef5045af0753
add permission .java
author | tatsuki |
---|---|
date | Tue, 16 Sep 2014 07:49:14 +0900 |
parents | f54d4ab5df4b |
children | f9b26747ef63 |
files | src/main/java/alice/jungle/persistent/PersistentJungleTree.java src/main/java/alice/jungle/transaction/NetworkDefaultJungleTree.java src/main/java/app/bbs/NetworkBulletinBoard.java src/main/java/app/bbs/NetworkJungleBulletinBoard.java src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java src/main/java/app/bbs/thinks/ShowMatrix.java src/main/java/app/bbs/thinks/permission.java src/test/java/alice/jungle/log/example/FindMatrixTest.java |
diffstat | 8 files changed, 157 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/jungle/persistent/PersistentJungleTree.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentJungleTree.java Tue Sep 16 07:49:14 2014 +0900 @@ -55,8 +55,9 @@ @Override public InterfaceTraverser getTraverser() { - // TODO Auto-generated method stub - return null; + TreeContext tc = repository.get(); + ChangeSet cs = tc.getChangeSet(); + return new InterfaceTraverser(getRootNode(), cs.getIndex(), getTreeEditor()); } @Override
--- a/src/main/java/alice/jungle/transaction/NetworkDefaultJungleTree.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/main/java/alice/jungle/transaction/NetworkDefaultJungleTree.java Tue Sep 16 07:49:14 2014 +0900 @@ -58,8 +58,9 @@ @Override public InterfaceTraverser getTraverser() { - // TODO Auto-generated method stub - return null; + TreeContext tc = repository.get(); + ChangeSet cs = tc.getChangeSet(); + return new InterfaceTraverser(getRootNode(), cs.getIndex(), getTreeEditor()); } @Override
--- a/src/main/java/app/bbs/NetworkBulletinBoard.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/main/java/app/bbs/NetworkBulletinBoard.java Tue Sep 16 07:49:14 2014 +0900 @@ -19,4 +19,5 @@ public void deleteNode(String _board, String _path, String id); public void editMatrixMessage(String boardName, String path, String author, String msg, String key); + public String searchJungle(String requestName, String permmitName); }
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Tue Sep 16 07:49:14 2014 +0900 @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Iterator; import java.util.concurrent.atomic.AtomicInteger; import fj.data.List; @@ -31,6 +32,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; 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.traverser.Traversal; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; @@ -732,6 +734,72 @@ return new getAttributeImp(target); } + public TreeNode search(JungleTree tree ,String searchAttribute,String key){ + InterfaceTraverser ifTraverser = tree.getTraverser(); + Iterator<Pair<TreeNode, NodePath>> 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; + } + 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 "承認者がデータに無い人物です"; + + if (!compare(searchNode, "上位申請権限")) + return "権限がありません(この申請の承認は上位申請者である必要があります"; + + String position = searchNode.getAttributes().getString("mes1"); + + JungleTree grantTree = jungle.getTreeByName("役職"); + searchNode = search(grantTree , position,"mes"); + + if (!compare(searchNode, "准教授権限") || !!compare(searchNode, "教授権限")) + return "権限がありません(この申請の承認は助教授か、教授である必要があります"; + + return "申請が受理されました"; + } + + public int getRequestNum() { return requestCounter.get(); }
--- a/src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java Tue Sep 16 07:49:14 2014 +0900 @@ -32,6 +32,7 @@ import app.bbs.thinks.createAttributeMatrix; import app.bbs.thinks.deleteAttributeServlet; import app.bbs.thinks.deleteNodeServlet; +import app.bbs.thinks.permission; public class StartBBSCodeSegment extends CodeSegment { @@ -87,6 +88,7 @@ String deleteAttributePath = "/deleteAttribute"; String deleteNodePath = "/deleteNode"; String editNodePath = "/editNode"; + String permissionPath = "/permission"; Server serv = new Server(bbsPort); ThreadPool thp = serv.getThreadPool(); Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS); @@ -102,7 +104,7 @@ // Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath); Servlet board = new ShowMessageWithTimeStampServlet(cassaBBS,createBoardMessagePath,editMessagePath,showMatrixPath, thp); Servlet matrix = new ShowMatrix(cassaBBS,createFolderPath,editNodePath, showMatrixPath, createAttributePath, editAttributePath,deleteAttributePath,deleteNodePath,thp); - + Servlet per = new permission(cassaBBS,permissionPath,thp); ServletHandler context = new ServletHandler(); context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath); @@ -117,6 +119,7 @@ context.addServletWithMapping(new ServletHolder(editAttribute),editAttributePath); context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath); context.addServletWithMapping(new ServletHolder(matrix),showMatrixPath); + context.addServletWithMapping(new ServletHolder(per),permissionPath); /* * For write benchmark */
--- a/src/main/java/app/bbs/thinks/ShowMatrix.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/main/java/app/bbs/thinks/ShowMatrix.java Tue Sep 16 07:49:14 2014 +0900 @@ -44,6 +44,7 @@ } public void doGet(HttpServletRequest _req, HttpServletResponse _res) { + final String bname = _req.getParameter(PARAM_BOARD_NAME); String path = _req.getParameter(PARAM_NODE_PATH); String nodeName = _req.getParameter(PARAM_NODE_NAME);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/app/bbs/thinks/permission.java Tue Sep 16 07:49:14 2014 +0900 @@ -0,0 +1,69 @@ +package app.bbs.thinks; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.util.thread.ThreadPool; + +import app.bbs.NetworkBulletinBoard; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; + +import org.eclipse.jetty.util.thread.ThreadPool; + +import app.bbs.NetworkBulletinBoard; + +public class permission extends HttpServlet{ + private static final long serialVersionUID = 1L; + private final NetworkBulletinBoard bbs; + private static final String REQUEST_NAME = "name1"; + private static final String PERMMIT_NAME = "name2"; + + public permission(NetworkBulletinBoard _bbs, + String permissionPath, ThreadPool thp) { + bbs = _bbs; + + } + + public void doGet(HttpServletRequest _req, HttpServletResponse _res) { + + try { + _res.setCharacterEncoding("UTF-8"); + PrintWriter _pw = _res.getWriter(); + _pw.write("<h1>" + " 承認フォーム " + "</h1>\n"); + _pw.write("<html><body><h1>edit message</h1>"); + _pw.write("<form method='POST'\n"); + _pw.write("<p>申請者名<br/> <input type='textarea' name='name1'/> </p>\n"); + _pw.write("<p>承認者名<br/> <input type='textarea' name='name2'/> </p>\n"); + _pw.write("<p><input type='submit' value='submit'/></p>\n"); + _pw.write("</body></html>"); + _pw.flush(); + _res.setCharacterEncoding("UTF-8"); + } catch (Exception _e) { + _res.setStatus(500); + } + } + + public void doPost(HttpServletRequest _req,HttpServletResponse _res) + { + String requestName = _req.getParameter(REQUEST_NAME); + String permmitName = _req.getParameter(PERMMIT_NAME); + + try{ + _res.setCharacterEncoding("UTF-8"); + PrintWriter pw = _res.getWriter(); + pw.write(bbs.searchJungle(requestName,permmitName)); + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + } + +}
--- a/src/test/java/alice/jungle/log/example/FindMatrixTest.java Mon Sep 15 16:31:04 2014 +0900 +++ b/src/test/java/alice/jungle/log/example/FindMatrixTest.java Tue Sep 16 07:49:14 2014 +0900 @@ -1,11 +1,15 @@ package alice.jungle.log.example; + + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Iterator; +import org.junit.Test; + import fj.Ord; import fj.data.List; import fj.data.TreeMap; @@ -36,9 +40,10 @@ public class FindMatrixTest extends TestCase { + @Test public static void main(String[] args) throws IOException { PersistentJournal journal = new PersistentJournal(); - journal.setOutputFile(new File("./log/test.log")); + journal.setOutputFile(new File("./log/1.log")); Jungle jungle = new PersistentJungle(journal, "uuid", new DefaultTreeEditor(new DefaultTraverser())); String treeName = treeLoad(jungle); @@ -53,7 +58,7 @@ byte[] byteAttribute = attribute.array(); String str = new String(byteAttribute); System.out.println(str); - return str.equals("株式会社フタコ放送"); + return str.equals("比嘉健太"); } return false; } @@ -84,7 +89,7 @@ public static ChangeListReader getChangeList() throws FileNotFoundException { PersistentJournal journal1 = new PersistentJournal(); - journal1.setInputFile(new File("./_log_/1410589309338.log")); + journal1.setInputFile(new File("./log/1410802370082.log")); ChangeListReader reader = journal1.getReader(); return reader; }