Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 24:96b9017b0e44
add roleDescriptionElementIdsTest and method
author | one |
---|---|
date | Mon, 27 Oct 2014 12:06:11 +0900 |
parents | a9dc4ffd1f52 |
children | 6f9439ca3eb5 |
files | src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/roleDescriptionElementIdsTest.java |
diffstat | 2 files changed, 90 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 10:40:29 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 12:06:11 2014 +0900 @@ -772,10 +772,71 @@ return targetId; } - - - + public Iterator<String> roleDescriptionElementIds(String id, LinkedList<String> filterIds) { + + Iterator<String> orgIds = deepParentOrganizationIdsPlus(id, filterIds); + + LinkedList<String> rdeIds = new LinkedList<String>(); + + for (;orgIds.hasNext();) { + String orgId = orgIds.next(); + Iterator<String> roleIds = roleIds(orgId); + for (;roleIds.hasNext();) { + String roleId = roleIds.next(); + String rdeId = getRde(roleId); + String[] rdeSplit = rdeId.split(" "); + for (String rde : rdeSplit) { + if (!rde.equals("")) + rdeIds.add(rde); + } + } + } + + return rdeIds.iterator(); + } - + private String getRde(String roleId) { + + InterfaceTraverser traverser = roleTree.getTraverser(); + + Iterator<Pair<TreeNode,NodePath>> roleIterator = traverser.find( + (TreeNode node) -> { + String element = node.getAttributes().getString("element"); + if (element == null) + return false; + if (!element.equals("Role")) + return false; + String id = node.getAttributes().getString("id"); + if (id == null) + return false; + if (id.equals(roleId)) + return true; + return false; + }); + + if (!roleIterator.hasNext()) + return ""; + + TreeNode roleNode = roleIterator.next().left(); + + Iterator<Pair<TreeNode,NodePath>> rdeIterator = traverser.find( + (TreeNode node) -> { + String element = node.getAttributes().getString("element"); + if (element == null) + return false; + if (!element.equals("roleDescriptionElementRefIds")) + return false; + String rde = node.getAttributes().getString("text"); + if (rde != null) + return true; + return false; + },roleNode); + + if (!rdeIterator.hasNext()) + return ""; + + return rdeIterator.next().left().getAttributes().getString("text"); + } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/roleDescriptionElementIdsTest.java Mon Oct 27 12:06:11 2014 +0900 @@ -0,0 +1,25 @@ +package jp.ac.u_ryukyu.cr.ie.tatsuki.functionTest; + +import java.util.Iterator; +import java.util.LinkedList; + +import jp.ac.u_ryukyu.cr.ie.tatsuki.bbs.JuGrix; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; +import junit.framework.Assert; + +import org.junit.Test; + +public class roleDescriptionElementIdsTest { + + @Test + public void roleDescriptionElementIdsTest(){ + JuGrix jugrix = new JuGrix(); + LinkedList<String> ids = new LinkedList<String>(); + //ids.add("o:34"); + Iterator<String> rdeIds = jugrix.roleDescriptionElementIds("o:2",ids); + Assert.assertEquals(rdeIds.next(),"rde:3"); + Assert.assertEquals(rdeIds.next(),"rde:2"); + Assert.assertEquals(rdeIds.next(),"rde:1"); + Assert.assertEquals(rdeIds.next(),"rde:10"); + } +}