Author: fdesbois Date: 2012-04-06 17:46:09 +0200 (Fri, 06 Apr 2012) New Revision: 3240 Url: http://chorem.org/repositories/revision/pollen/3240 Log: - remove useless serviceContext in creators - problem with choice topiaId in jsp - simple merge for the moment : remove all and create new Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.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-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-04-06 15:46:09 UTC (rev 3240) @@ -81,14 +81,12 @@ } public static Function<VotingList, VotingList> newVotingListCreator( - PollenServiceContext serviceContext, Function<PersonToList, PersonToList> persontoListCreator) { - return new VotingListCreator(serviceContext, persontoListCreator); + return new VotingListCreator(persontoListCreator); } - public static Function<PersonToList, PersonToList> newPersonToListCreator( - PollenServiceContext serviceContext) { - return new PersonToListCreator(serviceContext); + public static Function<PersonToList, PersonToList> newPersonToListCreator() { + return new PersonToListCreator(); } public static class TextChoiceCreator implements Function<Choice, Choice> { @@ -137,13 +135,9 @@ public static class VotingListCreator implements Function<VotingList, VotingList> { - protected final PollenServiceContext serviceContext; - protected final Function<PersonToList, PersonToList> persontoListCreator; - protected VotingListCreator(PollenServiceContext serviceContext, - Function<PersonToList, PersonToList> persontoListCreator) { - this.serviceContext = serviceContext; + protected VotingListCreator(Function<PersonToList, PersonToList> persontoListCreator) { this.persontoListCreator = persontoListCreator; } @@ -176,12 +170,6 @@ public static class PersonToListCreator implements Function<PersonToList, PersonToList> { - protected final PollenServiceContext serviceContext; - - protected PersonToListCreator(PollenServiceContext serviceContext) { - this.serviceContext = serviceContext; - } - @Override public PersonToList apply(PersonToList input) { PersonToList result = new PersonToListImpl(); 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-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-04-06 15:46:09 UTC (rev 3240) @@ -24,6 +24,7 @@ package org.chorem.pollen.services.impl; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -196,14 +197,16 @@ for (VotingList votingListLoaded : source.getVotingList()) { VotingList votingListEditable = newInstance(votingListDAO); result.addVotingList(votingListEditable); + // Do not keep votingLists topiaId, to simplify the update will delete old votingLists and create new ones PollenBinderHelper.simpleCopy( - votingListLoaded, votingListEditable, !clone); + votingListLoaded, votingListEditable, false); for (PersonToList personToListLoaded : votingListLoaded.getPollAccountPersonToList()) { PersonToList personToListEditable = newInstance(personToListDAO); votingListEditable.addPollAccountPersonToList(personToListEditable); + // Do not keep personToLists topiaId, to simplify the update will delete old personToLists and create new ones PollenBinderHelper.simpleCopy( - personToListLoaded, personToListEditable, !clone); + personToListLoaded, personToListEditable, false); PollAccount personLoaded = personToListLoaded.getPollAccount(); PollAccount personEditable = newInstance(pollAccountDAO); @@ -274,8 +277,8 @@ } // -- PreventRule -- // - for (Choice choice : poll.getChoice()) { - saveChoice(result, choice); + for (PreventRule choice : poll.getPreventRule()) { + savePreventRule(result, choice); } // -- VotingList -- // @@ -321,7 +324,6 @@ creatorToUpdate.setEmail(creator.getEmail()); // -- Choices -- // - if (!voteStarted) { pollToUpdate.clearChoice(); @@ -336,11 +338,9 @@ } // -- VotingLists -- // - - // FIXME-fdesbois-2012-04-05 : missing delete-orphan on VotingList, if PollType change, VotingList must be deleted - // FIXME-fdesbois-2012-04-05 : manage remove - if (!voteStarted) { + + pollToUpdate.clearVotingList(); for (VotingList votingList : poll.getVotingList()) { saveVotingList(pollToUpdate, votingList); } @@ -856,6 +856,19 @@ createThumbnail(pollChoiceImage, pollChoiceImageThumb, 100); } + public void addVoteToPoll(Poll poll, Vote vote) { + + String pollId = poll.getTopiaId(); + String voteId = vote.getTopiaId(); + + Poll pollToUpdate = getEntityById(Poll.class, pollId); + Vote voteToAdd = getEntityById(Vote.class, voteId); + + pollToUpdate.addVote(voteToAdd); + + commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]"); + } + public PersonToList getNewPersonToList(PollAccount pollAccount) { PersonToList result = newInstance(getDAO(PersonToList.class)); result.setWeight(1); @@ -872,50 +885,6 @@ return result; } - public void addVoteToPoll(Poll poll, Vote vote) { - - String pollId = poll.getTopiaId(); - String voteId = vote.getTopiaId(); - - Poll pollToUpdate = getEntityById(Poll.class, pollId); - Vote voteToAdd = getEntityById(Vote.class, voteId); - - pollToUpdate.addVote(voteToAdd); - - commitTransaction("Can't add the vote [" + voteId + "] to the poll [" + pollId + "]"); - - -// TopiaContext transaction = null; -// try { -// transaction = rootContext.beginTransaction(); -// -// pollDAO = PollenModelDAOHelper.getPollDAO(transaction); -// Poll pollEntity = pollDAO.findByTopiaId(pollId); -// VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction); -// Vote voteEntity = voteDAO.findByTopiaId(voteId); -// -// if (log.isDebugEnabled()) { -// log.debug(pollEntity + " " + voteEntity); -// } -// -// pollEntity.addVote(voteEntity); -// pollDAO.update(pollEntity); -// -// transaction.commitTransaction(); -// -// if (log.isDebugEnabled()) { -// log.debug("Entity updated: " + pollId); -// } -// -// return true; -// } catch (Exception e) { -// ContextUtil.doCatch(e, transaction); -// return false; -// } finally { -// ContextUtil.doFinally(transaction); -// } - } - protected void saveVotingList(Poll poll, VotingList votingList) { VotingListDAO votingListDAO = getDAO(VotingList.class); @@ -923,54 +892,51 @@ PollAccountDAO pollAccountDAO = getDAO(PollAccount.class); // Prepare the VotingList and add it to the poll - VotingList votingListLoaded; + VotingList result; if (votingList.getTopiaId() == null) { - votingListLoaded = create(votingListDAO); - poll.addVotingList(votingListLoaded); + result = create(votingListDAO); + poll.addVotingList(result); } else { - votingListLoaded = poll.getVotingListByTopiaId(votingList.getTopiaId()); + result = poll.getVotingListByTopiaId(votingList.getTopiaId()); - // FIXME-fdesbois-2012-04-05 : why the poll association is not keeped ?!? - votingListLoaded.setPoll(poll); + // FIXME-fdesbois-2012-04-05 : why the poll association is not keeped ?!? because of the clear + result.setPoll(poll); } - votingListLoaded.setName(votingList.getName()); - votingListLoaded.setWeight(votingList.getWeight()); + result.setName(votingList.getName()); + result.setWeight(votingList.getWeight()); // Merge PersonToList + List<PersonToList> personToListsUpdated = Lists.newArrayList(); for (PersonToList personToList : votingList.getPollAccountPersonToList()) { + PollAccount pollAccount = personToList.getPollAccount(); + PersonToList personToListLoaded; + PollAccount pollAccountLoaded; if (personToList.getTopiaId() == null) { personToListLoaded = create(personToListDAO); - votingListLoaded.addPollAccountPersonToList(personToListLoaded); // The model doesn't have any composition for this relation, // the link must be set in both objects - personToListLoaded.setVotingList(votingListLoaded); + personToListLoaded.setVotingList(result); - } else { - personToListLoaded = votingListLoaded.getPollAccountPersonToListByTopiaId(personToList.getTopiaId()); - } - -// personToListLoaded.setHasVoted(personToList.isHasVoted()); - personToListLoaded.setWeight(personToList.getWeight()); - - PollAccount pollAccount = personToList.getPollAccount(); - PollAccount pollAccountLoaded = personToListLoaded.getPollAccount(); - - // Create the pollAccount if not exists - if (pollAccountLoaded == null) { pollAccountLoaded = create(pollAccountDAO); pollAccountLoaded.setAccountId(pollAccount.getAccountId()); personToListLoaded.setPollAccount(pollAccountLoaded); + + } else { + personToListLoaded = getEntityById(PersonToList.class, personToList.getTopiaId()); + pollAccountLoaded = personToListLoaded.getPollAccount(); } + personToListsUpdated.add(personToListLoaded); + personToListLoaded.setWeight(personToList.getWeight()); pollAccountLoaded.setEmail(pollAccount.getEmail()); -// pollAccountLoaded.setUserAccount(pollAccount.getUserAccount()); pollAccountLoaded.setVotingId(pollAccount.getVotingId()); } + result.setPollAccountPersonToList(personToListsUpdated); } protected void savePreventRule(Poll poll, PreventRule preventRule) { Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-04-06 15:46:09 UTC (rev 3240) @@ -220,6 +220,11 @@ _("pollen.action.createPoll"); } + public String getPageTitle() { + return isEdit() ? getPoll().getTitle() : + _("pollen.title.createPoll"); + } + public boolean isVoteStarted() { return isEdit() && poll.sizeVote() > 0; } @@ -261,15 +266,14 @@ public Function<PersonToList, PersonToList> getPersontoListCreator() { if (persontoListCreator == null) { - persontoListCreator = PollenServiceFunctions.newPersonToListCreator(serviceContext); + persontoListCreator = PollenServiceFunctions.newPersonToListCreator(); } return persontoListCreator; } public Function<VotingList, VotingList> getVotingListCreator() { if (votingListCreator == null) { - votingListCreator = PollenServiceFunctions.newVotingListCreator(serviceContext, - getPersontoListCreator()); + votingListCreator = PollenServiceFunctions.newVotingListCreator(getPersontoListCreator()); } return votingListCreator; } Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayVotingList.java 2012-04-06 15:46:09 UTC (rev 3240) @@ -104,9 +104,9 @@ public String execute() throws Exception { Function<PersonToList, PersonToList> persontoListCreator = - PollenServiceFunctions.newPersonToListCreator(serviceContext); + PollenServiceFunctions.newPersonToListCreator(); Function<VotingList, VotingList> votingListCreator = - PollenServiceFunctions.newVotingListCreator(serviceContext, persontoListCreator); + PollenServiceFunctions.newVotingListCreator(persontoListCreator); // if (StringUtils.isNotEmpty(tokenId)) { // Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/SavePoll.java 2012-04-06 15:46:09 UTC (rev 3240) @@ -311,15 +311,16 @@ if (isEdit()) { service.updatePoll(poll); + addActionMessage(_("pollen.information.poll.updated")); } else { service.createPoll(poll); + addActionMessage(_("pollen.information.poll.created")); } // remove all stuff from session getPollenSession().clearDynamicData(); - addActionMessage(_("pollen.information.poll.created")); return SUCCESS; } Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-04-06 15:46:09 UTC (rev 3240) @@ -61,7 +61,7 @@ <title><s:text name="pollen.title.createPoll"/></title> -<h1 class="title${pageLogo}"><s:text name="pollen.title.createPoll"/></h1> +<h1 class="title${pageLogo}"><s:property value="%{pageTitle}"/></h1> <s:form method="POST" id="registerForm" namespace="/poll" enctype="multipart/form-data"> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-04-06 12:56:20 UTC (rev 3239) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-04-06 15:46:09 UTC (rev 3240) @@ -40,7 +40,7 @@ <s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set> <s:set name="prefix">textChoice_<s:property value="%{#choiceNumber}"/></s:set> <div id='choicesTEXT_<s:property value="choiceNumber"/>'> - <s:hidden key='%{#prefix}.topiaId' value='%{choice.topiaId}' label=''/> + <s:hidden key='%{#prefix}.topiaId' value='%{#choice.topiaId}' label=''/> <div class="fleft choiceName"> <s:label for="%{#prefix}.name" id="choicesTEXT_label_%{#choiceNumber}" theme="simple" value=''/> @@ -84,7 +84,7 @@ <s:set name="prefix">dateChoice_<s:property value="%{#choiceNumber}"/></s:set> <div id='choicesDATE_<s:property value="choiceNumber"/>'> <s:hidden key='%{#prefix}.topiaId' id='%{#prefix}.topiaId' - value='%{choice.topiaId}' label='' theme="simple" /> + value='%{#choice.topiaId}' label='' theme="simple" /> <div class="fleft choiceName"> <s:label for="%{#prefix}.name" id="choicesDATE_label_%{choiceNumber}" theme="simple" value=''/> @@ -129,7 +129,7 @@ <s:set name="choiceNumber"><s:property value="%{#status.index}"/></s:set> <s:set name="prefix">imageChoice_<s:property value="%{#choiceNumber}"/></s:set> <div id='choicesIMAGE_<s:property value="choiceNumber"/>'> - <s:hidden key='%{#prefix}.topiaId' value='%{choice.topiaId}' label=''/> + <s:hidden key='%{#prefix}.topiaId' value='%{#choice.topiaId}' label=''/> <div class="fleft choiceName"> <s:label for="%{#prefix}.name" id="choicesIMAGE_label_%{choiceNumber}" theme="simple" value=''/>