Skip to content

Content Drive: folder copy, async job endpoint and frontend wiring #37062

Closed

Description

@zJaaal

Description

Folder copy over a Content Drive multi-select, end to end: the asynchronous backend endpoint and the Content Drive wiring that drives it. One ticket, one operation, one deliverable — copy works in the product when this closes.

Re-split 2026-09-14. This ticket previously carried the backend for copy and bulk delete, with the frontend for copy, delete and move all sitting on #37063. The three tickets are now one per operation, each carrying its own backend and frontend, so each can be handed to one developer and finished without waiting on a sibling. No design decision changed — copy is still an async job for the reasons recorded below. Bulk delete is now #37063, move is #37165.

Why this cannot be a synchronous REST call

Copy is a single unbounded transaction over a recursive walk:

Entry point What runs inside that one transaction
FolderAPIImpl.copy @WrapInTransaction (FolderAPIImpl.java:369,387) FolderFactoryImpl.copy recurses over file assets (:501), pages (:516), links (:539) and child folders (:550)

Copying a folder holding thousands of assets holds one long transaction and times out at the proxy, and a multi-select multiplies it by the size of the selection. An earlier version of this work proposed a synchronous endpoint and designed around the expected timeout ("per-source transactions at least mean a timeout does not lose the folders already done"). Designing around an expected timeout is an async design with none of the machinery, so it is built as one.

Per-folder child lists are also loaded whole rather than paged, so peak memory is bounded by the widest single folder, not by the subtree. That is survivable; the transaction is the part that is not.

The job-queue framework already exists

No new infrastructure. com.dotcms.jobs.business is complete and Postgres-backed: JobProcessor, @Queue, Cancellable, ProgressTracker, retry policies, PostgresJobQueue, AbandonedJobDetector, RealTimeJobMonitor.

JobQueueResource (/v1/jobs) already exposes everything the caller needs after submission:

  • GET /v1/jobs/{jobId}/status
  • POST /v1/jobs/{jobId}/cancel
  • GET /v1/jobs/{jobId}/monitor, an SSE EventOutput
  • paginated active / completed / successful / failed / canceled / abandoned

Closest precedents to copy: CleanAssetsJobProcessor and FixAssetsJobProcessor (@Queue + Cancellable + AtomicBoolean cancel flag + progress reported only when the rounded percentage changes + a summary in getResultMetadata). ImportContentletsProcessor is the older precedent.


Backend

Proposed contract

A domain endpoint that enqueues and returns immediately, following the _import precedent of a domain resource wrapping the job queue rather than making callers post to the generic /v1/jobs/{queueName}:

POST /api/v1/assets/folders/_copy   -> 202, queue "folderCopy"
{
  "sourcePaths": ["//demo.dotcms.com/projects/alpha/", "//demo.dotcms.com/projects/beta/"],
  "destinationPath": "//demo.dotcms.com/archive/"
}

Answers 202 with the job handle:

{ "entity": { "jobId": "e6d9bae8-657b-4e2f-8524-c0222db66355", "statusUrl": "/api/v1/jobs/e6d9bae8-.../status" } }

The body is shared with move (#37165) deliberately, so the two folder relocation operations stay symmetrical.

Validation that can be done at submission time still uses status codes: a malformed body or an unresolvable destination is 400/404 before a job is created. Per-source outcomes are the job's business.

Pieces to build, all following patterns already in WebAssetResource:

Piece Follow
Immutable request form AbstractFolderDeletionRequestForm: @Value.Immutable, @JsonSerialize/@JsonDeserialize, @Schema with RequiredMode.REQUIRED and examples
Path to folder resolution folders/_delete (WebAssetResource.java:314) resolves assetPath; do the same for sources and destination
Permission gate WebResource.InitBuilder as in deleteFolder, plus READ on source and WRITE / CAN_ADD_CHILDREN on destination
OpenAPI @Operation annotations, then regenerate openapi.yaml

Per-path results move into the job result, they do not disappear

JobProcessor.getResultMetadata(Job) returns Map<String, Object>, so the per-path contract survives verbatim, just relocated out of a synchronous response body:

{
  "successCount": 3,
  "failCount": 2,
  "results": [
    { "path": "//demo.dotcms.com/projects/alpha/", "success": true },
    { "path": "//demo.dotcms.com/projects/beta/", "success": false, "error": "NAME_COLLISION", "message": "..." }
  ]
}

Each source folder is its own transaction, so one collision does not roll back the folders already copied. This shape is shared with #37063 and #37165 — the three must not diverge.

The real work is chunking, not the endpoint

Wrapping this in a job does not by itself fix the transaction. A job holding one 40-minute transaction is still one 40-minute transaction; it just stops timing out at the proxy. Meaningful progress, working cancellation and bounded memory all require chunking inside the recursion, which means changing FolderFactoryImpl, not only adding a JobProcessor. Estimate this ticket on that, not on the endpoint.

Cancellation semantics

A cancelled copy leaves the partial subtree in place at the destination, matching the CleanAssetsJobProcessor precedent — the user can delete it. Cancellation may land mid-folder. Two jobs copying overlapping subtrees must not run concurrently; the second submission is rejected with a readable reason rather than queued.


Frontend

Content Drive's action center operates on contentlets. Folders are selectable in the table but cannot be copied. This is the wiring.

#33468 already describes the intended destination-picker UX (a picker, not drag-and-drop, with a toast on completion), so this is the implementation of that for folder copy.

The job-progress primitive comes from #37166

Nothing in core-web calls /v1/jobs today, so a reusable primitive has to be built. #37166 (bulk file upload) owns it, because #32356 asks for the richer version (per-file progress and per-file cancel) and a primitive that satisfies upload satisfies the folder actions too. This ticket consumes it. Whichever of #37062 / #37063 / #37165 / #37166 lands first builds it to #37166's stated requirements and the rest reuse it unchanged — do not build it four times.

The flow: submit and get a jobId, follow the job, render progress, handle the terminal state, then report the result and refresh.

Following the job has two options and the cheap one is available:

  • GET /v1/jobs/{jobId}/monitor is an SSE EventOutput, and because it is a GET, native EventSource works with no shim. Worth stating explicitly: dot-content-drive-action-center.component.ts:126 records that the legacy _bulkfire SSE path was skipped precisely because "native EventSource cannot POST a body". That objection does not apply here — submission is a normal POST returning a jobId, monitoring is a separate GET.
  • GET /v1/jobs/{jobId}/status polling is the fallback if SSE proves awkward behind the proxy.

Things the primitive has to get right, which are easy to miss:

  • A job outlives the component. Navigating away, or closing the dialog, does not cancel it. Either the outcome stays discoverable when the user comes back, or the UI must say plainly that it will not be. Do not silently lose a running job's result.
  • Cancellation is exposed over POST /v1/jobs/{jobId}/cancel, with copy wording: cancelling leaves a partial copy at the destination.

Bulk means per-path results, not a boolean

The toast must report the server's counts, not the selection size — the same rule the existing quick actions follow. A per-folder failure has to name the folder and say why: name collision, permission, unresolvable path.

Copying a folder copies everything in it. The grid and the sidebar tree both refresh once the job completes, since they reload separately.

Acceptance Criteria

Submission

  • POST /api/v1/assets/folders/_copy accepts several sourcePaths plus one destinationPath, enqueues a folderCopy job and returns 202 with jobId and statusUrl
  • An immutable request form follows the AbstractFolderDeletionRequestForm pattern, with @Schema descriptions and examples on every property
  • A malformed body returns 400; an unresolvable destination returns 404, before any job is created
  • A caller with no rights to enqueue, or no WRITE / CAN_ADD_CHILDREN on the destination, gets 403 at submission
  • A destination resolving to a folder or to a site root both work; both FolderAPI.copy overloads already exist

Job execution

  • The processor is @Queue-annotated, implements Cancellable, and reports progress through Job#progressTracker() only when the rounded percentage changes
  • Each source folder runs in its own transaction; a failure on one does not roll back sources already completed nor abort the remaining ones
  • The recursion is chunked so that a folder with tens of thousands of descendants does not run in a single transaction and does not hold the whole subtree in memory
  • getResultMetadata returns successCount, failCount and a per-path results array; every failure carries a machine-readable error and a human-readable message
  • Copying a folder onto itself is a per-path failure naming the folder
  • Copying a folder into one of its own descendants is a per-path failure naming both folders
  • A name collision at the destination is a per-path failure, never a silent success
  • A per-source permission failure (no READ on source, no CAN_ADD_CHILDREN on destination) is reported per path
  • An unresolvable source path is a per-path failure, not a request-level error
  • The self-target and descendant-target guards and the index refresh live in FolderAPI.copy, not in the processor or the resource; BrowserAjax.copyFolder (BrowserAjax.java:963-970) is updated to rely on them so the logic exists once
  • Cancelling a copy leaves the partial subtree in place and the job result records how far it got
  • A submission overlapping an in-flight job's subtree is rejected with a readable reason rather than queued

Frontend

Docs and tests

  • The @Operation description states that the operation is asynchronous, names the folderCopy queue, and points at the /v1/jobs/{jobId} status, cancel and monitor endpoints
  • openapi.yaml regenerated from the annotations and committed alongside the Java changes
  • Integration tests cover: happy path over several folders, mixed partial failure, self-target, descendant-target, name collision, permission denied, folder-vs-site-root destination, cancellation mid-run, and a subtree large enough to exercise more than one chunk
  • Jest specs cover: progress updates, success, partial failure, job failure, cancellation, permission-denied, and teardown while a job is in flight

Priority

Medium

Additional Context

History of the decisions on this ticket, so they are not relitigated.

  • 2026-08-24 — copy became async. It previously proposed three synchronous endpoints (_copy, _move, _bulkdelete) and recorded async as "deliberately out of scope". That call did not survive review; the reasoning is under Why this cannot be a synchronous REST call.
  • 2026-08-24 — move was split out to Content Drive: folder move, batched async job endpoint and frontend wiring #37165. Move does not belong with copy because its cost profile is different: FolderFactoryImpl.move (:581) mints a new folder identifier and re-points every contentlet individually, which copy does not do.
  • 2026-09-14 — re-split by operation. Backend and frontend for copy now live together here.

The shipped single _delete (WebAssetResource.java:314) is untouched by this ticket. It takes one assetPath (AbstractFolderDeletionRequestForm:24) and is what the Content Drive context menu already uses. Bulk delete is #37063.

Two adjacent folder operations need no backend work at all:

Publish all is not being carried forward. Previously listed as a bulk fire with +conFolder:<folderInode>; dropped as unsupported. PublishFactory.publishAsset(Folder, ...) (PublishFactory.java:206) publishes contentlets directly and bypasses workflow schemes entirely, so the alternative is worse than the gap. Anything under a folder can still be published by selecting it and firing a workflow action.

Related: #37063 (bulk folder delete, end to end — same job-result contract), #37165 (folder move, end to end — shares the request body shape), #37166 (owns the job-progress primitive this ticket consumes, and reuses this ticket's job-result contract), #33468 (move/copy destination picker UX), #35161 (folder push publish family), #32302 (folder CRUD backend, original source of this carve-out), #32357 (the async folder move/copy feature this sits under), #36046 (bulk delete/download endpoints for publishing), #33999 (parent epic).

Activity

  1. added theissue type on Aug 14, 2026
  2. moved this from New to Current Sprint Backlog in dotCMS - Product Planningon Aug 14, 2026
  3. changed the title [-]Expose folder copy and move as REST endpoints[/-] [+]Expose bulk folder copy, move and delete as REST endpoints[/+] on Aug 20, 2026
  4. changed the title [-]Expose bulk folder copy, move and delete as REST endpoints[/-] [+]Async bulk folder copy and delete via the job queue[/+] on Aug 24, 2026
  5. zJaaal commented on Aug 24, 2026

    @zJaaal
    MemberAuthor

    Retitled and rewritten (2026-08-24): move split out to #37165, copy and bulk delete are now job-queue operations rather than synchronous endpoints. Reasoning and the verified code references are in the body; the What changed section also records a claim about folder move that this correction reverses.

    Analysis and edit by Claude (Claude Code), posted from @zJaaal's account.

  6. 147 remaining items

  7. removed their assignment
    on Sep 30, 2026
  8. self-assigned this
    on Oct 1, 2026
  9. rjvelazco commented on Oct 5, 2026

    @rjvelazco
    Member

    ✅ QA PASSED (with follow-ups that need discussion)

    Bulk folder duplicate works as specified: the dedicated endpoint and the Content Drive UI duplicate folders in place, with everything they hold, and enforce the 50-folder limit. While testing we found four issues outside this ticket's scope. They're filed separately and need a product/architecture decision, so they don't block this one.

    ✅ Post-merge test plan

    Case Result
    Duplicate several folders in place, with all their content ✅ 202 with submitted: 2; job SUCCESS with successCount: 2. qa-bulkdup-a_copy has child (with its file), the live file, the working-only page and the generic contentlet; qa-bulkdup-b_copy has the archived file. Originals unchanged.
    Request without authentication ✅ 401
    Front-end-only user ✅ Refused, but with 401 (lacks one of the required role [DOTCMS_BACK_END_USER]), not the 403 the plan expects. Bulk delete answers the same, so the plan should say 401.
    One folder over the advertised limit (folderBulkDuplicate.maxPaths = 50) ✅ 400 with OVER_MAX_PATHS on assetPaths

    ✅ UI (Content Drive)

    Check Result
    Action Center Duplicate Folder on a multi-select ✅
    Right-click Duplicate on one folder ✅
    Status indicator while it runs, then one toast; listing and tree reload ✅
    Over 50 selected: runs on the first 50 ✅
    A child folder selected with its parent counts as covered (warning, not error) ✅
    User X duplicates a folder with a subfolder X can't read ✅ Duplicate succeeds; see #37893 below
    qa-content-drive-number-copy.mov
    qa-deplicate-hidden-content.mov
    qa-duplication-from-a-frontend-user.mov
    qa-duplication-without-credentials.mov
    qa-normal-duplicate-and-havy-duplication-with-nested-levels.mov

    ⚠️ Follow-ups that need discussion (not blocking)

    1. #37895 — Duplicate allowed while another user is deleting the folder; the delete rolls back (High)
    User A bulk-deleted a folder with 15,000 files. While it ran, user B duplicated its subfolder: accepted with 202, no warning. The copy landed inside the folder being deleted, so after ~2.5 minutes the delete failed with a raw SQL error (Cannot delete as this path has children … check_child_assets()) and rolled back completely.
    Decision needed: we propose that while a delete runs, nothing else may act on what it covers (duplicate, move, upload, edit). The refusal would name who is deleting, e.g. "This folder is being deleted by Admin User. It can't be duplicated right now."

    2. #37893 — Duplicating a folder copies subfolders and files the user cannot read (Medium)
    Only the top folder's permissions are checked. The shipped recursive copy and this PR's system-user second pass copy everything inside, including a subfolder and a file user X has no READ on. The copies keep their permissions, so X still can't open them (no read leak seen), but X can multiply restricted content without the owner knowing.
    Decision needed: skip unreadable items (and say so in the result), refuse the folder, or keep copying everything as intended. Also confirm that restrictions coming from inheritance survive the copy (not tested).

    3. #37883 — /api/v1/jobs/folderBulkDuplicate skips the 50-folder limit (Medium)
    The limit is checked only in _bulkduplicate. Posting the same 51 paths to the generic job-queue endpoint returned 200 and duplicated all 51. Bulk delete and upload probably have the same gap (not verified).
    Decision needed: have the processor validate its own input (Validator, as ImportContentletsProcessor does), or stop the generic endpoint from creating jobs on these queues.

    4. #37894 — Repeat copies are named X_copy_copy (Low)
    The second duplicate of main_folder was named main_folder_copy_copy. Proposed: main_folder_copy_1, _copy_2, …, plus a case-insensitive name check (the code review flagged a likely failure for Alpha next to an existing alpha_copy).

    Not reproduced (from a code review of #37760)

    • Refusal reasons may reveal whether a folder the user can't read exists (PERMISSION_DENIED vs PATH_NOT_FOUND).
    • Any back-end user can read or cancel another user's job through /api/v1/jobs/{jobId} (existing job-queue behavior).
    • Two duplicates into the same parent wait on each other with no timeout.

    Drafted with Claude Code, reviewed and posted by @rjvelazco.

  10. removed their assignment
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions