Rev 1310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | jmachado | 1 | package pt.estgp.estgweb.services.surveys; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import pt.estgp.estgweb.domain.*; |
||
5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
6 | import pt.estgp.estgweb.domain.views.*; |
||
7 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
8 | |||
9 | import java.util.Date; |
||
10 | import java.util.List; |
||
11 | |||
12 | /** |
||
13 | * @author: Duarte Santos |
||
14 | * @date: 05-08-2011 |
||
15 | * @time: 17:06 |
||
16 | * @email: a12564 [at] estgp [dot] pt |
||
17 | */ |
||
18 | |||
19 | public class InsertSurveyAnswersService implements IService |
||
20 | { |
||
21 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(InsertSurveyAnswersService.class); |
||
22 | |||
23 | private LoadSurveyService loadSurveyService = new LoadSurveyService(); |
||
24 | |||
684 | jmachado | 25 | public SurveyView run(long responseId, SurveyView surveyView, UserSession userSession) |
671 | jmachado | 26 | { |
27 | SurveyResponse response = DaoFactory.getSurveyResponseDaoImpl().load(responseId); |
||
28 | |||
29 | if(response.isAnswered()) return null; |
||
30 | |||
31 | for(SurveyQuestionView qView : surveyView.getQuestions()) |
||
32 | { |
||
33 | for(SurveyQuestionItemView iView : qView.getItems()) |
||
34 | { |
||
35 | for(SurveyQuestionCandidateAnswerView cView : iView.getCandidates()) |
||
36 | { |
||
37 | for(SurveyQuestionAnswerView aView : cView.getAnswers()) |
||
38 | { |
||
39 | if(aView.getId() <= 0) |
||
40 | { |
||
41 | SurveyQuestionAnswerImpl a = DomainObjectFactory.createSurveyQuestionAnswerImpl(); |
||
42 | aView.persistViewInObject(a); |
||
43 | |||
44 | SurveyQuestionCandidateAnswerImpl c = (SurveyQuestionCandidateAnswerImpl) DaoFactory.getSurveyQuestionCandidateAnswerDaoImpl().load(cView.getId()); |
||
45 | |||
46 | a.setCandidateAnswer(c); |
||
47 | a.setResponse(response); |
||
48 | |||
49 | DaoFactory.getSurveyQuestionAnswerDaoImpl().save(a); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | response.setDate(new 5+0%2Fdocs%2Fapi+Date">Date()); |
||
57 | response.setAnswered(true); |
||
58 | |||
684 | jmachado | 59 | logger.info("Answer inserted to survey with id: "+surveyView.getId()); |
60 | |||
671 | jmachado | 61 | return loadSurveyService.run(surveyView.getId(), userSession); |
62 | } |
||
63 | } |