Package com.jalios.jcms.vote
Class VoteManager
- java.lang.Object
-
- com.jalios.jcms.db.BasicDBListener
-
- com.jalios.jcms.vote.VoteManager
-
- All Implemented Interfaces:
DBConstants
,DBListener
,PluginComponent
,VoteConstants
,JPropertiesListener
public class VoteManager extends BasicDBListener implements DBConstants, VoteConstants, JPropertiesListener
This class gives Utils to handle vote- Since:
- jcms-8.0.0
- Author:
- bransard
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
VoteManager.CacheEntry
-
Field Summary
-
Fields inherited from interface com.jalios.jcms.db.DBConstants
ALL_CATEGORIES_SET_FIELD, ATTACH_WS_SET_FIELD, AUTH_GRP_SET_FIELD, AUTH_MBR_SET_FIELD, AUTHOR_ID_FIELD, CATEGORIES_SET_FIELD, CDATE_FIELD, CHANNEL_JCMSDB_PROP, CLASSIFICATION_LEVEL_FIELD, DBDATA_URID, EXTENDED_READ_RIGHTS, HAS_ATTACH_WS_FIELD, HAS_NO_READ_RIGHTS, HIBERNATE_MAPPING_ADATE, HIBERNATE_MAPPING_AUTHOR, HIBERNATE_MAPPING_CDATE, HIBERNATE_MAPPING_EDATE, HIBERNATE_MAPPING_HAS_ATTACH_WS, HIBERNATE_MAPPING_HASNOREADRIGHTS, HIBERNATE_MAPPING_MAININSTANCE_ID, HIBERNATE_MAPPING_MAJORVERSION, HIBERNATE_MAPPING_MDATE, HIBERNATE_MAPPING_MERGE_DATE, HIBERNATE_MAPPING_MERGE_ID, HIBERNATE_MAPPING_MINORVERSION, HIBERNATE_MAPPING_OPAUTHOR, HIBERNATE_MAPPING_PDATE, HIBERNATE_MAPPING_PSTATUS, HIBERNATE_MAPPING_READ_ACK, HIBERNATE_MAPPING_READERCOUNT, HIBERNATE_MAPPING_RESTRICTIVE_UPDATE_RIGHTS, HIBERNATE_MAPPING_TITLE, HIBERNATE_MAPPING_TRACKED, HIBERNATE_MAPPING_UDATE, HIBERNATE_MAPPING_VOTECOUNT, HIBERNATE_MAPPING_VOTESCORE, HIBERNATE_MAPPING_WORKFLOW_ID, HIBERNATE_MAPPING_WORKSPACE_ID, MAX_HIBERNATE_MAPPING_PUBLICATION, MDATE_FIELD, OPAUTHOR_ID_FIELD, PSTATUS_FIELD, ROW_ID_FIELD, SCROLL_FETCH_SIZE, WORKFLOW_ID_FIELD, WORKSPACE_ID_FIELD
-
Fields inherited from interface com.jalios.jcms.vote.VoteConstants
ALERT_DOMAIN, ALERT_NAME_NEGATIVE_VOTE, ALERT_NAME_POSITIVE_VOTE, ANONYMIZE_DOWNVOTE_PROP, ANONYMIZE_VOTE_PROP, CACHE_SIZE_PROP, DEFAULT_VOTE_TEMPLATE_PROP, DEFAULT_VOTELIST_TEMPLATE_PROP, ICON_VOTE_NEGATIVE_HL_PROP, ICON_VOTE_NEGATIVE_PROP, ICON_VOTE_POSITIVE_HL_PROP, ICON_VOTE_POSITIVE_PROP, PUBLICATION_ID_FIELD, RATING_FIELD, SEND_VOTE_NOTIFICATION_PROP, UI_VOTE_NEGATIVE, UI_VOTE_NEGATIVE_HL, UI_VOTE_POSITIVE, UI_VOTE_POSITIVE_HL, UNVOTABLE_TYPES_PROP, VOTE_DEFAULT_VALUE_PROP, VOTE_ENABLED_PROP, VOTE_TAG_USAGE_ACTION, VOTE_TAG_USAGE_VOTELIST
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Publication
cancelVote(Publication pub, Member mbr)
Cancel the vote bound on a Publication and a Memberboolean
canVote(Publication pub, Member mbr)
Return true if given Member can Vote on given PublicationVote
createVote(Publication pub, Member mbr, java.util.Map context, int rating)
Creates a vote and returns itControllerStatus
deleteAllVote(Member mbr)
Delete all votes of aMember
ControllerStatus
deleteAllVote(Publication pub, Member mbr)
Delete all votes of aPublication
java.lang.String
getDefaultNegativeVoteHighlightIcon()
java.lang.String
getDefaultNegativeVoteIcon()
java.lang.String
getDefaultPositiveVoteHighlightIcon()
java.lang.String
getDefaultPositiveVoteIcon()
java.lang.String
getDefaultVoteListTemplateJsp()
java.lang.String
getDefaultVoteTemplateJsp()
static VoteManager
getInstance()
java.lang.String
getJcmsId(java.lang.String sentence)
Returns the jcmsId from a given sentence for the ttCard "ttLike"java.util.List<Vote>
getNegativeVoteList(Publication pub)
Return the positive vote List for given Publicationjava.util.List<Vote>
getPositiveVoteList(Publication pub)
Return the positive vote List for given Publicationjava.util.Set<Member>
getPublicationVoteAllMemberSet(Publication pub)
Returns the Set of all Members who have voted on given Publicationjava.util.Set<Member>
getPublicationVoteMemberSet(Publication pub, boolean positive)
Return the Set<Member> who have voted on given Publication, depending on vote anonymization choicesVote
getVote(Publication pub, Member mbr)
Return a Vote bound on given Publication and given Memberint
getVoteCount(Publication pub)
Returns the count of vote on the given publicationint
getVoteCountFromDatabase(java.lang.String pubId)
int[]
getVoteCountFromVoteTable(Publication pub)
java.lang.String
getVoteIcon(int iconType)
java.util.List<Vote>
getVoteList(Publication pub)
Return the vote List for given Publicationjava.util.List<Vote>
getVoteList(Publication pub, java.lang.String orderBy)
Return the vote List for given Publication with given orderint
getVoteScore(Publication pub)
Return the voteScore of given Publication and update the voteCountMap if not in mapint
getVoteScoreFromDatabase(java.lang.String pubId)
boolean
hasVote(Publication pub)
Returns true if the given publication has been voted.boolean
hasVoted(Publication pub, Member mbr)
Returns true if given Member has already voted for given Publicationvoid
invalidateVoteCountMap(java.lang.String pubId)
Invalidate the count of comment on the given publication.boolean
isDownVoteAnonymized()
boolean
isPointMode()
boolean
isSendVoteNotification()
boolean
isUnvotableType(java.lang.Class clazz)
Returns true if the given class is unvotableboolean
isVotable(Publication pub)
boolean
isVoteAnonymized()
boolean
isVoteEnabled()
void
notifyAuthor(Vote vote)
Notifies the Publication's author that he has received a new votevoid
onPostDelete(DBData data, org.hibernate.event.PostDeleteEvent event, boolean firstTime)
This method is called after a DBData has been deleted.void
onPostInsert(DBData data, org.hibernate.event.PostInsertEvent event, boolean firstTime)
This method is called after a DBData has been created.void
onPostUpdate(DBData data, org.hibernate.event.PostUpdateEvent event, boolean firstTime)
This method is called after a DBData has been updated.java.lang.Object[]
performVote(Publication pub, Member mbr, boolean positiveVote)
void
propertiesChange(JProperties properties)
Invoked after properties have been modified in JCMS and save on disk.void
recomputePublicationVote(Publication pub)
Recompute the Publication voteCount and voteScore by querying all its votesvoid
updatePubVoteWorkspace(Publication pub)
Update vote's Workspace if the Workspace of the Publication differs from the Workspace of votesvoid
updateVoteMap(java.lang.String pubId)
Recompute the count of vote on the given publication.void
updateVoteMapValue(java.lang.String pubId, VoteManager.CacheEntry cacheEntry)
Update values for a given Publication id in the cache vote map-
Methods inherited from class com.jalios.jcms.db.BasicDBListener
getAdateFromState, getAuthorIdFromState, getCdateFromState, getDateFromState, getEdateFromState, getMdateFromState, getPdateFromState, getPrePstatus, getPrePstatus, getPstatusFromState, hasNoChange, hasNoChange, init, onPreUpdate
-
-
-
-
Method Detail
-
getInstance
public static VoteManager getInstance()
-
propertiesChange
public void propertiesChange(JProperties properties)
Description copied from interface:JPropertiesListener
Invoked after properties have been modified in JCMS and save on disk.You cannot alter the value received in parameters.
Note that properties parameter may be null, a limited set of site properties, or all site properties.
To check that a property has been modified, reload the "current" property instead using
channel.getProperties
orchannel.getProperty
.- Specified by:
propertiesChange
in interfaceJPropertiesListener
- Parameters:
properties
- the properties which have been submitted to change
-
getPositiveVoteList
public java.util.List<Vote> getPositiveVoteList(Publication pub)
Return the positive vote List for given Publication- Parameters:
pub
- the Publication- Returns:
- the positive vote List for given Publication
- Since:
- jcms-8.0.0
-
getNegativeVoteList
public java.util.List<Vote> getNegativeVoteList(Publication pub)
Return the positive vote List for given Publication- Parameters:
pub
- the Publication- Returns:
- the positive vote List for given Publication
- Since:
- jcms-8.0.2
-
getVoteList
public java.util.List<Vote> getVoteList(Publication pub)
Return the vote List for given Publication- Parameters:
pub
- the Publication- Returns:
- the vote List for given Publication
- Since:
- jcms-8.0.0
-
getVoteList
public java.util.List<Vote> getVoteList(Publication pub, java.lang.String orderBy)
Return the vote List for given Publication with given order- Parameters:
pub
- the PublicationorderBy
- the order of the query- Returns:
- the vote List for given Publication
- Since:
- jcms-9.0.2
-
getPublicationVoteAllMemberSet
public java.util.Set<Member> getPublicationVoteAllMemberSet(Publication pub)
Returns the Set of all Members who have voted on given Publication- Parameters:
pub
- the Publication- Returns:
- a Set<Member> who have voted on given Publication
- Since:
- jcms-8.0.0
-
getPublicationVoteMemberSet
public java.util.Set<Member> getPublicationVoteMemberSet(Publication pub, boolean positive)
Return the Set<Member> who have voted on given Publication, depending on vote anonymization choices- Parameters:
pub
- the Publicationpositive
- , if true, returns only members who has made a positive vote. If false, it returns only members who made a negative vote- Returns:
- the Set<Member> who have voted on given Publication, depending on vote anonymization choices
- Since:
- jcms-8.0.0
-
isVotable
public boolean isVotable(Publication pub)
- Parameters:
pub
- the Publication- Returns:
- true if given Publication can be voted
- Since:
- jcms-8.0.0
-
isUnvotableType
public boolean isUnvotableType(java.lang.Class clazz)
Returns true if the given class is unvotable- Parameters:
clazz
- the class to check- Returns:
- boolean true if the given class is unvotable
-
isVoteEnabled
public boolean isVoteEnabled()
- Returns:
- true if the property "vote.enabled.boolean" is set to true
- Since:
- jcms-8.0.0
-
isPointMode
public boolean isPointMode()
- Returns:
- true if vote value is > 1
- Since:
- jcms-8.0.1
-
isVoteAnonymized
public boolean isVoteAnonymized()
- Returns:
- true if the property "vote.anonymize-vote.boolean" is set to true
- Since:
- jcms-8.0.0
-
isDownVoteAnonymized
public boolean isDownVoteAnonymized()
- Returns:
- true if the property "vote.anonymize-downvote.boolean" is set to true
- Since:
- jcms-8.0.0
-
isSendVoteNotification
public boolean isSendVoteNotification()
- Returns:
- true if the property "vote.notification.vote-received.boolean" is set to true
- Since:
- jcms-8.0.0
-
canVote
public boolean canVote(Publication pub, Member mbr)
Return true if given Member can Vote on given Publication- Parameters:
pub
- the Publicationmbr
- the Member- Returns:
- true if given Member can Vote on given Publication
- Since:
- jcms-8.0.0
-
performVote
public java.lang.Object[] performVote(Publication pub, Member mbr, boolean positiveVote)
- Parameters:
pub
- the votedPublication
mbr
- the voterMember
positiveVote
- set true if positive vote- Returns:
- the voted Publication with updated rating(for DBData)
- Since:
- jcms-8.0.0
-
deleteAllVote
public ControllerStatus deleteAllVote(Member mbr)
Delete all votes of aMember
- Parameters:
mbr
- theMember
- Returns:
- a
ControllerStatus
-
deleteAllVote
public ControllerStatus deleteAllVote(Publication pub, Member mbr)
Delete all votes of aPublication
- Parameters:
pub
- thePublication
mbr
-Member
deleting thePublication
- Returns:
- a
ControllerStatus
-
cancelVote
public Publication cancelVote(Publication pub, Member mbr)
Cancel the vote bound on a Publication and a Member- Parameters:
pub
- the publicationmbr
- the Member- Returns:
- the publication
- Since:
- jcms-8.0.0
-
getVote
public Vote getVote(Publication pub, Member mbr)
Return a Vote bound on given Publication and given Member- Parameters:
pub
- the Publicationmbr
- the Member- Returns:
- a Vote bound on given Publication and given Member
- Since:
- jcms-8.0.0
-
createVote
public Vote createVote(Publication pub, Member mbr, java.util.Map context, int rating)
Creates a vote and returns it- Parameters:
pub
- the Publicationmbr
- the Membercontext
- the context Maprating
- of the vote (pts)- Returns:
- a Vote after creating it
- Since:
- jcms-8.0.0
-
hasVoted
public boolean hasVoted(Publication pub, Member mbr)
Returns true if given Member has already voted for given Publication- Parameters:
pub
- the Publicationmbr
- the Member- Returns:
- true if given Member has already voted for given Publication
- Since:
- jcms-8.0.0
-
getVoteCountFromVoteTable
public int[] getVoteCountFromVoteTable(Publication pub)
- Parameters:
pub
- the Publication- Returns:
- the positive vote count and negative vote count for given Publication
-
getVoteCount
public int getVoteCount(Publication pub)
Returns the count of vote on the given publication- Parameters:
pub
- the publication- Returns:
- the count of vote on the given publication
- Since:
- jcms-8.0.0
-
getVoteScore
public int getVoteScore(Publication pub)
Return the voteScore of given Publication and update the voteCountMap if not in map- Parameters:
pub
- the Publication- Returns:
- the voteScore of given Publication and update the voteCountMap if not in map
- Since:
- jcms-8.0.0
-
getVoteScoreFromDatabase
public int getVoteScoreFromDatabase(java.lang.String pubId)
-
hasVote
public boolean hasVote(Publication pub)
Returns true if the given publication has been voted.- Parameters:
pub
- the publication- Returns:
- true if the given publication has been voted.
- Since:
- jcms-8.0.0
-
invalidateVoteCountMap
public void invalidateVoteCountMap(java.lang.String pubId)
Invalidate the count of comment on the given publication.- Parameters:
pubId
- the id of the publication- Since:
- jcms-8.0.0
-
updateVoteMap
public void updateVoteMap(java.lang.String pubId)
Recompute the count of vote on the given publication.- Parameters:
pubId
- the id of the publication- Since:
- jcms-8.0.0
-
getVoteCountFromDatabase
public int getVoteCountFromDatabase(java.lang.String pubId)
-
updateVoteMapValue
public void updateVoteMapValue(java.lang.String pubId, VoteManager.CacheEntry cacheEntry)
Update values for a given Publication id in the cache vote map- Parameters:
pubId
- the Publication idcacheEntry
- theVoteManager.CacheEntry
to update- Since:
- jcms-8.0.0
-
recomputePublicationVote
public void recomputePublicationVote(Publication pub)
Recompute the Publication voteCount and voteScore by querying all its votes- Parameters:
pub
- the Publication- Since:
- jcms-8.0.0
-
getDefaultVoteTemplateJsp
public java.lang.String getDefaultVoteTemplateJsp()
- Returns:
- the default jsp template to display the vote link in front office
- Since:
- jcms-8.0.0
-
getDefaultVoteListTemplateJsp
public java.lang.String getDefaultVoteListTemplateJsp()
- Returns:
- the default jsp template to display the vote link in front office
- Since:
- jcms-8.0.0
-
notifyAuthor
public void notifyAuthor(Vote vote)
Notifies the Publication's author that he has received a new vote- Parameters:
vote
- theVote
- Since:
- jcms-8.0.0
-
getVoteIcon
public java.lang.String getVoteIcon(int iconType)
- Parameters:
iconType
- the type of the icon- Returns:
- the like icon based on needed state to display in the jsp
- Since:
- jcms-8.0.0
-
getDefaultPositiveVoteIcon
public java.lang.String getDefaultPositiveVoteIcon()
- Returns:
- the default icon for like
- Since:
- jcms-8.0.0
-
getDefaultPositiveVoteHighlightIcon
public java.lang.String getDefaultPositiveVoteHighlightIcon()
- Returns:
- the default icon for dislike
- Since:
- jcms-8.0.0
-
getDefaultNegativeVoteIcon
public java.lang.String getDefaultNegativeVoteIcon()
- Returns:
- the default icon for like
- Since:
- jcms-8.0.0
-
getDefaultNegativeVoteHighlightIcon
public java.lang.String getDefaultNegativeVoteHighlightIcon()
- Returns:
- the default icon for dislike
- Since:
- jcms-8.0.0
-
getJcmsId
public java.lang.String getJcmsId(java.lang.String sentence)
Returns the jcmsId from a given sentence for the ttCard "ttLike"- Parameters:
sentence
- the String returned in context by the ttCard mechanism- Returns:
- the jcmsId from a given sentence for the ttCard "ttLike"
- Since:
- jcms-8.0.0
-
updatePubVoteWorkspace
public void updatePubVoteWorkspace(Publication pub)
Update vote's Workspace if the Workspace of the Publication differs from the Workspace of votes- Parameters:
pub
- thePublication
- Since:
- jcms-9.0.1
-
onPostInsert
public void onPostInsert(DBData data, org.hibernate.event.PostInsertEvent event, boolean firstTime)
Description copied from interface:DBListener
This method is called after a DBData has been created.- Specified by:
onPostInsert
in interfaceDBListener
- Overrides:
onPostInsert
in classBasicDBListener
- Parameters:
data
- the data.event
- the event.firstTime
- true on the JSync replica on which the operation took place and false on the other replicas.- See Also:
DBListener.onPostInsert(DBData, PostInsertEvent, boolean)
-
onPostUpdate
public void onPostUpdate(DBData data, org.hibernate.event.PostUpdateEvent event, boolean firstTime)
Description copied from interface:DBListener
This method is called after a DBData has been updated.- Specified by:
onPostUpdate
in interfaceDBListener
- Overrides:
onPostUpdate
in classBasicDBListener
- Parameters:
data
- the data.event
- the event.firstTime
- true on the JSync replica on which the operation took place and false on the other replicas.- See Also:
DBListener.onPostUpdate(DBData, PostUpdateEvent, boolean)
-
onPostDelete
public void onPostDelete(DBData data, org.hibernate.event.PostDeleteEvent event, boolean firstTime)
Description copied from interface:DBListener
This method is called after a DBData has been deleted.- Specified by:
onPostDelete
in interfaceDBListener
- Overrides:
onPostDelete
in classBasicDBListener
- Parameters:
data
- the deleted DBData. WARNING! In a JSync Cluster, when firstTime is false, this data will be null. In this case, to get information about this deleted data, you must use the event and in particular event.getId(), which returns the JPlatform ID of the data, and event.getDeletedState() which returns the attributes of the data.event
- the eventfirstTime
- true on the JSync replica on which the operation took place and false on the other replicas.- See Also:
DBListener.onPostDelete(DBData, PostDeleteEvent, boolean)
-
-