Esempio n. 1
0
 public static void loadStatDay(PollModel pollModel, String day) throws Exception {
   PollStatDayDAO statDAO = PollDAOFactory.getInstance().getPollStatDayDAO();
   List<PollStatDayModel> list =
       statDAO.loadAllByPollAndDate(pollModel.getPollIndexModel().getIdPollIndex(), day);
   Iterator<PollStatDayModel> it = list.iterator();
   while (it.hasNext()) {
     PollStatDayModel statModel = it.next();
     pollModel.getStatMap().put(statModel.getIdPollOption().toString(), statModel);
   }
 }
Esempio n. 2
0
 public static boolean saveData(PollDataModel dataModel) throws Exception {
   PollDAOFactory daoFactory = PollDAOFactory.getInstance();
   PollDataDAO dataDAO = daoFactory.getPollDataDAO();
   PollAnswerDAO answerDAO = daoFactory.getPollAnswerDAO();
   dataModel.setIdPollData(dataDAO.generateId());
   dataModel.setDataTime(new Timestamp(System.currentTimeMillis()));
   Iterator<PollAnswerModel> itAnswer = dataModel.getListPollAnswer().iterator();
   List<OpDAO> listOp = new ArrayList<OpDAO>();
   listOp.add(dataDAO.newInsertOpDAO(dataModel));
   while (itAnswer.hasNext()) {
     PollAnswerModel answerModel = itAnswer.next();
     answerModel.setIdPollData(dataModel.getIdPollData());
     answerModel.setIdPollAnswer(answerDAO.generateId());
     listOp.add(answerDAO.newInsertOpDAO(answerModel));
   }
   return answerDAO.updateTransaction(listOp);
 }
Esempio n. 3
0
 public static PollModel loadQuestionary(String name) throws Exception {
   PollModel pollModel = new PollModel();
   PollDAOFactory daoFactory = PollDAOFactory.getInstance();
   PollIndexDAO indexDAO = daoFactory.getPollIndexDAO();
   PollQuestionDAO questionDAO = daoFactory.getPollQuestionDAO();
   PollOptionDAO optionDAO = daoFactory.getPollOptionDAO();
   // carico il questionario
   PollIndexModel indexModel = indexDAO.loadOneByName(name);
   pollModel.setPollIndexModel(indexModel);
   List<PollQuestionModel> listQuestion = questionDAO.loadAllByIndex(indexModel.getIdPollIndex());
   indexModel.setListPollQuestion(listQuestion);
   Iterator<PollQuestionModel> itQuestion = listQuestion.iterator();
   while (itQuestion.hasNext()) {
     PollQuestionModel questionModel = itQuestion.next();
     List<PollOptionModel> listOption =
         optionDAO.loadAllByQuestion(questionModel.getIdPollQuestion());
     Iterator<PollOptionModel> itOption = listOption.iterator();
     questionModel.setListPollOption(listOption);
     pollModel.populateOptionMap(questionModel);
     while (itOption.hasNext()) {
       PollOptionModel optionModel = itOption.next();
       if (optionModel.getIdPollOptionParent() != null
           && optionModel.getIdPollOptionParent().longValue() != 0
           && optionModel.getIdPollOptionParent().longValue()
               != optionModel.getIdPollOption().longValue()) {
         itOption.remove();
         PollOptionModel optionParentMadel =
             pollModel.getOptionMap().get(optionModel.getIdPollOptionParent().toString());
         List<PollOptionModel> kids = optionParentMadel.getListPollOptionKids();
         if (kids == null) {
           kids = new ArrayList<PollOptionModel>();
           optionParentMadel.setListPollOptionKids(kids);
         }
         kids.add(optionModel);
       }
     }
   }
   return pollModel;
 }