Class SuggestedRevisionService

java.lang.Object
fr.paris.lutece.plugins.wiki.service.SuggestedRevisionService

public final class SuggestedRevisionService extends Object
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 Details

    • create

      public static SuggestedRevision create(SuggestedRevision suggestion)
      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

      public static SuggestedRevision findById(int nId)
      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

      public static boolean isSuggestible(AbstractWikiItem item)
      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

      public static Map<Integer,Integer> countPendingByEntities(List<Integer> entityIds)
      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 user
      nEntityId - 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 id
      reviewer - display name of the approver
      strReviewComment - optional comment from the reviewer
      strResolvedContent - 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

      public static List<MergeBlock> computeMergeBlocks(SuggestedRevision s, Revision current)
      Computes the three-way merge blocks for a suggestion against the given current revision.
      Parameters:
      s - the suggestion
      current - 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

      public static int[] diffStats(SuggestedRevision s)
      Computes diff statistics for a suggestion against the revision that was current when it was proposed. Mirrors GitHub's +X -Y indicator. 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

      public static SuggestedRevision reject(int nSuggestionId, String reviewer, String strReviewComment)
      Rejects a pending suggestion.
      Parameters:
      nSuggestionId - the suggestion id
      reviewer - display name of the rejecter
      strReviewComment - optional motive from the reviewer
      Returns:
      the rejected suggestion (or null if not found / not pending)
    • deleteByOwner

      public static boolean deleteByOwner(int nSuggestionId, String strAuthorGuid)
      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 id
      strAuthorGuid - the requester guid (must match the suggestion's author)
      Returns:
      true if the suggestion was deleted, false otherwise