Module: Dor::Shelvable

Extended by:
ActiveSupport::Concern
Includes:
Itemizable
Included in:
BasicItem
Defined in:
lib/dor/models/shelvable.rb

Constant Summary

Constants included from Itemizable

Itemizable::DIFF_FILENAME, Itemizable::DIFF_QUERY

Instance Method Summary collapse

Methods included from Itemizable

#clear_diff_cache, #get_content_diff

Instance Method Details

#get_shelve_diffObject

retrieve the differences between the current contentMetadata and the previously ingested version (filtering to select only the files that should be shelved to stacks)



27
28
29
30
31
32
# File 'lib/dor/models/shelvable.rb', line 27

def get_shelve_diff
  inventory_diff_xml = self.get_content_diff(:shelve)
  inventory_diff = Moab::FileInventoryDifference.parse(inventory_diff_xml)
  shelve_diff = inventory_diff.group_difference("content")
  shelve_diff
end

#get_stacks_locationObject

get the stack location based on the contentMetadata stacks attribute or using the default value from the config file if it doesn’t exist



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dor/models/shelvable.rb', line 49

def get_stacks_location
  
   = self.datastreams['contentMetadata']
  unless .nil? or .stacks.length == 0
    stacks_location = .stacks[0]        
    if stacks_location.start_with?"/"  #Absolute stacks path
      return stacks_location
    else        
      raise "stacks attribute for item: "+self.id+ " contentMetadata should start with /. The current value is "+stacks_location
    end
  end      
  return Config.stacks.local_stacks_root #Default stacks
   
end

#shelveObject

Push file changes for shelve-able files into the stacks



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dor/models/shelvable.rb', line 9

def shelve
  # retrieve the differences between the current contentMetadata and the previously ingested version
  shelve_diff = get_shelve_diff
  stacks_object_pathname = get_stacks_location
  # determine the location of the object's files in the stacks area
  stacks_druid = DruidTools::StacksDruid.new id, stacks_object_pathname
  stacks_object_pathname = Pathname(stacks_druid.path)
  # determine the location of the object's content files in the workspace area
  workspace_druid = DruidTools::Druid.new(id,Config.stacks.local_workspace_root)
  workspace_content_pathname = workspace_content_dir(shelve_diff, workspace_druid)
  # delete, rename, or copy files to the stacks area
  DigitalStacksService.remove_from_stacks(stacks_object_pathname, shelve_diff)
  DigitalStacksService.rename_in_stacks(stacks_object_pathname, shelve_diff)
  DigitalStacksService.shelve_to_stacks(workspace_content_pathname, stacks_object_pathname, shelve_diff)
end

#workspace_content_dir(content_diff, workspace_druid) ⇒ Pathname

Find the location of the object’s content files in the workspace area

Parameters:

  • content_diff (Moab::FileGroupDifference)

    The differences between the current contentMetadata and the previously ingested version

  • workspace_druid (DruidTools::Druid)

    the location of the object’s files in the workspace area

Returns:

  • (Pathname)

    The location of the object’s content files in the workspace area



38
39
40
41
42
43
44
# File 'lib/dor/models/shelvable.rb', line 38

def workspace_content_dir (content_diff, workspace_druid)
  deltas = content_diff.file_deltas
  filelist = deltas[:modified] + deltas[:added] + deltas[:copyadded].collect{|old,new| new}
  return nil if filelist.empty?
  content_pathname = Pathname(workspace_druid.find_filelist_parent('content', filelist))
  content_pathname
end