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.snapshot; 020 021import java.io.IOException; 022import java.util.List; 023 024import org.nuxeo.apidoc.api.BundleGroup; 025import org.nuxeo.apidoc.api.BundleInfo; 026import org.nuxeo.apidoc.api.ComponentInfo; 027import org.nuxeo.apidoc.api.DocumentationItem; 028import org.nuxeo.apidoc.api.ExtensionInfo; 029import org.nuxeo.apidoc.api.ExtensionPointInfo; 030import org.nuxeo.apidoc.api.OperationInfo; 031import org.nuxeo.apidoc.api.SeamComponentInfo; 032import org.nuxeo.apidoc.api.ServiceInfo; 033import org.nuxeo.apidoc.documentation.ResourceDocumentationItem; 034import org.nuxeo.apidoc.introspection.BundleGroupImpl; 035import org.nuxeo.apidoc.introspection.BundleInfoImpl; 036import org.nuxeo.apidoc.introspection.ComponentInfoImpl; 037import org.nuxeo.apidoc.introspection.ExtensionInfoImpl; 038import org.nuxeo.apidoc.introspection.OperationInfoImpl; 039import org.nuxeo.apidoc.introspection.RuntimeSnapshot; 040import org.nuxeo.apidoc.introspection.SeamComponentInfoImpl; 041import org.nuxeo.apidoc.introspection.ServerInfo; 042import org.nuxeo.apidoc.introspection.ServiceInfoImpl; 043import org.nuxeo.ecm.automation.OperationDocumentation; 044 045import com.fasterxml.jackson.annotation.JsonIgnore; 046import com.fasterxml.jackson.annotation.JsonProperty; 047import com.fasterxml.jackson.core.JsonGenerator; 048import com.fasterxml.jackson.core.JsonParser; 049import com.fasterxml.jackson.databind.DeserializationFeature; 050import com.fasterxml.jackson.databind.ObjectMapper; 051import com.fasterxml.jackson.databind.ObjectReader; 052import com.fasterxml.jackson.databind.ObjectWriter; 053import com.fasterxml.jackson.databind.module.SimpleModule; 054 055public interface DistributionSnapshot extends DistributionSnapshotDesc { 056 057 String TYPE_NAME = "NXDistribution"; 058 059 String CONTAINER_TYPE_NAME = "Workspace"; 060 061 String PROP_NAME = "nxdistribution:name"; 062 063 String PROP_VERSION = "nxdistribution:version"; 064 065 String PROP_KEY = "nxdistribution:key"; 066 067 /** 068 * @since 8.3 069 */ 070 String PROP_LATEST_FT = "nxdistribution:latestFT"; 071 072 /** 073 * @since 8.3 074 */ 075 String PROP_LATEST_LTS = "nxdistribution:latestLTS"; 076 077 /** 078 * @since 8.3 079 */ 080 String PROP_ALIASES = "nxdistribution:aliases"; 081 082 /** 083 * @since 8.3 084 */ 085 String PROP_HIDE = "nxdistribution:hide"; 086 087 /** 088 * @since 8.3 089 */ 090 String PROP_RELEASED = "nxdistribution:released"; 091 092 String getKey(); 093 094 void cleanPreviousArtifacts(); 095 096 List<BundleGroup> getBundleGroups(); 097 098 BundleGroup getBundleGroup(String groupId); 099 100 List<String> getBundleIds(); 101 102 BundleInfo getBundle(String id); 103 104 List<String> getComponentIds(); 105 106 List<String> getJavaComponentIds(); 107 108 List<String> getXmlComponentIds(); 109 110 ComponentInfo getComponent(String id); 111 112 List<String> getServiceIds(); 113 114 ServiceInfo getService(String id); 115 116 List<String> getExtensionPointIds(); 117 118 ExtensionPointInfo getExtensionPoint(String id); 119 120 List<String> getContributionIds(); 121 122 List<ExtensionInfo> getContributions(); 123 124 ExtensionInfo getContribution(String id); 125 126 List<String> getBundleGroupChildren(String groupId); 127 128 List<Class<?>> getSpi(); 129 130 @JsonIgnore 131 List<String> getSeamComponentIds(); 132 133 List<SeamComponentInfo> getSeamComponents(); 134 135 SeamComponentInfo getSeamComponent(String id); 136 137 boolean containsSeamComponents(); 138 139 OperationInfo getOperation(String id); 140 141 List<OperationInfo> getOperations(); 142 143 /** 144 * @since 8.3 145 */ 146 boolean isLatestFT(); 147 148 /** 149 * @since 8.3 150 */ 151 boolean isLatestLTS(); 152 153 /** 154 * @since 8.3 155 */ 156 List<String> getAliases(); 157 158 /** 159 * @since 8.3 160 */ 161 boolean isHidden(); 162 163 /** 164 * @since 8.3 165 * 166 */ 167 ServerInfo getServerInfo(); 168 169 public static ObjectWriter jsonWriter() throws IOException { 170 return jsonMapper().writerFor(DistributionSnapshot.class) 171 .withoutRootName() 172 .with(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM) 173 .without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); 174 } 175 176 public static ObjectReader jsonReader() throws IOException { 177 return jsonMapper().readerFor(DistributionSnapshot.class) 178 .withoutRootName() 179 .without(JsonParser.Feature.AUTO_CLOSE_SOURCE) 180 .with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT); 181 } 182 183 public static ObjectMapper jsonMapper() { 184 final ObjectMapper mapper = 185 new ObjectMapper().registerModule(new SimpleModule() 186 .addAbstractTypeMapping(DistributionSnapshot.class, RuntimeSnapshot.class) 187 .addAbstractTypeMapping(BundleInfo.class, BundleInfoImpl.class) 188 .addAbstractTypeMapping(BundleGroup.class, BundleGroupImpl.class) 189 .addAbstractTypeMapping(ComponentInfo.class, ComponentInfoImpl.class) 190 .addAbstractTypeMapping(ExtensionInfo.class, ExtensionInfoImpl.class) 191 .addAbstractTypeMapping(OperationInfo.class, OperationInfoImpl.class) 192 .addAbstractTypeMapping(SeamComponentInfo.class, SeamComponentInfoImpl.class) 193 .addAbstractTypeMapping(ServiceInfo.class, ServiceInfoImpl.class) 194 .addAbstractTypeMapping(DocumentationItem.class, ResourceDocumentationItem.class)); 195 mapper.addMixIn(OperationDocumentation.Param.class, OperationDocParamMixin.class); 196 return mapper; 197 } 198 199 static abstract class OperationDocParamMixin { 200 abstract @JsonProperty("isRequired") String isRequired(); 201 } 202}