Author: fdesbois Date: 2009-12-10 19:37:55 +0100 (Thu, 10 Dec 2009) New Revision: 2814 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java Log: Ano #87 : problem with vote modification Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2009-12-09 19:11:58 UTC (rev 2813) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2009-12-10 18:37:55 UTC (rev 2814) @@ -21,9 +21,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.converters.DataPollAccountConverter; import org.chorem.pollen.business.converters.DataVoteConverter; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.VoteDTO; +import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.PollAccountDAO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteDAO; @@ -57,20 +60,36 @@ // création du compte associé au vote s'il n'existe pas // sinon mise à jour du compte - ServicePollAccount spa = new ServicePollAccountImpl(); + //ServicePollAccount spa = new ServicePollAccountImpl(); if (pollAccountDTO != null) { pollAccountDTO.setHasVoted(true); - PollAccountDTO account = spa.findPollAccountById(pollAccountDTO - .getId()); - if (account != null) { - log.debug("Compte associé au vote : " + account.getId()); - spa.updatePollAccount(pollAccountDTO); - voteDTO.setPollAccountId(account.getId()); + PollAccountDAO pollAccountDAO = PollenModelDAOHelper.getPollAccountDAO(transaction); + + PollAccount pollAccountEntity = + pollAccountDAO.findByTopiaId(pollAccountDTO.getId()); + +// PollAccountDTO account = spa.findPollAccountById(pollAccountDTO +// .getId()); + if (pollAccountEntity == null) { + log.debug("Nouveau compte associé au vote"); + pollAccountEntity = pollAccountDAO.create(); +// voteDTO.setPollAccountId(spa +// .createPollAccount(pollAccountDTO)); } else { - log.debug("Nouveau compte associé au vote"); - voteDTO.setPollAccountId(spa - .createPollAccount(pollAccountDTO)); + log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId()); + //spa.updatePollAccount(pollAccountDTO); + //voteDTO.setPollAccountId(account.getId()); + } + // Fill pollAccountEntity from DTO in argument + DataPollAccountConverter pollAccountConverter = new DataPollAccountConverter(); + pollAccountConverter.setTransaction(transaction); + pollAccountConverter.populatePollAccountEntity(pollAccountDTO, + pollAccountEntity); + // Update pollAccountEntity + pollAccountDAO.update(pollAccountEntity); + + voteDTO.setPollAccountId(pollAccountEntity.getTopiaId()); voteDTO.setVotingListId(pollAccountDTO.getVotingListId()); voteDTO.setWeight(pollAccountDTO.getWeight()); log.debug("Poids du vote : " + voteDTO.getWeight()); @@ -97,8 +116,8 @@ } return topiaId; - } catch (TopiaException e) { - ContextUtil.doCatch(e, transaction); + } catch (Exception eee) { + ContextUtil.doCatch(eee, transaction, "Problem when creating vote with pollAccount"); return null; } } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2009-12-09 19:11:58 UTC (rev 2813) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2009-12-10 18:37:55 UTC (rev 2814) @@ -283,14 +283,23 @@ } } + public static void doCatch(TopiaException e, TopiaContext transaction) { + doCatch(e, transaction, "Échec lors du déroulement de la transaction"); + } + /** * Méthode exécutée lorsqu'une exception est détectée. * - * @param e l'exception + * @param eee + * @param message * @param transaction la transaction courante */ - public static void doCatch(TopiaException e, TopiaContext transaction) { + public static void doCatch(Exception eee, TopiaContext transaction, String message) { + if (log.isErrorEnabled()) { + log.error(message, eee); + } + // rollback de la transaction courante if (transaction != null) { try { @@ -311,9 +320,5 @@ } } } - - if (log.isErrorEnabled()) { - log.error("Échec lors du déroulement de la transaction", e); - } } } \ No newline at end of file