Exemplo n.º 1
0
    def modifyObjectAction(self, object, new_attr):
        """
        Modify the object using an action.
        The result is the action which has already been executed.
        """
        old_id = object.id
        object.checkEditable()
        old_attr = object.getAttributes()
        new_id = new_attr["id"]
        domain = object.update_domain

        if old_id != new_id:
            existing = self.get(new_id)
            if (existing is not None) and (existing is not object):
                duplicateIdentifierError(new_id)
            apply_updates = Updates(Update(domain, "delete", old_id), Update(domain, "create", new_id))
            unapply_updates = Updates(Update(domain, "delete", new_id), Update(domain, "create", old_id))
        else:
            apply_updates = Updates(Update(domain, "update", new_id))
            unapply_updates = apply_updates

        action = Action(
            ActionHandler(apply_updates, self._setattr, object, new_attr),
            ActionHandler(unapply_updates, self._setattr, object, old_attr),
        )
        if old_id != new_id and object.original_id:
            set_original = Action(
                ActionHandler(apply_updates, self._set_original_id, object, None),
                ActionHandler(unapply_updates, self._set_original_id, object, object.original_id),
            )
            action.chain(set_original)
        action.apply()
        if old_id != new_id:
            self._updateObjects(action, object.references, object, old_attr)
            self._updateObjects(action, object.getReferents())
        object.onModifyAction(action, old_attr)
        return action
Exemplo n.º 2
0
 def checkIdentifierUnicity(self, identifier):
     if identifier in self.resources:
         duplicateIdentifierError(identifier)