7
|
1 package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs;
|
|
2
|
|
3 import java.util.Iterator;
|
11
|
4 import java.util.LinkedList;
|
8
|
5 import java.util.regex.Matcher;
|
|
6 import java.util.regex.Pattern;
|
7
|
7
|
15
|
8 import fj.Ord;
|
|
9 import fj.P2;
|
|
10 import fj.data.TreeMap;
|
7
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser;
|
9
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
7
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
|
|
18
|
|
19 public class JuGrix {
|
|
20
|
8
|
21 JungleTree personTree;
|
|
22 JungleTree organizationTree;
|
12
|
23 JungleTree roleTree;
|
23
|
24 JungleTree rdeTree;
|
8
|
25 public JuGrix(){
|
|
26 try{
|
|
27 loadXml reader = new loadXml();
|
|
28 personTree = reader.loadTestData("Person.xml");
|
|
29 organizationTree = reader.loadTestData("Organization.xml");
|
12
|
30 roleTree = reader.loadTestData("Role.xml");
|
23
|
31 rdeTree = reader.loadTestData("RoleDescriptionElement.xml");
|
8
|
32 } catch (Exception e) {
|
|
33 e.printStackTrace();
|
|
34 }
|
|
35 }
|
12
|
36
|
8
|
37 public boolean isActive(String id){
|
7
|
38
|
8
|
39 InterfaceTraverser ifTraverser = personTree.getTraverser();
|
7
|
40 Iterator<Pair<TreeNode,NodePath>> pairIterator = ifTraverser.find(
|
|
41 (TreeNode node) -> {
|
|
42 String personId = node.getAttributes().getString("id");
|
|
43 if (personId == null)
|
|
44 return false;
|
|
45 if (personId.equals(id))
|
|
46 return true;
|
|
47 return false;
|
|
48 }
|
|
49 ,"id",id);
|
|
50
|
|
51 if (pairIterator.hasNext())
|
|
52 return true;
|
|
53 return false;
|
|
54
|
|
55 }
|
|
56
|
12
|
57 public Iterator<String> personIds(String orgId, LinkedList<String> roleIds){
|
17
|
58 return personIdsSearch(orgId, roleIds).iterator();
|
7
|
59 }
|
|
60
|
18
|
61 public LinkedList<String> personIdLink(String orgId, LinkedList<String> roleIds){
|
|
62 return personIdsSearch(orgId, roleIds);
|
|
63 }
|
|
64
|
12
|
65 public Iterator<String> personIds(LinkedList<String> orgIds ,LinkedList<String> roleIds){
|
7
|
66
|
13
|
67 LinkedList<String> personIds = new LinkedList<String>();
|
11
|
68
|
12
|
69 for (String orgId : orgIds) {
|
|
70 personIds.addAll(personIdsSearch(orgId, roleIds));
|
7
|
71 }
|
|
72 return personIds.iterator();
|
|
73 }
|
|
74
|
12
|
75 private LinkedList<String> personIdsSearch(String id, LinkedList<String> roleIds) {
|
|
76
|
|
77 if (!filter(id, roleIds))
|
|
78 return new LinkedList<String>();
|
|
79
|
|
80 InterfaceTraverser personTraverser = personTree.getTraverser();
|
|
81 Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = personTraverser.find(
|
7
|
82 (TreeNode node) -> {
|
|
83 String personId = node.getAttributes().getString("element");
|
|
84 if (personId == null)
|
|
85 return false;
|
|
86 if (personId.equals("Person"))
|
|
87 return true;
|
|
88 return false;
|
|
89 }
|
|
90 ,"element","Person");
|
|
91
|
11
|
92 LinkedList<String> names = new LinkedList<String>();
|
12
|
93
|
7
|
94 for (;pairPersonIterator.hasNext();) {
|
|
95
|
|
96 Pair<TreeNode, NodePath> pairPerson = pairPersonIterator.next();
|
12
|
97 Iterator<Pair<TreeNode,NodePath>> pairIdIterator = personTraverser.find(
|
7
|
98 (TreeNode node) -> {
|
|
99 String personId = node.getAttributes().getString("text");
|
|
100 if (personId == null)
|
|
101 return false;
|
|
102 if (personId.equals(id))
|
|
103 return true;
|
|
104 return false;
|
|
105 }
|
15
|
106 ,pairPerson.left());
|
12
|
107
|
|
108 if (pairIdIterator.hasNext()) {
|
|
109 String name = pairPerson.left().getAttributes().getString("id");
|
|
110 names.add(name);
|
|
111 }
|
|
112 }
|
|
113 return names;
|
|
114 }
|
|
115
|
|
116
|
|
117 public boolean filter(String orgId, LinkedList<String> roleIds) {
|
|
118 if (roleIds == null)
|
|
119 return true;
|
|
120
|
|
121 InterfaceTraverser orgTraverser = organizationTree.getTraverser();
|
|
122
|
|
123 Iterator<Pair<TreeNode,NodePath>> orgNodeIterator = orgTraverser.find(
|
|
124 (TreeNode node) -> {
|
|
125 String personId = node.getAttributes().getString("element");
|
|
126 if (personId == null)
|
|
127 return false;
|
17
|
128 if (!personId.equals("Organization"))
|
|
129 return false;
|
12
|
130 String compareOrgId = node.getAttributes().getString("id");
|
17
|
131 if (compareOrgId == null)
|
12
|
132 return false;
|
|
133 if (compareOrgId.equals(orgId))
|
|
134 return true;
|
|
135 return false;
|
17
|
136 });
|
12
|
137
|
|
138 if (!orgNodeIterator.hasNext())
|
|
139 return false;
|
|
140
|
|
141 TreeNode searchNode = orgNodeIterator.next().left();
|
|
142
|
|
143 for (String id : roleIds) {
|
|
144 Pattern personPattern = Pattern.compile("r:");
|
|
145 Matcher personMacher = personPattern.matcher(id);
|
|
146 if (personMacher.find()) {
|
|
147 if (!roleFilter(id , searchNode))
|
|
148 return false;
|
|
149 }
|
|
150
|
|
151 Pattern organizationPattern = Pattern.compile("rde:");
|
|
152 Matcher organizationMacher = organizationPattern.matcher(id);
|
|
153 if (organizationMacher.find()) {
|
|
154 if (!rdeFilter(id,searchNode))
|
|
155 return false;
|
|
156 }
|
|
157 }
|
|
158 return true;
|
|
159 }
|
|
160
|
|
161 private boolean rdeFilter(String id, TreeNode targetNode) {
|
|
162
|
|
163 InterfaceTraverser orgTraverser = organizationTree.getTraverser();
|
|
164 Iterator<Pair<TreeNode,NodePath>> pairIdIterator = orgTraverser.find(
|
|
165 (TreeNode node) -> {
|
|
166 String element = node.getAttributes().getString("element");
|
|
167 if (element == null)
|
|
168 return false;
|
|
169 if (!element.equals("roleRefId"))
|
|
170 return false;
|
|
171 String roleId = node.getAttributes().getString("text");
|
|
172 if (roleId != null)
|
|
173 return true;
|
|
174 return false;
|
|
175 }
|
15
|
176 ,targetNode);
|
12
|
177
|
|
178 TreeMap<String, String> idMap = TreeMap.empty(Ord.stringOrd);
|
|
179 for (; pairIdIterator.hasNext();) {
|
|
180 String roleId = pairIdIterator.next().left().getAttributes().getString("text");
|
|
181 idMap = idMap.set(roleId,roleId);
|
|
182 }
|
|
183
|
|
184 Iterator<P2<String, String>> ids = idMap.iterator();
|
|
185 InterfaceTraverser roleTraverser = roleTree.getTraverser();
|
|
186
|
|
187 for (;ids.hasNext();) {
|
|
188 String roleId = ids.next()._1();
|
|
189 Iterator<Pair<TreeNode,NodePath>> roleNodeIterator = roleTraverser.find(
|
|
190 (TreeNode node) -> {
|
|
191 String element = node.getAttributes().getString("element");
|
|
192 if (element == null)
|
|
193 return false;
|
|
194 if (!element.equals("Role"))
|
|
195 return false;
|
|
196 String compareRoleId = node.getAttributes().getString("id");
|
|
197 if (compareRoleId == null)
|
|
198 return false;
|
|
199 if (compareRoleId.equals(roleId))
|
|
200 return true;
|
|
201 return false;
|
|
202 }
|
|
203 ,"id",roleId);
|
|
204
|
|
205 for (;roleNodeIterator.hasNext();) {
|
|
206 TreeNode roleNode = roleNodeIterator.next().left();
|
|
207 Iterator<Pair<TreeNode,NodePath>> rdeNodeIterator = roleTraverser.find(
|
|
208 (TreeNode node) -> {
|
|
209 String elementName = node.getAttributes().getString("element");
|
|
210 if (elementName == null)
|
|
211 return false;
|
|
212 if (!elementName.equals("roleDescriptionElementRefIds"))
|
|
213 return false;
|
|
214 String rdeId = node.getAttributes().getString("text");
|
|
215 if (rdeId == null)
|
|
216 return false;
|
|
217 Pattern personPattern = Pattern.compile(id);
|
|
218 Matcher personMacher = personPattern.matcher(rdeId);
|
|
219 if (personMacher.find())
|
|
220 return true;
|
|
221 return false;
|
|
222 }
|
15
|
223 ,roleNode);
|
12
|
224
|
|
225 if (!rdeNodeIterator.hasNext())
|
|
226 return false;
|
|
227 }
|
7
|
228
|
|
229 }
|
12
|
230 return true;
|
|
231 }
|
|
232
|
|
233 public boolean roleFilter(String id, TreeNode orgNode) {
|
17
|
234 System.out.println(orgNode.getAttributes().getString("id"));
|
12
|
235 InterfaceTraverser orgTraverser = organizationTree.getTraverser();
|
|
236
|
|
237 Iterator<Pair<TreeNode,NodePath>> pairIdIterator = orgTraverser.find(
|
|
238 (TreeNode node) -> {
|
|
239 String elementName = node.getAttributes().getString("element");
|
|
240 if (elementName == null)
|
|
241 return false;
|
17
|
242 if (!elementName.equals("roleRefIds"))
|
12
|
243 return false;
|
|
244 String roleId = node.getAttributes().getString("text");
|
|
245 if (roleId == null)
|
|
246 return false;
|
|
247 if (roleId.equals(id))
|
|
248 return true;
|
|
249 return false;
|
|
250 }
|
15
|
251 ,orgNode);
|
12
|
252
|
|
253 if (pairIdIterator.hasNext()){
|
|
254 System.out.println(pairIdIterator.next().left().getAttributes().getString("text"));
|
|
255 return true;
|
|
256 }
|
|
257 return false;
|
7
|
258 }
|
8
|
259
|
|
260 public Iterator<String> roleIds(String id) {
|
|
261 Pattern personPattern = Pattern.compile("p:");
|
|
262 Matcher personMacher = personPattern.matcher(id);
|
|
263 if (personMacher.find()) {
|
|
264 return searchRoleIds(personTree, id, "Person");
|
|
265 }
|
|
266
|
|
267 Pattern organizationPattern = Pattern.compile("o:");
|
|
268 Matcher organizationMacher = organizationPattern.matcher(id);
|
|
269 if (organizationMacher.find()) {
|
|
270 return searchRoleIds(organizationTree, id, "Organization");
|
|
271 }
|
|
272
|
|
273 return null;
|
|
274 }
|
7
|
275
|
8
|
276 public Iterator<String> searchRoleIds(JungleTree tree, String id, String element){
|
|
277
|
|
278 InterfaceTraverser ifTraverser = tree.getTraverser();
|
|
279 Iterator<Pair<TreeNode,NodePath>> searchTargetIterator = ifTraverser.find(
|
|
280 (TreeNode node) -> {
|
|
281 String nodeElement = node.getAttributes().getString("element");
|
|
282 if (nodeElement == null)
|
|
283 return false;
|
|
284 if (!nodeElement.equals(element))
|
|
285 return false;
|
|
286 String nodeId = node.getAttributes().getString("id");
|
|
287 if (nodeId == null)
|
|
288 return false;
|
|
289 if (nodeId.equals(id))
|
|
290 return true;
|
|
291 return false;
|
|
292 }
|
|
293 ,"id",id);
|
|
294
|
11
|
295 LinkedList<String> ids = new LinkedList<String>();
|
9
|
296
|
8
|
297 for (;searchTargetIterator.hasNext();) {
|
|
298
|
|
299 Pair<TreeNode, NodePath> searchTargetPair = searchTargetIterator.next();
|
|
300 Iterator<Pair<TreeNode,NodePath>> pairIdIterator = ifTraverser.find(
|
|
301 (TreeNode node) -> {
|
|
302 String nodeElement = node.getAttributes().getString("element");
|
|
303 if (nodeElement == null)
|
|
304 return false;
|
|
305 if (!nodeElement.equals("roleRefId"))
|
|
306 return false;
|
|
307 String nodeId = node.getAttributes().getString("text");
|
|
308 if (nodeId != null)
|
|
309 return true;
|
|
310 return false;
|
|
311 }
|
|
312 ,searchTargetPair.left());
|
|
313
|
|
314
|
|
315 for (;pairIdIterator.hasNext();){
|
|
316 Pair<TreeNode, NodePath> idNodePath = pairIdIterator.next();
|
|
317 String attribute = idNodePath.left().getAttributes().getString("text");
|
|
318
|
|
319 Iterator<String> checkList = ids.iterator();
|
|
320 for (;checkList.hasNext();) {
|
|
321 if(checkList.next().equals(attribute))
|
|
322 attribute = null;
|
|
323 }
|
|
324
|
|
325 if (attribute != null) {
|
11
|
326 ids.add(attribute);
|
8
|
327 System.out.println("-------------------------" + attribute + "-------------------------");
|
|
328 }
|
|
329 }
|
|
330 }
|
|
331 return ids.iterator();
|
|
332 }
|
|
333
|
|
334
|
|
335 public Iterator<String> competentRoleId(String personId) {
|
|
336
|
|
337 InterfaceTraverser ifTraverser = personTree.getTraverser();
|
11
|
338 Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = searchPerson(personId, ifTraverser);
|
8
|
339
|
9
|
340 if (!pairPersonIterator.hasNext())
|
|
341 return new NullIterator();
|
|
342 TreeNode person = pairPersonIterator.next().left();
|
|
343
|
|
344 Iterator<Pair<TreeNode,NodePath>> targetPairIterator = ifTraverser.find(
|
|
345 (TreeNode node) -> {
|
|
346 String nodeElement = node.getAttributes().getString("element");
|
|
347 if (nodeElement == null)
|
|
348 return false;
|
|
349 if (!nodeElement.equals("priority"))
|
|
350 return false;
|
|
351 String priority = node.getAttributes().getString("text");
|
|
352 if (priority == null)
|
|
353 return false;
|
|
354 if (priority.equals("0"))
|
|
355 return true;
|
|
356 return false;
|
|
357 }
|
|
358 ,person);
|
|
359
|
|
360
|
11
|
361 LinkedList<String> idList = new LinkedList<String>();
|
9
|
362 for (;targetPairIterator.hasNext();) {
|
|
363 NodePath searchPath = targetPairIterator.next().right();
|
|
364 Pair<Integer, NodePath> searchPair = searchPath.last();
|
|
365 NodePath targetPath = searchPair.right().add(searchPair.left() + 1);
|
|
366 TreeNode targetNode = getTarget(person, targetPath);
|
|
367 String id = targetNode.getAttributes().getString("text");
|
11
|
368 idList.add(id);
|
9
|
369 }
|
|
370
|
|
371 return idList.iterator();
|
8
|
372 }
|
7
|
373
|
10
|
374
|
|
375 public Iterator<String> concurrentRoleIds(String personId) {
|
|
376
|
|
377 InterfaceTraverser ifTraverser = personTree.getTraverser();
|
11
|
378 Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = searchPerson(
|
|
379 personId, ifTraverser);
|
10
|
380
|
|
381 if (!pairPersonIterator.hasNext())
|
|
382 return new NullIterator();
|
|
383 TreeNode person = pairPersonIterator.next().left();
|
|
384
|
|
385 Iterator<Pair<TreeNode,NodePath>> targetPairIterator = ifTraverser.find(
|
|
386 (TreeNode node) -> {
|
|
387 String nodeElement = node.getAttributes().getString("element");
|
|
388 if (nodeElement == null)
|
|
389 return false;
|
|
390 if (!nodeElement.equals("priority"))
|
|
391 return false;
|
|
392 String priority = node.getAttributes().getString("text");
|
|
393 if (priority == null)
|
|
394 return false;
|
|
395 if (!priority.equals("0"))
|
|
396 return true;
|
|
397 return false;
|
|
398 }
|
|
399 ,person);
|
|
400
|
|
401
|
11
|
402 LinkedList<String> idList = new LinkedList<String>();
|
10
|
403 for (;targetPairIterator.hasNext();) {
|
|
404 NodePath searchPath = targetPairIterator.next().right();
|
|
405 Pair<Integer, NodePath> searchPair = searchPath.last();
|
|
406 NodePath targetPath = searchPair.right().add(searchPair.left() + 1);
|
|
407 TreeNode targetNode = getTarget(person, targetPath);
|
|
408 String id = targetNode.getAttributes().getString("text");
|
11
|
409 idList.add(id);
|
10
|
410 }
|
|
411
|
|
412 return idList.iterator();
|
|
413 }
|
11
|
414 private Iterator<Pair<TreeNode, NodePath>> searchPerson(String personId,
|
|
415 InterfaceTraverser ifTraverser) {
|
|
416 Iterator<Pair<TreeNode,NodePath>> pairPersonIterator = ifTraverser.find(
|
|
417 (TreeNode node) -> {
|
|
418 String nodeElement = node.getAttributes().getString("element");
|
|
419 if (nodeElement == null)
|
|
420 return false;
|
|
421 if (!nodeElement.equals("Person"))
|
|
422 return false;
|
|
423 String nodeId = node.getAttributes().getString("id");
|
|
424 if (nodeId == null)
|
|
425 return false;
|
|
426 if (nodeId.equals(personId))
|
|
427 return true;
|
|
428 return false;
|
|
429 }
|
|
430 ,"element","Person");
|
|
431 return pairPersonIterator;
|
|
432 }
|
|
433
|
18
|
434
|
|
435
|
|
436 public Iterator<String> deepPersonIds(String orgId, LinkedList<String> filterIds) {
|
|
437
|
|
438 Iterator<String> childrensIterator = deepChildOrganizationIds(orgId, new LinkedList<String>());
|
|
439 if (!childrensIterator.hasNext())
|
|
440 return new NullIterator();
|
|
441
|
|
442 LinkedList<String> childrenPersonList = new LinkedList<String>();
|
19
|
443 //childrenPersonList.addAll(personIdLink(orgId, filterIds));
|
18
|
444 for (;childrensIterator.hasNext();) {
|
|
445 String id = childrensIterator.next();
|
|
446 childrenPersonList.addAll(personIdLink(id, filterIds));
|
|
447 }
|
|
448
|
|
449 return childrenPersonList.iterator();
|
|
450 }
|
|
451
|
19
|
452 public Iterator<String> deepChildOrganizationIdsPlus(String orgId, LinkedList<String> filterIds) {
|
|
453 LinkedList<String> orgList = new LinkedList<String>();
|
|
454 if (filter(orgId, filterIds))
|
|
455 orgList.add(orgId);
|
|
456 orgList.addAll(_deepChildOrganizationIds(orgId,filterIds));
|
|
457 return orgList.iterator();
|
|
458 }
|
|
459
|
17
|
460 public Iterator<String> deepChildOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
|
461 return _deepChildOrganizationIds(orgId,filterIds).iterator();
|
|
462 }
|
|
463
|
|
464 public LinkedList<String> _deepChildOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
|
465
|
19
|
466 Iterator<String> childrensIterator = childOrganizationIds(orgId,new LinkedList<String>());
|
17
|
467 if (!childrensIterator.hasNext())
|
|
468 return new LinkedList<String>();
|
|
469
|
|
470 LinkedList<String> childrenList = new LinkedList<String>();
|
|
471 for (;childrensIterator.hasNext();) {
|
|
472 String childrenId = childrensIterator.next();
|
|
473 if(filter(childrenId,filterIds))
|
|
474 childrenList.add(childrenId);
|
|
475 childrenList.addAll(_deepChildOrganizationIds(childrenId, filterIds));
|
|
476 }
|
|
477
|
|
478 return childrenList;
|
|
479 }
|
|
480
|
11
|
481
|
19
|
482 public Iterator<String> childOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
|
483 if(!filter(orgId,filterIds))
|
|
484 return new NullIterator();
|
|
485 InterfaceTraverser orgTraverser = organizationTree.getTraverser();
|
|
486 Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = orgTraverser.find(
|
|
487 (TreeNode node) -> {
|
|
488 String nodeElement = node.getAttributes().getString("element");
|
|
489 if (nodeElement == null)
|
|
490 return false;
|
|
491 if (!nodeElement.equals("Organization"))
|
|
492 return false;
|
|
493 String nodeId = node.getAttributes().getString("id");
|
|
494 if (nodeId == null)
|
|
495 return false;
|
|
496 if (nodeId.equals(orgId))
|
|
497 return true;
|
|
498 return false;
|
|
499 }
|
|
500 ,"element","Organization");
|
11
|
501
|
|
502 if (!pairPersonIterator.hasNext())
|
|
503 return new NullIterator();
|
|
504 TreeNode person = pairPersonIterator.next().left();
|
|
505
|
19
|
506
|
|
507 Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdsIterator = orgTraverser.find(
|
11
|
508 (TreeNode node) -> {
|
|
509 String nodeElement = node.getAttributes().getString("element");
|
|
510 if (nodeElement == null)
|
|
511 return false;
|
|
512 if (nodeElement.equals("childOrganizations"))
|
|
513 return true;
|
|
514 return false;
|
|
515 }
|
|
516 ,person);
|
|
517
|
|
518 if (!chilrenOrgIdsIterator.hasNext())
|
|
519 return new NullIterator();
|
|
520
|
|
521 TreeNode chilerenOrgIds = chilrenOrgIdsIterator.next().left();
|
|
522
|
19
|
523 Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdIterator = orgTraverser.find(
|
11
|
524 (TreeNode node) -> {
|
|
525 String nodeElement = node.getAttributes().getString("element");
|
|
526 if (nodeElement == null)
|
|
527 return false;
|
|
528 if (!nodeElement.equals("organizationRefIds"))
|
|
529 return false;
|
|
530 nodeElement = node.getAttributes().getString("text");
|
|
531 if (nodeElement != null)
|
|
532 return true;
|
|
533 return false;
|
|
534 }
|
16
|
535 ,chilerenOrgIds);
|
11
|
536
|
|
537 LinkedList<String> ids = new LinkedList<String>();
|
|
538
|
|
539 for (;chilrenOrgIdIterator.hasNext();) {
|
|
540 ids.add(chilrenOrgIdIterator.next().left().getAttributes().getString("text"));
|
|
541 }
|
|
542
|
|
543 return ids.iterator();
|
|
544 }
|
|
545
|
|
546
|
10
|
547
|
9
|
548 public TreeNode getTarget(TreeNode node , NodePath path){
|
|
549 TreeNode target;
|
|
550 Pair<Integer, NodePath> pathNode = path.pop();
|
|
551 int num = pathNode.left();
|
|
552 NodePath newPath = pathNode.right();
|
|
553 if (num == -1 && newPath.size() != 0)
|
|
554 return getTarget(node, newPath);
|
|
555
|
|
556 Either<Error, TreeNode> either = node.getChildren().at(num);
|
|
557 if (either.isA())
|
|
558 return node;
|
|
559
|
|
560 TreeNode child = either.b();
|
|
561 if (pathNode.right().size() == 0)
|
|
562 return child;
|
|
563
|
|
564 target = getTarget(child,pathNode.right());
|
|
565 return target;
|
|
566 }
|
10
|
567
|
9
|
568 class NullIterator implements Iterator<String>{
|
7
|
569
|
9
|
570 @Override
|
|
571 public boolean hasNext() {
|
|
572 return false;
|
|
573 }
|
|
574
|
|
575 @Override
|
|
576 public String next() {
|
|
577 return null;
|
|
578 }
|
|
579
|
|
580 }
|
10
|
581
|
15
|
582 public String rolePriority(String personId, String roleId) {
|
|
583 InterfaceTraverser personTraverser = personTree.getTraverser();
|
|
584 Iterator<Pair<TreeNode,NodePath>> personIterator = personTraverser.find(
|
|
585 (TreeNode node) -> {
|
|
586 String element = node.getAttributes().getString("element");
|
|
587 if (element == null)
|
|
588 return false;
|
|
589 if (!element.equals("Person"))
|
|
590 return false;
|
|
591 String nodeId = node.getAttributes().getString("id");
|
|
592 if (nodeId == null)
|
|
593 return false;
|
|
594 if (nodeId.equals(personId))
|
|
595 return true;
|
|
596 return false;
|
|
597 });
|
|
598
|
|
599 if (!personIterator.hasNext())
|
|
600 return "";
|
|
601
|
|
602 TreeNode targetNode = personIterator.next().left();
|
|
603
|
|
604 Iterator<Pair<TreeNode,NodePath>> priorityIterator = personTraverser.find(
|
|
605 (TreeNode node) -> {
|
|
606 String element = node.getAttributes().getString("element");
|
|
607 if (element == null)
|
|
608 return false;
|
|
609 if (!element.equals("roleRefId"))
|
|
610 return false;
|
|
611 String compareRoleId = node.getAttributes().getString("text");
|
|
612 if (compareRoleId == null)
|
|
613 return false;
|
|
614 if (compareRoleId.equals(roleId))
|
|
615 return true;
|
|
616 return false;
|
|
617 },targetNode);
|
|
618
|
|
619 for (;priorityIterator.hasNext();) {
|
|
620 Pair<TreeNode, NodePath> priorityPair = priorityIterator.next();
|
|
621 NodePath roleNodePath = priorityPair.right();
|
|
622 Pair<Integer, NodePath> last = roleNodePath.last();
|
|
623 NodePath priorityNodePath = last.right().add(last.left() - 1);
|
|
624 TreeNode priorityNode = getTarget(targetNode,priorityNodePath);
|
|
625 if (priorityNode.getAttributes().getString("element").equals("priority"))
|
|
626 return priorityNode.getAttributes().getString("text");
|
|
627 }
|
|
628 return "";
|
|
629 }
|
|
630
|
20
|
631 public Iterator<String> parentOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
21
|
632 return _parentOrganizationIds(orgId, filterIds).iterator();
|
|
633 }
|
|
634 public LinkedList<String> _parentOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
20
|
635
|
|
636 InterfaceTraverser orgTraverser = organizationTree.getTraverser();
|
|
637 Iterator<Pair<TreeNode,NodePath>> orgIterator = orgTraverser.find(
|
|
638 (TreeNode node) -> {
|
|
639 String element = node.getAttributes().getString("element");
|
|
640 if (element == null)
|
|
641 return false;
|
|
642 if (!element.equals("Organization"))
|
|
643 return false;
|
|
644 String nodeId = node.getAttributes().getString("id");
|
|
645 if (nodeId == null)
|
|
646 return false;
|
|
647 if (nodeId.equals(orgId))
|
|
648 return true;
|
|
649 return false;
|
|
650 });
|
|
651
|
|
652 if (!orgIterator.hasNext())
|
21
|
653 return new LinkedList<String>();
|
20
|
654
|
|
655 TreeNode orgNode = orgIterator.next().left();
|
|
656
|
|
657 Iterator<Pair<TreeNode,NodePath>> parentOrgIterator = orgTraverser.find(
|
|
658 (TreeNode node) -> {
|
|
659 String element = node.getAttributes().getString("element");
|
|
660 if (element == null)
|
|
661 return false;
|
|
662 if (element.equals("parentOrganizations"))
|
|
663 return true;
|
|
664 return false;
|
|
665 }, orgNode);
|
|
666
|
|
667 LinkedList<String> parentIds = new LinkedList<String>();
|
|
668
|
|
669 for (;parentOrgIterator.hasNext();) {
|
|
670 TreeNode parentOrgNode = parentOrgIterator.next().left();
|
|
671
|
|
672 Iterator<Pair<TreeNode,NodePath>> parentNodeIterator = orgTraverser.find(
|
|
673 (TreeNode node) -> {
|
|
674 String element = node.getAttributes().getString("element");
|
|
675 if (element == null)
|
|
676 return false;
|
|
677 if (!element.equals("organizationRefId"))
|
|
678 return false;
|
|
679 String parentId = node.getAttributes().getString("text");
|
|
680 if (parentId != null)
|
|
681 return true;
|
|
682 return false;
|
|
683 }, parentOrgNode);
|
|
684
|
|
685 for (;parentNodeIterator.hasNext();) {
|
|
686 String parentId = parentNodeIterator.next().left().getAttributes().getString("text");
|
|
687 if (filter(parentId, filterIds))
|
|
688 parentIds.add(parentId);
|
|
689 }
|
|
690
|
|
691
|
|
692 }
|
|
693
|
21
|
694 return parentIds;
|
|
695 }
|
|
696
|
|
697 public Iterator<String> deepParentOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
|
698 return _deepParentOrganizationIds(orgId, filterIds).iterator();
|
|
699 }
|
22
|
700
|
21
|
701 public LinkedList<String> _deepParentOrganizationIds(String orgId, LinkedList<String> filterIds) {
|
|
702
|
|
703
|
|
704 Iterator<String> parentIds = parentOrganizationIds(orgId, filterIds);
|
|
705 if (!parentIds.hasNext())
|
|
706 return new LinkedList<String>();
|
|
707
|
|
708 LinkedList<String> parentIdList = new LinkedList<String>();
|
|
709
|
|
710 for (;parentIds.hasNext();) {
|
|
711 String parentId = parentIds.next();
|
|
712 if (filter(parentId, filterIds))
|
|
713 parentIdList.add(parentId);
|
|
714 parentIdList.addAll(_deepParentOrganizationIds(parentId, filterIds));
|
|
715 }
|
|
716 return parentIdList;
|
20
|
717 }
|
|
718
|
22
|
719 public Iterator<String> deepParentOrganizationIdsPlus(String id,LinkedList<String> filterIds) {
|
|
720 LinkedList<String> parentIds = new LinkedList<String>();
|
|
721 if (filter(id, filterIds))
|
|
722 parentIds.add(id);
|
|
723 parentIds.addAll(_deepParentOrganizationIds(id,filterIds));
|
|
724 return parentIds.iterator();
|
|
725 }
|
|
726
|
23
|
727 public String stringPathToId(String args) {
|
|
728 String[] splitPath = args.split(":");
|
|
729
|
|
730 String str = splitPath[2];
|
|
731 for (int count = 3; count < splitPath.length;count++) {
|
|
732 str = str + ":" + splitPath[count];
|
|
733 }
|
|
734
|
|
735 final String StrPath = str;
|
|
736
|
|
737 InterfaceTraverser traverser = null;
|
|
738 TreeNode root = null ;
|
|
739 if (splitPath[0].equals("r")) {
|
|
740 traverser = roleTree.getTraverser();
|
|
741 root = roleTree.getRootNode();
|
|
742 }
|
|
743 if (splitPath[0].equals("rde")) {
|
|
744 traverser = rdeTree.getTraverser();
|
|
745 root = rdeTree.getRootNode();
|
|
746 }
|
|
747
|
|
748 Iterator<Pair<TreeNode,NodePath>> idIterator = traverser.find(
|
|
749 (TreeNode node) -> {
|
|
750 String element = node.getAttributes().getString("element");
|
|
751 if (element == null)
|
|
752 return false;
|
|
753 if (!element.equals("path"))
|
|
754 return false;
|
|
755 String pathString = node.getAttributes().getString("text");
|
|
756 if (pathString == null)
|
|
757 return false;
|
|
758 if (pathString.equals(StrPath))
|
|
759 return true;
|
|
760 return false;
|
|
761 });
|
|
762
|
|
763 if (!idIterator.hasNext())
|
|
764 return "";
|
|
765
|
|
766 Pair<TreeNode, NodePath> nodePair = idIterator.next();
|
|
767 NodePath path = nodePair.right();
|
|
768 NodePath targetPath = path.last().right();
|
|
769
|
|
770 TreeNode targetNode = getTarget(root, targetPath);
|
|
771 String targetId = targetNode.getAttributes().getString("id");
|
|
772 return targetId;
|
|
773 }
|
|
774
|
11
|
775
|
16
|
776
|
|
777
|
17
|
778
|
18
|
779
|
|
780
|
7
|
781 }
|