Sha256: 574fe5bce5fb947710d6ebb06c3eb15fa4fd185f5a02a2a9c49806dd52c363e8

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'rest-client'
require 'active_fedora'

module Dor
  class SuriService
    # If Dor::Config.suri.mint_ids is set to true, then this method
    # returns Config.suri.id_namespace:id_from_suri
    # Throws an exception if there were any problems
    def self.mint_id quantity=nil
      want_array = quantity.is_a?(Numeric)
      quantity = 1 if quantity.nil?
      ids = []
      if Config.suri.mint_ids
        #Post with no body
        resource = RestClient::Resource.new("#{Config.suri.url}/suri2/namespaces/#{Config.suri.id_namespace}",
                                  :user => Config.suri.user, :password => Config.suri.pass)
        ids = resource["identifiers?quantity=#{quantity}"].post('').chomp.split(/\n/).collect { |id| "#{Config.suri.id_namespace}:#{id.strip}" }
      else
        repo = ActiveFedora::Base.respond_to?(:connection_for_pid) ? ActiveFedora::Base.connection_for_pid(0) : ActiveFedora.fedora.connection
        resp = Nokogiri::XML(repo.next_pid :numPIDs => quantity)
        ids = resp.xpath('/pidList/pid').collect { |node| node.text }
      end
      return want_array ? ids : ids.first

#    rescue Exception => e
#      Rails.logger.error("Unable to mint id from suri: #{e.to_s}")
#      raise e
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dor-services-5.2.0 lib/dor/services/suri_service.rb