@Test public void getChildNodesInLevelOrderReturnsChildNodesInLevelOrder() { var firstLevelNodeDn1 = "first-level-child-1"; var firstLevelNodeDn2 = "first-level-child-2"; var secondLevelNodeDn = "second-level-child"; var rootNode = new LdapUserNode() .setDirectReportsDn(List.of(firstLevelNodeDn1, firstLevelNodeDn2)); var firstLevelNode1 = new LdapUserNode() .setDirectReportsDn(List.of(secondLevelNodeDn)); var firstLevelNode2 = new LdapUserNode(); var secondLevelNode = new LdapUserNode(); var dnNodeMap = Map.of( firstLevelNodeDn1, firstLevelNode1, firstLevelNodeDn2, firstLevelNode2, secondLevelNodeDn, secondLevelNode); var expectedOrder = List.of(firstLevelNode1, firstLevelNode2, secondLevelNode); var actualOrder = userUpdater.getChildNodesInLevelOrder(rootNode, dnNodeMap); assertThat(actualOrder).containsExactlyElementsOf(expectedOrder); }
List<LdapUserNode> getChildNodesInLevelOrder(@NonNull LdapUserNode node, @NonNull Map<String, LdapUserNode> dnNodeMap) { var childNodesInLevelOrder = new ArrayList<LdapUserNode>(); var childDnDeque = new LinkedList<>(node.getDirectReportsDn()); while(!childDnDeque.isEmpty()) { var childDn = childDnDeque.removeFirst(); if(!dnNodeMap.containsKey(childDn)) { var message = String.format("Child node with DN '%s' not found!", childDn); throw new IllegalArgumentException(message); } var childNode = dnNodeMap.get(childDn); childDnDeque.addAll(childNode.getDirectReportsDn()); childNodesInLevelOrder.add(childNode); } return childNodesInLevelOrder; }
UserUpdater { List<LdapUserNode> getChildNodesInLevelOrder(@NonNull LdapUserNode node, @NonNull Map<String, LdapUserNode> dnNodeMap) { var childNodesInLevelOrder = new ArrayList<LdapUserNode>(); var childDnDeque = new LinkedList<>(node.getDirectReportsDn()); while(!childDnDeque.isEmpty()) { var childDn = childDnDeque.removeFirst(); if(!dnNodeMap.containsKey(childDn)) { var message = String.format("Child node with DN '%s' not found!", childDn); throw new IllegalArgumentException(message); } var childNode = dnNodeMap.get(childDn); childDnDeque.addAll(childNode.getDirectReportsDn()); childNodesInLevelOrder.add(childNode); } return childNodesInLevelOrder; } }
UserUpdater { List<LdapUserNode> getChildNodesInLevelOrder(@NonNull LdapUserNode node, @NonNull Map<String, LdapUserNode> dnNodeMap) { var childNodesInLevelOrder = new ArrayList<LdapUserNode>(); var childDnDeque = new LinkedList<>(node.getDirectReportsDn()); while(!childDnDeque.isEmpty()) { var childDn = childDnDeque.removeFirst(); if(!dnNodeMap.containsKey(childDn)) { var message = String.format("Child node with DN '%s' not found!", childDn); throw new IllegalArgumentException(message); } var childNode = dnNodeMap.get(childDn); childDnDeque.addAll(childNode.getDirectReportsDn()); childNodesInLevelOrder.add(childNode); } return childNodesInLevelOrder; } UserUpdater(HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                       RepositoryUserService repoUserService,
                       UserDataRepository userDataRepo,
                       LdapAdapter ldapAdapter,
                       List<Normalizer<UserData>> normalizers); }
UserUpdater { List<LdapUserNode> getChildNodesInLevelOrder(@NonNull LdapUserNode node, @NonNull Map<String, LdapUserNode> dnNodeMap) { var childNodesInLevelOrder = new ArrayList<LdapUserNode>(); var childDnDeque = new LinkedList<>(node.getDirectReportsDn()); while(!childDnDeque.isEmpty()) { var childDn = childDnDeque.removeFirst(); if(!dnNodeMap.containsKey(childDn)) { var message = String.format("Child node with DN '%s' not found!", childDn); throw new IllegalArgumentException(message); } var childNode = dnNodeMap.get(childDn); childDnDeque.addAll(childNode.getDirectReportsDn()); childNodesInLevelOrder.add(childNode); } return childNodesInLevelOrder; } UserUpdater(HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                       RepositoryUserService repoUserService,
                       UserDataRepository userDataRepo,
                       LdapAdapter ldapAdapter,
                       List<Normalizer<UserData>> normalizers); void updateHierarchyAndUserData(); }
UserUpdater { List<LdapUserNode> getChildNodesInLevelOrder(@NonNull LdapUserNode node, @NonNull Map<String, LdapUserNode> dnNodeMap) { var childNodesInLevelOrder = new ArrayList<LdapUserNode>(); var childDnDeque = new LinkedList<>(node.getDirectReportsDn()); while(!childDnDeque.isEmpty()) { var childDn = childDnDeque.removeFirst(); if(!dnNodeMap.containsKey(childDn)) { var message = String.format("Child node with DN '%s' not found!", childDn); throw new IllegalArgumentException(message); } var childNode = dnNodeMap.get(childDn); childDnDeque.addAll(childNode.getDirectReportsDn()); childNodesInLevelOrder.add(childNode); } return childNodesInLevelOrder; } UserUpdater(HierarchyTreeNodeRepository hierarchyTreeNodeRepo,
                       RepositoryUserService repoUserService,
                       UserDataRepository userDataRepo,
                       LdapAdapter ldapAdapter,
                       List<Normalizer<UserData>> normalizers); void updateHierarchyAndUserData();  }