Module: ActiveFedora::DigitalObject::DatastreamBootstrap

Included in:
ActiveFedora::DigitalObject, SolrDigitalObject, UnsavedDigitalObject
Defined in:
lib/active_fedora/digital_object.rb

Instance Method Summary collapse

Instance Method Details

#datastream_object_for(dsid, options = {}, ds_spec = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_fedora/digital_object.rb', line 7

def datastream_object_for dsid, options={}, ds_spec=nil
  # ds_spec is nil when called from Rubydora for existing datastreams, so it should not be autocreated
  ds_spec ||= (original_class.ds_specs[dsid] || {}).merge(:autocreate=>false)
  ds = ds_spec.fetch(:type, ActiveFedora::Datastream).new(self, dsid, options)
  attributes = {}
  attributes[:asOfDateTime] ||= asOfDateTime if self.respond_to? :asOfDateTime
  attributes[:dsLabel] = ds_spec[:label] if ds_spec[:label].present?
  attributes[:controlGroup] = ds_spec[:control_group] if ds_spec[:control_group].present?
  attributes[:versionable] = ds_spec[:versionable] unless ds_spec[:versionable].nil?
  if attributes[:controlGroup]=='E'
    if !ds_spec[:disseminator].present? && ds_spec[:url].present?
      attributes[:dsLocation]= ds_spec[:url]
    end
  elsif attributes[:controlGroup]=='R'
    attributes[:dsLocation]= ds_spec[:url]
  end
  ds.default_attributes = attributes
  # would rather not load profile here in the call to .new?, so trusting :autocreate attribute
  if ds_spec[:autocreate] # and ds.new?
    ds.datastream_will_change!
  end
  ds
end