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.introspection; 018 019import java.util.ArrayList; 020import java.util.HashMap; 021import java.util.List; 022import java.util.Map; 023 024import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 025import org.nuxeo.apidoc.api.BundleGroup; 026import org.nuxeo.apidoc.documentation.AssociatedDocumentsImpl; 027import org.nuxeo.apidoc.documentation.ResourceDocumentationItem; 028import org.nuxeo.ecm.core.api.CoreSession; 029 030public class BundleGroupImpl extends BaseNuxeoArtifact implements BundleGroup { 031 032 protected final String key; 033 034 protected final String name; 035 036 protected final List<BundleGroup> subGroups = new ArrayList<BundleGroup>(); 037 038 protected final List<String> bundleIds = new ArrayList<String>(); 039 040 protected final String version; 041 042 protected final List<String> parentIds = new ArrayList<String>(); 043 044 protected Map<String, ResourceDocumentationItem> liveDoc; 045 046 public BundleGroupImpl(String key, String version) { 047 this.key = key; 048 if (key.startsWith("grp:")) { 049 name = key.substring(4); 050 } else { 051 name = key; 052 } 053 this.version = version; 054 } 055 056 void addParent(String bgId) { 057 parentIds.add(bgId); 058 } 059 060 public String getKey() { 061 return key; 062 } 063 064 @Override 065 public String getName() { 066 return name; 067 } 068 069 public void add(BundleGroupImpl group) { 070 subGroups.add(group); 071 } 072 073 public void add(String bundleId) { 074 bundleIds.add(bundleId); 075 } 076 077 @Override 078 public List<BundleGroup> getSubGroups() { 079 return subGroups; 080 } 081 082 @Override 083 public List<String> getBundleIds() { 084 return bundleIds; 085 } 086 087 @Override 088 public String getId() { 089 return key; 090 } 091 092 @Override 093 public String getVersion() { 094 return version; 095 } 096 097 @Override 098 public String getArtifactType() { 099 return TYPE_NAME; 100 } 101 102 @Override 103 public String getHierarchyPath() { 104 String path = ""; 105 for (String parentId : parentIds) { 106 path = path + "/" + parentId; 107 } 108 return path + "/" + getId(); 109 } 110 111 public void addLiveDoc(Map<String, ResourceDocumentationItem> newLiveDoc) { 112 if (liveDoc == null) { 113 liveDoc = new HashMap<String, ResourceDocumentationItem>(); 114 } 115 if (newLiveDoc != null) { 116 for (String key : newLiveDoc.keySet()) { 117 if (newLiveDoc.get(key) != null) { 118 liveDoc.put(key, new ResourceDocumentationItem(newLiveDoc.get(key), this)); 119 } 120 } 121 } 122 } 123 124 @Override 125 public AssociatedDocumentsImpl getAssociatedDocuments(CoreSession session) { 126 AssociatedDocumentsImpl docs = super.getAssociatedDocuments(session); 127 if (liveDoc != null) { 128 docs.setLiveDoc(liveDoc); 129 } 130 return docs; 131 } 132 133 public Map<String, ResourceDocumentationItem> getLiveDoc() { 134 return liveDoc; 135 } 136 137}