Class: Dor::SuriService

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/suri_service.rb

Class Method Summary collapse

Class Method Details

.mint_id(quantity = nil) ⇒ Object

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dor/services/suri_service.rb', line 9

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