Module: Dor::Shelvable

Extended by:
ActiveSupport::Concern
Included in:
Item
Defined in:
lib/dor/models/concerns/shelvable.rb

Instance Method Summary collapse

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)



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

def get_shelve_diff
  inventory_diff = get_content_diff(:shelve)
  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



46
47
48
49
50
51
52
53
54
# File 'lib/dor/models/concerns/shelvable.rb', line 46

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

#shelveObject

Push file changes for shelve-able files into the stacks



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

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



36
37
38
39
40
41
42
# File 'lib/dor/models/concerns/shelvable.rb', line 36

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