001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.apidoc.api; 020 021import java.util.ArrayList; 022import java.util.Collections; 023import java.util.List; 024 025import org.nuxeo.apidoc.snapshot.DistributionSnapshot; 026 027public class BundleGroupTreeHelper { 028 029 protected final DistributionSnapshot distrib; 030 031 public BundleGroupTreeHelper(DistributionSnapshot distrib) { 032 this.distrib = distrib; 033 } 034 035 protected void browseBundleGroup(BundleGroup group, int level, List<BundleGroupFlatTree> tree) { 036 BundleGroupFlatTree info = new BundleGroupFlatTree(group, level); 037 tree.add(info); 038 List<BundleGroup> subGroups = group.getSubGroups(); 039 Collections.sort(subGroups, new NuxeoArtifactComparator()); 040 for (BundleGroup subGroup : subGroups) { 041 browseBundleGroup(subGroup, level + 1, tree); 042 } 043 } 044 045 public List<BundleGroupFlatTree> getBundleGroupSubTree(String groupId) { 046 BundleGroup group = distrib.getBundleGroup(groupId); 047 List<BundleGroupFlatTree> tree = new ArrayList<>(); 048 browseBundleGroup(group, 0, tree); 049 return tree; 050 } 051 052 public List<BundleGroupFlatTree> getBundleGroupTree() { 053 List<BundleGroupFlatTree> tree = new ArrayList<>(); 054 055 List<BundleGroup> bgroups = distrib.getBundleGroups(); 056 Collections.sort(bgroups, new NuxeoArtifactComparator()); 057 for (BundleGroup group : bgroups) { 058 browseBundleGroup(group, 0, tree); 059 } 060 return tree; 061 } 062 063}