Lately, I've been working on better supporting update, updateContent, delete, and deleteContent. As such, I'm thinking through exhaustive constraints and logic that would 1.) guarantee data integrity and 2.) allow these actions to work cleanly. Here's what I've come up with so far:
UPDATE (note: metadata only)
- Prevent the UUID from changing
- No need to check relationships targeting this artifact
- Block the action if any generic or modeled relationships target this artifact or any of its derived artifacts ("referential constraint")
- Derived relationships (ie, automatically generated and not editable by clients, such as importsXsds) targeting this artifact should be automatically removed, if all other constraints pass.
- A content update has the potential to change a primary artifact's set of derived artifacts. I was thinking that the derived artifacts would be deleted (not trashed, but completely removed), then regenerated.
- If generic/modeled relationships target any of the derived artifacts, block the update.
- Derived relationships will be regenerated on the primary artifact.
- In addition, if any custom properties or classifiers are attached to a derived artifact, block the update. This is to protect clients from unknowingly deleting custom metadata, plus it furthers the "impact analysis" concept.
- This has the potential to be the most complicated discussion. At first glance, the action seems pointless -- a document artifact should never be without content. However, the spec allows document artifacts to be created in two shots: one to create the metadata and one to populate its content. Therefore, a content-less state is possible and must be supported.
- If generic/modeled relationships target any of the derived artifacts, block the delete.
- When looking for relationships that target the artifact in question, only the root tree is considered. Ie, if a relationship source is deleted and moved to the trash, its relationships do not necessarily have to be removed (nor should they).
- Relevant JIRAs: [SRAMP-601] Support deleting an artifact's content - JBoss Issue Tracker, [SRAMP-541] Tighten the restrictions on artifact content updates - JBoss Issue Tracker, probably others
I already have some of the constraint queries in place. However, once we've nailed down the definitive rules, I'll switch to a test-first approach and make sure all bases are covered.