Author: fdesbois Date: 2010-02-26 14:32:46 +0100 (Fri, 26 Feb 2010) New Revision: 2887 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml Log: - Remove method findByPollId in servicePoll --> refactor UI / business (dto update after creation) - Add creatorName attribute in PollDTO to avoid conflict with creatorId in creation Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-02-26 13:32:46 UTC (rev 2887) @@ -174,6 +174,7 @@ PollAccount creator = entity.getCreator(); UserAccount user = creator.getUserAccount(); dto.setCreatorId(creator.getTopiaId()); + dto.setCreatorName(creator.getVotingId()); dto.setCreatorEmail(creator.getEmail()); if (creator.getUserAccount() != null) { dto.setUserId(user.getTopiaId()); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-02-26 13:32:46 UTC (rev 2887) @@ -73,10 +73,13 @@ private String userId = ""; - // Carefull, not TopiaId but pollAccount.votingId = creator name depends - // on case : for saving, it's the votingId, for display it's the topiaId + /** topiaId of the creator (pollAccount) **/ private String creatorId = ""; + /** name of the creator (pollAccount.votingId) **/ + private String creatorName; + + /** email of the creator **/ private String creatorEmail = ""; private List<CommentDTO> comments = new ArrayList<CommentDTO>(); @@ -303,6 +306,14 @@ this.creatorId = creatorId; } + public String getCreatorName() { + return creatorName; + } + + public void setCreatorName(String creatorName) { + this.creatorName = creatorName; + } + public String getCreatorEmail() { return creatorEmail; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-02-26 13:32:46 UTC (rev 2887) @@ -55,16 +55,6 @@ public boolean deletePoll(String pollId); /** - * Récupération d'un sondage à partir de son identifiant ToPIA - * - * @param pollId identifiant topia du sondage - * @return le sondage - * @deprecated use {@link #findPollByPollId } with the correct id instead - */ - @Deprecated - public PollDTO findPollById(String pollId); - - /** * Récupération d'un sondage à partir de son identifiant. * * @param pollId identifiant du sondage (différent du topiaId) Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-02-26 13:32:46 UTC (rev 2887) @@ -99,7 +99,8 @@ pollDAO = PollenModelDAOHelper.getPollDAO(transaction); // Create with a new pollId generated for links - Poll entity = pollDAO.create(PollenContext.createPollenUrlId()); + String pollId = PollenContext.createPollenUrlId(); + Poll entity = pollDAO.create(pollId); PollenConverter.convert(pollDTO, entity); // ** Manage the poll creator @@ -136,6 +137,12 @@ } result = entity.getTopiaId(); + + // Update dto : need creator and id update + // WARN : Update for choices, preventRules and + // votingLists is not needed in this case + PollenConverter.convert(entity, pollDTO); + } catch (Exception eee) { PollenContext.doCatch(eee, _("pollen.error.servicePoll.createPoll", @@ -150,7 +157,7 @@ /** * Prepare pollAccount as creator for {@code poll} save. If userId is * defined, the pollAccount will be searched in database testing all fields - * (user, creatorId as votingId and email). If no result is found or no + * (user, creatorName as votingId and email). If no result is found or no * userId, a new pollAccount is created. * * @param transaction current TopiaContext @@ -169,7 +176,7 @@ // Prepare properties for find or create Map<String, Object> accountProperties = new HashMap<String, Object>(); accountProperties.put(PollAccount.USER_ACCOUNT, user); - accountProperties.put(PollAccount.VOTING_ID, poll.getCreatorId()); + accountProperties.put(PollAccount.VOTING_ID, poll.getCreatorName()); accountProperties.put(PollAccount.EMAIL, poll.getCreatorEmail()); PollAccountDAO accountDAO = @@ -304,52 +311,7 @@ } } - /** - * This method must be deleted after ui refactor in PollCreation page. - * Only used for CreationValidation page that not need complete poll data. - * Only main and creator params will be load in dto using - * {@link ConverterHelper#convert(Poll, PollDTO) } - * - * @param id topiaId of the poll - * @return the PollDTO corresponding - */ @Override - public PollDTO findPollById(String id) { - TopiaContext transaction = null; - PollDTO result = null; - try { - transaction = rootContext.beginTransaction(); - - pollDAO = PollenModelDAOHelper.getPollDAO(transaction); - - Poll pollEntity = pollDAO.findByTopiaId(id); - - if (pollEntity != null) { - result = PollenConverter.convert(pollEntity, new PollDTO()); - } - -// if (pollEntity != null) { -// converter.setTransaction(transaction); -// result = converter.createPollDTO(pollEntity); -// } - - //transaction.commitTransaction(); - - if (log.isDebugEnabled()) { - log.debug("Entity found: " - + ((result == null) ? "null" : result.getId())); - } - - return result; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction); - return null; - } finally { - PollenContext.doFinally(transaction); - } - } - - @Override public PollDTO findPollByPollId(String pollId) { TopiaContext transaction = null; PollDTO result = null; Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-02-26 13:32:46 UTC (rev 2887) @@ -93,7 +93,7 @@ dto.setBeginChoiceDate(new Date()); dto.setBeginDate(new Date()); dto.setChoiceType(ChoiceType.TEXT); - dto.setCreatorId("erwan"); + dto.setCreatorName("erwan"); dto.setDescription("Test_createPoll"); dto.setEndDate(new Date()); dto.setAnonymous(false); @@ -187,27 +187,6 @@ } /** - * Test of findPollById method, of class ServicePollImpl. - */ - @Test - public void testFindPollById() throws Exception { - TestManager.start("testFindPollById"); - instance = new ServicePollImpl(); - - String pollId = ""; - PollDTO dto = new PollDTO(); - dto.setDescription("Test_findPollById"); - dto.setTitle("Test_findPollById"); - dto.setAnonymous(false); - dto.setPollType(PollType.FREE); - dto.setChoiceType(ChoiceType.TEXT); - dto.setVoteCounting(VoteCountingType.NORMAL); - pollId = instance.createPoll(dto); - PollDTO result = instance.findPollById(pollId); - assertEquals(pollId, result.getId()); - } - - /** * Test of findPollByPollId method, of class ServicePollImpl. */ @Test @@ -224,7 +203,7 @@ dto.setChoiceType(ChoiceType.TEXT); dto.setVoteCounting(VoteCountingType.NORMAL); pollId = instance.createPoll(dto); - String pollUID = instance.findPollById(pollId).getPollId(); + String pollUID = dto.getPollId(); log.debug("pollUID : " + pollUID); PollDTO result = instance.findPollByPollId(pollUID); log.debug("title : " + result.getTitle()); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-02-26 13:32:46 UTC (rev 2887) @@ -796,9 +796,11 @@ private void createPoll() { // Création du sondage - poll.setId(servicePoll.createPoll(poll)); + servicePoll.createPoll(poll); - if (poll.getId() != null) { + // FD-20100226 : Can't be null, an exception will be thrown if a + // problem comes from createPoll + //if (poll.getId() != null) { // Création des images if (poll.getChoiceType() == ChoiceType.IMAGE) { @@ -806,13 +808,15 @@ ImageUtil.saveImages(imgTypeChoices, dir); } - // Mise à jour du sondage - poll = servicePoll.findPollById(poll.getId()); + // FD-20100226 : not necessary, the service will update + // automatically the poll when it was created + // Mise à jour du sondage : + //poll = servicePoll.findPollById(poll.getId()); // Mise à jour du flux Atom et envoi d'un mail de confirmation addFeedEntry(); sendMailNotification(); - } + //} } /** Ajout d'une entrée dans le flux de syndication */ @@ -1178,7 +1182,7 @@ // Initialisation du sondage poll = new PollDTO(); if (userExists) { - poll.setCreatorId(user.getLogin()); + poll.setCreatorName(user.getLogin()); poll.setCreatorEmail(user.getEmail()); } @@ -1215,10 +1219,11 @@ poll = PollHelper.getPoll(oldPoll); // Initialisation du créateur du sondage - PollAccountDTO creator = servicePollAccount.findPollAccountById(oldPoll - .getCreatorId()); - poll.setCreatorId(creator.getVotingId()); - poll.setCreatorEmail(creator.getEmail()); +// PollAccountDTO creator = servicePollAccount.findPollAccountById(oldPoll +// .getCreatorId()); + //poll.setCreatorId(oldPoll.getCreatorId()); + poll.setCreatorName(oldPoll.getCreatorName()); + poll.setCreatorEmail(oldPoll.getCreatorEmail()); // Initialisation des règles de notification notificationPreventRule = PollHelper Modified: trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-02-25 15:17:00 UTC (rev 2886) +++ trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-02-26 13:32:46 UTC (rev 2887) @@ -15,7 +15,7 @@ <legend>${stepLegend}</legend> <div> <t:label for="votingId" /> - <t:textfield t:id="votingId" t:value="poll.creatorid" t:validate="required,minlength=2"/> + <t:textfield t:id="votingId" t:value="poll.creatorName" t:validate="required,minlength=2"/> </div> <div> <t:label for="email" />