Class: Dor::DatastreamBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/datastream_builder.rb

Overview

The ContentMetadata and DescMetadata robot are allowed to build the datastream by reading a file from the /dor/workspace that matches the datastream name. This allows assembly or pre-assembly to prebuild the datastreams from templates or using other means (like the assembly-objectfile gem) and then have those datastreams picked up and added to the object during accessionWF.

This class builds that datastream using the content of a file if such a file exists and is newer than the object’s current datastream (see above); otherwise, builds the datastream by calling build_fooMetadata_datastream.

Instance Method Summary collapse

Constructor Details

#initialize(object:, datastream:, force: false, required: false) ⇒ ActiveFedora::Datastream

Parameters:

  • object (ActiveFedora::Base)

    The object that contains the datastream

  • datastream (ActiveFedora::Datastream)

    The datastream object

  • force (Boolean) (defaults to: false)

    Should we overwrite existing datastream?

  • required (Boolean) (defaults to: false)

    If set to true, raise an error if we can’t build the datastream



20
21
22
23
24
25
26
# File 'lib/dor/services/datastream_builder.rb', line 20

def initialize(object:, datastream:, force: false, required: false)
  @object = object
  @datastream = datastream
  @force = force
  @required = required
  @filename = 
end

Instance Method Details

#buildObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/dor/services/datastream_builder.rb', line 28

def build
  # See if datastream exists as a file and if the file's timestamp is newer than datastream's timestamp.
  if file_newer_than_datastream?
    create_from_file(filename)
  elsif force || empty_datastream?
    create_default
  end
  # Check for success.
  raise "Required datastream #{datastream_name} could not be populated!" if required && empty_datastream?
end