Beispiel #1
0
  public void addPredefineItems() {
    int sitesGenerationCount = rand.nextInt(10);
    for (int i = 0; i < sitesGenerationCount; i++) {
      String siteId = UUID.randomUUID().toString();
      Site site = new Site(siteId, "SITE_" + i);
      // Generate groups:
      int groupsGenerationCount = rand.nextInt(10);
      for (int j = 0; j < groupsGenerationCount; j++) {
        String groupId = UUID.randomUUID().toString();
        Group group = new Group(groupId, "GROUP_" + j, siteId);
        int innerGroupsGenerationCount = rand.nextInt(10);
        for (int k = 0; k < innerGroupsGenerationCount; k++) {
          String innerGroupId = UUID.randomUUID().toString();
          Group innerGroup = new Group(innerGroupId, "GROUP_" + j + "_" + k, groupId);
          int widgetsGenerationCount = rand.nextInt(10);
          for (int l = 0; l < widgetsGenerationCount; l++) {
            Widget widget = new Widget(UUID.randomUUID().toString(), "WIDGET_" + l, innerGroupId);
            innerGroup.addWidget(widget);
          }
          group.addGroup(innerGroup);
        }
        site.addGroup(group);
      }

      this.sites.add(site);
    }
  }
Beispiel #2
0
  private Group findGroupInGroup(Group group, String id) {
    Group groupResult = null;

    // Is it this group:
    if (group.getId().equals(id)) {
      return group;
    }

    // Or inside inner groups:
    for (Group innerGroup : group.getInnerGroups()) {
      groupResult = findGroupInGroup(innerGroup, id);
      if (groupResult != null) {
        return groupResult;
      }
    }
    return null;
  }
Beispiel #3
0
  private Widget findWidgetInGroup(Group group, String id) {
    Widget widgetResult = null;
    // widget can be inside the group widgets
    for (Widget widget : group.getWidgets()) {
      if (widget.getId().equals(id)) {
        return widget;
      }
    }
    // or inside inner groups:
    for (Group innerGroup : group.getInnerGroups()) {
      widgetResult = findWidgetInGroup(innerGroup, id);
      if (widgetResult != null) {
        return widgetResult;
      }
    }

    return null;
  }