def update(self, document_name, options):
        """
        Process update plugins.

        This is needed to update document properties like tags without re-storing document itself.

        Has ability to:
            - update document indexes
            - update document revision (upload new file to existing code)
            - update document tags
            TODO: continue this...

        @param options: should be dict with certain keys and values set that represent call requirements.
            keys and their meaning:
                - 'new_type' to change Document type.
                    Should be of DocumentTypeRule model instance selected with desired type OR unicode PK of that model
        """
        log.debug("UPDATE Document %s, options: %s" % (document_name, options))
        new_name = self.option_in_options("new_name", options)
        new_type = self.option_in_options("new_type", options)
        new_file_revision = self.option_in_options("update_file", options)
        user = self.option_in_options("user", options)

        # Sequence to make a new name for file.
        # TODO: this deletes all old revisions, instead of real rename of all files...
        # Must become a plugins sequence task.
        if new_name:
            extension = self.option_in_options("extension", options)
            renaming_doc = self.read(document_name, options={"extension": extension, "user": user})
            if new_name != renaming_doc.get_filename():
                ufile = UploadedFile(renaming_doc.get_file_obj(), new_name, content_type=renaming_doc.get_mimetype())
                document = self.create(ufile, {"user": user})
                if not self.errors:
                    self.delete(renaming_doc.get_filename(), options={"extension": extension, "user": user})
                return document

        operator = PluginsOperator()
        doc = self.init_Document_with_data(options, document_name=document_name)
        if new_type is not None:
            # HACK: Read the data and remove thumbnails in one call
            old_document = self.read(document_name, {"user": user, "only_metadata": True, "remove_thumbnails": True})
            # Retrieving file revisions and storing into self for plugins modifications.
            fr_data = old_document.get_file_revisions_data()
            for rev_id in fr_data.iterkeys():
                temp_doc = self.read(document_name, {"user": user, "revision": rev_id})
                doc.file_revisions[rev_id] = temp_doc.get_file_obj()
        # Storing new file revision of an object. It requires content setup from uploaded file.
        if new_file_revision:
            if "content_type" in new_file_revision.__dict__.iterkeys():
                doc.set_mimetype(new_file_revision.content_type)
            else:
                error = "Error updating file revision for file: %s" % new_file_revision
                log.error(error)
                self.errors.append(error)
        doc = operator.process_pluginpoint(pluginpoints.BeforeUpdatePluginPoint, document=doc)
        doc = operator.process_pluginpoint(pluginpoints.UpdatePluginPoint, document=doc)
        doc = operator.process_pluginpoint(pluginpoints.DatabaseUpdatePluginPoint, document=doc)
        self.check_errors_in_operator(operator)
        return doc
    def update(self, document_name, options):
        """
        Process update plugins.

        This is needed to update document properties like tags without re-storing document itself.

        Has ability to:
            - update document indexes
            - update document revision (upload new file to existing code)
            - update document tags
            TODO: continue this...

        @param options: should be dict with certain keys and values set that represent call requirements.
            keys and their meaning:
                - 'new_type' to change Document type.
                    Should be of DocumentTypeRule model instance selected with desired type OR unicode PK of that model
        """
        log.debug('UPDATE Document %s, options: %s' % (document_name, options))
        new_name = self.option_in_options('new_name', options)
        new_file_revision = self.option_in_options('update_file', options)
        user = self.option_in_options('user', options)

        # Sequence to make a new name for file.
        # TODO: this deletes all old revisions, instead of real rename of all files...
        # Must become a plugins sequence task.
        if new_name:
            extension = self.option_in_options('extension', options)
            renaming_doc = self.read(document_name, options={'extension': extension, 'user': user})
            if new_name != renaming_doc.get_filename():
                ufile = UploadedFile(renaming_doc.get_file_obj(), new_name, content_type=renaming_doc.get_mimetype())
                document = self.create(ufile, {'user': user})
                if not self.errors:
                    self.delete(renaming_doc.get_filename(), options={'extension': extension, 'user': user})
                return document

        operator = PluginsOperator()
        doc = self.init_Document_with_data(options, document_name=document_name)
        # Storing new file revision of an object. It requires content setup from uploaded file.
        if new_file_revision:
            if 'content_type' in new_file_revision.__dict__.iterkeys():
                doc.set_mimetype(new_file_revision.content_type)
            else:
                error = 'Error updating file revision for file: %s' % new_file_revision
                log.error(error)
                self.errors.append(error)
        doc = operator.process_pluginpoint(pluginpoints.BeforeUpdatePluginPoint, document=doc)
        doc = operator.process_pluginpoint(pluginpoints.UpdatePluginPoint, document=doc)
        doc = operator.process_pluginpoint(pluginpoints.DatabaseUpdatePluginPoint, document=doc)
        self.check_errors_in_operator(operator)
        return doc
 def delete(self, document_name, options):
     """Deletes Document() or it's parts from DMS."""
     log.debug("DELETEE Document %s, options: %s" % (document_name, options))
     operator = PluginsOperator()
     doc = self.init_Document_with_data(options, document_name=document_name)
     if self.option_in_options("delete_revision", options):
         doc = self.read(document_name, options)
     doc = operator.process_pluginpoint(pluginpoints.BeforeRemovalPluginPoint, document=doc)
     self.check_errors_in_operator(operator)
     return doc