model/reference.rb
# Retrieve information from Crossref, using doi, and create a canonical document
#
Retrieve information from Crossref, using doi, and create a canonical document
Retrieve information from Crossref using doi and create a canonical document
def add_doi(doi_n)
    status=Result.new
    crossref_doi=CrossrefDoi.process_doi(doi_n)
    unless crossref_doi
      status.error(I18n::t("add_doi.cant_process_doi", doi:doi_n))
      return status
    end
    $db.transaction do
      if self[:doi]==doi_n
        status.info(I18n::t("add_doi.doi_already_on_reference", doi:doi_n, reference:self[:text]))
      else
        self.update(:doi=>doi_without_http(doi_n))
        status.success(I18n::t('add_doi.doi_set_to_reference', doi:doi_n, reference:self[:text]))
      end
      if self[:canonical_document_id].nil?
        can_doc=CanonicalDocument[:doi=>doi_without_http(doi_n)]
        if can_doc
          self.update(:canonical_document_id=>can_doc[:id])
          status.info(I18n::t('add_doi.reference_to_canonical_document', canonical_document:can_doc[:title], reference:self[:text] ))
        else 
          integrator=CrossrefDoi.reference_integrator_json(doi)
          fields = [:title,:author,:year,:journal, :volume, :pages, :doi, :journal_abbr,:abstract]
          fields_update=fields.inject({}) {|ac,v|
            ac[v]= integrator.send(v); ac;
          }
          if fields_update[:year].nil?
            status.error(I18n::t('add_doi.doi_without_year', doi:doi_n))
            fields_update[:year]=0
          end
          can_doc_id=CanonicalDocument.insert(fields_update)
          self.update(:canonical_document_id=>can_doc_id)
          status.success(I18n::t('add_doi.new_canonical_document', can_doc_id:can_doc_id, can_doc_text:integrator.ref_apa_6))
        end
        $db.after_rollback {
          status=Result.new
          status.error(I18n::t('add_doi.rollback', reference:self[:text]))
        }
      end
    end
    status
  end
def add_doi ( doi_n ) status = Result . new crossref_doi = CrossrefDoi . process_doi ( doi_n ) unless crossref_doi status . error ( I18n :: t ( "add_doi.cant_process_doi" , doi : doi_n ) ) return status end $db . transaction do if self [ :doi ] == doi_n status . info ( I18n :: t ( "add_doi.doi_already_on_reference" , doi : doi_n , reference : self [ :text ] ) ) else self . update ( :doi => doi_without_http ( doi_n ) ) status . success ( I18n :: t ( 'add_doi.doi_set_to_reference' , doi : doi_n , reference : self [ :text ] ) ) end if self [ :canonical_document_id ] . nil? can_doc = CanonicalDocument [ :doi => doi_without_http ( doi_n ) ] if can_doc self . update ( :canonical_document_id => can_doc [ :id ] ) status . info ( I18n :: t ( 'add_doi.reference_to_canonical_document' , canonical_document : can_doc [ :title ] , reference : self [ :text ] ) ) else integrator = CrossrefDoi . reference_integrator_json ( doi ) fields = [ :title , :author , :year , :journal , :volume , :pages , :doi , :journal_abbr , :abstract ] fields_update = fields . inject ( { } ) { | ac , v | ac [ v ] = integrator . send ( v ) ; ac ; } if fields_update [ :year ] . nil? status . error ( I18n :: t ( 'add_doi.doi_without_year' , doi : doi_n ) ) fields_update [ :year ] = 0 end can_doc_id = CanonicalDocument . insert ( fields_update ) self . update ( :canonical_document_id => can_doc_id ) status . success ( I18n :: t ( 'add_doi.new_canonical_document' , can_doc_id : can_doc_id , can_doc_text : integrator . ref_apa_6 ) ) end $db . after_rollback { status = Result . new status . error ( I18n :: t ( 'add_doi.rollback' , reference : self [ :text ] ) ) } end end status end
Retrieve information from Crossref, using doi, and create a canonical document
Retrieve information from Crossref using doi and create a canonical document
#$log.info("Agregar #{doi_n} a #{self[:id]}") ##$log.info(co) # No existe el canónico, lo debo crear ##$log.info(integrator) # En casos muy raros no está el año. Tengo que reportar error, no más
doi_n