001/* 002 * Copyright 2010 Anyware Services 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 */ 016package org.ametys.plugins.forms; 017 018import java.util.ArrayList; 019import java.util.Collection; 020import java.util.HashSet; 021import java.util.LinkedHashMap; 022import java.util.List; 023import java.util.Map; 024import java.util.Set; 025 026/** 027 * Class representing a form. 028 */ 029public class Form 030{ 031 /** The form id. */ 032 protected String _id; 033 /** The form label. */ 034 protected String _label; 035 /** The field which indicates the email to send an acknowledgement of receipt. */ 036 protected String _receiptFieldId; 037 /** The email address of the sender. Can be empty to use default one. */ 038 protected String _receiptFieldFromAddress; 039 /** The subject og the email. Cannot be empty */ 040 protected String _receiptFieldSubject; 041 /** The body of the email. Cannot be empty */ 042 protected String _receiptFieldBody; 043 /** The id of the page where to redirect to. Can be empty */ 044 protected String _redirectTo; 045 /** The form emails. */ 046 protected Set<String> _notificationEmails; 047 048 /** The form content ID. */ 049// protected String _contentId; 050 051 /** The form fields. */ 052 protected List<Field> _fields; 053 054 /** The form fieldsets. */ 055 protected List<Fieldset> _fieldsets; 056 057 /** The name of the form's workflow */ 058 protected String _workflowName; 059 060 /** The content id */ 061 protected String _contentId; 062 063 /** 064 * Default constructor. 065 */ 066 public Form() 067 { 068 this("", "", "", "", "", "", new HashSet<String>(), "", new ArrayList<Field>(), new ArrayList<Fieldset>(), "", ""); 069 } 070 071 /** 072 * Constructor with parameters. 073 * @param id the form ID. 074 * @param label the form label. 075 * @param receiptFieldId the acknowledgement of receipt field ID. 076 * @param receiptFieldFromAddress The sender address for the receipt mail. Can be empty 077 * @param receiptFieldSubject The receipt mail subject 078 * @param receiptFieldBody The receipt mail body 079 * @param emails the form emails. 080 * @param contentId the form content ID. 081 * @param fields the form fields. 082 * @param fieldsets the form fieldsets. 083 * @param redirectTo the id of the page where to redirect to 084 * @param workflowName the name of the workflow 085 */ 086 public Form(String id, String label, String receiptFieldId, String receiptFieldFromAddress, String receiptFieldSubject, String receiptFieldBody, Set<String> emails, String contentId, Collection<Field> fields, Collection<Fieldset> fieldsets, String redirectTo, String workflowName) 087 { 088 this._id = id; 089 this._label = label; 090 this._receiptFieldId = receiptFieldId; 091 this._receiptFieldFromAddress = receiptFieldFromAddress; 092 this._receiptFieldSubject = receiptFieldSubject; 093 this._receiptFieldBody = receiptFieldBody; 094 this._notificationEmails = emails; 095 this._contentId = contentId; 096 this._fields = new ArrayList<>(fields); 097 this._fieldsets = new ArrayList<>(fieldsets); 098 this._redirectTo = redirectTo; 099 this._workflowName = workflowName; 100 } 101 102 /** 103 * Get the id. 104 * @return the id 105 */ 106 public String getId() 107 { 108 return _id; 109 } 110 111 /** 112 * Set the id. 113 * @param id the id to set 114 */ 115 public void setId(String id) 116 { 117 this._id = id; 118 } 119 120 /** 121 * Get the label. 122 * @return the label 123 */ 124 public String getLabel() 125 { 126 return _label; 127 } 128 129 /** 130 * Set the label. 131 * @param label the label to set 132 */ 133 public void setLabel(String label) 134 { 135 this._label = label; 136 } 137 138 /** 139 * Get the acknowledgement of receipt field ID. 140 * @return the acknowledgement of receipt field ID. 141 */ 142 public String getReceiptFieldId() 143 { 144 return _receiptFieldId; 145 } 146 147 /** 148 * Set the acknowledgement of receipt field ID. 149 * @param receiptFieldId the acknowledgement of receipt field ID. 150 */ 151 public void setReceiptFieldId(String receiptFieldId) 152 { 153 this._receiptFieldId = receiptFieldId; 154 } 155 156 /** 157 * Get the receiptFieldFromAddress 158 * @return the receiptFieldFromAddress 159 */ 160 public String getReceiptFieldFromAddress() 161 { 162 return _receiptFieldFromAddress; 163 } 164 165 /** 166 * Set the receiptFieldFromAddress 167 * @param receiptFieldFromAddress the receiptFieldFromAddress to set 168 */ 169 public void setReceiptFieldFromAddress(String receiptFieldFromAddress) 170 { 171 _receiptFieldFromAddress = receiptFieldFromAddress; 172 } 173 174 /** 175 * Get the receiptFieldBody 176 * @return the receiptFieldBody 177 */ 178 public String getReceiptFieldBody() 179 { 180 return _receiptFieldBody; 181 } 182 183 /** 184 * Set the receiptFieldBody 185 * @param receiptFieldBody the receiptFieldBody to set 186 */ 187 public void setReceiptFieldBody(String receiptFieldBody) 188 { 189 _receiptFieldBody = receiptFieldBody; 190 } 191 192 /** 193 * Get the receiptFieldSubject 194 * @return the receiptFieldSubject 195 */ 196 public String getReceiptFieldSubject() 197 { 198 return _receiptFieldSubject; 199 } 200 201 /** 202 * Set the receiptFieldSubject 203 * @param receiptFieldSubject the receiptFieldSubject to set 204 */ 205 public void setReceiptFieldSubject(String receiptFieldSubject) 206 { 207 _receiptFieldSubject = receiptFieldSubject; 208 } 209 210 /** 211 * Get the emails. 212 * @return the emails 213 */ 214 public Set<String> getNotificationEmails() 215 { 216 return _notificationEmails; 217 } 218 219 /** 220 * Set the emails. 221 * @param emails the emails to set 222 */ 223 public void setNotificationEmails(Set<String> emails) 224 { 225 this._notificationEmails = emails; 226 } 227 228 /** 229 * Get the content ID. 230 * @return the content ID. 231 */ 232 public String getContentId() 233 { 234 return _contentId; 235 } 236 237 /** 238 * Set the content ID. 239 * @param contentId the content ID to set. 240 */ 241 public void setContentId(String contentId) 242 { 243 this._contentId = contentId; 244 } 245 246 /** 247 * Get the fields. 248 * @return the fields 249 */ 250 public List<Field> getFields() 251 { 252 return _fields; 253 } 254 255 /** 256 * Set the fields. 257 * @param fields the fields to set 258 */ 259 public void setFields(Collection<Field> fields) 260 { 261 _fields = new ArrayList<>(fields); 262 } 263 264 /** 265 * Get a copy of the form's fields, indexed by its ID. 266 * @return a copy of the form's fields, indexed by its ID. 267 */ 268 public Map<String, Field> getFieldMap() 269 { 270 Map<String, Field> fieldMap = new LinkedHashMap<>(); 271 for (Field field : _fields) 272 { 273 fieldMap.put(field.getId(), field); 274 } 275 return fieldMap; 276 } 277 278 /** 279 * Get the fieldsets. 280 * @return the fieldsets 281 */ 282 public List<Fieldset> getFieldsets() 283 { 284 return _fieldsets; 285 } 286 287 /** 288 * Set the fieldsets. 289 * @param fieldsets the fieldsets to set 290 */ 291 public void setFieldsets(Collection<Fieldset> fieldsets) 292 { 293 this._fieldsets = new ArrayList<>(fieldsets); 294 } 295 296 /** 297 * the redirectTo 298 * @return the redirectTo 299 */ 300 public String getRedirectTo() 301 { 302 return _redirectTo; 303 } 304 305 /** 306 * the redirectTo 307 * @param redirectTo the redirectTo to set 308 */ 309 public void setRedirectTo(String redirectTo) 310 { 311 _redirectTo = redirectTo; 312 } 313 314 /** 315 * Retrieve the name of the workflow of this form's entries 316 * @return the name of the workflow used 317 */ 318 public String getWorkflowName() 319 { 320 return _workflowName; 321 } 322 323 /** 324 * Set the name of the workflow of this form's entries 325 * @param workflowName the name of the workflow to use 326 */ 327 public void setWorkflowName(String workflowName) 328 { 329 _workflowName = workflowName; 330 } 331}