Mercurial > hg > Database > jungle-network
annotate src/main/java/app/bbs/NetworkJungleBulletinBoard.java @ 187:f9b26747ef63
add matrixBullet in board
author | tatsuki |
---|---|
date | Sat, 27 Sep 2014 16:23:21 +0900 |
parents | ef5045af0753 |
children | 269bada9eedc |
rev | line source |
---|---|
112 | 1 package app.bbs; |
38 | 2 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
3 import java.io.File; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
4 import java.io.IOException; |
38 | 5 import java.nio.ByteBuffer; |
187 | 6 import java.text.SimpleDateFormat; |
7 import java.util.Date; | |
186 | 8 import java.util.Iterator; |
38 | 9 import java.util.concurrent.atomic.AtomicInteger; |
39 | 10 |
179 | 11 import fj.data.List; |
12 import fj.data.TreeMap; | |
39 | 13 import alice.jungle.core.NetworkDefaultJungle; |
124 | 14 import alice.jungle.persistent.AliceJournal; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
15 import alice.jungle.persistent.NetworkJournal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
16 import alice.jungle.persistent.PersistentJournal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
17 import alice.jungle.transaction.JungleUpdater; |
166 | 18 import app.bbs.thinks.getAttributeImp; |
38 | 19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; |
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | |
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
125 | 22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; |
38 | 23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; |
180 | 26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; |
38 | 27 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
28 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; | |
176 | 29 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
30 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; | |
179 | 31 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; |
176 | 32 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; |
33 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; | |
38 | 34 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; |
165 | 35 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; |
38 | 36 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; |
186 | 37 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; |
165 | 38 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traversal; |
38 | 39 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
40 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
41 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
42 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; | |
180 | 43 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; |
179 | 44 import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Logging; |
165 | 45 import junit.framework.Assert; |
38 | 46 |
165 | 47 public class NetworkJungleBulletinBoard implements NetworkBulletinBoard { |
38 | 48 private final Jungle jungle; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
49 private final NetworkJournal journal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
50 private final String LOG_DIR; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
51 private Boolean persistentFlag; |
165 | 52 private AtomicInteger requestCounter; |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
53 private long renewTime; |
165 | 54 |
55 private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
56 journal = _journal; |
176 | 57 jungle = new NetworkDefaultJungle(journal, _uuid, |
58 new DefaultTreeEditor(new DefaultTraverser())); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
59 BulletinBoardJungleManager.setJungle(jungle); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
60 persistentFlag = false; |
147
202ea963ec20
Added requestCounter in BulletinBoardJungleManager
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
146
diff
changeset
|
61 requestCounter = BulletinBoardJungleManager.getRequestCounter(); |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
62 LOG_DIR = "./log"; |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
63 renewTime = 0; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
64 } |
165 | 65 |
66 public NetworkJungleBulletinBoard(String _uuid) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
67 this(_uuid, new AliceJournal()); |
124 | 68 jungle.createNewTree("boards"); |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
69 } |
165 | 70 |
71 public static NetworkBulletinBoard NewPersistentJungle(String _uuid) { | |
176 | 72 NetworkJungleBulletinBoard board = new NetworkJungleBulletinBoard( |
73 _uuid, new PersistentJournal()); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
74 board.persistentFlag = true; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
75 return board; |
38 | 76 } |
165 | 77 |
124 | 78 public void init() { |
165 | 79 if (!persistentFlag) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
80 return; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
81 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
82 checkAndCreateLogDirectory(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
83 try { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
84 commitLogRecover(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
85 } catch (IOException e) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
86 e.printStackTrace(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
87 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
88 } |
165 | 89 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
90 public void checkAndCreateLogDirectory() { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
91 File logFile = new File(LOG_DIR); |
165 | 92 if (!logFile.exists()) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
93 logFile.mkdir(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
94 return; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
95 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
96 if (logFile.isFile()) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
97 logFile.delete(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
98 logFile.mkdir(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
99 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
100 } |
165 | 101 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
102 public void commitLogRecover() throws IOException { |
165 | 103 File[] logFiles = new File(LOG_DIR).listFiles(); |
104 for (File logFile : logFiles) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
105 commitLogRecover(logFile); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
106 logFile.delete(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
107 } |
165 | 108 if (jungle.getTreeByName("boards") == null) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
109 jungle.createNewTree("boards"); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
110 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
111 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
112 |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
113 private void commitLogRecover(File logFile) throws IOException { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
114 journal.setInputFile(logFile); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
115 ChangeListReader reader = journal.getReader(); |
165 | 116 if (reader == null) |
117 return; | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
118 for (ChangeList chList : reader) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
119 String treeName = chList.getTreeName(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
120 JungleTree tree = jungle.getTreeByName(treeName); |
165 | 121 if (tree == null) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
122 tree = jungle.createNewTree(treeName); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
123 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
124 JungleTreeEditor editor = tree.getLocalTreeEditor(); |
176 | 125 Either<Error, JungleTreeEditor> either = JungleUpdater.edit(editor, |
126 chList); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
127 editor = either.b(); |
165 | 128 if (either.isA()) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
129 throw new IOException("Failed commit log recovery"); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
130 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
131 editor.success(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
132 } |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
112
diff
changeset
|
133 } |
38 | 134 |
165 | 135 public Iterable<String> getBoards() { |
38 | 136 JungleTree tree = jungle.getTreeByName("boards"); |
176 | 137 TreeNode node = tree.getRootNode(); |
178 | 138 Children chs = node.getChildren(); |
165 | 139 |
176 | 140 IterableConverter.Converter<String, TreeNode> converter = new IterableConverter.Converter<String, TreeNode>() { |
141 public String conv(TreeNode _b) { | |
38 | 142 ByteBuffer e = _b.getAttributes().get("name"); |
173 | 143 System.out.println(new String(e.array())); |
38 | 144 return new String(e.array()); |
145 } | |
146 }; | |
165 | 147 |
176 | 148 return new IterableConverter<String, TreeNode>(chs, converter); |
38 | 149 } |
165 | 150 |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
151 public long getRenewTime(String _boardName) { |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
152 return renewTime; |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
153 } |
38 | 154 |
167 | 155 public void createBoards(final String _name, final String _author, final String _initMessage, final String _editKey) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
156 requestCounter.incrementAndGet(); |
165 | 157 if (null == jungle.createNewTree(_name)) { |
38 | 158 throw new IllegalStateException(); |
159 } | |
165 | 160 |
38 | 161 JungleTree tree = jungle.getTreeByName("boards"); |
162 JungleTreeEditor editor = tree.getTreeEditor(); | |
163 DefaultNodePath root = new DefaultNodePath(); | |
165 | 164 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, 0); |
165 if (either.isA()) { | |
38 | 166 throw new IllegalStateException(); |
167 } | |
168 editor = either.b(); | |
165 | 169 |
176 | 170 either = editor.putAttribute(root.add(0), "name", |
171 ByteBuffer.wrap(_name.getBytes())); | |
165 | 172 if (either.isA()) { |
38 | 173 throw new IllegalStateException(); |
174 } | |
175 editor = either.b(); | |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
176 final long timestamp = System.currentTimeMillis(); |
129
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
177 ByteBuffer tBuffer = ByteBuffer.allocate(16); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
178 tBuffer.putLong(timestamp); |
165 | 179 either = editor.putAttribute(root.add(0), "timestamp", tBuffer); |
180 if (either.isA()) { | |
129
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
181 throw new IllegalStateException(); |
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
182 } |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
183 either = either.b().success(); |
165 | 184 if (either.isA()) { |
38 | 185 throw new IllegalStateException(); |
186 } | |
165 | 187 |
38 | 188 tree = jungle.getTreeByName(_name); |
189 editor = tree.getTreeEditor(); | |
165 | 190 either = editor.addNewChildAt(root, 0); |
191 if (either.isA()) { | |
38 | 192 throw new IllegalStateException(); |
193 } | |
194 editor = either.b(); | |
165 | 195 |
196 NodeEditor e = new NodeEditor() { | |
176 | 197 ByteBuffer tBuffer2 = ByteBuffer.allocate(16); |
198 | |
179 | 199 public Either<Error,Logging> edit(TreeNode node) { |
200 Logging logNode = wrap(node , new DefaultOperationLog()); | |
201 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
202 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b(); | |
203 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
204 tBuffer2.putLong(timestamp); |
179 | 205 logNode = logNode.getAttributes().put("timestamp", tBuffer2).b(); |
206 return DefaultEither.newB(logNode); | |
207 } | |
208 @Override | |
209 public Logging wrap(TreeNode node, OperationLog op) { | |
210 return new LoggingNode(node, op); | |
211 } | |
212 @Override | |
180 | 213 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 214 // TODO Auto-generated method stub |
215 return null; | |
176 | 216 } |
217 | |
38 | 218 }; |
165 | 219 |
220 either = editor.edit(root.add(0), e); | |
221 if (either.isA()) { | |
38 | 222 throw new IllegalStateException(); |
223 } | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
224 either.b().success(); |
147
202ea963ec20
Added requestCounter in BulletinBoardJungleManager
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
146
diff
changeset
|
225 |
38 | 226 } |
227 | |
167 | 228 public void createFolder(final String _board, final String _author, final String _message, final String _editKey, String _nodeNum) { |
38 | 229 JungleTree tree = jungle.getTreeByName(_board); |
165 | 230 if (tree == null) { |
38 | 231 throw new IllegalStateException(); |
232 } | |
176 | 233 |
165 | 234 DefaultNodePath path = new DefaultNodePath(); |
235 try { | |
236 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
237 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
176 | 238 path = path.add(Integer.parseInt(_nodeNum.substring(count, |
239 count + 1))); | |
165 | 240 } |
241 } catch (Exception _e) { | |
242 } | |
243 requestCounter.incrementAndGet(); | |
46 | 244 Either<Error, JungleTreeEditor> either; |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
245 final long timestamp = System.currentTimeMillis(); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
246 final ByteBuffer tBuffer = ByteBuffer.allocate(16); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
247 tBuffer.putLong(timestamp); |
176 | 248 |
165 | 249 do { |
176 | 250 TreeNode node = tree.getRootNode(); |
165 | 251 DefaultTraverser traverser = new DefaultTraverser(); |
176 | 252 // TraversableNodeWrapper<Node> traversable = new |
253 // TraversableNodeWrapper<Node>(node); | |
165 | 254 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
178 | 255 Either<Error, Traversal> ret = traverser.traverse(node, |
176 | 256 evaluator); |
165 | 257 if (ret.isA()) { |
258 Assert.fail(); | |
259 } | |
260 | |
178 | 261 Traversal traversal = ret.b(); |
176 | 262 TreeNode target = traversal.destination(); |
263 int size = target.getChildren().size(); | |
65 | 264 JungleTreeEditor editor = tree.getTreeEditor(); |
165 | 265 either = editor.addNewChildAt(path, size); |
266 if (either.isA()) { | |
38 | 267 throw new IllegalStateException(); |
268 } | |
269 editor = either.b(); | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
270 |
165 | 271 NodeEditor e = new NodeEditor() { |
176 | 272 |
179 | 273 public Either<Error,Logging> edit(TreeNode node) { |
274 Logging logNode = wrap(node , new DefaultOperationLog()); | |
275 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
276 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
277 return DefaultEither.newB(logNode); | |
278 } | |
279 | |
280 @Override | |
281 public Logging wrap(TreeNode node, OperationLog op) { | |
282 return new LoggingNode(node, op); | |
283 } | |
284 | |
285 @Override | |
180 | 286 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 287 // TODO Auto-generated method stub |
288 return null; | |
176 | 289 } |
290 | |
38 | 291 }; |
292 path = path.add(size); | |
165 | 293 either = editor.edit(path, e); |
294 if (either.isA()) { | |
38 | 295 throw new IllegalStateException(); |
296 } | |
297 editor = either.b(); | |
46 | 298 either = editor.success(); |
165 | 299 } while (either.isA()); |
93 | 300 |
38 | 301 } |
302 | |
167 | 303 public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) { |
165 | 304 requestCounter.incrementAndGet(); |
305 JungleTree tree = jungle.getTreeByName(_board); | |
306 if (tree == null) { | |
307 throw new IllegalStateException(); | |
308 } | |
309 | |
310 Either<Error, JungleTreeEditor> either; | |
311 final long timestamp = System.currentTimeMillis(); | |
312 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
313 tBuffer.putLong(timestamp); | |
314 do { | |
176 | 315 |
316 TreeNode node = tree.getRootNode(); | |
165 | 317 int size = node.getChildren().size(); |
318 DefaultNodePath path = new DefaultNodePath(); | |
319 | |
320 JungleTreeEditor editor = tree.getTreeEditor(); | |
321 either = editor.addNewChildAt(path, size); | |
322 if (either.isA()) { | |
323 throw new IllegalStateException(); | |
324 } | |
325 editor = either.b(); | |
326 | |
327 NodeEditor e = new NodeEditor() { | |
179 | 328 public Either<Error,Logging> edit(TreeNode node) { |
329 Logging logNode = wrap(node , new DefaultOperationLog()); | |
330 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
331 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
332 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
333 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
334 return DefaultEither.newB(logNode); | |
335 } | |
336 | |
337 @Override | |
338 public Logging wrap(TreeNode node, OperationLog op) { | |
339 return new LoggingNode(node, op); | |
340 } | |
341 | |
342 @Override | |
180 | 343 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 344 // TODO Auto-generated method stub |
345 return null; | |
176 | 346 } |
347 | |
165 | 348 }; |
349 path = path.add(size); | |
350 either = editor.edit(path, e); | |
351 if (either.isA()) { | |
352 throw new IllegalStateException(); | |
353 } | |
354 editor = either.b(); | |
355 either = editor.success(); | |
356 } while (either.isA()); | |
357 | |
358 } | |
359 | |
176 | 360 public void editMessage(String _board, String _nodeNum,final String _author, final String _message, final String _editKey) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
361 requestCounter.incrementAndGet(); |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
362 final long timestamp = System.currentTimeMillis(); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
363 final ByteBuffer tBuffer = ByteBuffer.allocate(16); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
364 tBuffer.putLong(timestamp); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
365 JungleTree tree = jungle.getTreeByName(_board); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
366 Either<Error, JungleTreeEditor> either = null; |
176 | 367 |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
368 do { |
38 | 369 DefaultNodePath path = new DefaultNodePath(); |
168 | 370 try { |
371 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
372 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
176 | 373 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); |
168 | 374 } |
375 } catch (Exception _e) { | |
376 } | |
65 | 377 JungleTreeEditor editor = tree.getTreeEditor(); |
165 | 378 NodeEditor e = new NodeEditor() { |
179 | 379 public Either<Error,Logging> edit(TreeNode node) { |
380 Logging logNode = wrap(node , new DefaultOperationLog()); | |
381 System.out.println(new String(node.getAttributes().get("mes").array())); | |
382 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
383 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
384 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
385 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
176 | 386 System.out.println(new String(node.getAttributes().get("mes").array())); |
179 | 387 return DefaultEither.newB(logNode); |
388 } | |
389 | |
390 @Override | |
391 public Logging wrap(TreeNode node, OperationLog op) { | |
392 return new LoggingNode(node, op); | |
393 } | |
394 | |
395 @Override | |
180 | 396 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 397 // TODO Auto-generated method stub |
398 return null; | |
176 | 399 } |
400 | |
38 | 401 }; |
165 | 402 either = editor.edit(path, e); |
403 if (either.isA()) { | |
38 | 404 throw new IllegalStateException(); |
405 } | |
406 editor = either.b(); | |
46 | 407 either = editor.success(); |
165 | 408 } while (either.isA()); |
409 renewTime = timestamp; | |
410 } | |
166 | 411 |
167 | 412 public void createAttribute(String _board, String _uuid, final String _author, final String _message, final String _editKey) { |
165 | 413 requestCounter.incrementAndGet(); |
414 final long timestamp = System.currentTimeMillis(); | |
415 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
416 tBuffer.putLong(timestamp); | |
417 JungleTree tree = jungle.getTreeByName(_board); | |
418 Either<Error, JungleTreeEditor> either = null; | |
419 DefaultNodePath path = new DefaultNodePath(); | |
420 do { | |
421 try { | |
422 for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { | |
423 if (!_uuid.substring(count, count + 1).equals("/")) | |
176 | 424 path = path.add(Integer.parseInt(_uuid.substring(count, |
425 count + 1))); | |
165 | 426 } |
427 } catch (Exception _e) { | |
428 } | |
176 | 429 |
165 | 430 JungleTreeEditor editor = tree.getTreeEditor(); |
431 NodeEditor e = new NodeEditor() { | |
176 | 432 String str; |
433 | |
179 | 434 public Either<Error,Logging> edit(TreeNode node) { |
435 Logging logNode = wrap(node , new DefaultOperationLog()); | |
176 | 436 str = "0"; |
166 | 437 int count = 0; |
179 | 438 for (; logNode.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { |
176 | 439 } |
168 | 440 str = String.valueOf(count); |
179 | 441 logNode = logNode.getAttributes().put("mes" + str,ByteBuffer.wrap(_message.getBytes())).b(); |
442 logNode = logNode.getAttributes().put("timestamp" + str, tBuffer).b(); | |
443 return DefaultEither.newB(logNode); | |
444 } | |
445 | |
446 @Override | |
447 public Logging wrap(TreeNode node, OperationLog op) { | |
448 return new LoggingNode(node, op); | |
449 } | |
450 | |
451 @Override | |
180 | 452 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 453 // TODO Auto-generated method stub |
454 return null; | |
176 | 455 } |
456 | |
165 | 457 }; |
458 either = editor.edit(path, e); | |
459 if (either.isA()) { | |
460 throw new IllegalStateException(); | |
461 } | |
462 editor = either.b(); | |
463 either = editor.success(); | |
464 } while (either.isA()); | |
465 } | |
166 | 466 |
173 | 467 public void editAttribute(String boardName, String _path, final String id, final String _message) { |
168 | 468 requestCounter.incrementAndGet(); |
469 final long timestamp = System.currentTimeMillis(); | |
470 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
471 tBuffer.putLong(timestamp); | |
472 JungleTree tree = jungle.getTreeByName(boardName); | |
473 Either<Error, JungleTreeEditor> either = null; | |
474 DefaultNodePath path = new DefaultNodePath(); | |
475 do { | |
476 try { | |
477 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
478 if (!_path.substring(count, count + 1).equals("/")) | |
176 | 479 path = path.add(Integer.parseInt(_path.substring(count, |
480 count + 1))); | |
168 | 481 } |
482 } catch (Exception _e) { | |
483 } | |
176 | 484 |
168 | 485 JungleTreeEditor editor = tree.getTreeEditor(); |
486 NodeEditor e = new NodeEditor() { | |
179 | 487 public Either<Error,Logging> edit(TreeNode node) { |
488 Logging logNode = wrap(node , new DefaultOperationLog()); | |
168 | 489 // EnableNodeWrapper<T> node = _e.getWrap(); |
179 | 490 logNode = logNode.getAttributes().put("mes" + id,ByteBuffer.wrap(_message.getBytes())).b(); |
491 logNode = logNode.getAttributes().put("timestamp" + id, tBuffer).b(); | |
492 return DefaultEither.newB(logNode); | |
493 } | |
494 | |
495 @Override | |
496 public Logging wrap(TreeNode node, OperationLog op) { | |
497 return new LoggingNode(node, op); | |
498 } | |
499 | |
500 @Override | |
180 | 501 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 502 // TODO Auto-generated method stub |
503 return null; | |
176 | 504 } |
505 | |
168 | 506 }; |
507 either = editor.edit(path, e); | |
508 if (either.isA()) { | |
509 throw new IllegalStateException(); | |
510 } | |
511 editor = either.b(); | |
512 either = editor.success(); | |
513 } while (either.isA()); | |
514 } | |
176 | 515 |
170 | 516 public void deleteNode(String _board, String _path, String _id) { |
517 requestCounter.incrementAndGet(); | |
518 int id = Integer.parseInt(_id); | |
519 final long timestamp = System.currentTimeMillis(); | |
520 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
521 tBuffer.putLong(timestamp); | |
522 JungleTree tree = jungle.getTreeByName(_board); | |
523 Either<Error, JungleTreeEditor> either = null; | |
524 DefaultNodePath path = new DefaultNodePath(); | |
525 do { | |
526 try { | |
527 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
528 if (!_path.substring(count, count + 1).equals("/")) | |
176 | 529 path = path.add(Integer.parseInt(_path.substring(count,count + 1))); |
170 | 530 } |
531 } catch (Exception _e) { | |
532 } | |
176 | 533 |
170 | 534 JungleTreeEditor editor = tree.getTreeEditor(); |
168 | 535 |
170 | 536 either = editor.deleteChildAt(path, id); |
537 if (either.isA()) { | |
538 throw new IllegalStateException(); | |
539 } | |
540 editor = either.b(); | |
541 either = editor.success(); | |
542 } while (either.isA()); | |
176 | 543 |
170 | 544 } |
176 | 545 |
546 public void deleteAttribute(String _board, String _path, final String id) { | |
169 | 547 requestCounter.incrementAndGet(); |
548 final long timestamp = System.currentTimeMillis(); | |
549 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
550 tBuffer.putLong(timestamp); | |
551 JungleTree tree = jungle.getTreeByName(_board); | |
552 Either<Error, JungleTreeEditor> either = null; | |
553 DefaultNodePath path = new DefaultNodePath(); | |
554 do { | |
555 try { | |
556 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
557 if (!_path.substring(count, count + 1).equals("/")) | |
176 | 558 path = path.add(Integer.parseInt(_path.substring(count, |
559 count + 1))); | |
169 | 560 } |
561 } catch (Exception _e) { | |
175 | 562 System.out.println("屑"); |
169 | 563 } |
176 | 564 |
169 | 565 JungleTreeEditor editor = tree.getTreeEditor(); |
566 NodeEditor e = new NodeEditor() { | |
179 | 567 public Either<Error,Logging> edit(TreeNode node) { |
568 Logging logNode = wrap(node , new DefaultOperationLog()); | |
569 logNode = logNode.getAttributes().delete("mes" + id).b(); | |
570 logNode = logNode.getAttributes().delete("timestamp" + id).b(); | |
169 | 571 int count = Integer.parseInt(id); |
179 | 572 for (; logNode.getAttributes().get("mes" + String.valueOf(count + 1)) != null;) { |
573 logNode = logNode.getAttributes().put("mes" + count,node.getAttributes().get("mes"+ String.valueOf(count + 1))).b(); | |
574 logNode = logNode.getAttributes().put("timestamp" + count, tBuffer).b(); | |
176 | 575 count++; |
576 } | |
577 if (count != Integer.parseInt(id)) { | |
179 | 578 logNode = logNode.getAttributes().delete("timestamp" + count).b(); |
579 logNode = logNode.getAttributes().delete("mes" + count).b(); | |
171 | 580 } |
581 | |
179 | 582 return DefaultEither.newB(logNode); |
583 } | |
584 | |
585 @Override | |
586 public Logging wrap(TreeNode node, OperationLog op) { | |
587 return new LoggingNode(node, op); | |
588 } | |
589 | |
590 @Override | |
180 | 591 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 592 // TODO Auto-generated method stub |
593 return null; | |
176 | 594 } |
595 | |
169 | 596 }; |
597 either = editor.edit(path, e); | |
598 if (either.isA()) { | |
599 throw new IllegalStateException(); | |
600 } | |
601 editor = either.b(); | |
602 either = editor.success(); | |
603 } while (either.isA()); | |
604 } | |
605 | |
176 | 606 public void editMatrixMessage(String _board, String _uuid, |
607 final String _author, final String _message, final String _editKey) { | |
165 | 608 requestCounter.incrementAndGet(); |
609 final long timestamp = System.currentTimeMillis(); | |
610 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
611 tBuffer.putLong(timestamp); | |
612 JungleTree tree = jungle.getTreeByName(_board); | |
613 Either<Error, JungleTreeEditor> either = null; | |
614 do { | |
615 DefaultNodePath path = new DefaultNodePath(); | |
616 path = path.add(Integer.parseInt(_uuid)); | |
617 | |
618 JungleTreeEditor editor = tree.getTreeEditor(); | |
619 NodeEditor e = new NodeEditor() { | |
179 | 620 public Either<Error,Logging> edit(TreeNode node) { |
621 Logging logNode = wrap(node , new DefaultOperationLog()); | |
622 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
623 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
624 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
625 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
626 return DefaultEither.newB(logNode); | |
627 } | |
628 | |
629 @Override | |
630 public Logging wrap(TreeNode node, OperationLog op) { | |
631 return new LoggingNode(node, op); | |
632 } | |
633 | |
634 @Override | |
180 | 635 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 636 // TODO Auto-generated method stub |
637 return null; | |
176 | 638 } |
165 | 639 }; |
640 either = editor.edit(path, e); | |
641 if (either.isA()) { | |
642 throw new IllegalStateException(); | |
643 } | |
644 editor = either.b(); | |
645 either = editor.success(); | |
646 } while (either.isA()); | |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
647 renewTime = timestamp; |
38 | 648 } |
649 | |
165 | 650 public Iterable<BoardMessage> getMessages(String _boardName) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
651 requestCounter.incrementAndGet(); |
38 | 652 JungleTree tree = jungle.getTreeByName(_boardName); |
176 | 653 TreeNode node = tree.getRootNode(); |
178 | 654 Children chs = node.getChildren(); |
38 | 655 final AtomicInteger counter = new AtomicInteger(0); |
176 | 656 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { |
657 public BoardMessage conv(TreeNode _b) { | |
165 | 658 String uuid = Integer.toString(counter.get()); |
176 | 659 String author = new String(_b.getAttributes().get("author").array()); |
167 | 660 String message = new String(_b.getAttributes().get("mes").array()); |
165 | 661 counter.incrementAndGet(); |
662 return new BoardMessageImpl(author, message, uuid); | |
663 } | |
664 }; | |
176 | 665 return new IterableConverter<BoardMessage, TreeNode>(chs, converter); |
165 | 666 } |
667 | |
668 public Iterable<BoardMessage> getFolder(String _boardName, String _nodeNum) { | |
166 | 669 |
165 | 670 DefaultNodePath path = new DefaultNodePath(); |
671 try { | |
672 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
673 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
167 | 674 path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); |
165 | 675 } |
676 } catch (Exception _e) { | |
677 } | |
678 requestCounter.incrementAndGet(); | |
679 JungleTree tree = jungle.getTreeByName(_boardName); | |
176 | 680 TreeNode node = tree.getRootNode(); |
165 | 681 |
682 DefaultTraverser traverser = new DefaultTraverser(); | |
176 | 683 // TraversableNodeWrapper<Node> traversable = new |
684 // TraversableNodeWrapper<Node>(node); | |
165 | 685 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
178 | 686 Either<Error, Traversal> ret = traverser.traverse(node, |
176 | 687 evaluator); |
165 | 688 if (ret.isA()) { |
689 Assert.fail(); | |
690 } | |
691 | |
178 | 692 Traversal traversal = ret.b(); |
176 | 693 TreeNode target = traversal.destination(); |
178 | 694 Children chs = target.getChildren(); |
165 | 695 |
696 final AtomicInteger counter = new AtomicInteger(0); | |
176 | 697 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { |
698 public BoardMessage conv(TreeNode _b) { | |
38 | 699 String uuid = Integer.toString(counter.get()); |
176 | 700 String message = new String(_b.getAttributes().get("mes") |
701 .array()); | |
38 | 702 counter.incrementAndGet(); |
167 | 703 return new BoardMessageImpl(null, message, uuid); |
38 | 704 } |
705 }; | |
176 | 706 return new IterableConverter<BoardMessage, TreeNode>(chs, converter); |
38 | 707 } |
166 | 708 |
709 public getAttributeImp getAttribute(String _boardName, String _nodeNum) { | |
710 | |
711 DefaultNodePath path = new DefaultNodePath(); | |
712 try { | |
713 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
714 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
176 | 715 path = path.add(Integer.parseInt(_nodeNum.substring(count, |
716 count + 1))); | |
166 | 717 } |
718 } catch (Exception _e) { | |
719 } | |
720 requestCounter.incrementAndGet(); | |
721 JungleTree tree = jungle.getTreeByName(_boardName); | |
176 | 722 TreeNode node = tree.getRootNode(); |
166 | 723 |
724 DefaultTraverser traverser = new DefaultTraverser(); | |
725 DefaultEvaluator evaluator = new DefaultEvaluator(path); | |
178 | 726 Either<Error, Traversal> ret = traverser.traverse(node, |
176 | 727 evaluator); |
166 | 728 if (ret.isA()) { |
729 Assert.fail(); | |
730 } | |
731 | |
178 | 732 Traversal traversal = ret.b(); |
176 | 733 TreeNode target = traversal.destination(); |
734 return new getAttributeImp(target); | |
166 | 735 } |
165 | 736 |
186 | 737 public TreeNode search(JungleTree tree ,String searchAttribute,String key){ |
738 InterfaceTraverser ifTraverser = tree.getTraverser(); | |
739 Iterator<Pair<TreeNode, NodePath>> searchNode = ifTraverser.find( | |
740 (TreeNode node) -> { | |
741 ByteBuffer attribute = node.getAttributes().get(key); | |
742 if(attribute != null){ | |
743 byte[] byteAttribute = attribute.array(); | |
744 String str = new String(byteAttribute); | |
745 System.out.println(str); | |
746 return str.equals(searchAttribute); | |
747 } | |
748 return false; | |
749 } | |
750 ); | |
751 | |
752 if (!searchNode.hasNext()) | |
753 return null; | |
754 return searchNode.next().left(); | |
755 | |
756 } | |
757 | |
758 public boolean compare(TreeNode compareNode, String compareAttribute) { | |
759 String labName = compareNode.getAttributes().getString("mes"); | |
760 if (labName.equals(compareAttribute)) | |
761 return true; | |
762 | |
763 int loopCount = 0; | |
764 for (loopCount = 0 ;compareNode.getAttributes().getString("mes" + loopCount) != null; loopCount++ ) { | |
765 labName = compareNode.getAttributes().getString("mes" + loopCount); | |
766 if (labName.equals(compareAttribute)) | |
767 return true; | |
768 } | |
769 | |
770 return false; | |
771 } | |
187 | 772 |
186 | 773 public String searchJungle(String requestName , String approvalName) { |
774 JungleTree tree = jungle.getTreeByName("人物"); | |
775 | |
776 | |
777 TreeNode searchNode = search(tree , requestName,"mes"); | |
187 | 778 if (searchNode == null){ |
779 fail(requestName,approvalName,"申請者がデータに無い人物です"); | |
186 | 780 return "申請者がデータに無い人物です"; |
187 | 781 } |
186 | 782 |
187 | 783 if (!compare(searchNode, "河野研")){ |
784 fail(requestName,approvalName,"河野研以外に所属している人は、この申請をすることが出来ません"); | |
186 | 785 return "河野研以外に所属している人は、この申請をすることが出来ません"; |
187 | 786 } |
186 | 787 |
788 searchNode = search(tree , approvalName,"mes"); | |
187 | 789 if (searchNode == null){ |
790 fail(requestName,approvalName,"承認者がデータに無い人物です"); | |
186 | 791 return "承認者がデータに無い人物です"; |
187 | 792 } |
186 | 793 |
794 String position = searchNode.getAttributes().getString("mes1"); | |
795 | |
796 JungleTree grantTree = jungle.getTreeByName("役職"); | |
797 searchNode = search(grantTree , position,"mes"); | |
798 | |
187 | 799 if (!compare(searchNode, "准教授権限") && !compare(searchNode, "教授権限")){ |
800 fail(requestName,approvalName,"権限がありません(この申請の承認は助教授か、教授である必要があります"); | |
186 | 801 return "権限がありません(この申請の承認は助教授か、教授である必要があります"; |
187 | 802 } |
186 | 803 |
187 | 804 searchNode = search(tree , approvalName,"mes"); |
805 if (searchNode == null){ | |
806 fail(requestName,approvalName,"申請者がデータに無い人物です"); | |
807 return "申請者がデータに無い人物です"; | |
808 } | |
809 | |
810 if (!compare(searchNode, "上位申請権限")){ | |
811 fail(requestName,approvalName,"権限がありません(この申請の承認は上位申請者である必要があります"); | |
812 return "権限がありません(この申請の承認は上位申請者である必要があります"; | |
813 } | |
814 success(requestName,approvalName); | |
815 | |
816 return "申請が受理されました"; | |
186 | 817 } |
818 | |
187 | 819 public void fail(String requestName, String approvalName, String reason){ |
820 JungleTree contextTree = jungle.getTreeByName("申請"); | |
821 JungleTreeEditor editor = contextTree.getTreeEditor(); | |
822 editor = editor.putAttribute(new DefaultNodePath(),"mes0", ByteBuffer.wrap(("申請者名 = " + requestName).getBytes())).b(); | |
823 editor = editor.putAttribute(new DefaultNodePath(),"mes1", ByteBuffer.wrap(("申請内容".getBytes()))).b(); | |
824 Date date = new Date(); | |
825 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); | |
826 String time = sdf.format(date); | |
827 editor = editor.putAttribute(new DefaultNodePath(),"mes2", ByteBuffer.wrap(("承認時間 = " + time).getBytes())).b(); | |
828 | |
829 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes", ByteBuffer.wrap("否認書".getBytes())).b(); | |
830 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes0", ByteBuffer.wrap(("否認者名 = " + approvalName).getBytes())).b(); | |
831 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes1", ByteBuffer.wrap(("否認理由 = " + reason).getBytes())).b(); | |
832 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes2", ByteBuffer.wrap(("承認時間 = " + time).getBytes())).b(); | |
833 editor.success(); | |
834 } | |
835 | |
836 public void success(String requestName, String approvalName){ | |
837 JungleTree contextTree = jungle.getTreeByName("申請"); | |
838 JungleTreeEditor editor = contextTree.getTreeEditor(); | |
839 editor = editor.putAttribute(new DefaultNodePath(),"mes0", ByteBuffer.wrap(("申請者名 = " + requestName).getBytes())).b(); | |
840 editor = editor.putAttribute(new DefaultNodePath(),"mes1", ByteBuffer.wrap(("申請内容".getBytes()))).b(); | |
841 Date date = new Date(); | |
842 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); | |
843 String time = sdf.format(date); | |
844 editor = editor.putAttribute(new DefaultNodePath(),"mes2", ByteBuffer.wrap(("承認時間" + time).getBytes())).b(); | |
845 | |
846 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes", ByteBuffer.wrap("承認書".getBytes())).b(); | |
847 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes0", ByteBuffer.wrap(("承認者名 = " + approvalName).getBytes())).b(); | |
848 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes1", ByteBuffer.wrap("承認理由 = 権限があってるので許可した".getBytes())).b(); | |
849 editor = editor.putAttribute(new DefaultNodePath().add(0),"mes2", ByteBuffer.wrap(("承認時間" + time).getBytes())).b(); | |
850 editor.success(); | |
851 } | |
186 | 852 |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
853 public int getRequestNum() { |
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
854 return requestCounter.get(); |
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
855 } |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
856 |
165 | 857 private static class BoardMessageImpl implements BoardMessage { |
38 | 858 private final String author; |
859 private final String message; | |
860 private final String uuid; | |
165 | 861 |
862 public BoardMessageImpl(String _author, String _message, String _uuid) { | |
38 | 863 author = _author; |
864 message = _message; | |
865 uuid = _uuid; | |
866 } | |
867 | |
165 | 868 public String getAuthor() { |
38 | 869 return author; |
870 } | |
871 | |
165 | 872 public String getMessage() { |
38 | 873 return message; |
874 } | |
875 | |
165 | 876 public String getUUID() { |
38 | 877 return uuid; |
878 } | |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
879 |
38 | 880 } |
124 | 881 |
176 | 882 public String sanitize(String str) { |
883 if (str == null) { | |
884 return str; | |
885 } | |
886 str = str.replaceAll("&", "&"); | |
887 str = str.replaceAll("<", "<"); | |
888 str = str.replaceAll(">", ">"); | |
889 str = str.replaceAll("\"", """); | |
890 str = str.replaceAll("'", "'"); | |
891 return str; | |
892 } | |
170 | 893 |
38 | 894 } |