001/*
002 *  Copyright 2011 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.survey.data;
017
018import java.util.ArrayList;
019import java.util.Date;
020import java.util.List;
021
022import org.ametys.core.user.UserIdentity;
023
024/**
025 * Class representing a survey session, i.e. all the responses of a user to a survey.
026 */
027public class SurveySession
028{
029    
030    /** The session ID. */
031    protected int _id;
032    
033    /** The survey ID. */
034    protected String _surveyId;
035    
036    /** The login of the person who answered the survey. */
037    protected String _login;
038    
039    /** The population of the person who answered the survey. */
040    protected String _population;
041    
042    /** The IP address of the person who answered the survey. */
043    protected String _ipAddress;
044    
045    /** The date and time at which the person completed the survey. */
046    protected Date _submittedAt;
047    
048    /** The list of answers. */
049    protected List<SurveyAnswer> _answers;
050    
051    /**
052     * Build a SurveySession object.
053     */
054    public SurveySession()
055    {
056        this(Integer.MIN_VALUE, null, null, null, null, new ArrayList<>());
057    }
058    
059    /**
060     * Build a SurveySession object.
061     * @param id the session ID.
062     * @param surveyId the survey ID.
063     * @param user the user.
064     * @param ipAddress the user IP address.
065     * @param submittedAt the date of completion.
066     * @param answers the list of answers.
067     */
068    public SurveySession(int id, String surveyId, UserIdentity user, String ipAddress, Date submittedAt, List<SurveyAnswer> answers)
069    {
070        this._id = id;
071        this._surveyId = surveyId;
072        this._login = user != null ? user.getLogin() : null;
073        this._population = user != null ? user.getPopulationId() : null;
074        this._ipAddress = ipAddress;
075        this._submittedAt = submittedAt;
076        this._answers = answers;
077    }
078
079    /**
080     * Get the id.
081     * @return the id
082     */
083    public int getId()
084    {
085        return _id;
086    }
087
088    /**
089     * Set the id.
090     * @param id the id to set
091     */
092    public void setId(int id)
093    {
094        this._id = id;
095    }
096
097    /**
098     * Get the surveyId.
099     * @return the surveyId
100     */
101    public String getSurveyId()
102    {
103        return _surveyId;
104    }
105
106    /**
107     * Set the surveyId.
108     * @param surveyId the surveyId to set
109     */
110    public void setSurveyId(String surveyId)
111    {
112        this._surveyId = surveyId;
113    }
114
115    /**
116     * Get the login of the user answering the survey
117     * @return the user login
118     */
119    public String getLogin()
120    {
121        return _login;
122    }
123    
124    /**
125     * Set the login of the user answering the survey
126     * @param login the login
127     */
128    public void setLogin(String login)
129    {
130        _login = login;
131    }
132    
133    /**
134     * Get the population of the user answering the survey
135     * @return the user identity
136     */
137    public String getPopulation()
138    {
139        return _population;
140    }
141    
142    /**
143     * Set the population of the user answering the survey
144     * @param population the population
145     */
146    public void setPopulation(String population)
147    {
148        _population = population;
149    }
150
151    /**
152     * Set the identity of the user answering the survey
153     * @param user the user identity
154     */
155    public void setUser(UserIdentity user)
156    {
157        this._login = user != null ? user.getLogin() : "";
158        this._population = user != null ? user.getPopulationId() : "";
159    }
160    
161    /**
162     * Get the identity of the user answering the survey
163     * @return the user identity
164     */
165    public UserIdentity getUser()
166    {
167        if (this._login != null)
168        {
169            return new UserIdentity(this._login, this._population);
170        }
171        return null;
172    }
173
174    /**
175     * Get the ipAddress.
176     * @return the ipAddress
177     */
178    public String getIpAddress()
179    {
180        return _ipAddress;
181    }
182
183    /**
184     * Set the ipAddress.
185     * @param ipAddress the ipAddress to set
186     */
187    public void setIpAddress(String ipAddress)
188    {
189        this._ipAddress = ipAddress;
190    }
191
192    /**
193     * Get the submittedAt.
194     * @return the submittedAt
195     */
196    public Date getSubmittedAt()
197    {
198        return _submittedAt;
199    }
200
201    /**
202     * Set the submittedAt.
203     * @param submittedAt the submittedAt to set
204     */
205    public void setSubmittedAt(Date submittedAt)
206    {
207        this._submittedAt = submittedAt;
208    }
209
210    /**
211     * Get the answers.
212     * @return the answers
213     */
214    public List<? extends SurveyAnswer> getAnswers()
215    {
216        return _answers;
217    }
218    
219    /**
220     * Set the answers.
221     * @param answers the answers to set
222     */
223    public void setAnswers(List<SurveyAnswer> answers)
224    {
225        this._answers = answers;
226    }
227    
228}