r2995 - in trunk: . pollen-business/src/main/java/org/chorem/pollen/entity pollen-business/src/main/java/org/chorem/pollen/service pollen-business/src/main/xmi
Author: fdesbois Date: 2010-05-12 23:11:26 +0200 (Wed, 12 May 2010) New Revision: 2995 Url: http://chorem.org/repositories/revision/pollen/2995 Log: - Implementation of createPoll method - Use of nuiton-utils 1.3 snapshot Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java Removed: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java trunk/pollen-business/src/main/xmi/pollen.zargo trunk/pom.xml Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java 2010-05-12 21:11:26 UTC (rev 2995) @@ -0,0 +1,30 @@ +package org.chorem.pollen.entity; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Created: 12 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class FavoriteListImpl extends FavoriteListAbstract { + + @Override + public Collection<Participant> getParticipants() { + Collection<Participant> results = new ArrayList<Participant>(); + for (FavoriteParticipant account : getFavoriteParticipant()) { + results.add(account); + } + return results; + } + + @Override + public void addParticipant(Participant participant) { + } + + @Override + public void removeParticipant(Participant participant) { + } +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteListImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java 2010-05-12 17:42:29 UTC (rev 2994) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/FavoriteParticipantImpl.java 2010-05-12 21:11:26 UTC (rev 2995) @@ -1,24 +0,0 @@ - -package org.chorem.pollen.entity; - -/** - * FavoriteParticipantImpl - * - * Created: 28 avr. 2010 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class FavoriteParticipantImpl extends FavoriteParticipantAbstract { - - private static final long serialVersionUID = 1L; - - @Override - public String getId() { - return getTopiaId(); - } - -} Added: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java 2010-05-12 21:11:26 UTC (rev 2995) @@ -0,0 +1,34 @@ +package org.chorem.pollen.entity; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Created: 12 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class PollAccountImpl extends PollAccountAbstract { + + @Override + public Collection<Participant> getParticipants() { + // for a simple account, will return null + if (!list) { + return null; + } + Collection<Participant> results = new ArrayList<Participant>(); + for (PollAccount account : getChild()) { + results.add(account); + } + return results; + } + + @Override + public void addParticipant(Participant participant) { + } + + @Override + public void removeParticipant(Participant participant) { + } +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/entity/PollAccountImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-12 17:42:29 UTC (rev 2994) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/service/ServicePollImpl.java 2010-05-12 21:11:26 UTC (rev 2995) @@ -1,20 +1,32 @@ package org.chorem.pollen.service; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.chorem.pollen.PollenBinderHelper; import org.chorem.pollen.PollenBusinessException; import org.chorem.pollen.PollenContext; import org.chorem.pollen.PollenDAOHelper; import org.chorem.pollen.PollenException; +import org.chorem.pollen.common.PollType; import org.chorem.pollen.entity.Choice; +import org.chorem.pollen.entity.ChoiceDAO; import org.chorem.pollen.entity.Comment; +import org.chorem.pollen.entity.Participant; +import org.chorem.pollen.entity.ParticipantList; import org.chorem.pollen.entity.Poll; import org.chorem.pollen.entity.PollAccount; +import org.chorem.pollen.entity.PollAccountDAO; import org.chorem.pollen.entity.PollAccountImpl; +import org.chorem.pollen.entity.PollDAO; import org.chorem.pollen.entity.PollImpl; import org.chorem.pollen.entity.UserAccount; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; /** * ServicePoll @@ -74,19 +86,140 @@ @Override protected void executeCreatePoll(TopiaContext transaction, - List<Object> errorArgs, Poll poll) throws TopiaException { + List<Object> errorArgs, Poll poll, Collection<ParticipantList> lists) + throws TopiaException, IllegalArgumentException { errorArgs.add(poll.getTitle()); errorArgs.add(poll.getUid()); - PollenDAOHelper.getPollDAO(transaction).create(poll); + PollDAO dao = PollenDAOHelper.getPollDAO(transaction); - // need to create uid for both poll and creator - // need to create creator (name, email, user, admin) + // Create newPoll and copy simple properties from poll source + Poll newPoll = createBasicPoll(transaction, poll); + // Create accounts depends on pollType and lists argument + List<PollAccount> accounts = createPollAccounts(transaction, + newPoll.getPollType(), lists); + + // Create newPoll choices + List<Choice> choices = createPollChoices(transaction, poll.getChoice()); + + dao.update(newPoll); + transaction.commitTransaction(); } + protected Poll createBasicPoll(TopiaContext transaction, Poll source) + throws TopiaException { + PollDAO dao = PollenDAOHelper.getPollDAO(transaction); + + PollAccountDAO accountDAO = + PollenDAOHelper.getPollAccountDAO(transaction); + + // Create newPoll and copy simple properties from poll source + Poll newPoll = dao.create(context.createPollenUrlId()); + + PollenBinderHelper.getSimpleTopiaBinder(Poll.class). + copyExcluding(source, newPoll, + Poll.UID, + Poll.CLOSED, + Poll.CREATOR); + + // Create creator and set him to the poll + PollAccount creator = accountDAO.create(context.createPollenUrlId()); + + PollenBinderHelper.getSimpleTopiaBinder(PollAccount.class). + copy(source.getCreator(), creator, + PollAccount.NAME, + PollAccount.EMAIL, + PollAccount.WEIGHT, + PollAccount.ADMIN); + accountDAO.update(creator); + + newPoll.setCreator(creator); + return newPoll; + } + + protected List<PollAccount> createPollAccounts(TopiaContext transaction, + PollType type, + Collection<ParticipantList> lists) + throws TopiaException, IllegalArgumentException { + + List<PollAccount> results = new ArrayList<PollAccount>(); + + PollAccountDAO accountDAO = + PollenDAOHelper.getPollAccountDAO(transaction); + + switch (type) { + case RESTRICTED: + if (CollectionUtils.isEmpty(lists)) { + throw new IllegalArgumentException("lists can't be empty" + + " for restricted poll"); + } + // Create accounts only on first participant list + results = createPersonAccounts(accountDAO, + lists.iterator().next()); + break; + case GROUP: + if (CollectionUtils.isEmpty(lists)) { + throw new IllegalArgumentException("lists can't be empty" + + " for group poll"); + } + + for (ParticipantList list : lists) { + // Create the accountList + PollAccount accountList = accountDAO.create( + context.createPollenUrlId()); + accountList.setList(true); + accountList.setName(list.getName()); + + // Create account children + List<PollAccount> accounts = + createPersonAccounts(accountDAO, list); + accountList.setChild(accounts); + + // Add the accountList to the newPoll + results.add(accountList); + } + } + return results; + } + + protected List<PollAccount> createPersonAccounts(PollAccountDAO dao, + ParticipantList list) + throws TopiaException { + + List<PollAccount> results = new ArrayList<PollAccount>(); + + for (Participant participant : list.getParticipants()) { + String accountUid = context.createPollenUrlId(); + PollAccount account = dao.create(accountUid); + account.setName(participant.getName()); + account.setEmail(participant.getEmail()); + account.setWeight(participant.getWeight()); + dao.update(account); + results.add(account); + } + return results; + } + + protected List<Choice> createPollChoices(TopiaContext transaction, + List<Choice> source) + throws TopiaException { + + ChoiceDAO dao = PollenDAOHelper.getChoiceDAO(transaction); + + List<Choice> results = new ArrayList<Choice>(); + + for (Choice choice : source) { + Choice newChoice = dao.create(); + PollenBinderHelper.getSimpleTopiaBinder(Choice.class). + copy(choice, newChoice); + results.add(newChoice); + } + return results; + } + @Override protected void executeUpdatePoll(TopiaContext transaction, Poll poll) throws TopiaException { Modified: trunk/pollen-business/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-05-12 17:42:29 UTC (rev 2994) +++ trunk/pom.xml 2010-05-12 21:11:26 UTC (rev 2995) @@ -319,7 +319,7 @@ <i18n.version>1.2.2</i18n.version> <tapestry.version>5.1.0.5</tapestry.version> <nuiton-web.version>0.1-SNAPSHOT</nuiton-web.version> - <nuiton-utils.version>1.2.2</nuiton-utils.version> + <nuiton-utils.version>1.3-SNAPSHOT</nuiton-utils.version> <processor.version>1.0.2</processor.version> <!--Multilanguage maven-site -->
participants (1)
-
fdesbois@users.chorem.org