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.content;
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    /** The limit of entries */
048    protected String _limit;
049    /** The message to display when they are remaining places */
050    protected String _remainingPlaces;
051    /** The message to display when they are no remaining places */
052    protected String _noRemainingPlaces;
053    
054    /** The form content ID. */
055//    protected String _contentId;
056    
057    /** The form fields. */
058    protected List<Field> _fields;
059    
060    /** The form fieldsets. */
061    protected List<Fieldset> _fieldsets;
062    
063    /** The name of the form's workflow */
064    protected String _workflowName;
065    
066    /** The content id */
067    protected String _contentId;
068
069    /**
070     * Default constructor.
071     */
072    public Form()
073    {
074        this("", "", "", "", "", "", new HashSet<String>(), "", new ArrayList<Field>(), new ArrayList<Fieldset>(), "", "", "", "", "");
075    }
076    
077    /**
078     * Constructor with parameters.
079     * @param id the form ID.
080     * @param label the form label.
081     * @param receiptFieldId the acknowledgement of receipt field ID.
082     * @param receiptFieldFromAddress The sender address for the receipt mail. Can be empty
083     * @param receiptFieldSubject The receipt mail subject
084     * @param receiptFieldBody The receipt mail body
085     * @param emails the form emails.
086     * @param contentId the form content ID.
087     * @param fields the form fields.
088     * @param fieldsets the form fieldsets.
089     * @param redirectTo the id of the page where to redirect to
090     * @param workflowName the name of the workflow
091     * @param limit the limit of entries
092     * @param remainingPlaces the remainingPlaces
093     * @param noRemainingPlaces the noRemainingPlaces
094     */
095    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, String limit, String remainingPlaces, String noRemainingPlaces)
096    {
097        this._id = id;
098        this._label = label;
099        this._receiptFieldId = receiptFieldId;
100        this._receiptFieldFromAddress = receiptFieldFromAddress;
101        this._receiptFieldSubject = receiptFieldSubject;
102        this._receiptFieldBody = receiptFieldBody;
103        this._notificationEmails = emails;
104        this._contentId = contentId;
105        this._fields = new ArrayList<>(fields);
106        this._fieldsets = new ArrayList<>(fieldsets);
107        this._redirectTo = redirectTo;
108        this._workflowName = workflowName;
109        this._limit = limit;
110        this._remainingPlaces = remainingPlaces;
111        this._noRemainingPlaces = noRemainingPlaces;
112    }
113
114    /**
115     * Get the id.
116     * @return the id
117     */
118    public String getId()
119    {
120        return _id;
121    }
122
123    /**
124     * Set the id.
125     * @param id the id to set
126     */
127    public void setId(String id)
128    {
129        this._id = id;
130    }
131
132    /**
133     * Get the label.
134     * @return the label
135     */
136    public String getLabel()
137    {
138        return _label;
139    }
140
141    /**
142     * Set the label.
143     * @param label the label to set
144     */
145    public void setLabel(String label)
146    {
147        this._label = label;
148    }
149
150    /**
151     * Get the acknowledgement of receipt field ID.
152     * @return the acknowledgement of receipt field ID.
153     */
154    public String getReceiptFieldId()
155    {
156        return _receiptFieldId;
157    }
158    
159    /**
160     * Set the acknowledgement of receipt field ID.
161     * @param receiptFieldId the acknowledgement of receipt field ID.
162     */
163    public void setReceiptFieldId(String receiptFieldId)
164    {
165        this._receiptFieldId = receiptFieldId;
166    }
167    
168    /**
169     * Get the receiptFieldFromAddress
170     * @return the receiptFieldFromAddress
171     */
172    public String getReceiptFieldFromAddress()
173    {
174        return _receiptFieldFromAddress;
175    }
176    
177    /**
178     * Set the receiptFieldFromAddress
179     * @param receiptFieldFromAddress the receiptFieldFromAddress to set
180     */
181    public void setReceiptFieldFromAddress(String receiptFieldFromAddress)
182    {
183        _receiptFieldFromAddress = receiptFieldFromAddress;
184    }
185    
186    /**
187     * Get the receiptFieldBody
188     * @return the receiptFieldBody
189     */
190    public String getReceiptFieldBody()
191    {
192        return _receiptFieldBody;
193    }
194    
195    /**
196     * Set the receiptFieldBody
197     * @param receiptFieldBody the receiptFieldBody to set
198     */
199    public void setReceiptFieldBody(String receiptFieldBody)
200    {
201        _receiptFieldBody = receiptFieldBody;
202    }
203    
204    /**
205     * Get the receiptFieldSubject
206     * @return the receiptFieldSubject
207     */
208    public String getReceiptFieldSubject()
209    {
210        return _receiptFieldSubject;
211    }
212    
213    /**
214     * Set the receiptFieldSubject
215     * @param receiptFieldSubject the receiptFieldSubject to set
216     */
217    public void setReceiptFieldSubject(String receiptFieldSubject)
218    {
219        _receiptFieldSubject = receiptFieldSubject;
220    }
221    
222    /**
223     * Get the emails.
224     * @return the emails
225     */
226    public Set<String> getNotificationEmails()
227    {
228        return _notificationEmails;
229    }
230
231    /**
232     * Set the emails.
233     * @param emails the emails to set
234     */
235    public void setNotificationEmails(Set<String> emails)
236    {
237        this._notificationEmails = emails;
238    }
239    
240    /**
241     * Get the content ID.
242     * @return the content ID.
243     */
244    public String getContentId()
245    {
246        return _contentId;
247    }
248
249    /**
250     * Set the content ID.
251     * @param contentId the content ID to set.
252     */
253    public void setContentId(String contentId)
254    {
255        this._contentId = contentId;
256    }
257    
258    /**
259     * Get the fields.
260     * @return the fields
261     */
262    public List<Field> getFields()
263    {
264        return _fields;
265    }
266    
267    /**
268     * Set the fields.
269     * @param fields the fields to set
270     */
271    public void setFields(Collection<Field> fields)
272    {
273        _fields = new ArrayList<>(fields);
274    }
275    
276    /**
277     * Get a copy of the form's fields, indexed by its ID.
278     * @return a copy of the form's fields, indexed by its ID.
279     */
280    public Map<String, Field> getFieldMap()
281    {
282        Map<String, Field> fieldMap = new LinkedHashMap<>();
283        for (Field field : _fields)
284        {
285            fieldMap.put(field.getId(), field);
286        }
287        return fieldMap;
288    }
289    
290    /**
291     * Get the fieldsets.
292     * @return the fieldsets
293     */
294    public List<Fieldset> getFieldsets()
295    {
296        return _fieldsets;
297    }
298    
299    /**
300     * Set the fieldsets.
301     * @param fieldsets the fieldsets to set
302     */
303    public void setFieldsets(Collection<Fieldset> fieldsets)
304    {
305        this._fieldsets = new ArrayList<>(fieldsets);
306    }
307
308    /**
309     * the redirectTo
310     * @return the redirectTo
311     */
312    public String getRedirectTo()
313    {
314        return _redirectTo;
315    }
316    
317    /**
318     * the redirectTo
319     * @param redirectTo the redirectTo to set
320     */
321    public void setRedirectTo(String redirectTo)
322    {
323        _redirectTo = redirectTo;
324    }
325    
326    /**
327     * Retrieve the name of the workflow of this form's entries
328     * @return the name of the workflow used
329     */
330    public String getWorkflowName()
331    {
332        return _workflowName;
333    }
334
335    /**
336     * Set the name of the workflow of this form's entries
337     * @param workflowName the name of the workflow to use
338     */
339    public void setWorkflowName(String workflowName)
340    {
341        _workflowName = workflowName;
342    }
343
344    /**
345     * the limit of entries in the form
346     * @return the limit of entries
347     */
348    public String getLimit()
349    {
350        return _limit;
351    }
352
353    /**
354     * Set the limit of entries in the form
355     * @param limit the limit of entries
356     */
357    public void setLimit(String limit)
358    {
359        this._limit = limit;
360    }
361
362    /**
363     * Get the message to display when they are remaining places
364     * @return the remainingPlaces
365     */
366    public String getRemainingPlaces()
367    {
368        return _remainingPlaces;
369    }
370
371    /**
372     * Set the message to display when they are remaining places
373     * @param remainingPlaces the remainingPlaces to set
374     */
375    public void setRemainingPlaces(String remainingPlaces)
376    {
377        this._remainingPlaces = remainingPlaces;
378    }
379
380    /**
381     * Get the message to display when they are no remaining places
382     * @return the remainingPlaces
383     */
384    public String getNoRemainingPlaces()
385    {
386        return _noRemainingPlaces;
387    }
388
389    /**
390     * Set the message to display when they are no remaining places
391     * @param noRemainingPlaces the noRemainingPlaces to set
392     */
393    public void setNoRemainingPlaces(String noRemainingPlaces)
394    {
395        this._noRemainingPlaces = noRemainingPlaces;
396    }
397}