Class: Mrt::Ingest::IObject

Inherits:
Object
  • Object
show all
Defined in:
lib/mrt/ingest/iobject.rb

Overview

An object prepared for ingest into Merritt.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ IObject

Options can have the keys :primary_identifier, :local_identifier, :server, or :erc. :erc can be a #File, #Uri or a #Hash of metadata. :server is a #OneTimeServer.



54
55
56
57
58
59
60
# File 'lib/mrt/ingest/iobject.rb', line 54

def initialize(options={})
  @primary_identifier = options[:primary_identifier]
  @local_identifier = options[:local_identifier]
  @erc = options[:erc] || Hash.new
  @components = []
  @server = options[:server] || Mrt::Ingest::OneTimeServer.new
end

Instance Attribute Details

#ercObject

Returns the value of attribute erc.



49
50
51
# File 'lib/mrt/ingest/iobject.rb', line 49

def erc
  @erc
end

#local_identifierObject

Returns the value of attribute local_identifier.



49
50
51
# File 'lib/mrt/ingest/iobject.rb', line 49

def local_identifier
  @local_identifier
end

#primary_identifierObject

Returns the value of attribute primary_identifier.



49
50
51
# File 'lib/mrt/ingest/iobject.rb', line 49

def primary_identifier
  @primary_identifier
end

Instance Method Details

#add_component(where, options = {}) ⇒ Object

Add a component to the object. where can be either a #URI or a #File. Options is a hash whose keys may be :name, :digest, :mime_type, or :size. If :digest is supplied, it must be a subclass of Mrt::Ingest::MessageDigest::Base. If where is a #File, it will be hosted on an embedded web server.



67
68
69
# File 'lib/mrt/ingest/iobject.rb', line 67

def add_component(where, options={})
  @components.push(Component.new(@server, where, options))
end

#finish_ingestObject

Wait for the ingest of this object to finish.



137
138
139
140
141
# File 'lib/mrt/ingest/iobject.rb', line 137

def finish_ingest
  # XXX Right now we only join the hosting server; in the future
  # we will check the status via the ingest server.
  join_server
end

#join_serverObject

:nodoc:



106
107
108
# File 'lib/mrt/ingest/iobject.rb', line 106

def join_server # :nodoc:
  return @server.join_server()
end

#mk_manifest(manifest, erc_component) ⇒ Object

:nodoc:



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/mrt/ingest/iobject.rb', line 114

def mk_manifest(manifest, erc_component) # :nodoc:
  manifest.write("#%checkm_0.7\n")
  manifest.write("#%profile http://uc3.cdlib.org/registry/ingest/manifest/mrt-ingest-manifest\n")
  manifest.write("#%prefix | mrt: | http://uc3.cdlib.org/ontology/mom#\n")
  manifest.write("#%prefix | nfo: | http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#\n")
  manifest.write("#%fields | nfo:fileUrl | nfo:hashAlgorithm | nfo:hashValue | nfo:fileSize | nfo:fileLastModified | nfo:fileName | mrt:mimeType\n")
  @components.each { |c|
    manifest.write(c.to_manifest_entry)
  }
  manifest.write(erc_component.to_manifest_entry)
  manifest.write("#%EOF\n")
end

#mk_request(profile, submitter) ⇒ Object

Make a Mrt::Ingest::Request object for this mrt-object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mrt/ingest/iobject.rb', line 72

def mk_request(profile, submitter)
  erc_component = case @erc
                  when URI, File, Tempfile
                    Component.new(@server, @erc, :name => 'mrt-erc.txt')
                  when Hash
                    uri_str, path = @server.add_file do |f|
                      @erc.each_pair do |k, v|
                        f.write("#{k}: #{v}\n")
                      end
                    end
                    Component.new(@server, 
                                  URI.parse(uri_str), 
                                  :name => 'mrt-erc.txt',
                                  :digest => Mrt::Ingest::MessageDigest::MD5.from_file(File.new(path)))
                  else
                    raise IngestException.new("Bad ERC supplied: must be a URI, File, or Hash")
                  end
  manifest_file = Tempfile.new("mrt-ingest")
  mk_manifest(manifest_file, erc_component)
  # reset to beginning
  manifest_file.open
  return Mrt::Ingest::Request.
    new(:file               => manifest_file,
        :filename           => manifest_file.path.split(/\//).last,
        :type               => "object-manifest",
        :submitter          => submitter,
        :profile            => profile,
        :primary_identifier => @primary_identifier)
end

#start_ingest(client, profile, submitter) ⇒ Object

Begin an ingest on the given client, with a profile and submitter.



129
130
131
132
133
134
# File 'lib/mrt/ingest/iobject.rb', line 129

def start_ingest(client, profile, submitter)
  request = mk_request(profile, submitter)
  start_server
  @response = client.ingest(request)
  return @response
end

#start_serverObject

:nodoc:



102
103
104
# File 'lib/mrt/ingest/iobject.rb', line 102

def start_server # :nodoc:
  return @server.start_server()
end

#stop_serverObject

:nodoc:



110
111
112
# File 'lib/mrt/ingest/iobject.rb', line 110

def stop_server # :nodoc:
  return @server.stop_server()
end