001/* 002 * (C) Copyright 2006-2011 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 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation; 020 021import org.nuxeo.common.xmap.annotation.XNode; 022import org.nuxeo.common.xmap.annotation.XNodeList; 023import org.nuxeo.common.xmap.annotation.XObject; 024import org.nuxeo.ecm.automation.core.Constants; 025import org.nuxeo.ecm.automation.core.OperationChainContribution; 026import org.nuxeo.ecm.platform.forms.layout.api.WidgetDefinition; 027 028import java.io.Serializable; 029import java.util.Arrays; 030 031/** 032 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 033 * @author <a href="mailto:grenard@nuxeo.com">Guillaume Renard</a> 034 */ 035public class OperationDocumentation implements Comparable<OperationDocumentation>, Serializable { 036 037 private static final long serialVersionUID = 1L; 038 039 public String id; 040 041 /** 042 * @since 7.1 043 */ 044 public String[] aliases; 045 046 /** 047 * an array of size multiple of 2. Each pair in the array is the input and output type of a method. 048 */ 049 public String[] signature; 050 051 public String category; 052 053 public String label; 054 055 public String requires; 056 057 public String since; 058 059 /** 060 * @since 5.9.1 061 */ 062 public String deprecatedSince; 063 064 /** 065 * @since 5.9.1 066 */ 067 public boolean addToStudio; 068 069 /** 070 * @since 5.9.1 071 */ 072 public String implementationClass; 073 074 public String description; 075 076 public Param[] params; 077 078 public WidgetDefinition[] widgetDefinitions; 079 080 /** 081 * The operations listing in case of a chain. 082 */ 083 public OperationChainContribution.Operation[] operations; 084 085 // optional URL indicating the relative path (relative to the automation 086 // service home) 087 // of the page where the operation is exposed 088 public String url; 089 090 public OperationDocumentation(String id) { 091 this.id = id; 092 url = id; 093 } 094 095 @XObject("param") 096 public static class Param implements Serializable, Comparable<Param> { 097 private static final long serialVersionUID = 1L; 098 099 @XNode("@name") 100 public String name; 101 102 @XNode("@description") 103 public String description; 104 105 @XNode("@type") 106 public String type; // the data type 107 108 // is this useful (?) 109 public String widget; // the widget type 110 111 // is this useful (?) 112 @XNodeList(value = "value", type = String[].class, componentType = String.class) 113 public String[] values; // the default values 114 115 // is this useful (?) 116 @XNode("@order") 117 public int order; 118 119 // is this useful (?) 120 @XNode("@required") 121 public boolean required; 122 123 public Param() { 124 } 125 126 public String getName() { 127 return name; 128 } 129 130 /** 131 * @since 5.7.3 132 */ 133 public String getDescription() { 134 return description; 135 } 136 137 public String getType() { 138 return type; 139 } 140 141 public String getWidget() { 142 return widget; 143 } 144 145 public String[] getValues() { 146 return values; 147 } 148 149 public boolean isRequired() { 150 return required; 151 } 152 153 public int getOrder() { 154 return order; 155 } 156 157 @Override 158 public String toString() { 159 return name + " [" + type + "] " + (required ? "required" : "optional"); 160 } 161 162 @Override 163 public int compareTo(Param o) { 164 if (order != 0 && o.order != 0) { 165 if (order < o.order) { 166 return -1; 167 } else if (order > o.order) { 168 return 1; 169 } 170 } 171 if (required && !o.required) { 172 return -1; 173 } 174 if (o.required && !required) { 175 return 1; 176 } 177 return name.compareTo(o.name); 178 } 179 } 180 181 @Override 182 public int compareTo(OperationDocumentation o) { 183 String s1 = label == null ? id : label; 184 String s2 = o.label == null ? o.id : o.label; 185 return s1.compareTo(s2); 186 } 187 188 public String getDescription() { 189 return description; 190 } 191 192 /** 193 * @since 5.9.1 194 */ 195 public String getSince() { 196 return since; 197 } 198 199 /** 200 * @since 5.9.1 201 */ 202 public String getDeprecatedSince() { 203 return deprecatedSince; 204 } 205 206 /** 207 * @since 5.9.1 208 */ 209 public boolean isAddToStudio() { 210 return addToStudio; 211 } 212 213 /** 214 * @since 5.9.1 215 */ 216 public String getImplementationClass() { 217 return implementationClass; 218 } 219 220 /** 221 * @since 5.9.4 222 */ 223 public boolean isChain() { 224 return (id != null && id.startsWith(Constants.CHAIN_ID_PREFIX)) || Constants.CAT_CHAIN.equals(category); 225 } 226 227 public String[] getSignature() { 228 return signature; 229 } 230 231 public String getCategory() { 232 return category; 233 } 234 235 public String getId() { 236 return id; 237 } 238 239 public String getUrl() { 240 return url; 241 } 242 243 public String getLabel() { 244 return label; 245 } 246 247 public String getRequires() { 248 return requires; 249 } 250 251 public Param[] getParams() { 252 return params; 253 } 254 255 public String[] getAliases() { 256 return aliases; 257 } 258 259 public void setAliases(String[] aliases) { 260 this.aliases = aliases; 261 } 262 263 public OperationChainContribution.Operation[] getOperations() { 264 return operations; 265 } 266 267 @Override 268 public String toString() { 269 return category + " > " + label + " [" + id + ": " + Arrays.asList(signature) + "] (" + params + ")\n" 270 + description; 271 } 272}