Class SuggestedRevisionService
java.lang.Object
fr.paris.lutece.plugins.wiki.service.SuggestedRevisionService
Application service handling the lifecycle of suggested revisions: creating
a proposal, listing the inbox of a reviewer, approving (which materialises
a real Revision via
RevisionService) and rejecting.-
Method Summary
Modifier and TypeMethodDescriptionstatic SuggestedRevisionApproves a pending suggestion.static List<MergeBlock>computeMergeBlocks(SuggestedRevision s, Revision current) Computes the three-way merge blocks for a suggestion against the given current revision.countPendingByEntities(List<Integer> entityIds) Counts pending suggestions for a batch of entities in a single query.static intcountPendingByEntity(int nEntityId) Returns the count of pending suggestions on a wiki item.static SuggestedRevisioncreate(SuggestedRevision suggestion) Persists a new pending suggestion proposed by a user without edit rights.static booleandeleteByOwner(int nSuggestionId, String strAuthorGuid) Deletes a pending suggestion when initiated by its author.static int[]Computes diff statistics for a suggestion against the revision that was current when it was proposed.static SuggestedRevisionfindById(int nId) Returns a suggestion by its primary key.static SuggestedRevisionfindMyPending(fr.paris.lutece.portal.service.security.LuteceUser user, int nEntityId) Returns the pending suggestion submitted by the given user on the given wiki item, if one exists.static List<SuggestedRevision>getMine(fr.paris.lutece.portal.service.security.LuteceUser user) Returns the suggestions submitted by the given user, regardless of status.static List<SuggestedRevision>getReview(fr.paris.lutece.portal.service.security.LuteceUser user) Returns the list of pending suggestions targeting wiki items the given user has the right to edit.static booleanTells whether suggestions are allowed on the given item type.static Map<Integer,AbstractWikiItem> loadItemsByEntityId(List<SuggestedRevision> suggestions) Bulk-loads the wiki items referenced by a list of suggestions, in a single query.static SuggestedRevisionRejects a pending suggestion.
-
Method Details
-
create
Persists a new pending suggestion proposed by a user without edit rights.- Parameters:
suggestion- the suggestion to create (status will be forced to PENDING)- Returns:
- the persisted suggestion
-
findById
Returns a suggestion by its primary key.- Parameters:
nId- the suggestion id- Returns:
- the suggestion or null
-
countPendingByEntity
public static int countPendingByEntity(int nEntityId) Returns the count of pending suggestions on a wiki item.- Parameters:
nEntityId- the wiki item id- Returns:
- the count
-
isSuggestible
Tells whether suggestions are allowed on the given item type. Currently restricted to items that carry a reviewable content: pages, books and spaces.- Parameters:
item- the targeted wiki item- Returns:
- true when proposing/approving a revision on this item is supported
-
countPendingByEntities
Counts pending suggestions for a batch of entities in a single query.- Parameters:
entityIds- the entity ids- Returns:
- a map of entity id to pending count
-
getMine
public static List<SuggestedRevision> getMine(fr.paris.lutece.portal.service.security.LuteceUser user) Returns the suggestions submitted by the given user, regardless of status. Backs the "mine" view (the proposer's history).- Parameters:
user- the lutece user- Returns:
- the user's own suggestions
-
findMyPending
public static SuggestedRevision findMyPending(fr.paris.lutece.portal.service.security.LuteceUser user, int nEntityId) Returns the pending suggestion submitted by the given user on the given wiki item, if one exists. Used to enforce the "one pending proposal per user per page" rule and to surface a warning on the page view.- Parameters:
user- the lutece usernEntityId- the wiki item id- Returns:
- the pending suggestion if any, null otherwise
-
getReview
public static List<SuggestedRevision> getReview(fr.paris.lutece.portal.service.security.LuteceUser user) Returns the list of pending suggestions targeting wiki items the given user has the right to edit. Backs the "review" view (the reviewer's queue).- Parameters:
user- the lutece user- Returns:
- pending suggestions visible to this reviewer
-
loadItemsByEntityId
public static Map<Integer,AbstractWikiItem> loadItemsByEntityId(List<SuggestedRevision> suggestions) Bulk-loads the wiki items referenced by a list of suggestions, in a single query.- Parameters:
suggestions- the suggestions to load items for- Returns:
- a map of entity id to wiki item
-
approve
public static SuggestedRevision approve(int nSuggestionId, String reviewer, String strReviewComment, String strResolvedContent) Approves a pending suggestion. With an explicit resolved content, it is applied verbatim; otherwise a three-way merge against the current revision is attempted.- Parameters:
nSuggestionId- the suggestion idreviewer- display name of the approverstrReviewComment- optional comment from the reviewerstrResolvedContent- content explicitly resolved by the reviewer, or null to attempt auto-merge- Returns:
- the approved suggestion, or null when not found or when an unresolved conflict leaves the suggestion in PENDING
-
computeMergeBlocks
Computes the three-way merge blocks for a suggestion against the given current revision.- Parameters:
s- the suggestioncurrent- the current revision of the targeted item (may be null)- Returns:
- the ordered merge blocks, or an empty list when no merge is required
-
diffStats
Computes diff statistics for a suggestion against the revision that was current when it was proposed. Mirrors GitHub's+X -Yindicator. The conflict flag is only meaningful for PENDING suggestions: it tells whether the proposed change still merges cleanly against the up-to-date current revision.- Parameters:
s- the suggestion to analyse- Returns:
- a three-element array
[additions, deletions, hasConflict](hasConflict is 0 or 1)
-
reject
Rejects a pending suggestion.- Parameters:
nSuggestionId- the suggestion idreviewer- display name of the rejecterstrReviewComment- optional motive from the reviewer- Returns:
- the rejected suggestion (or null if not found / not pending)
-
deleteByOwner
Deletes a pending suggestion when initiated by its author. The suggestion must be in PENDING status. Approved or rejected proposals are kept as audit history and cannot be removed.- Parameters:
nSuggestionId- the suggestion idstrAuthorGuid- the requester guid (must match the suggestion's author)- Returns:
- true if the suggestion was deleted, false otherwise
-