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.client.model; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.Arrays; 024import java.util.List; 025 026/** 027 * This is a copy of OperationDocumentation from automation-core - must be keep in sync 028 * 029 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 030 */ 031public class OperationDocumentation implements Comparable<OperationDocumentation>, Serializable { 032 033 private static final long serialVersionUID = 1L; 034 035 public String id; 036 037 public String[] aliases; 038 039 /** 040 * An array of size multiple of 2. Each pair in the array is the input and output type of a method. 041 */ 042 public String[] signature; 043 044 public String category; 045 046 public String label; 047 048 public String requires; 049 050 public String since; 051 052 public String description; 053 054 public List<Param> params; 055 056 // optional URL indicating the relative path (relative to the automation 057 // service home) 058 // of the page where the operation is exposed 059 public String url; 060 061 /** 062 * Should only be used by marshaller 063 */ 064 public OperationDocumentation() { 065 this(null); 066 } 067 068 public OperationDocumentation(String id) { 069 this.id = id; 070 this.url = id; 071 this.params = new ArrayList<OperationDocumentation.Param>(); 072 } 073 074 public int compareTo(OperationDocumentation o) { 075 String s1 = label == null ? id : label; 076 String s2 = o.label == null ? o.id : o.label; 077 return s1.compareTo(s2); 078 } 079 080 public String getDescription() { 081 return description; 082 } 083 084 public String[] getSignature() { 085 return signature; 086 } 087 088 public String getCategory() { 089 return category; 090 } 091 092 public String getId() { 093 return id; 094 } 095 096 public String getUrl() { 097 return url; 098 } 099 100 public String getLabel() { 101 return label; 102 } 103 104 public String getRequires() { 105 return requires; 106 } 107 108 public List<Param> getParams() { 109 return params; 110 } 111 112 public String[] getAliases() { 113 return aliases; 114 } 115 116 @Override 117 public String toString() { 118 return category + " > " + label + " [" + id + ": " + Arrays.asList(signature) + "] (" + params + ")\n" 119 + description; 120 } 121 122 public static class Param implements Serializable, Comparable<Param> { 123 private static final long serialVersionUID = 1L; 124 125 public String name; 126 127 public String description; 128 129 public String type; // the data type 130 131 public String widget; // the widget type 132 133 public String[] values; // the default values 134 135 public boolean isRequired; 136 137 public String getName() { 138 return name; 139 } 140 141 /** 142 * @since 5.7.3 143 */ 144 public String getDescription() { 145 return description; 146 } 147 148 public String getType() { 149 return type; 150 } 151 152 public String getWidget() { 153 return widget; 154 } 155 156 public String[] getValues() { 157 return values; 158 } 159 160 public boolean isRequired() { 161 return isRequired; 162 } 163 164 @Override 165 public String toString() { 166 return name + " [" + type + "] " + (isRequired ? "required" : "optional"); 167 } 168 169 public int compareTo(Param o) { 170 if (isRequired && !o.isRequired) { 171 return -1; 172 } 173 if (o.isRequired && !isRequired) { 174 return 1; 175 } 176 return name.compareTo(o.name); 177 } 178 } 179}