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.browse; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import javax.ws.rs.GET; 025import javax.ws.rs.Path; 026import javax.ws.rs.Produces; 027 028import org.nuxeo.apidoc.api.BundleGroup; 029import org.nuxeo.apidoc.api.BundleGroupFlatTree; 030import org.nuxeo.apidoc.api.BundleGroupTreeHelper; 031import org.nuxeo.apidoc.api.NuxeoArtifact; 032import org.nuxeo.ecm.webengine.model.WebObject; 033 034@WebObject(type = "bundleGroup") 035public class BundleGroupWO extends NuxeoArtifactWebObject { 036 037 @Override 038 @GET 039 @Produces("text/html") 040 @Path("introspection") 041 public Object doGet() { 042 BundleGroup group = getTargetBundleGroup(); 043 BundleGroupTreeHelper bgth = new BundleGroupTreeHelper(getSnapshotManager().getSnapshot(getDistributionId(), 044 ctx.getCoreSession())); 045 List<BundleGroupFlatTree> tree = bgth.getBundleGroupSubTree(nxArtifactId); 046 return getView("view").arg("group", group).arg("groupId", nxArtifactId).arg("tree", tree); 047 } 048 049 public BundleGroup getTargetBundleGroup() { 050 return getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getBundleGroup(nxArtifactId); 051 } 052 053 @Override 054 public NuxeoArtifact getNxArtifact() { 055 return getTargetBundleGroup(); 056 } 057 058 public List<BundleWO> getBundles() { 059 List<BundleWO> result = new ArrayList<BundleWO>(); 060 061 BundleGroup group = getTargetBundleGroup(); 062 for (String bid : group.getBundleIds()) { 063 result.add((BundleWO) ctx.newObject("bundle", bid)); 064 } 065 return result; 066 } 067 068 public List<BundleGroupWO> getSubGroups() { 069 List<BundleGroupWO> result = new ArrayList<BundleGroupWO>(); 070 071 BundleGroup group = getTargetBundleGroup(); 072 for (BundleGroup bg : group.getSubGroups()) { 073 result.add((BundleGroupWO) ctx.newObject("bundleGroup", bg.getId())); 074 } 075 return result; 076 } 077 078}