001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.client.model; 013 014import java.io.Serializable; 015import java.util.ArrayList; 016import java.util.Arrays; 017import java.util.List; 018 019/** 020 * This is a copy of OperationDocumentation from automation-core - must be keep in sync 021 * 022 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 023 */ 024public class OperationDocumentation implements Comparable<OperationDocumentation>, Serializable { 025 026 private static final long serialVersionUID = 1L; 027 028 public String id; 029 030 public String[] aliases; 031 032 /** 033 * An array of size multiple of 2. Each pair in the array is the input and output type of a method. 034 */ 035 public String[] signature; 036 037 public String category; 038 039 public String label; 040 041 public String requires; 042 043 public String since; 044 045 public String description; 046 047 public List<Param> params; 048 049 // optional URL indicating the relative path (relative to the automation 050 // service home) 051 // of the page where the operation is exposed 052 public String url; 053 054 /** 055 * Should only be used by marshaller 056 */ 057 public OperationDocumentation() { 058 this(null); 059 } 060 061 public OperationDocumentation(String id) { 062 this.id = id; 063 this.url = id; 064 this.params = new ArrayList<OperationDocumentation.Param>(); 065 } 066 067 public int compareTo(OperationDocumentation o) { 068 String s1 = label == null ? id : label; 069 String s2 = o.label == null ? o.id : o.label; 070 return s1.compareTo(s2); 071 } 072 073 public String getDescription() { 074 return description; 075 } 076 077 public String[] getSignature() { 078 return signature; 079 } 080 081 public String getCategory() { 082 return category; 083 } 084 085 public String getId() { 086 return id; 087 } 088 089 public String getUrl() { 090 return url; 091 } 092 093 public String getLabel() { 094 return label; 095 } 096 097 public String getRequires() { 098 return requires; 099 } 100 101 public List<Param> getParams() { 102 return params; 103 } 104 105 public String[] getAliases() { 106 return aliases; 107 } 108 109 @Override 110 public String toString() { 111 return category + " > " + label + " [" + id + ": " + Arrays.asList(signature) + "] (" + params + ")\n" 112 + description; 113 } 114 115 public static class Param implements Serializable, Comparable<Param> { 116 private static final long serialVersionUID = 1L; 117 118 public String name; 119 120 public String description; 121 122 public String type; // the data type 123 124 public String widget; // the widget type 125 126 public String[] values; // the default values 127 128 public boolean isRequired; 129 130 public String getName() { 131 return name; 132 } 133 134 /** 135 * @since 5.7.3 136 */ 137 public String getDescription() { 138 return description; 139 } 140 141 public String getType() { 142 return type; 143 } 144 145 public String getWidget() { 146 return widget; 147 } 148 149 public String[] getValues() { 150 return values; 151 } 152 153 public boolean isRequired() { 154 return isRequired; 155 } 156 157 @Override 158 public String toString() { 159 return name + " [" + type + "] " + (isRequired ? "required" : "optional"); 160 } 161 162 public int compareTo(Param o) { 163 if (isRequired && !o.isRequired) { 164 return -1; 165 } 166 if (o.isRequired && !isRequired) { 167 return 1; 168 } 169 return name.compareTo(o.name); 170 } 171 } 172}