-
Notifications
You must be signed in to change notification settings - Fork 2
/
bundle_context.rb
94 lines (74 loc) · 2.31 KB
/
bundle_context.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class BundleContext < ApplicationRecord
belongs_to :user
validates :project_name, presence: true, null: false
validates :content_structure, presence: true, null: false
validates :bundle_dir, presence: true, null: false
validates :staging_style_symlink, inclusion: { in: [ true, false ] }
validates :content_metadata_creation, presence: true, null: false
validate :verify_bundle_directory
validate :verify_content_metadata_creation
after_initialize :normalize_bundle_dir
enum content_structure: {
"simple_image_structure" => 0,
"simple_book_structure" => 1,
"book_as_iamge_structure" => 2,
"file_structure" => 3,
"smpl_structure" => 4
}
enum content_metadata_creation: {
"default_style" => 0,
"filename_style" => 1,
"smpl_style" => 2
}
def staging_dir
'/dor/assembly'
end
def normalize_bundle_dir
self[:bundle_dir].chomp("/") if bundle_dir
end
def progress_log_file
Tempfile.new.path(id) #FIXME: (#78)
end
def content_exclusion #FIXME: Delete everywhere in code (#227)
nil
end
def file_attr
nil # FIXME can get rid of this (#228)
end
def validate_files?
false #FIXME delete everwhere in code (#230)
end
def content_tag_override? #TODO: find where this is used as a conditional and delete code that won't be executed (#231)
true
end
def smpl_manifest
'smpl_manifest.csv'
end
def manifest
'manifest.csv'
end
def path_in_bundle(rel_path)
File.join(bundle_dir, rel_path)
end
# On first call, loads the manifest data, caches results
# @return [Array<ActiveSupport::HashWithIndifferentAccess>]
def manifest_rows
@manifest_rows ||= CsvImporter.parse_to_hash(path_in_bundle(manifest))
end
def manifest_cols
{
label: 'label',
source_id: 'sourceid',
object_container: 'object', #object referring to filename or foldername
druid: 'druid'
}
end
private
def verify_bundle_directory
return if errors.key?(:bundle_dir)
errors.add(:bundle_dir, "Bundle directory: #{bundle_dir} not found.") unless File.directory?(bundle_dir)
end
def verify_content_metadata_creation
errors.add(:content_metadata_creation, "The SMPL manifest #{smpl_manifest} was not found in #{bundle_dir}.") if smpl_style? && !File.exist?(File.join(bundle_dir, smpl_manifest))
end
end