r3172 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
Author: tchemit Date: 2012-03-08 01:20:21 +0100 (Thu, 08 Mar 2012) New Revision: 3172 Url: http://chorem.org/repositories/revision/pollen/3172 Log: continue to clean Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-08 00:20:00 UTC (rev 3171) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-08 00:20:21 UTC (rev 3172) @@ -76,7 +76,7 @@ // add it to poll pollToUpdate.addComment(commentCreated); - commitTransaction("Could not create comment "+comment.getText()); + commitTransaction("Could not create comment " + comment.getText()); // feed notification @@ -109,7 +109,7 @@ //FIXME Should we also delete the associated pollAccount ? dao.delete(comment); - commitTransaction("Could not delete comment "+comment.getText()); + commitTransaction("Could not delete comment " + comment.getText()); } catch (TopiaException e) { throw new PollenTechnicalException(e); Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-08 00:20:00 UTC (rev 3171) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-08 00:20:21 UTC (rev 3172) @@ -29,25 +29,32 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.PollenFunctions; import org.chorem.pollen.bean.PollResult; import org.chorem.pollen.bean.PollResultList; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.Result; import org.chorem.pollen.business.persistence.ResultDAO; +import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.votecounting.business.NumberMethod; import org.chorem.pollen.votecounting.dto.ChoiceDTO; import org.chorem.pollen.votecounting.dto.PollDTO; +import org.chorem.pollen.votecounting.dto.PollExportDTO; import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO; -import org.chorem.pollen.votecounting.services.ServiceVoteCounting; -import org.chorem.pollen.votecounting.services.ServiceVoteCountingImpl; +import org.chorem.pollen.votecounting.services.ImportExportService; +import org.chorem.pollen.votecounting.services.VoteCountingService; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -65,32 +72,38 @@ /** log. */ private static final Log log = LogFactory.getLog(PollResultsService.class); - public PollResultList getGroupResults(String pollId) { - return generateResults(pollId, null, true, true); - } + public PollResultList getResults(String pollId) throws PollNotFoundException { - public PollResultList getNormalResults(String pollId) { - return generateResults(pollId, null, true, false); + PollService pollService = newService(PollService.class); + Poll poll = pollService.getPollByPollId(pollId); + + if (poll == null) { + throw new PollNotFoundException(); + } + PollResultList result; + if (poll.getPollType() == PollType.GROUP) { + result = generateResults(poll, null, true, true); + } else { + result = generateResults(poll, null, true, false); + } + return result; } /** * Génère les résultats d'un sondage (= un dépouillement). * - * @param pollId le sondage + * @param poll le sondage * @param voteCounting type de dépouillement * @param byGroup résultats par groupe * @param groupOnly résultats uniquement par groupe * @return les résultats du sondage */ - private PollResultList generateResults(String pollId, + private PollResultList generateResults(Poll poll, VoteCountingType voteCounting, boolean byGroup, boolean groupOnly) { - PollService pollService = newService(PollService.class); - Poll poll = pollService.getPollByPollId(pollId); -// DataResultConverter converter = new DataResultConverter(transaction); if (log.isDebugEnabled()) { log.debug(poll.getPollId() + " (" + voteCounting + ") has results: " + hasResults(poll, voteCounting)); @@ -99,7 +112,7 @@ // Dépouillement du sondage. // S'il n'existe pas de résultats ou si le sondage est encore ouvert. //if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) { - PollDTO dto = pollService.createPollDTOForVoteCounting(poll); + PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); if (voteCounting != null) { dto.setVoteCounting(voteCounting); @@ -108,15 +121,10 @@ // clear result (they will be regenerated ! (a big shame)) poll.clearResult(); - ServiceVoteCounting service = new ServiceVoteCountingImpl(); + VoteCountingService service = new VoteCountingService(); - VoteCountingResultDTO result; + VoteCountingResultDTO result = service.execute(dto); - if (PollType.GROUP == poll.getPollType()) { - result = service.executeGroupCounting(dto); - } else { - result = service.executeVoteCounting(dto); - } ResultDAO daoResult = getDAO(Result.class); for (ChoiceDTO choice : result.getChoices()) { @@ -178,6 +186,47 @@ return resultList; } + public String exportPolltoXml(String pollId) throws PollNotFoundException { + + // Recherche du sondage + + PollService pollService = newService(PollService.class); + + Poll poll = pollService.getPollByPollId(pollId); + + if (poll == null) { + throw new PollNotFoundException(); + } + + PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); + + VoteCountingService service = new VoteCountingService(); + + List<VoteCountingResultDTO> results = Lists.newArrayList(); + + VoteCountingResultDTO result = service.executeVoteCounting(dto); + + results.add(result); + + if (poll.getPollType() == PollType.GROUP) { + VoteCountingResultDTO groupResult = + service.executeGroupCounting(dto); + results.add(groupResult); + } + + // Transformation du sondage + PollExportDTO pollExport = new PollExportDTO(); + pollExport.setPollId(dto.getPollId()); + pollExport.setPoll(dto); + pollExport.setVoteCountingResults(results); + + // Export du sondage + ImportExportService serviceExport = new ImportExportService(); + String content = serviceExport.exportToXml(pollExport); + + return content; + } + /** * Retourne la liste des résultats d'un sondage sous forme de DTOs. * @@ -203,7 +252,8 @@ return results; } - public String getResultValue(Choice choice, Collection<PollResult> results) { + public String getResultValue(Choice choice, + Collection<PollResult> results) { String val = ""; for (PollResult result : results) { @@ -215,9 +265,10 @@ return val; } - public List<PollResult> createNumberVoteCountingResult(PollResultList resultListDTO, - Multimap<String, String> choicesResults, - Multimap<String, String> subtitles) { + public List<PollResult> createNumberVoteCountingResult( + PollResultList resultListDTO, + Multimap<String, String> choicesResults, + Multimap<String, String> subtitles) { Preconditions.checkNotNull(resultListDTO); Preconditions.checkNotNull(choicesResults); Preconditions.checkNotNull(subtitles); @@ -347,31 +398,32 @@ return val; } - /** - * Création des résultats de sondage à partir d'un dto de résultats de - * sondage. - * - * @param ePoll poll à remplir - * @param dto le dto des résultats de sondage. - */ - protected void populateResultEntities(Poll ePoll, VoteCountingResultDTO dto) { - for (ChoiceDTO choice : dto.getChoices()) { +// /** +// * Création des résultats de sondage à partir d'un dto de résultats de +// * sondage. +// * +// * @param ePoll poll à remplir +// * @param dto le dto des résultats de sondage. +// */ +// protected void populateResultEntities(Poll ePoll, +// VoteCountingResultDTO dto) { +// for (ChoiceDTO choice : dto.getChoices()) { +// +// ResultDAO daoResult = getDAO(Result.class); +// Result eResult = create(daoResult); +// +// Choice eChoice = ePoll.getChoiceByTopiaId(choice.getIdChoice()); +// +// ePoll.addResult(eResult); +// +// eResult.setName(eChoice.getName()); +// eResult.setByGroup(dto.isByGroup()); +// eResult.setPoll(ePoll); +// eResult.setResultValue(String.valueOf(choice.getValue())); +// eResult.setVoteCountingType(dto.getTypeVoteCounting()); +// } +// } - ResultDAO daoResult = getDAO(Result.class); - Result eResult = create(daoResult); - - Choice eChoice = ePoll.getChoiceByTopiaId(choice.getIdChoice()); - - ePoll.addResult(eResult); - - eResult.setName(eChoice.getName()); - eResult.setByGroup(dto.isByGroup()); - eResult.setPoll(ePoll); - eResult.setResultValue(String.valueOf(choice.getValue())); - eResult.setVoteCountingType(dto.getTypeVoteCounting()); - } - } - /** * Retourne vrai si le sondage a des résultats. * @@ -398,166 +450,6 @@ return hasresult; } -// public PollResultList getAllResults(String pollId) { -// return getResults(pollId, null, false, false); -// } -// -// public PollResultList getResultsByVoteCounting(String pollId, -// VoteCountingType voteCounting) { -// return getResults(pollId, voteCounting, false, false); -// } -// -// /** -// * Récupère les résultats d'un sondage (sans rien dépouiller). -// * -// * @param pollId le sondage -// * @param voteCounting type de dépouillement -// * @param byGroup résultats par groupe -// * @param groupOnly résultats uniquement par groupe -// * @return les résultats du sondage -// */ -// private PollResultList getResults(String pollId, -// VoteCountingType voteCounting, -// boolean byGroup, -// boolean groupOnly) { -// -// PollService pollService = newService(PollService.class); -// Poll poll = pollService.getPollByPollId(pollId); -// -//// DataResultConverter converter = new DataResultConverter(transaction); -// if (log.isDebugEnabled()) { -// log.debug(poll.getPollId() + " (" + voteCounting -// + ") has results: " + hasResults(poll, voteCounting)); -// } -// -// // Dépouillement du sondage. -// // S'il n'existe pas de résultats ou si le sondage est encore ouvert. -// //if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) { -// PollDTO dto = pollService.createPollDTOForVoteCounting(poll); -// -// if (voteCounting != null) { -// dto.setVoteCounting(voteCounting); -// } -// -//// // clear result (they will be regenerated ! (a big shame)) -//// poll.clearResult(); -// -//// ServiceVoteCounting service = new ServiceVoteCountingImpl(); -//// -//// VoteCountingResultDTO result; -//// -//// if (PollType.GROUP == poll.getPollType()) { -//// result = service.executeGroupCounting(dto); -//// } else { -//// result = service.executeVoteCounting(dto); -//// } -//// for (ChoiceDTO choice : result.getChoices()) { -//// -//// ResultDAO daoResult = getDAO(Result.class); -//// Result eResult = create(daoResult); -//// -//// Choice eChoice = poll.getChoiceByTopiaId(choice.getIdChoice()); -//// -//// poll.addResult(eResult); -//// -//// eResult.setName(eChoice.getName()); -//// eResult.setByGroup(result.isByGroup()); -//// eResult.setPoll(poll); -//// eResult.setResultValue(String.valueOf(choice.getValue())); -//// eResult.setVoteCountingType(result.getTypeVoteCounting()); -//// } -// -// // Conversion et trie des résultats -// List<PollResult> list = createPollResults(poll); -// -// VoteCountingType voteCountingType = poll.getVoteCountingType(); -// -// Iterator<PollResult> it = list.iterator(); -// while (it.hasNext()) { -// PollResult currentResult = it.next(); -// -// // Cas d'un dépouillement particulier -// // Suppression des resultats qui ne sont pas de se dépouillement -// if (voteCounting != null -// && currentResult.getVoteCountingType() != voteCounting) { -// it.remove(); -// } -// -// // Cas d'un sondage de type GROUP avec filtre -// if (byGroup) { -// -// // Filtre group : Suppression resultats non group -// if (groupOnly && !currentResult.isByGroup()) { -// it.remove(); -// } -// -// // Filtre non group : Suppression resultats group -// else if (!groupOnly && currentResult.isByGroup()) { -// it.remove(); -// } -// -// // Suppression des autres resultats de depouillements differents -// if (currentResult.getVoteCountingType() != voteCountingType) { -// it.remove(); -// } -// } -// } -// -// PollResultList resultListDTO = new PollResultList(); -// resultListDTO.setPollResults(list); -// resultListDTO.setVoteCountingResult(null); -// -// return resultListDTO; -// } -// -// public String exportPoll(String pollId) { -// TopiaContext transaction = getTransaction(); -// try { -// -// // Recherche du sondage -// PollDAO daoPoll = PollenDAOHelper.getPollDAO(transaction); -// Poll ePoll = daoPoll.findByPollId(pollId); -// -// // Dépouillement du sondage. -// DataResultConverter converter = new DataResultConverter(transaction); -// PollDTO dto = DataVoteCountingConverter -// .createPollDTOForVoteCounting(ePoll); -// -// ePoll.clearResult(); -// -// ServiceVoteCounting service = new ServiceVoteCountingImpl(); -// List<VoteCountingResultDTO> results = new ArrayList<VoteCountingResultDTO>(); -// VoteCountingResultDTO result = service.executeVoteCounting(dto); -// converter.populateResultEntities(result); -// results.add(result); -// -// if (EnumController.isGroupType(ePoll)) { -// VoteCountingResultDTO groupResult = service -// .executeGroupCounting(dto); -// converter.populateResultEntities(groupResult); -// results.add(groupResult); -// } -// -// // Transformation du sondage -// PollExportDTO pollExport = new PollExportDTO(); -// pollExport.setPollId(pollId); -// pollExport.setPoll(dto); -// pollExport.setVoteCountingResults(results); -// -// // Export du sondage -// ServiceExport serviceExport = new ServiceExportImpl(); -// String filename = serviceExport.executeExport(pollExport); -// -// if (log.isInfoEnabled()) { -// log.info("Poll exported: " + pollId); -// } -// -// return filename; -// } catch (Exception e) { -// throw new PollenTechnicalException("Could not export results", e); -// } -// } - // public String importPoll(String filePath) { // return importPoll(filePath, null); // } @@ -588,31 +480,31 @@ // return topiaId; // } -// /** -// * Retourne une chaîne contenant les résultats du sondage. -// * -// * @param poll le sondage -// * @param results les résultats du sondage -// * @return les résultats sous forme de chaine de caractères -// */ -// public String getResultsAsString(Poll poll, Collection<Result> results) { -// -// DateFormat dateFormat = new SimpleDateFormat(); -// StringBuilder res = new StringBuilder(""); -// Iterator<Result> it = results.iterator(); -// while (it.hasNext()) { -// Result result = it.next(); -// if (poll.getChoiceType() == ChoiceType.DATE) { -// Date date = new Date(Long.parseLong(result.getName())); -// res.append(dateFormat.format(date)); -// } else { -// res.append(result.getName()); -// } -// res.append("=").append(removeTrailing0(result.getResultValue())); -// if (it.hasNext()) { -// res.append(", "); -// } -// } -// return res.toString(); -// } + /** + * Retourne une chaîne contenant les résultats du sondage. + * + * @param poll le sondage + * @param results les résultats du sondage + * @return les résultats sous forme de chaine de caractères + */ + public String getResultsAsString(Poll poll, Collection<Result> results) { + + DateFormat dateFormat = new SimpleDateFormat(); + StringBuilder res = new StringBuilder(""); + Iterator<Result> it = results.iterator(); + while (it.hasNext()) { + Result result = it.next(); + if (poll.getChoiceType() == ChoiceType.DATE) { + Date date = new Date(Long.parseLong(result.getName())); + res.append(dateFormat.format(date)); + } else { + res.append(result.getName()); + } + res.append("=").append(removeTrailing0(result.getResultValue())); + if (it.hasNext()) { + res.append(", "); + } + } + return res.toString(); + } } Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-08 00:20:00 UTC (rev 3171) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-08 00:20:21 UTC (rev 3172) @@ -34,7 +34,6 @@ import org.chorem.pollen.bean.PollImageChoice; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.ChoiceDAO; -import org.chorem.pollen.business.persistence.Comment; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.PersonToListDAO; import org.chorem.pollen.business.persistence.Poll; @@ -46,7 +45,6 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteDAO; -import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListDAO; import org.chorem.pollen.common.ChoiceType; @@ -55,13 +53,6 @@ import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.services.exceptions.PollVoteNotFoundException; -import org.chorem.pollen.votecounting.business.NumberMethod; -import org.chorem.pollen.votecounting.dto.CommentDTO; -import org.chorem.pollen.votecounting.dto.PollChoiceDTO; -import org.chorem.pollen.votecounting.dto.PollDTO; -import org.chorem.pollen.votecounting.dto.VoteToChoiceDTO; -import org.chorem.pollen.votecounting.dto.VotingGroupDTO; -import org.chorem.pollen.votecounting.dto.VotingPersonDTO; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.web.struts2.FilterPagerUtil; @@ -82,11 +73,6 @@ /** Logger. */ private static final Log log = LogFactory.getLog(PollService.class); - - /** Représente l'action qui envoi un email de notification. */ - public static final String RULE_EMAIL_ACTION = "emailAction"; - - /** * Build a new Poll instance with given {@code user} as administrator * @@ -261,12 +247,13 @@ commitTransaction("Could not create poll " + poll.getTitle()); String pollVoteUrl = getPollVoteUrl(poll); + String pollEditUrl = getPollEditUrl(poll); // email notification EmailService emailService = newService(EmailService.class); emailService.onPollCreated(poll, pollVoteUrl, - getPollEditUrl(poll)); + pollEditUrl); // feed notification PollFeedService pollFeedService = newService(PollFeedService.class); @@ -295,21 +282,7 @@ url.append(':').append(poll.getCreator().getAccountId()); return url.toString(); } - /* - private void addFeedEntry() { - PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId()); - String voteURL = siteURL + "poll/votefor/" + poll.getPollId(); - File feedFile = feedContext.getFile(poll.getPollId()); - FeedUtil.createFeed(feedFile, "atom_1.0", messages.format( - "pollFeed_title", poll.getTitle()), siteURL, messages.format( - "pollFeed_desc", poll.getDescription())); - FeedUtil.feedFeed(feedFile, messages.format("pollFeed_createTitle", - creator.getVotingId()), voteURL, messages - .get("pollFeed_createContent")); - } - */ - public List<Poll> getPolls(FilterPagerUtil.FilterPagerBean pager) { Preconditions.checkNotNull(pager); @@ -331,7 +304,8 @@ } } - public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) { + public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager, + UserAccount user) { Preconditions.checkNotNull(pager); Preconditions.checkNotNull(user); @@ -354,13 +328,15 @@ } } - public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) { + public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager, + UserAccount user) { Preconditions.checkNotNull(pager); Preconditions.checkNotNull(user); UserService userService = newService(UserService.class); - UserAccount userToUse = userService.getEntityById(UserAccount.class, user.getTopiaId()); + UserAccount userToUse = userService.getEntityById(UserAccount.class, + user.getTopiaId()); //FIXME Use a query to do this to avoid in memory pagination String email = userToUse.getEmail(); @@ -423,22 +399,6 @@ UserAccount userToUse = userService.getEntityById(UserAccount.class, user.getTopiaId()); -// List<Poll> allPolls = Lists.newArraPagerUtil.computeRecordIndexesAndPagesNumber(pager);yList(); -// for (PollAccount pollAccount : userToUse.getPollAccount()) { -// for (Vote vote : pollAccount.getVote()) { -// Poll poll = vote.getPoll(); -// if (!allPolls.contains(poll)) { -// allPolls.add(poll); -// } -// } -// } -// int records = allPolls.size(); -// pager.setRecords(records); -// PagerUtil.computeRecordIndexesAndPagesNumber(pager); -// List<Poll> result = FilterPagerUtil.getPageFromList(allPolls, pager); -// return result; - - PollDAO pollDao = getDAO(Poll.class); VoteDAO voteDao = getDAO(Vote.class); @@ -454,10 +414,6 @@ TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery, pager); -// query.addDistinct(); -// query.setSelect("e." + Vote.PROPERTY_POLL); -// query.addWhere("e." + Vote.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, userToUse); - List<Poll> result = pollDao.findAllByQuery(query); return result; } catch (TopiaException e) { @@ -609,111 +565,6 @@ } } - public PollDTO createPollDTOForVoteCounting(Poll poll) { - PollDTO result = new PollDTO(poll.getPollId()); - result.setTitle(poll.getTitle()); - result.setDescription(poll.getDescription()); - result.setBeginChoiceDate(poll.getBeginChoiceDate()); - result.setBeginDate(poll.getBeginDate()); - result.setEndDate(poll.getEndDate()); - result.setAnonymous(poll.isAnonymous()); - result.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed()); - result.setPublicResults(poll.isPublicResults()); - result.setContinuousResults(poll.isContinuousResults()); - result.setChoiceAddAllowed(poll.isChoiceAddAllowed()); - result.setClosed(poll.isClosed()); - result.setCreatorId(poll.getCreator().getVotingId()); - result.setCreatorEmail(poll.getCreator().getEmail()); - result.setMaxChoiceNb(poll.getMaxChoiceNb()); - result.setPollType(poll.getPollType()); - result.setChoiceType(poll.getChoiceType()); - result.setVoteCounting(poll.getVoteCountingType()); - - for (Comment comment : poll.getComment()) { - result.getComments().add(createPollCommentDTO(comment)); - } - for (Choice choice : poll.getChoice()) { - result.getChoices().add(createPollChoiceDTO(choice)); - } - if (poll.getVotingList() != null && !poll.getVotingList().isEmpty()) { - for (VotingList list : poll.getVotingList()) { - result.getVotingGroups().add(createVotingGroupDTO(list)); - } - } else { - // un groupe par défaut si il y en a pas - VotingGroupDTO group = new VotingGroupDTO("unique", 1); - group.setName("unique"); - for (Vote vote : poll.getVote()) { - group.getVotingPersons().add(createVotingPersonDTO(vote)); - } - result.getVotingGroups().add(group); - } - return result; - } - - private CommentDTO createPollCommentDTO(Comment comment) { - CommentDTO commentDTO = new CommentDTO( - comment.getPollAccount().getVotingId(), comment.getText()); - return commentDTO; - } - - private PollChoiceDTO createPollChoiceDTO(Choice choice) { - PollChoiceDTO choiceDTO = new PollChoiceDTO(choice.getTopiaId()); - String choiceName = choice.getName(); - choiceDTO.setName(choiceName); - choiceDTO.setHidden(choiceName != null && - choiceName.startsWith(NumberMethod.HIDDEN_PREFIX)); - choiceDTO.setDescription(choice.getDescription()); - return choiceDTO; - } - - private VotingGroupDTO createVotingGroupDTO(VotingList list) { - VotingGroupDTO group = new VotingGroupDTO(list.getTopiaId(), list - .getWeight()); - group.setName(list.getName()); - - for (PersonToList pToList : list.getPollAccountPersonToList()) { - Vote vote = getPollVoteByPollAccount(list.getPoll(), pToList - .getPollAccount()); - if (vote != null) { - // Pas de vote pour cette personne : doit engendrer erreur ?!? - group.getVotingPersons().add(createVotingPersonDTO(vote)); - } - } - return group; - } - - private VotingPersonDTO createVotingPersonDTO(Vote vote) { - VotingPersonDTO votingPerson = new VotingPersonDTO(vote - .getPollAccount().getVotingId(), vote.getWeight()); - votingPerson.setEmail(vote.getPollAccount().getEmail()); - - for (VoteToChoice vToChoice : vote.getChoiceVoteToChoice()) { - if (vToChoice != null && vToChoice.getChoice() != null) { - votingPerson.getChoices().add(createVoteToChoiceDTO(vToChoice)); - } - } - return votingPerson; - } - - private VoteToChoiceDTO createVoteToChoiceDTO(VoteToChoice vToChoice) { - String topiaId = vToChoice.getChoice().getTopiaId(); - VoteToChoiceDTO vote = new VoteToChoiceDTO(topiaId, vToChoice - .getVoteValue()); - - return vote; - } - - /* A Deplacer au bon endroit (PollImpl) si c'est possible */ - private static Vote getPollVoteByPollAccount(Poll poll, PollAccount account) { - for (Vote vote : poll.getVote()) { - if (account.getTopiaId().equals(vote.getPollAccount().getTopiaId())) { - return vote; - } - } - return null; - } - public File getPollChoiceImageFile(String pollId, String choiceId, boolean thumb) { @@ -742,9 +593,12 @@ String location = choice.getLocation(); - File pollChoiceImage = getPollChoiceImageFile(poll.getPollId(), choice.getName(), false); - File pollChoiceImageThumb = getPollChoiceImageFile(poll.getPollId(), choice.getName(), true); + String pollId = poll.getPollId(); + String name = choice.getName(); + File pollChoiceImage = getPollChoiceImageFile(pollId, name, false); + File pollChoiceImageThumb = getPollChoiceImageFile(pollId, name, true); + FileUtils.copyFile(new File(location), pollChoiceImage); createThumbnail(pollChoiceImage, pollChoiceImageThumb, 100); } Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java 2012-03-08 00:20:00 UTC (rev 3171) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java 2012-03-08 00:20:21 UTC (rev 3172) @@ -28,7 +28,6 @@ import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PreventRule; -import org.chorem.pollen.business.persistence.PreventRuleDAO; import org.chorem.pollen.services.PollenServiceSupport; import java.util.Date; @@ -45,8 +44,7 @@ private static final Log log = LogFactory.getLog(PreventRuleService.class); public PreventRule createAddVotePreventRule() { - PreventRuleDAO dao = getDAO(PreventRule.class); - PreventRule rule = newInstance(dao); + PreventRule rule = newInstance(getDAO(PreventRule.class)); rule.setScope("vote"); rule.setSensibility(1); rule.setRepeated(true); @@ -54,8 +52,7 @@ } public PreventRule createRemindPreventRule(int sensibility) { - PreventRuleDAO dao = getDAO(PreventRule.class); - PreventRule rule = newInstance(dao); + PreventRule rule = newInstance(getDAO(PreventRule.class)); rule.setScope("rappel"); rule.setSensibility(sensibility); rule.setRepeated(false); Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-08 00:20:00 UTC (rev 3171) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-08 00:20:21 UTC (rev 3172) @@ -44,12 +44,9 @@ import org.nuiton.util.beans.Binder; import org.nuiton.web.struts2.FilterPagerUtil; -import java.net.URL; import java.util.List; -import java.util.Locale; import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.l_; public class UserService extends PollenServiceSupport { Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-08 00:20:00 UTC (rev 3171) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-08 00:20:21 UTC (rev 3172) @@ -47,114 +47,103 @@ /** Logger. */ private static final Log log = LogFactory.getLog(VoteService.class); - public String createVote(Vote vote, PollAccount pollAccount) { - TopiaContext transaction = getTransaction(); + public void createVote(Vote vote, PollAccount pollAccount) { - String topiaId; - try { - - // création du compte associé au vote s'il n'existe pas - // sinon mise à jour du compte - //ServicePollAccount spa = new ServicePollAccountImpl(); - if (pollAccount == null) { - vote.setPollAccount(null); - } else { + // création du compte associé au vote s'il n'existe pas + // sinon mise à jour du compte + //ServicePollAccount spa = new ServicePollAccountImpl(); + if (pollAccount == null) { + vote.setPollAccount(null); + } else { // pollAccount.setHasVoted(true); - PollAccountDAO pollAccountDAO = - PollenDAOHelper.getPollAccountDAO(transaction); + PollAccountDAO pollAccountDAO = + getDAO(PollAccount.class); - PollAccount pollAccountEntity = - pollAccountDAO.findByTopiaId(pollAccount.getTopiaId()); + PollAccount pollAccountEntity = + getEntityById(PollAccount.class, pollAccount.getTopiaId()); // PollAccountDTO account = spa.findPollAccountById(pollAccountDTO // .getId()); - if (pollAccountEntity == null) { - log.debug("Nouveau compte associé au vote"); - pollAccountEntity = pollAccountDAO.create(); + if (pollAccountEntity == null) { + log.debug("Nouveau compte associé au vote"); + pollAccountEntity = create(pollAccountDAO); // voteDTO.setPollAccountId(spa // .createPollAccount(pollAccountDTO)); - } else { - log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId()); - //spa.updatePollAccount(pollAccountDTO); - //voteDTO.setPollAccountId(account.getId()); + } else { + log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId()); + //spa.updatePollAccount(pollAccountDTO); + //voteDTO.setPollAccountId(account.getId()); - } - // Fill pollAccountEntity from DTO in argument + } + // Fill pollAccountEntity from DTO in argument // DataPollAccountConverter pollAccountConverter = new DataPollAccountConverter(); // pollAccountConverter.setTransaction(transaction); // pollAccountConverter.populatePollAccountEntity(pollAccountDTO, // pollAccountEntity); - // Update pollAccountEntity - pollAccountDAO.update(pollAccountEntity); + // Update pollAccountEntity +// pollAccountDAO.update(pollAccountEntity); - vote.setPollAccount(pollAccountEntity); + vote.setPollAccount(pollAccountEntity); // vote.setVotingListId(pollAccount.getVotingListId()); // vote.setWeight(pollAccount.getWeight()); - log.debug("Poids du vote : " + vote.getWeight()); - } + log.debug("Poids du vote : " + vote.getWeight()); + } - VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction); + VoteDAO voteDAO = getDAO(Vote.class); - Vote voteEntity = voteDAO.create(); + Vote voteEntity = create(voteDAO); // converter.setTransaction(transaction); // converter.populateVoteEntity(vote, voteEntity); // converter.populateChoiceVote(vote, voteEntity); - topiaId = voteEntity.getTopiaId(); - if (log.isDebugEnabled()) { - log.debug("Entity created: " + topiaId); - } - - return topiaId; - } catch (Exception e) { - throw new PollenTechnicalException("Could not obtain votes", e); + if (log.isDebugEnabled()) { + log.debug("Entity created: " + voteEntity.getTopiaId()); } + + commitTransaction("Could not create vote"); + + // email notification + + // feed notification + + } - public boolean updateVote(Vote vote) { - TopiaContext transaction = getTransaction(); - try { + public void updateVote(Vote vote) throws VoteNotFoundException { - VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction); - Vote voteEntity = voteDAO.findByTopiaId(vote.getTopiaId()); + Vote entityToUpdate = getEntityById(Vote.class, vote.getTopiaId()); + + if (entityToUpdate == null) { + throw new VoteNotFoundException(); + } // converter.setTransaction(transaction); // converter.populateVoteEntity(voteDTO, voteEntity); - voteDAO.update(voteEntity); - if (log.isDebugEnabled()) { - log.debug("Entity updated: " + vote.getTopiaId()); - } - - return true; - } catch (Exception e) { - throw new PollenTechnicalException("Could not update vote", e); + if (log.isDebugEnabled()) { + log.debug("Entity updated: " + vote.getTopiaId()); } + commitTransaction("Could not update vote"); + } - public boolean deleteVote(String voteId) { - TopiaContext transaction = getTransaction(); - try { + public void deleteVote(String voteId) throws VoteNotFoundException { - VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction); - Vote voteEntity = voteDAO.findByTopiaId(voteId); + Vote entityToDelete = getEntityById(Vote.class, voteId); - if (voteEntity == null) { - throw new VoteNotFoundException(); - } + if (entityToDelete == null) { + throw new VoteNotFoundException(); + } - voteDAO.delete(voteEntity); + delete(getDAO(Vote.class), entityToDelete); - if (log.isDebugEnabled()) { - log.debug("Entity deleted: " + voteId); - } - - return true; - } catch (Exception e) { - throw new PollenTechnicalException("Could not obtain votes", e); + if (log.isDebugEnabled()) { + log.debug("Entity deleted: " + voteId); } + + commitTransaction("Could not delete vote"); } public List<Vote> getVotesByPoll(Poll poll,
participants (1)
-
tchemit@users.chorem.org