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.



71
72
73
74
75
76
77
# File 'lib/mrt/ingest/iobject.rb', line 71

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.



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

def erc
  @erc
end

#local_identifierObject

Returns the value of attribute local_identifier.



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

def local_identifier
  @local_identifier
end

#primary_identifierObject

Returns the value of attribute primary_identifier.



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

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.



84
85
86
# File 'lib/mrt/ingest/iobject.rb', line 84

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

#finish_ingestObject

Wait for the ingest of this object to finish.



156
157
158
159
160
# File 'lib/mrt/ingest/iobject.rb', line 156

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:



125
126
127
# File 'lib/mrt/ingest/iobject.rb', line 125

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

#mk_manifest(manifest, erc_component) ⇒ Object

:nodoc:



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/mrt/ingest/iobject.rb', line 133

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/mrt/ingest/iobject.rb', line 89

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|
                      f.write("erc:\n")
                      @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,
        :local_identifier => @local_identifier,
        :primary_identifier => @primary_identifier)
end

#start_ingest(client, profile, submitter) ⇒ Object

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



148
149
150
151
152
153
# File 'lib/mrt/ingest/iobject.rb', line 148

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

#start_serverObject

:nodoc:



121
122
123
# File 'lib/mrt/ingest/iobject.rb', line 121

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

#stop_serverObject

:nodoc:



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

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