Ga naar hoofdinhoud

Copying and moving objects

Two acts that look alike and are not. A move keeps who the object is; a copy makes a new object.

Specs​

Move: same object, new place​

POST /api/objects/{register}/{schema}/{id}/move

The object goes to another register and schema and keeps its uuid. Its audit trail, versions, files, notes and watchers all stay with it, because they are keyed on the uuid. Generated numbers (x-openregister-generated) are kept as they are.

POST /api/objects/{register}/{schema}/{id}/copy

{
"overrides": { "naam": "Zaaksysteem B" },
"include": ["relationRows", "incoming"]
}
  • The caller needs read on the source (else 404) and create on the schema (else 403). Without a session the answer is 401.
  • The new object is made through the normal create path, so validation, defaults, generated identifiers and the audit trail all apply. A body the create path refuses is answered as that refusal (for example 422 with the validation errors), and nothing is written.
  • The copy gets its own uuid, and starts its own audit trail and versions from its first save. The source is never changed.

What is never copied​

  • The identity: id, uuid and the @self metadata.
  • Control keys starting with _.
  • Properties the platform mints (x-openregister-generated): the copy gets a fresh number.
  • An upsert: _upsertOn is refused with 422, because a copy always creates.
KindWhat happens
relationRowsEach relation row of the source (manual links to objects and external links) is re-created with the copy as its source. Provenance rows (split, derive) and prose rows are not copied, because they describe the source, not the copy. A row to an object the caller cannot read is skipped.
incomingEvery object whose array reference holds the source gets the copy added beside it. Each such object is read and updated under the caller's own rights. A single-valued reference is left alone: pointing it at the copy would take it away from the source.
filesEvery file attached to the source is copied to the copy's folder, after the copy and its other links are committed (the file system is not transactional). Each file is reported copied, or failed with a reason; a failed file does not undo the copy.

An unknown kind is refused with 422.

A link the caller may not write is reported, not forced, and does not stop the copy. The new object and its links are written in one transaction: if the create is refused, or a link step fails unexpectedly, nothing is written (answer 500 for the latter).

The answer​

201:

{
"object": { "...": "the new object" },
"links": {
"relationRows": [{ "id": "…", "title": "Conduction", "outcome": "copied", "reason": null }],
"incoming": [{ "id": "…", "title": "Basis", "outcome": "skipped", "reason": "You may not update this object." }],
"files": [{ "id": "812", "title": "besluit.pdf", "outcome": "copied", "reason": null }]
}
}
  • lib/Controller/ObjectsController.php (copy(), move())
  • lib/Service/Object/CopyPayload.php, lib/Service/Object/CopyObject.php, lib/Service/Object/CopyFiles.php
  • lib/Service/Object/MoveObject.php