Module: Dor::Itemizable

Extended by:
ActiveSupport::Concern
Included in:
Publishable, Shelvable
Defined in:
lib/dor/models/itemizable.rb

Constant Summary collapse

DIFF_FILENAME =
'cm_inv_diff'
DIFF_QUERY =
DIFF_FILENAME.gsub('_', '-')

Instance Method Summary collapse

Instance Method Details

#clear_diff_cacheObject

Deletes all cm_inv_diff files in the workspace for the Item


16
17
18
19
20
21
22
23
# File 'lib/dor/models/itemizable.rb', line 16

def clear_diff_cache
  if Dor::Config.stacks.local_workspace_root.nil?
    raise ArgumentError, 'Missing Dor::Config.stacks.local_workspace_root' 
  end
  druid = DruidTools::Druid.new(self.pid, Dor::Config.stacks.local_workspace_root)
  diff_pattern = File.join(druid.temp_dir, DIFF_FILENAME + '.*')
  FileUtils.rm_f Dir.glob(diff_pattern)
end

#get_content_diff(subset = :all, version = nil) ⇒ String

Retrieves file difference manifest for contentMetadata from SDR


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dor/models/itemizable.rb', line 30

def get_content_diff(subset = :all, version = nil)
  if Dor::Config.stacks.local_workspace_root.nil?
    raise Dor::ParameterError, 'Missing Dor::Config.stacks.local_workspace_root' 
  end
  unless %w{all shelve preserve publish}.include?(subset.to_s)
    raise Dor::ParameterError, "Invalid subset value: #{subset}"
  end

  # fetch content metadata inventory difference from SDR
  if Dor::Config.sdr.rest_client.nil?
    raise Dor::ParameterError, 'Missing Dor::Config.sdr.rest_client'
  end
  sdr_client = Dor::Config.sdr.rest_client
  current_content = self.datastreams['contentMetadata'].content
  if current_content.nil?
    raise Dor::Exception, "Missing contentMetadata datastream"
  end
  query_string = { :subset => subset.to_s }
  query_string[:version] = version.to_s unless version.nil?
  query_string = URI.encode_www_form(query_string)
  sdr_query = "objects/#{self.pid}/#{DIFF_QUERY}?#{query_string}"
  response = sdr_client[sdr_query].post(current_content, :content_type => 'application/xml')
  response
end