Class PlannedChangesService
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPlannedChangesService(DocDetailsRepository docDetailsRepository, DocHistoryRepository docHistoryRepository, MediaRepository mediaRepository) -
Method Summary
Modifier and TypeMethodDescriptionactiveHistory(int docId) Finds the newest history record still marked for publication.voidcancel(int docId) Cancels pending revisions and removes the page's planned media and working files.voidcompleteSave(DocHistory saved) Deactivates older pending revisions after the replacement history has been saved.static PlannedChangesServicestatic booleanhasPrivateReferences(Object bean) Detects planned references in readable string fields annotated with@Column.initialize(int docId) Initializes planned media from the page's live media once, then returns its pending history ID.voidprepareSave(DocDetails doc, Identity user) Prepares and validates an edited revision before the editor saves its scheduled history.static voidPrevents private planned references from entering live data through ordinary editing or restoration.voidrequirePlannedMedia(int docId) Requires an active planned media set before accepting a media operation.voidvalidateMedia(sk.iway.spirit.model.Media item, int docId) Validates an individual planned media edit without inspecting its linked files.
-
Field Details
-
PLANNED_MEDIA_TABLE
- See Also:
-
-
Constructor Details
-
PlannedChangesService
public PlannedChangesService(DocDetailsRepository docDetailsRepository, DocHistoryRepository docHistoryRepository, MediaRepository mediaRepository)
-
-
Method Details
-
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 editingdocId- page ID owning the planned media set- Throws:
IllegalArgumentException- if the media set is inactive or a restricted field contains a planned reference
-
activeHistory
Finds the newest history record still marked for publication.- Parameters:
docId- page ID whose pending revisions are searched- Returns:
- highest pending history ID, or
nullwhen no pending revision exists
-
initialize
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
nullif 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
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 folderuser- editor whose write permissions are checked for public destination folders- Throws:
IllegalArgumentException- if the revision, files, permissions or destination conflicts prevent planningIllegalStateException- if planned working directories cannot be read
-
completeSave
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
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
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:
trueif any inspected value contains a planned-directory reference
-