KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > bizlogic > SurveyBL


1 /*
2 -- GeiNuke --
3 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
4 http://www.hostingjava.it/-geinuke/
5
6 This file is part of GeiNuke.
7
8    GeiNuke is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GeiNuke is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GeiNuke; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */

22 package com.geinuke.bizlogic;
23
24 import java.sql.SQLException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import com.geinuke.dao.*;
28 import com.geinuke.middle.ISurveyBL;
29 import com.geinuke.vo.SurveyAnswerVO;
30 import com.geinuke.vo.SurveyVO;
31 import com.geinuke.vo.SurveyVoteVO;
32
33
34 public class SurveyBL implements ISurveyBL{
35
36     public void delSurveyAnswerByAID(int aid) throws BLException {
37         try{
38             SurveyDAO dao=new SurveyDAO();
39             dao.delSurveyAnswerByAID(aid);
40             
41         }catch(SQLException JavaDoc sqle){
42             throw new DBException(sqle.getMessage());
43         }catch(Throwable JavaDoc t){
44             throw new BLException(t.getMessage());
45         }
46         
47     }
48
49     
50     public void delSurveyAnswersByESID(int esid) throws BLException {
51         try{
52             SurveyDAO dao=new SurveyDAO();
53             dao.delSurveyAnswersByESID(esid);
54             
55         }catch(SQLException JavaDoc sqle){
56             throw new DBException(sqle.getMessage());
57         }catch(Throwable JavaDoc t){
58             throw new BLException(t.getMessage());
59         }
60         
61     }
62
63     
64     public void delSurveyBySID(int sid) throws BLException {
65         try{
66             SurveyDAO dao=new SurveyDAO();
67             dao.delSurveyBySID(sid);
68             dao.delSurveyAnswersByESID(sid);
69         }catch(SQLException JavaDoc sqle){
70             throw new DBException(sqle.getMessage());
71         }catch(Throwable JavaDoc t){
72             throw new BLException(t.getMessage());
73         }
74         
75     }
76
77     
78     public SurveyVO getSurveyBySID(int sid) throws BLException {
79         SurveyVO s=null;
80         
81         try{
82             SurveyDAO dao=new SurveyDAO();
83             s=dao.getSurveyBySID(sid);
84             s.setAnswers(dao.getSurveyAnswersByESID(s.getSid()));
85             
86         }catch(SQLException JavaDoc sqle){
87             throw new DBException(sqle.getMessage());
88         }catch(Throwable JavaDoc t){
89             throw new BLException(t.getMessage());
90         }
91         return s;
92     }
93
94     
95     public ArrayList JavaDoc getSurveys() throws BLException {
96         ArrayList JavaDoc ll=null;
97         try{
98             SurveyDAO dao=new SurveyDAO();
99             ll=dao.getSurveys();
100             this.fillSurveys(ll);
101         }catch(SQLException JavaDoc sqle){
102             throw new DBException(sqle.getMessage());
103         }catch(Throwable JavaDoc t){
104             throw new BLException(t.getMessage());
105         }
106         return ll;
107     }
108     
109     protected void fillSurvey(SurveyVO su)throws BLException{
110         su.setAnswers(this.getSurveyAnswersByESID(su.getSid()));
111     }
112     
113     protected void fillSurveys(ArrayList JavaDoc list)throws BLException{
114         SurveyVO su=null;
115         for(int i=0;i<list.size();i++){
116             su=(SurveyVO)list.get(i);
117             this.fillSurvey(su);
118         }
119     }
120     
121     public ArrayList JavaDoc getSurveysByStatus(int status ) throws BLException {
122         ArrayList JavaDoc ll=null;
123         try{
124             SurveyDAO dao=new SurveyDAO();
125             ll=dao.getSurveysByStatus(status);
126             if(status==SurveyVO.STATUS_CURRENT){
127                 if(ll==null || ll.size()==0)
128                     ll=dao.getSurveysByStatus(SurveyVO.STATUS_ENABLED);
129             }
130             
131         }catch(SQLException JavaDoc sqle){
132             throw new DBException(sqle.getMessage());
133         }catch(Throwable JavaDoc t){
134             throw new BLException(t.getMessage());
135         }
136         return ll;
137     }
138     
139     public ArrayList JavaDoc getSurveyAnswersByESID(int sid) throws BLException {
140         ArrayList JavaDoc ll=null;
141         try{
142             SurveyDAO dao=new SurveyDAO();
143             ll=dao.getSurveyAnswersByESID(sid);
144             
145         }catch(SQLException JavaDoc sqle){
146             throw new DBException(sqle.getMessage());
147         }catch(Throwable JavaDoc t){
148             throw new BLException(t.getMessage());
149         }
150         return ll;
151     }
152
153     
154     public void insertSurvey(SurveyVO s) throws BLException {
155         try{
156             SurveyDAO dao=new SurveyDAO();
157             dao.insertSurvey(s);
158             ArrayList JavaDoc list=s.getAnswers();
159             SurveyAnswerVO sa=null;
160             for(int i=0;i<list.size();i++){
161                 sa=(SurveyAnswerVO)list.get(i);
162                 sa.setEsid(s.getSid());
163                 this.insertSurveyAnswer(sa);
164             }
165         }catch(SQLException JavaDoc sqle){
166             throw new DBException(sqle.getMessage());
167         }catch(Throwable JavaDoc t){
168             throw new BLException(t.getMessage());
169         }
170         
171     }
172
173     
174     public void insertSurveyAnswer(SurveyAnswerVO sa) throws BLException {
175         try{
176             SurveyDAO dao=new SurveyDAO();
177             dao.insertSurveyAnswer(sa);
178             
179         }catch(SQLException JavaDoc sqle){
180             throw new DBException(sqle.getMessage());
181         }catch(Throwable JavaDoc t){
182             throw new BLException(t.getMessage());
183         }
184         
185     }
186
187
188     public void updateSurveyAnswerVO(SurveyAnswerVO sa) throws BLException {
189         try{
190             SurveyDAO dao=new SurveyDAO();
191             dao.updateSurveyAnswerVO(sa);
192         }catch(SQLException JavaDoc sqle){
193             throw new DBException(sqle.getMessage());
194         }catch(Throwable JavaDoc t){
195             throw new BLException(t.getMessage());
196         }
197         
198     }
199     
200     public void updateSurveyVO(SurveyVO su) throws BLException {
201         try{
202             SurveyDAO dao=new SurveyDAO();
203             dao.updateSurveyVO(su);
204         }catch(SQLException JavaDoc sqle){
205             throw new DBException(sqle.getMessage());
206         }catch(Throwable JavaDoc t){
207             throw new BLException(t.getMessage());
208         }
209         
210     }
211     
212     public void updateSurveyVOStatus(int sid) throws BLException {
213         try{
214             SurveyDAO dao=new SurveyDAO();
215             SurveyVO su=dao.getSurveyBySID(sid);
216             int cStatus=su.getSStatus();
217             if(cStatus==0){
218                 su.setSStatus(cStatus+1);
219             }else if(cStatus==1){
220                 su.setSStatus(cStatus+1);
221             }else if(cStatus==2){
222                 su.setSStatus(0);
223             }
224             dao.updateSurveyVO(su);
225         }catch(SQLException JavaDoc sqle){
226             throw new DBException(sqle.getMessage());
227         }catch(Throwable JavaDoc t){
228             throw new BLException(t.getMessage());
229         }
230         
231     }
232
233
234     public boolean checkVote(int sid, int uid) throws BLException {
235         try{
236             SurveyDAO dao=new SurveyDAO();
237             
238             return dao.checkVote(sid,uid);
239         }catch(SQLException JavaDoc sqle){
240             throw new DBException(sqle.getMessage());
241         }catch(Throwable JavaDoc t){
242             throw new BLException(t.getMessage());
243         }
244     }
245
246
247     
248     public boolean checkVote(int sid, String JavaDoc ip) throws BLException {
249         try{
250             SurveyDAO dao=new SurveyDAO();
251             
252             return dao.checkVote(sid,ip);
253         }catch(SQLException JavaDoc sqle){
254             throw new DBException(sqle.getMessage());
255         }catch(Throwable JavaDoc t){
256             throw new BLException(t.getMessage());
257         }
258     }
259     
260     public void insertVote(SurveyVoteVO vo) throws BLException{
261         try{
262             SurveyDAO dao=new SurveyDAO();
263             dao.insertVote(vo);
264         }catch(SQLException JavaDoc sqle){
265             throw new DBException(sqle.getMessage());
266         }catch(Throwable JavaDoc t){
267             throw new BLException(t.getMessage());
268         }
269     }
270
271 }
272
Popular Tags