(self)
return document
Merge the current document with any previous revision
      or change its version to make sure it is still unique.

      NOTE: revision support is implemented in the Document
      class rather than within the ContributionTool
      because the ingestion process requires to analyse the content
      of the document first. Hence, it is not possible to
      do any kind of update operation until the whole ingestion
      process is completed, since update requires to know
      reference, version, language, etc. In addition,
      we have chosen to try to merge revisions after each
      metadata discovery as a way to make sure that any
      content added in the system through the ContributionTool
      (ex. through webdav) will be merged if necessary.
      It may be posssible though to split disoverMetadata and
      finishIngestion.
Merge the current document with any previous revision
      or change its version to make sure it is still unique.
Merge the current document with any previous revision or change its version to make sure it is still unique .
def mergeRevision(self):
    """
      Merge the current document with any previous revision
      or change its version to make sure it is still unique.

      NOTE: revision support is implemented in the Document
      class rather than within the ContributionTool
      because the ingestion process requires to analyse the content
      of the document first. Hence, it is not possible to
      do any kind of update operation until the whole ingestion
      process is completed, since update requires to know
      reference, version, language, etc. In addition,
      we have chosen to try to merge revisions after each
      metadata discovery as a way to make sure that any
      content added in the system through the ContributionTool
      (ex. through webdav) will be merged if necessary.
      It may be posssible though to split disoverMetadata and
      finishIngestion.
    """
    document = self
    if self.getReference():
      invalid_validation_state_list = ('archived', 'cancelled', 'deleted')
      catalog = self.getPortalObject().portal_catalog
      # Find all document with same (reference, version, language)
      kw = dict(portal_type=self.getPortalType(),
                reference=self.getReference(),
                query=NegatedQuery(Query(validation_state=invalid_validation_state_list)),
                sort_on='creation_date')

      if self.getVersion():
        kw['version'] = self.getVersion()
      if self.getLanguage():
        kw['language'] = self.getLanguage()
      document_list = catalog.unrestrictedSearchResults(**kw)
      existing_document = None
      # Select the first one which is not self and which
      # shares the same coordinates
      for o in document_list:
        if o.getRelativeUrl() != self.getRelativeUrl() and\
           o.getVersion() == self.getVersion() and\
           o.getLanguage() == self.getLanguage():
          existing_document = o.getObject()
          if existing_document.getValidationState() not in \
            invalid_validation_state_list:
            break
      else:
        existing_document = None

      # We found an existing document to update
      if existing_document is not None:
        document = existing_document
        if not _checkPermission(Permissions.ModifyPortalContent, existing_document):
          raise Unauthorized("[DMS] You are not allowed to update the existing document which has the same coordinates (id %s)" % existing_document.getId())
        else:
          update_kw = {}
          for k in self.propertyIds():
            if k not in FIXED_PROPERTY_IDS and self.hasProperty(k):
              update_kw[k] = self.getProperty(k)
          existing_document.edit(**update_kw)
          # Erase self
          self.getParentValue().manage_delObjects([self.getId(),])
    return document
def mergeRevision ( self ) : document = self if self . getReference ( ) : invalid_validation_state_list = ( 'archived' , 'cancelled' , 'deleted' ) catalog = self . getPortalObject ( ) . portal_catalog # Find all document with same (reference, version, language) kw = dict ( portal_type = self . getPortalType ( ) , reference = self . getReference ( ) , query = NegatedQuery ( Query ( validation_state = invalid_validation_state_list ) ) , sort_on = 'creation_date' ) if self . getVersion ( ) : kw [ 'version' ] = self . getVersion ( ) if self . getLanguage ( ) : kw [ 'language' ] = self . getLanguage ( ) document_list = catalog . unrestrictedSearchResults ( * * kw ) existing_document = None # Select the first one which is not self and which # shares the same coordinates for o in document_list : if o . getRelativeUrl ( ) != self . getRelativeUrl ( ) and o . getVersion ( ) == self . getVersion ( ) and o . getLanguage ( ) == self . getLanguage ( ) : existing_document = o . getObject ( ) if existing_document . getValidationState ( ) not in invalid_validation_state_list : break else : existing_document = None # We found an existing document to update if existing_document is not None : document = existing_document if not _checkPermission ( Permissions . ModifyPortalContent , existing_document ) : raise Unauthorized ( "[DMS] You are not allowed to update the existing document which has the same coordinates (id %s)" % existing_document . getId ( ) ) else : update_kw = { } for k in self . propertyIds ( ) : if k not in FIXED_PROPERTY_IDS and self . hasProperty ( k ) : update_kw [ k ] = self . getProperty ( k ) existing_document . edit ( * * update_kw ) # Erase self self . getParentValue ( ) . manage_delObjects ( [ self . getId ( ) , ] ) return document