eclipse-emfcloud / emfcloud-modelserver

Modelserver component
Other
40 stars 21 forks source link

API V2: Add support for Json Patch 'test' operations #178

Open CamilleLetavernier opened 2 years ago

CamilleLetavernier commented 2 years ago

Follow-up for PR #151

At the moment, we support a subset of the Json Patch standard (Add, Replace and Remove operations), as each operation needs to be carefully translated to an equivalent EMF Command.

The Json Patch standard also defines a 'test' operation, to make sure we're applying the patch on a consistent version of a model. We should add support for this 'test' operation in the Model Server, and reject the edit request for the entire patch if a test operation is not valid.

CamilleLetavernier commented 2 years ago

In general, it would also be interesting to have a "version" attribute for models, since the EMF.Cloud architecture is inherently asynchronous. At the moment, patches can be instantiated on the client side on an older version of the model, while a command is being processed, which could lead to unexpected results (Either a patch would not apply at all, or would apply in an inconsistent way).

For simple editions, like modifying attributes, this isn't an issue; but for more complex commands (Manipulating entire sub-trees or cross-references), 'test' operations might not be sufficient to ensure model consistency. With a generic version attribute on the model, we could 'test' for a specific version of the model before applying the patch.

This attribute also doesn't need to exist in the EMF Model: it can probably be derived as part of the Json Model generation, as an additional metadata attribute (e.g. $version). In this case, the ModelServer would only need to keep the current version in memory, without actually persisting it; and it would work with any model.