Class: Dor::DigitalStacksService

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

Class Method Summary collapse

Class Method Details

.prune_purl_dir(id) ⇒ Object



49
50
51
52
# File 'lib/dor/services/digital_stacks_service.rb', line 49

def self.prune_purl_dir(id)
  druid = DruidTools::PurlDruid.new(id, Dor::Config.stacks.local_document_cache_root)
  druid.prune!
end

.prune_stacks_dir(id) ⇒ Object

Assumes the digital stacks storage root is mounted to the local file system TODO since this is delegating to the Druid, this method may not be necessary



44
45
46
47
# File 'lib/dor/services/digital_stacks_service.rb', line 44

def self.prune_stacks_dir(id)
  stacks_druid_tree = DruidTools::StacksDruid.new(id, Config.stacks.local_stacks_root)
  stacks_druid_tree.prune!
end

.remove_from_stacks(id, files) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/dor/services/digital_stacks_service.rb', line 13

def self.remove_from_stacks(id, files)
  files.each do |file|
    dr = DruidTools::StacksDruid.new id, Config.stacks.local_stacks_root
    content = dr.find_content file
    FileUtils.rm content if content
  end
end

.rename_in_stacks(id, file_map) ⇒ Object

Parameters:

  • id (String)

    object pid

  • file_map (Array<Array<String>>)

    an array of two string arrays. Each inner array represents old-file/new-file mappings. First string is the old file name, second string is the new file name. e.g:

    [‘src1.file’, ‘dest1.file’], [‘src2.file’, ‘dest2.file’

    ]



24
25
26
27
28
29
30
# File 'lib/dor/services/digital_stacks_service.rb', line 24

def self.rename_in_stacks(id, file_map)
  dr = DruidTools::StacksDruid.new id, Config.stacks.local_stacks_root
  content_dir = dr.find_filelist_parent('content', file_map.first.first)
  file_map.each do |src, dest|
    File.rename(File.join(content_dir, src), File.join(content_dir, dest))
  end
end

.shelve_to_stacks(id, files) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/dor/services/digital_stacks_service.rb', line 32

def self.shelve_to_stacks(id, files)
  workspace_druid = DruidTools::Druid.new(id,Config.stacks.local_workspace_root)
  stacks_druid = DruidTools::StacksDruid.new(id,Config.stacks.local_stacks_root)
  files.each do |file|
    stacks_druid.content_dir
    workspace_file = workspace_druid.find_content(file)
    FileUtils.cp workspace_file, stacks_druid.content_dir
  end
end

.transfer_to_document_store(id, content, filename) ⇒ Object



7
8
9
10
11
# File 'lib/dor/services/digital_stacks_service.rb', line 7

def self.transfer_to_document_store(id, content, filename)
  druid = DruidTools::PurlDruid.new id, Config.stacks.local_document_cache_root
  druid.content_dir # create the druid tree if it doesn't exist yet
  File.open(File.join(druid.content_dir, filename), 'w') {|f| f.write content }
end