Exemple #1
0
  public static UnitForTree buildStructure(
      List<Accountability> accountabilities, AccountabilityType accountabilityType, Unit root) {
    if (root == null) return null;

    UnitForTree rootNode = new UnitForTree();
    rootNode.setId(root.getId());
    rootNode.setName(root.getName());
    buildChildren(accountabilities, rootNode);

    return rootNode;
  }
Exemple #2
0
  private static void buildChildren(List<Accountability> accountabilities, UnitForTree parent) {
    List<Unit> units = new ArrayList<Unit>();
    for (Accountability acc : accountabilities) {
      if (acc.getParent() == null) continue;
      if (StringUtils.equals(acc.getParent().getId(), parent.getId())
          && !StringUtils.equals(acc.getParent().getId(), acc.getChild().getId())) {
        units.add(acc.getChild());
      }
    }

    for (Unit child : units) {
      UnitForTree unitForTree = new UnitForTree();
      unitForTree.setId(child.getId());
      unitForTree.setName(child.getName());
      unitForTree.setPid(parent.getId());
      parent.getChildren().add(unitForTree);
      buildChildren(accountabilities, unitForTree);
    }
  }