Sha256: 488527a5c98aaec1411f143a7f82a577a12a9a8a903ab9f843cc96753f60681c

Contents?: true

Size: 1.23 KB

Versions: 13

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
      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

13 entries across 13 versions & 1 rubygems

Version Path
dor-services-5.6.0 lib/dor/services/suri_service.rb
dor-services-5.5.3 lib/dor/services/suri_service.rb
dor-services-5.5.2 lib/dor/services/suri_service.rb
dor-services-5.5.1 lib/dor/services/suri_service.rb
dor-services-5.5.0 lib/dor/services/suri_service.rb
dor-services-5.4.2 lib/dor/services/suri_service.rb
dor-services-5.4.1 lib/dor/services/suri_service.rb
dor-services-5.4.0 lib/dor/services/suri_service.rb
dor-services-5.3.4 lib/dor/services/suri_service.rb
dor-services-5.3.3 lib/dor/services/suri_service.rb
dor-services-5.3.2 lib/dor/services/suri_service.rb
dor-services-5.3.1 lib/dor/services/suri_service.rb
dor-services-5.3.0 lib/dor/services/suri_service.rb