Class: Dor::CleanupResetService

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

Overview

Remove all traces of the object's data files from the workspace and export areas

Class Method Summary collapse

Class Method Details

.cleanup_by_reset_druid(druid) ⇒ void


10
11
12
13
14
15
# File 'lib/dor/services/cleanup_reset_service.rb', line 10

def self.cleanup_by_reset_druid(druid)
  last_version = get_druid_last_version(druid) 
  cleanup_reset_workspace_content(druid, last_version, Config.cleanup.local_workspace_root)
  cleanup_reset_workspace_content(druid, last_version, Config.cleanup.local_assembly_root)
  cleanup_reset_export(druid, last_version)
end

.cleanup_reset_export(druid, last_version) ⇒ void


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dor/services/cleanup_reset_service.rb', line 61

def self.cleanup_reset_export(druid, last_version)
  id = druid.split(':').last
  base_bag_directory = File.join(Config.cleanup.local_export_home, id)
  
  bag_dir_list = get_reset_bag_dir_list(last_version, base_bag_directory)
  bag_dir_list.each do |bag_dir| 
    Pathname(bag_dir).rmtree
  end
  
  bag_tar_list = get_reset_bag_tar_list(last_version, base_bag_directory)
  bag_tar_list.each do |bag_tar| 
    Pathname(bag_tar).rmtree
  end
end

.cleanup_reset_workspace_content(druid, last_version, base) ⇒ void


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

def self.cleanup_reset_workspace_content(druid,last_version, base)
  base_druid = DruidTools::Druid.new(druid, base)
  base_druid_tree = base_druid.pathname.to_s
  #if it is truncated tree /aa/111/aaa/1111/content, 
  #we should follow the regular cleanup technique

  reset_directories = get_reset_dir_list(last_version, base_druid_tree)
  reset_directories.each do |path| 
    FileUtils.rm_rf(path)
  end
  base_druid.prune_ancestors(base_druid.pathname.parent)
end

.get_druid_last_version(druid) ⇒ Object


17
18
19
20
21
22
23
24
25
26
# File 'lib/dor/services/cleanup_reset_service.rb', line 17

def self.get_druid_last_version(druid)
  druid_obj = Dor::Item.find(druid)
  last_version = druid_obj.current_version.to_i
  
  #if the current version is still open, avoid this versioned directory
  if Dor::WorkflowService.get_lifecycle('dor', druid, 'accessioned').nil? then 
    last_version = last_version - 1 
  end
  return last_version
end

.get_reset_bag_dir_list(last_version, base_bag_directory) ⇒ void


79
80
81
82
83
84
85
86
# File 'lib/dor/services/cleanup_reset_service.rb', line 79

def self.get_reset_bag_dir_list(last_version, base_bag_directory)
  reset_bags = []    
  for i in 1..last_version do
    reset_path = "#{base_bag_directory}_v#{i}"
    reset_bags.append(reset_path) if File.exists?(reset_path) 
  end
  return reset_bags      
end

.get_reset_bag_tar_list(last_version, base_bag_directory) ⇒ void


91
92
93
94
95
96
97
98
# File 'lib/dor/services/cleanup_reset_service.rb', line 91

def self.get_reset_bag_tar_list(last_version, base_bag_directory)
  reset_bags = []    
  for i in 1..last_version do
    reset_path = "#{base_bag_directory}_v#{i}.tar"
    reset_bags.append(reset_path)  if File.exists?(reset_path) 
  end
  return reset_bags      
end

.get_reset_dir_list(last_version, base_druid_tree) ⇒ void


50
51
52
53
54
55
56
57
# File 'lib/dor/services/cleanup_reset_service.rb', line 50

def self.get_reset_dir_list(last_version, base_druid_tree)
  reset_directories = []    
  for i in 1..last_version 
    reset_path = "#{base_druid_tree}_v#{i}"
    reset_directories.append(reset_path) if File.exists?(reset_path) 
  end
  return reset_directories      
end