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