Module: Dor::Versionable

Extended by:
ActiveSupport::Concern
Includes:
Processable, Upgradable
Included in:
AdminPolicyObject, BasicItem, Collection, Set
Defined in:
lib/dor/models/versionable.rb

Constant Summary

Constants included from Processable

Processable::STATUS_CODE_DISP_TXT, Processable::STEPS

Instance Method Summary collapse

Methods included from Upgradable

add_upgrade_callback, included, run_upgrade_callbacks, #upgrade!

Methods included from Processable

#build_datastream, #cleanup, #empty_datastream?, #find_metadata_file, #initialize_workflow, #milestones, #set_workflows_datastream_location, #status, #status_info, #to_solr

Methods included from SolrDocHelper

#add_solr_value

Instance Method Details

#allows_modification?Boolean

Returns true if the object is in a state that allows it to be modified. States that will allow modification are: has not been submitted for accessioning, has an open version or has sdr-ingest set to hold.

Returns:

  • (Boolean)

    true if the object is in a state that allows it to be modified. States that will allow modification are: has not been submitted for accessioning, has an open version or has sdr-ingest set to hold



82
83
84
85
86
87
88
# File 'lib/dor/models/versionable.rb', line 82

def allows_modification?
  if Dor::WorkflowService.get_lifecycle('dor', pid, 'submitted') && ! new_version_open? && Dor::WorkflowService.get_workflow_status('dor', pid, 'accessionWF', 'sdr-ingest-transfer')!='hold'
    false
  else
    true
  end
end

#close_version(opts = {}) ⇒ Object Also known as: submit_version

Sets versioningWF:submit-version to completed and initiates accessionWF for the object

Parameters:

  • opts (Hash) (defaults to: {})

    optional params

Options Hash (opts):

  • :description (String)

    describes the version change

  • :significance (Symbol)

    which part of the version tag to increment :major, :minor, :admin (see Dor::VersionTag#increment)

  • :version_num (String)

    version number to archive rows with. Otherwise, current version is used

  • :start_accesion (Boolean)

    set to true if you want accessioning to start (default), false otherwise

Raises:

  • (Dor::Exception)

    if the object hasn’t been opened for versioning, or if accessionWF has already been instantiated or the current version is missing a tag or description



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dor/models/versionable.rb', line 62

def close_version(opts={})
  unless(opts.empty?)
    datastreams['versionMetadata'].update_current_version opts
    datastreams['versionMetadata'].save
  end

  raise Dor::Exception, 'latest version in versionMetadata requires tag and description before it can be closed' unless(datastreams['versionMetadata'].current_version_closeable?)
  raise Dor::Exception, 'Trying to close version on an object not opened for versioning' unless(new_version_open?)
  raise Dor::Exception, 'accessionWF already created for versioned object' if(Dor::WorkflowService.get_active_lifecycle('dor', pid, 'submitted'))

  Dor::WorkflowService.close_version 'dor', pid, opts.fetch(:start_accession, true)  # Default to creating accessionWF when calling close_version
end

#current_versionObject



49
50
51
# File 'lib/dor/models/versionable.rb', line 49

def current_version
  datastreams['versionMetadata'].current_version_id
end

#new_version_open?Boolean

Returns true if ‘opened’ lifecycle is active, false otherwise.

Returns:

  • (Boolean)

    true if ‘opened’ lifecycle is active, false otherwise



76
77
78
79
# File 'lib/dor/models/versionable.rb', line 76

def new_version_open?
  return true if(Dor::WorkflowService.get_active_lifecycle('dor', pid, 'opened'))
  false
end

#open_new_version(opts = {}) ⇒ Object Also known as: start_version

Increments the version number and initializes versioningWF for the object

Parameters:

  • opts (Hash) (defaults to: {})

    optional params

Options Hash (opts):

  • :assume_accessioned (Boolean)

    If true, does not check whether object has been accessioned.

  • :create_workflows_ds (Boolean)

    If false, initialize_workflow() will not initialize the workflows datastream.

  • :vers_md_upd_info (Hash)

    If present, used to add to the events datastream and set the desc and significance on the versionMetadata datastream

Raises:

  • (Dor::Exception)

    if the object hasn’t been accessioned, or if a version is already opened



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dor/models/versionable.rb', line 17

def open_new_version(opts = {})
  # During local development, we need a way to open a new version
  # even if the object has not been accessioned.
  raise(Dor::Exception, 'Object net yet accessioned') unless
    opts[:assume_accessioned] ||
    Dor::WorkflowService.get_lifecycle('dor', pid, 'accessioned')

  raise Dor::Exception, 'Object already opened for versioning' if(new_version_open?)
  raise Dor::Exception, 'Object currently being accessioned' if(Dor::WorkflowService.get_active_lifecycle('dor', pid, 'submitted'))

  vmd_ds = datastreams['versionMetadata']
  vmd_ds.increment_version
  vmd_ds.content = vmd_ds.ng_xml.to_s
  vmd_ds.save unless self.new_object?

  k = :create_workflows_ds
  if opts.has_key?(k)
    # During local development, Hydrus (or some other app running Fedora locally)
    # does not want this call to initialize the workflows datastream.
    initialize_workflow('versioningWF', 'dor', opts[k])
  else
    initialize_workflow('versioningWF')
  end

  vmd_upd_info = opts[:vers_md_upd_info]
  if vmd_upd_info
    datastreams['events'].add_event("open", vmd_upd_info[:opening_user_name], "Version #{vmd_ds.current_version_id.to_s} opened")
    vmd_ds.update_current_version({:description => vmd_upd_info[:description], :significance => vmd_upd_info[:significance].to_sym})
    save
  end
end