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 * Bogdan Stefanescu 018 * Thierry Delprat 019 */ 020package org.nuxeo.apidoc.introspection; 021 022import java.util.Collection; 023import java.util.HashMap; 024import java.util.HashSet; 025import java.util.Map; 026 027import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 028import org.nuxeo.apidoc.api.BundleGroup; 029import org.nuxeo.apidoc.api.BundleInfo; 030import org.nuxeo.apidoc.api.ComponentInfo; 031import org.nuxeo.apidoc.documentation.AssociatedDocumentsImpl; 032import org.nuxeo.apidoc.documentation.ResourceDocumentationItem; 033import org.nuxeo.ecm.core.api.CoreSession; 034 035import com.fasterxml.jackson.annotation.JsonCreator; 036import com.fasterxml.jackson.annotation.JsonIgnore; 037import com.fasterxml.jackson.annotation.JsonProperty; 038 039public class BundleInfoImpl extends BaseNuxeoArtifact implements BundleInfo { 040 041 protected final String bundleId; 042 043 protected final Collection<ComponentInfo> components = new HashSet<>(); 044 045 protected String fileName; 046 047 protected String manifest; // TODO 048 049 protected String[] requirements; 050 051 protected String groupId; 052 053 protected String artifactId; 054 055 protected String artifactVersion; 056 057 protected BundleGroup bundleGroup; 058 059 protected Map<String, ResourceDocumentationItem> liveDoc; 060 061 protected Map<String, ResourceDocumentationItem> parentLiveDoc; 062 063 @JsonCreator 064 BundleInfoImpl(@JsonProperty("bundleId") String bundleId, 065 @JsonProperty("fileName") String fileName, @JsonProperty("manifest") String manifest, @JsonProperty("requirements") String[] requirements, 066 @JsonProperty("groupId") String groupId, @JsonProperty("artifactId") String artifactId, 067 @JsonProperty("artifactVersion") String artifactVersion, 068 @JsonProperty("bundleGroup") BundleGroup bundleGroup, @JsonProperty("liveDoc") Map<String, ResourceDocumentationItem> liveDoc, 069 @JsonProperty("parentLiveDoc") Map<String, ResourceDocumentationItem> parentLiveDoc, @JsonProperty("location") String location) { 070 this.bundleId = bundleId; 071 this.fileName = fileName; 072 this.manifest = manifest; 073 this.requirements = requirements; 074 this.groupId = groupId; 075 this.artifactId = artifactId; 076 this.artifactVersion = artifactVersion; 077 this.bundleGroup = bundleGroup; 078 this.liveDoc = liveDoc; 079 this.parentLiveDoc = parentLiveDoc; 080 this.location = location; 081 } 082 083 public BundleGroup getBundleGroup() { 084 return bundleGroup; 085 } 086 087 public void setBundleGroup(BundleGroup bundleGroup) { 088 this.bundleGroup = bundleGroup; 089 } 090 091 protected String location; 092 093 public BundleInfoImpl(String bundleId) { 094 this.bundleId = bundleId; 095 } 096 097 @Override 098 public Collection<ComponentInfo> getComponents() { 099 return components; 100 } 101 102 public void addComponent(ComponentInfoImpl component) { 103 components.add(component); 104 } 105 106 @Override 107 public String getFileName() { 108 return fileName; 109 } 110 111 public void setFileName(String fileName) { 112 this.fileName = fileName; 113 } 114 115 @Override 116 public String getBundleId() { 117 return bundleId; 118 } 119 120 @Override 121 public String[] getRequirements() { 122 return requirements; 123 } 124 125 public void setRequirements(String[] requirements) { 126 this.requirements = requirements; 127 } 128 129 @Override 130 public String getManifest() { 131 return manifest; 132 } 133 134 public void setManifest(String manifest) { 135 this.manifest = manifest; 136 } 137 138 @Override 139 public String getLocation() { 140 return location; 141 } 142 143 public void setLocation(String location) { 144 this.location = location; 145 } 146 147 @Override 148 public String getGroupId() { 149 return groupId; 150 } 151 152 public void setGroupId(String groupId) { 153 this.groupId = groupId; 154 } 155 156 @Override 157 public String getArtifactId() { 158 return artifactId; 159 } 160 161 public void setArtifactId(String artifactId) { 162 this.artifactId = artifactId; 163 } 164 165 @Override 166 public String getArtifactVersion() { 167 return artifactVersion; 168 } 169 170 public void setArtifactVersion(String artifactVersion) { 171 this.artifactVersion = artifactVersion; 172 } 173 174 @Override 175 @JsonIgnore 176 public String getId() { 177 return bundleId; 178 } 179 180 @Override 181 @JsonIgnore 182 public String getVersion() { 183 return artifactVersion; 184 } 185 186 @Override 187 @JsonIgnore 188 public String getArtifactType() { 189 return TYPE_NAME; 190 } 191 192 @Override 193 @JsonIgnore 194 public String getHierarchyPath() { 195 return bundleGroup.getHierarchyPath() + "/" + getId(); 196 } 197 198 public void setLiveDoc(Map<String, ResourceDocumentationItem> liveDoc) { 199 this.liveDoc = liveDoc; 200 } 201 202 public void setParentLiveDoc(Map<String, ResourceDocumentationItem> parentLiveDoc) { 203 this.parentLiveDoc = parentLiveDoc; 204 } 205 206 protected Map<String, ResourceDocumentationItem> getMergedDocumentation() { 207 208 Map<String, ResourceDocumentationItem> merged = parentLiveDoc; 209 if (merged == null) { 210 merged = new HashMap<>(); 211 } 212 if (liveDoc != null) { 213 for (String key : liveDoc.keySet()) { 214 if (liveDoc.get(key) != null) { 215 merged.put(key, liveDoc.get(key)); 216 } 217 } 218 } 219 return merged; 220 } 221 222 @Override 223 public AssociatedDocumentsImpl getAssociatedDocuments(CoreSession session) { 224 AssociatedDocumentsImpl docs = super.getAssociatedDocuments(session); 225 docs.setLiveDoc(getMergedDocumentation()); 226 return docs; 227 } 228 229 @Override 230 public Map<String, ResourceDocumentationItem> getLiveDoc() { 231 return liveDoc; 232 } 233 234 @Override 235 public Map<String, ResourceDocumentationItem> getParentLiveDoc() { 236 return parentLiveDoc; 237 } 238 239}