Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 20:ae739e8d86a2
ad parentOrganizationsTest and method
author | one |
---|---|
date | Mon, 27 Oct 2014 08:50:16 +0900 |
parents | da872647cbe4 |
children | daf0c3c810f9 |
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/parentOrganizationIdsTest.java |
diffstat | 2 files changed, 88 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 08:18:42 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 08:50:16 2014 +0900 @@ -626,6 +626,69 @@ return ""; } + public Iterator<String> parentOrganizationIds(String orgId, LinkedList<String> filterIds) { + + InterfaceTraverser orgTraverser = organizationTree.getTraverser(); + Iterator<Pair<TreeNode,NodePath>> orgIterator = orgTraverser.find( + (TreeNode node) -> { + String element = node.getAttributes().getString("element"); + if (element == null) + return false; + if (!element.equals("Organization")) + return false; + String nodeId = node.getAttributes().getString("id"); + if (nodeId == null) + return false; + if (nodeId.equals(orgId)) + return true; + return false; + }); + + if (!orgIterator.hasNext()) + return new NullIterator(); + + TreeNode orgNode = orgIterator.next().left(); + + Iterator<Pair<TreeNode,NodePath>> parentOrgIterator = orgTraverser.find( + (TreeNode node) -> { + String element = node.getAttributes().getString("element"); + if (element == null) + return false; + if (element.equals("parentOrganizations")) + return true; + return false; + }, orgNode); + + LinkedList<String> parentIds = new LinkedList<String>(); + + for (;parentOrgIterator.hasNext();) { + TreeNode parentOrgNode = parentOrgIterator.next().left(); + + Iterator<Pair<TreeNode,NodePath>> parentNodeIterator = orgTraverser.find( + (TreeNode node) -> { + String element = node.getAttributes().getString("element"); + if (element == null) + return false; + if (!element.equals("organizationRefId")) + return false; + String parentId = node.getAttributes().getString("text"); + if (parentId != null) + return true; + return false; + }, parentOrgNode); + + for (;parentNodeIterator.hasNext();) { + String parentId = parentNodeIterator.next().left().getAttributes().getString("text"); + if (filter(parentId, filterIds)) + parentIds.add(parentId); + } + + + } + + return parentIds.iterator(); + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/parentOrganizationIdsTest.java Mon Oct 27 08:50:16 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 junit.framework.Assert; + +import org.junit.Test; + +public class parentOrganizationIdsTest { + @Test + public void parentOrganizationIdsTest() { + JuGrix jugrix = new JuGrix(); + LinkedList<String> filterIds = new LinkedList<String>(); + filterIds.add("r:2"); + Iterator<String> childrenIds = jugrix.parentOrganizationIds("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); + Assert.assertEquals(childrenIds.next(), "o:23"); + + filterIds.add("r:2w"); + childrenIds = jugrix.parentOrganizationIds("o:2", filterIds); + Assert.assertFalse(childrenIds.hasNext()); + } +}