Class PlannedChangesService

java.lang.Object
sk.iway.iwcm.doc.PlannedChangesService

@Service public class PlannedChangesService extends Object
Prepares, validates, publishes and cancels a page's planned files and media.

Page revisions remain in the existing history table. Planned media are stored separately under PLANNED_MEDIA_TABLE, while the page's initialization flag distinguishes an intentionally empty media set from an uninitialized one.

The editor and DocPublishService control page saves and history completion. Callers enforce page-edit permissions; this service checks destination-folder rights before publishing files. Database writes and file replacements are not one transaction: retryable steps retain planned source data until their live replacements are saved.

  • Field Details

  • Constructor Details

  • Method Details

    • getInstance

      public static PlannedChangesService getInstance()
    • requirePlannedMedia

      public void requirePlannedMedia(int docId)
      Requires an active planned media set before accepting a media operation.
      Parameters:
      docId - page ID whose initialization flag is checked
      Throws:
      IllegalArgumentException - if planned publishing is disabled or the media set is uninitialized
    • validateMedia

      public void validateMedia(sk.iway.spirit.model.Media item, int docId)
      Validates an individual planned media edit without inspecting its linked files.

      Requires initialized planned media and rejects private asset references in localized titles and the media group. File checks run when saving or publishing the page's plan.

      Parameters:
      item - media values submitted for editing
      docId - page ID owning the planned media set
      Throws:
      IllegalArgumentException - if the media set is inactive or a restricted field contains a planned reference
    • activeHistory

      public Long activeHistory(int docId)
      Finds the newest history record still marked for publication.
      Parameters:
      docId - page ID whose pending revisions are searched
      Returns:
      highest pending history ID, or null when no pending revision exists
    • initialize

      public Long initialize(int docId)
      Initializes planned media from the page's live media once, then returns its pending history ID.

      Media are scoped to the current domain. Before an uninitialized copy is attempted, any incomplete planned set is deleted. The initialization flag is written only after every copy is saved, allowing a failed attempt to restart from the live set. An already initialized set, including an empty one, is left unchanged.

      Parameters:
      docId - page ID whose planned media should be initialized
      Returns:
      newest pending history ID, or null if no revision is scheduled
      Throws:
      IllegalArgumentException - if planned publishing is disabled
    • cancel

      public void cancel(int docId)
      Cancels pending revisions and removes the page's planned media and working files.

      Clears publication and approval flags on pending history records, deletes planned media in the current domain and clears the initialization flag. Live content and publication backups are retained. Earlier writes are not rolled back if cleanup fails.

      Parameters:
      docId - page ID whose planned changes should be cancelled
      Throws:
      IllegalStateException - if planned working files cannot be deleted
    • prepareSave

      public void prepareSave(DocDetails doc, Identity user)
      Prepares and validates an edited revision before the editor saves its scheduled history.

      Requires a saved page, enabled history, a publication date and, when present, the active history ID. Initializes planned media and restores the live page's URL and folder on the supplied object. Checks restricted fields, references after a simulated rewrite, all staged files, destination permissions and conflicts with other plans.

      The existing plan is not cancelled here. Initialization and changes to the supplied object can already have happened when a later validation fails.

      Parameters:
      doc - edited page revision, modified to retain the live URL and folder
      user - editor whose write permissions are checked for public destination folders
      Throws:
      IllegalArgumentException - if the revision, files, permissions or destination conflicts prevent planning
      IllegalStateException - if planned working directories cannot be read
    • completeSave

      public void completeSave(DocHistory saved)
      Deactivates older pending revisions after the replacement history has been saved.
      Parameters:
      saved - persisted replacement revision; pending records with the same or a higher ID are retained
    • rejectPrivateReferences

      public static void rejectPrivateReferences(Object bean)
      Prevents private planned references from entering live data through ordinary editing or restoration.
      Parameters:
      bean - object whose persisted string properties are inspected
      Throws:
      IllegalArgumentException - with a localized message if a planned reference is found
    • hasPrivateReferences

      public static boolean hasPrivateReferences(Object bean)
      Detects planned references in readable string fields annotated with @Column.

      Inspects inherited fields as well as fields declared on the supplied class. HTML entities are decoded before matching. Unmapped computed properties are skipped to avoid invoking getters that can perform unrelated database work.

      Parameters:
      bean - object whose persisted string properties are inspected
      Returns:
      true if any inspected value contains a planned-directory reference