Class: Stash::Merritt::SubmissionPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/stash/merritt/submission_package.rb,
lib/stash/merritt/submission_package/merritt_oaidc_builder.rb,
lib/stash/merritt/submission_package/stash_wrapper_builder.rb,
lib/stash/merritt/submission_package/merritt_delete_builder.rb,
lib/stash/merritt/submission_package/merritt_datacite_builder.rb,
lib/stash/merritt/submission_package/data_one_manifest_builder.rb

Defined Under Namespace

Classes: DataONEManifestBuilder, MerrittDataciteBuilder, MerrittDeleteBuilder, MerrittOAIDCBuilder, StashWrapperBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ SubmissionPackage

Returns a new instance of SubmissionPackage.

Raises:

  • (ArgumentError)


19
20
21
22
23
# File 'lib/stash/merritt/submission_package.rb', line 19

def initialize(resource:)
  raise ArgumentError, "Resource (#{resource.id}) must have an identifier before submission" unless resource.identifier_str
  @resource = resource
  @zipfile = create_zipfile
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



16
17
18
# File 'lib/stash/merritt/submission_package.rb', line 16

def resource
  @resource
end

#zipfileObject (readonly)

Returns the value of attribute zipfile.



17
18
19
# File 'lib/stash/merritt/submission_package.rb', line 17

def zipfile
  @zipfile
end

Instance Method Details

#cleanup!Object



48
49
50
51
# File 'lib/stash/merritt/submission_package.rb', line 48

def cleanup!
  FileUtils.remove_dir(workdir)
  @zipfile = nil
end

#create_zipfileObject



38
39
40
41
42
43
44
45
46
# File 'lib/stash/merritt/submission_package.rb', line 38

def create_zipfile
  StashDatacite::PublicationYear.ensure_pub_year(resource)
  zipfile_path = File.join(workdir, "#{resource_id}_archive.zip")
  Zip::File.open(zipfile_path, Zip::File::CREATE) do |zipfile|
    builders.each { |builder| write_to_zipfile(zipfile, builder) }
    new_uploads.each { |upload| add_to_zipfile(zipfile, upload) }
  end
  zipfile_path
end

#dc3_xmlObject



29
30
31
# File 'lib/stash/merritt/submission_package.rb', line 29

def dc3_xml
  @dc3_xml ||= datacite_xml_factory.build_datacite_xml(datacite_3: true)
end

#resource_idObject



25
26
27
# File 'lib/stash/merritt/submission_package.rb', line 25

def resource_id
  resource.id
end

#resource_titleObject



33
34
35
36
# File 'lib/stash/merritt/submission_package.rb', line 33

def resource_title
  primary_title = resource.titles.where(title_type: nil).first
  primary_title.title.to_s if primary_title
end

#to_sObject



53
54
55
# File 'lib/stash/merritt/submission_package.rb', line 53

def to_s
  "#{self.class}: submission package for resource #{resource_id} (#{resource_title}"
end