org.chorem.pollen.services.impl
Class PollService

java.lang.Object
  extended by org.chorem.pollen.services.PollenServiceSupport
      extended by org.chorem.pollen.services.impl.PollService
All Implemented Interfaces:
PollenService

public class PollService
extends PollenServiceSupport


Field Summary
static String THUMB_PREFIX
           
 
Fields inherited from class org.chorem.pollen.services.PollenServiceSupport
serviceContext
 
Constructor Summary
PollService()
           
 
Method Summary
 void addChoice(String pollId, Choice choice)
           
 void attachPoll(Poll poll, UserAccount userAccount)
           
 void closePoll(String pollId, UserAccount userAccount, String accountId)
           
protected  PollAccount copyPollAccount(PollAccount source)
           
 Poll createPoll(Poll poll)
           
protected static void createThumbnail(File img, File thumbCopied, int width)
          Création d'une miniature.
 void deleteChoice(String pollId, String choiceId)
           
 void deletePoll(String pollId, UserAccount userAccount, String accountId)
           
 File generateThumbIfNeeded(File pollChoiceImage)
           
 List<Poll> getCreatedPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager, UserAccount user)
           
 Poll getExistingPollByPollId(String pollId)
           
 File getImageThumbFile(File imagePath)
          given the location of an image, gets his name as a thumb image.
 List<org.apache.commons.lang3.tuple.Pair<Poll,PollAccount>> getInvitedPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager, UserAccount user)
           
 Choice getNewChoice(ChoiceType choiceType)
           
 PersonToList getNewPersonToList(PollAccount pollAccount)
           
protected  Poll getNewPoll(UserAccount user)
          Build a new Poll instance with given user as creator
 PollAccount getNewPollAccount(UserAccount userAccount)
           
protected  Poll getNewPollCopy(String pollUid, UserAccount userAccount, boolean clone)
          Obtains a copy of an existing poll given his pollUid.
 List<org.apache.commons.lang3.tuple.Pair<Poll,PollAccount>> getParticipatedPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager, UserAccount user)
           
 PollAccount getPollAccountByAccountId(String accountId)
           
 PollAccount getPollAccountEditable(String accountId, UserAccount userAccount, Poll poll)
          Retrieve a pollAccount with accountId.
 Poll getPollByPollId(String pollId)
           
 File getPollChoiceImageFile(String pollId, String choiceId)
          Obtain the location of an image choice.
 Poll getPollEditable(String pollUid, UserAccount userAccount, boolean clone)
          Retrieve a Poll for edition.
 List<Poll> getPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager)
           
 List<Poll> getRunningPolls(boolean withEndDate)
           
 Map<String,Object> pollToMap(Poll poll, org.nuiton.util.beans.Binder<Poll,Poll> binder)
           
protected  Choice saveChoice(Poll poll, Choice choice)
           
 void saveImages(Poll poll, PollImageChoice choice)
          Sauvegarde des images d'un choix de type image.
protected  void savePreventRule(Poll poll, PreventRule preventRule)
           
protected  void saveVotingList(Poll poll, VotingList votingList, EmailService emailService)
           
 Poll updatePoll(Poll poll)
           
 
Methods inherited from class org.chorem.pollen.services.PollenServiceSupport
commitTransaction, create, createWithProperties, decorateDate, decorateDateTime, delete, flushTransaction, generateId, getConfiguration, getDAO, getDatePattern, getDateTimePattern, getEntities, getEntities, getEntityById, getLocale, getTransaction, newInstance, newService, setServiceContext, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THUMB_PREFIX

public static final String THUMB_PREFIX
See Also:
Constant Field Values
Constructor Detail

PollService

public PollService()
Method Detail

getPollEditable

public Poll getPollEditable(String pollUid,
                            UserAccount userAccount,
                            boolean clone)
                     throws PollNotFoundException
Retrieve a Poll for edition. It is loaded from database if pollUid is defined, otherwise a new instance is returned. The clone parameter will return the poll without any technical properties (topiaId) and ensure business ids (accountUid, pollUid) with new values. If userId matches an existing UserAccount, the resulting poll creator will be attached to it.

Parameters:
pollUid - Uid of the poll to edit, if not defined, a new poll is instanciated
userAccount - Optinal User account to attach to the creator
clone - Flag to copy or not ids in case of poll cloning
Returns:
the Poll ready for edition (no longer linked to the topia context)
Throws:
PollNotFoundException
See Also:
getNewPoll(UserAccount), getNewPollCopy(String, UserAccount, boolean)

pollToMap

public Map<String,Object> pollToMap(Poll poll,
                                    org.nuiton.util.beans.Binder<Poll,Poll> binder)

createPoll

public Poll createPoll(Poll poll)

updatePoll

public Poll updatePoll(Poll poll)
                throws PollNotFoundException
Throws:
PollNotFoundException

getPolls

public List<Poll> getPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager)

getCreatedPolls

public List<Poll> getCreatedPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager,
                                  UserAccount user)

getInvitedPolls

public List<org.apache.commons.lang3.tuple.Pair<Poll,PollAccount>> getInvitedPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager,
                                                                                   UserAccount user)

getParticipatedPolls

public List<org.apache.commons.lang3.tuple.Pair<Poll,PollAccount>> getParticipatedPolls(org.nuiton.topia.persistence.TopiaFilterPagerUtil.FilterPagerBean pager,
                                                                                        UserAccount user)

getRunningPolls

public List<Poll> getRunningPolls(boolean withEndDate)

getPollByPollId

public Poll getPollByPollId(String pollId)

getExistingPollByPollId

public Poll getExistingPollByPollId(String pollId)
                             throws PollNotFoundException
Throws:
PollNotFoundException

getPollAccountEditable

public PollAccount getPollAccountEditable(String accountId,
                                          UserAccount userAccount,
                                          Poll poll)
                                   throws PollAccountNotFound
Retrieve a pollAccount with accountId. This pollAccount will be attached to the given userAccount (only if not already attached). If the accountId is undefined, a new instance of PollAccount will be retrieved, otherwise a copy of the existing PollAccount is used. No create or update is done here. The poll is used to retrieve a potential existing vote with pollAccount linked to userAccount.

Parameters:
accountId - Id of the existing account (optional)
userAccount - UserAccount where account will be attached (optional)
poll - Poll where pollAccount will be added
Returns:
the existing PollAccount or a new instance
Throws:
PollAccountNotFound - if accountId is defined and doesn't match any existing PollAccount

getNewPoll

protected Poll getNewPoll(UserAccount user)
Build a new Poll instance with given user as creator

Parameters:
user - Build a new Poll instance with given user as creator
Returns:
Build a new Poll instance with given user as creator

getNewPollCopy

protected Poll getNewPollCopy(String pollUid,
                              UserAccount userAccount,
                              boolean clone)
                       throws PollNotFoundException
Obtains a copy of an existing poll given his pollUid.

If flag clone is setted to true, then all id will be removed (pollId, accountId, topiaId).

Parameters:
pollUid - the Poll.getPollId() of the poll to copy
userAccount - optional incoming user account to link to the Poll.getCreator()
clone - flag to clone or not the copy of the poll (if setted to true then all id will be removed).
Returns:
the copy of the poll
Throws:
PollNotFoundException - if poll was not found

copyPollAccount

protected PollAccount copyPollAccount(PollAccount source)

getNewPollAccount

public PollAccount getNewPollAccount(UserAccount userAccount)

getPollAccountByAccountId

public PollAccount getPollAccountByAccountId(String accountId)
                                      throws PollAccountNotFound
Throws:
PollAccountNotFound

deletePoll

public void deletePoll(String pollId,
                       UserAccount userAccount,
                       String accountId)
                throws PollNotFoundException,
                       PollAccountNotFound,
                       UnauthorizedPollAccessException
Throws:
PollNotFoundException
PollAccountNotFound
UnauthorizedPollAccessException

closePoll

public void closePoll(String pollId,
                      UserAccount userAccount,
                      String accountId)
               throws PollNotFoundException,
                      PollAccountNotFound,
                      UnauthorizedPollAccessException
Throws:
PollNotFoundException
PollAccountNotFound
UnauthorizedPollAccessException

attachPoll

public void attachPoll(Poll poll,
                       UserAccount userAccount)

getNewChoice

public Choice getNewChoice(ChoiceType choiceType)

addChoice

public void addChoice(String pollId,
                      Choice choice)
               throws PollNotFoundException
Throws:
PollNotFoundException

saveChoice

protected Choice saveChoice(Poll poll,
                            Choice choice)

deleteChoice

public void deleteChoice(String pollId,
                         String choiceId)
                  throws PollNotFoundException,
                         PollChoiceNotFoundException
Throws:
PollNotFoundException
PollChoiceNotFoundException

getPollChoiceImageFile

public File getPollChoiceImageFile(String pollId,
                                   String choiceId)
Obtain the location of an image choice.

Parameters:
pollId - the id of the poll containing the image choice
choiceId - the id of the choice to render
Returns:
the location of image
Since:
1.4

getImageThumbFile

public File getImageThumbFile(File imagePath)
given the location of an image, gets his name as a thumb image.

Parameters:
imagePath - location of the image
Returns:
location of the thumb of a given image
Since:
1.4

saveImages

public void saveImages(Poll poll,
                       PollImageChoice choice)
                throws IOException
Sauvegarde des images d'un choix de type image.

Parameters:
poll - le sondage contenant le choix
choice - le choix à sauvegarder.
Throws:
IOException - si un problème IO lors de la copie ou génération de la miniature

generateThumbIfNeeded

public File generateThumbIfNeeded(File pollChoiceImage)
                           throws IOException
Throws:
IOException

getNewPersonToList

public PersonToList getNewPersonToList(PollAccount pollAccount)

saveVotingList

protected void saveVotingList(Poll poll,
                              VotingList votingList,
                              EmailService emailService)
                       throws org.nuiton.topia.TopiaException
Throws:
org.nuiton.topia.TopiaException

savePreventRule

protected void savePreventRule(Poll poll,
                               PreventRule preventRule)

createThumbnail

protected static void createThumbnail(File img,
                                      File thumbCopied,
                                      int width)
                               throws IOException
Création d'une miniature.

Parameters:
img - L'image à miniaturiser.
thumbCopied - le chemin complet vers la miniature.
width - La largeur de la miniature.
Throws:
IOException - if could not create thumb image


Copyright © 2009-2012 CodeLutin. All Rights Reserved.