Analysis
Overview
The purpose of this task is to define the MetaChanges for the resources of R4 and their logic.
Task requirements
- There should be three kinds of MetaChanges - UNDO, REDO and SKIP.
- Every MetaChange should reverse the effect of previous one. This includes the concrete effect of the reversed change as well as all other effects of the fowling changes that were a result of the reversed change`s effect.
- The UNDO change is reversing the effect of a previous ModelChange.
- The REDO change is reversing the effect of the last UNDO change.
- The SKIP change is reversing any change in the resource history.
Task result
The task result will be source code.
Implementation idea
All MetaChanges could be implemented as instances of a single class with a certain type - UNDO, REDO or SKIP. This could be indicated with an enum field in the MetaChange. They should also keep the id of the revision the change which effect they want to reverse.
Related
GROUP_RESOURCE_MODEL_REDESIGN_R0
How to demo
This will be demonstrated with a test that creates a resource with a few changes in its history and skips the last, a middle revision and the first one.
Design
The MetaChangeType is an Enumeration representing the different kinds of meta changes. For now they are UNDO, REDO and SKIP.
The MetaChange class inherits the base Change class. It is immutable and has two private final properties – type and skippedRevision.
- type is MetaChangeType and should be used when deciding which the skipped revision should be. For example when the user wants to undo the skipped revision is the last revision with causing change that is neither UNDO nor SKIP.
- skippedRevision is a RevisionId that represents the revision the ChangeEffect of which should be reversed.
The MetaChange should have ChangeEffect getEffect(ResourceRevision revision) method to calculate the needed alterations to the current revision to revert the effect of the skipped one. It should neutralize the direct effect of the revision and all other effects resulting from it.
There will be a recursive method skipRevision that should take as arguments the revision up to which the changes effect should be reverted and a list of skipped revisions, i.e. revisions that are skipped and its effects should not be taken in consideration.
- If the revision is the one we want to skip its revert effect is returned. It is calculated as for any key of its causing effect are taken the values from the model of the last significant revision prior to the current.
- If the revision is caused by a meta-change (that is not the skipped one!) or by a insignificant change it recursively calls the reversion of the last significant revision prior to it.
- In case the change is ModelChange and it is significant the revert writes up to this revision is calculated by calling the method recursively. Then it is checked if this revision’s effect is affected by the resulting revertWrites, that is, if the causing effect reads any reverted keys. If it is not, the revert writes are returned. Otherwise the previous significant revision is taken and its model is modified to get the accurate model which should be given as argument to the getEffect() method of the model change. The accurate effect of this change is calculated and is added to the revert writes. Then they are returned. If an exception is caught while reevaluating the accurate effect, the whole change is considered invalid and its effect is reverted and returned plus the revert writes.
The ResourceRevision applyChange() method should be altered to apply MetaChanges using the getChangeEffect() method. It should also catch any exception occurring in the ChangeEffect method, i.e. catch Trowable because often changes are discovered to be invalid for a specific revision due to an assertation error and the ways to invalidate a ModelChange with any specified performAuto method are not foreseeable.
There is a test to all different cases for skipping an revision. [5800] [5830]
Implementation
Implementation is done according to the design - [5800], [5952], [5992], [5993]
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)