Class: Dor::VersionService

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

Overview

Open and close versions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work) ⇒ VersionService

Returns a new instance of VersionService.



14
15
16
# File 'lib/dor/services/version_service.rb', line 14

def initialize(work)
  @work = work
end

Instance Attribute Details

#workObject (readonly)

Returns the value of attribute work.



82
83
84
# File 'lib/dor/services/version_service.rb', line 82

def work
  @work
end

Class Method Details

.close(work, opts = {}) ⇒ Object



10
11
12
# File 'lib/dor/services/version_service.rb', line 10

def self.close(work, opts = {})
  new(work).close(opts)
end

.open(work, opts = {}) ⇒ Object



6
7
8
# File 'lib/dor/services/version_service.rb', line 6

def self.open(work, opts = {})
  new(work).open(opts)
end

Instance Method Details

#close(opts = {}) ⇒ Object

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/services/version_service.rb', line 62

def close(opts = {})
  unless opts.empty?
    work..update_current_version opts
    work..save
  end

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

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

#open(opts = {}) ⇒ Object

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, create_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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dor/services/version_service.rb', line 24

def open(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::Config.workflow.client.get_lifecycle('dor', work.pid, 'accessioned')
  raise Dor::Exception, 'Object already opened for versioning' if open?
  raise Dor::Exception, 'Object currently being accessioned' if Dor::Config.workflow.client.get_active_lifecycle('dor', work.pid, 'submitted')

  sdr_version = Sdr::Client.current_version work.pid

  vmd_ds = work.
  vmd_ds.sync_then_increment_version sdr_version
  vmd_ds.save unless work.new_record?

  k = :create_workflows_ds
  if opts.key?(k)
    # During local development, Hydrus (or another app w/ local Fedora) does not want to initialize workflows datastream.
    CreateWorkflowService.create_workflow(work, name: 'versioningWF', create_ds: opts[k])
  else
    CreateWorkflowService.create_workflow(work, name: 'versioningWF')
  end

  vmd_upd_info = opts[:vers_md_upd_info]
  return unless vmd_upd_info

  work.events.add_event('open', vmd_upd_info[:opening_user_name], "Version #{vmd_ds.current_version_id} opened")
  vmd_ds.update_current_version(description: vmd_upd_info[:description], significance: vmd_upd_info[:significance].to_sym)
  work.save
end

#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
80
# File 'lib/dor/services/version_service.rb', line 76

def open?
  return true if Dor::Config.workflow.client.get_active_lifecycle('dor', work.pid, 'opened')

  false
end