001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thierry Delprat 016 */ 017package org.nuxeo.apidoc.browse; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import javax.ws.rs.GET; 023import javax.ws.rs.Path; 024import javax.ws.rs.Produces; 025 026import org.nuxeo.apidoc.api.BundleGroup; 027import org.nuxeo.apidoc.api.BundleGroupFlatTree; 028import org.nuxeo.apidoc.api.BundleGroupTreeHelper; 029import org.nuxeo.apidoc.api.NuxeoArtifact; 030import org.nuxeo.ecm.webengine.model.WebObject; 031 032@WebObject(type = "bundleGroup") 033public class BundleGroupWO extends NuxeoArtifactWebObject { 034 035 @Override 036 @GET 037 @Produces("text/html") 038 @Path("introspection") 039 public Object doGet() { 040 BundleGroup group = getTargetBundleGroup(); 041 BundleGroupTreeHelper bgth = new BundleGroupTreeHelper(getSnapshotManager().getSnapshot(getDistributionId(), 042 ctx.getCoreSession())); 043 List<BundleGroupFlatTree> tree = bgth.getBundleGroupSubTree(nxArtifactId); 044 return getView("view").arg("group", group).arg("groupId", nxArtifactId).arg("tree", tree); 045 } 046 047 public BundleGroup getTargetBundleGroup() { 048 return getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getBundleGroup(nxArtifactId); 049 } 050 051 @Override 052 public NuxeoArtifact getNxArtifact() { 053 return getTargetBundleGroup(); 054 } 055 056 public List<BundleWO> getBundles() { 057 List<BundleWO> result = new ArrayList<BundleWO>(); 058 059 BundleGroup group = getTargetBundleGroup(); 060 for (String bid : group.getBundleIds()) { 061 result.add((BundleWO) ctx.newObject("bundle", bid)); 062 } 063 return result; 064 } 065 066 public List<BundleGroupWO> getSubGroups() { 067 List<BundleGroupWO> result = new ArrayList<BundleGroupWO>(); 068 069 BundleGroup group = getTargetBundleGroup(); 070 for (BundleGroup bg : group.getSubGroups()) { 071 result.add((BundleGroupWO) ctx.newObject("bundleGroup", bg.getId())); 072 } 073 return result; 074 } 075 076}