예제 #1
0
    def read(self, document_name, options):
        """
        Reads Document() data from DMS

        Method creates, instantiates and populates new Document() object.
        Using name and/or search filter criteria provided.

        Currently can read Document() with file object attached or either read only file info data.

        """
        log.debug("READ Document %s with options: %s" % (document_name, options))
        doc = Document()
        operator = PluginsOperator()
        # Checking if name really possible in current DMS config.
        try:
            doc.set_filename(document_name)
        except DmsException, e:
            self.errors.append(unicode(e.parameter))
            return doc
            pass
예제 #2
0
    def init_Document_with_data(self, options, doc=None, document_name=None, document_file=None):
        """Populate given Document() class with given properties from "options" provided

        Makes expansion of interaction methods with Document() simple.
        Expand this actions to add new interactions with Document() object...

        Connector between "options" passed to this CRUD manager and later Plugin() interactions.

        @options is a dict of operation options (that change behaviour of operations)
        @doc is a Document() instance
        @document_name is a name of a document being processed
        @document_file is a file object being processed
        """
        if doc is None:
            doc = Document()
        # All methods sequence, besides create()
        if document_name:
            doc.set_filename(document_name)
        # Usually create() method sequence
        if document_file:
            doc.set_file_obj(document_file)
            if hasattr(document_file, "content_type"):
                doc.set_mimetype(document_file.content_type)
        if options:
            try:
                for property_name, value in options.iteritems():
                    if property_name == "hashcode":
                        doc.set_hashcode(value)
                    if property_name == "revision":
                        doc.set_revision(value)
                    # Run for plugins without retrieving document. Only count file info data.
                    if property_name == "revision_count":
                        doc.update_options({"revision_count": True, "only_metadata": True})
                    if property_name == "extension":
                        doc.set_requested_extension(value)
                    if property_name == "tag_string":
                        if value:
                            doc.set_tag_string(value)
                            doc.update_options({property_name: value})
                    if property_name == "remove_tag_string":
                        if value:
                            doc.set_remove_tag_string(value)
                            doc.update_options({property_name: value})
                    if property_name == "new_indexes":
                        doc.update_db_info(value)
                    if property_name == "user":
                        doc.set_user(value)
                    if property_name == "index_info":
                        # Not to modify original data during workflow
                        data = value.copy()
                        doc.set_db_info(data)
                    if property_name == "new_type":
                        if value:
                            doc.set_change_type(value)
                    if property_name == "mark_revision_deleted":
                        if value:
                            doc.update_options({property_name: value})
                    if property_name == "delete_revision":
                        if value:
                            doc.update_options({property_name: value})
                            doc.set_revision(int(value))
                    if property_name in ["indexing_data", "thumbnail", "mark_deleted", "remove_thumbnails"]:
                        if value:
                            doc.update_options({property_name: True})
                    if property_name == "update_file":
                        doc.set_file_obj(value)
                        if value:
                            # Option for update function so we know we have a file update sequence
                            doc.update_options({property_name: True})
                if "only_metadata" in options:
                    doc.update_options({"only_metadata": options["only_metadata"]})
            except Exception, e:
                self.errors.append("Error working with Object: %s" % e)
                log.error(
                    "DocumentManager().init_Document_with_data() error: %s, doc: %s, options: %s, document_name: %s"
                    % (e, doc, options, document_name)
                )
                pass
            # Every method call should have a Django User inside. Validating that.
            if not "user" in options and not options["user"]:
                error = 'Wrong DocumentProcessor() method call. Should have a proper "user" option set'
                log.error(error)
                self.errors.append(error)
                raise DmsException(error, 500)