Class: Accessionable::Submission

Inherits:
Base
  • Object
show all
Defined in:
app/models/accessionable/submission.rb

Overview

Used by AccessionService to wrap one of the other accessionables when making an accessioning submission.

Defined Under Namespace

Classes: Contact

Constant Summary

Constants inherited from Base

Base::InvalidData

Instance Attribute Summary collapse

Attributes inherited from Base

#accession_number, #date_short

Instance Method Summary collapse

Methods inherited from Base

#accessionable_id, #add_updated_event, #center_name, #errors, #extract_accession_number, #extract_array_express_accession_number, #file_name, #label_scope, #released?, #schema_type, #update_array_express_accession_number!

Constructor Details

#initialize(service, user, *accessionables) ⇒ Submission

Returns a new instance of Submission.


7
8
9
10
11
12
13
14
# File 'app/models/accessionable/submission.rb', line 7

def initialize(service, user, *accessionables)
  @service = service
  @contact = Contact.new(user)
  @broker = service.broker
  @accessionables = accessionables

  super(accession_number)
end

Instance Attribute Details

#accessionablesObject (readonly)

Returns the value of attribute accessionables.


5
6
7
# File 'app/models/accessionable/submission.rb', line 5

def accessionables
  @accessionables
end

#aliasObject (readonly)

Returns the value of attribute alias.


5
6
7
# File 'app/models/accessionable/submission.rb', line 5

def alias
  @alias
end

#brokerObject (readonly)

Returns the value of attribute broker.


5
6
7
# File 'app/models/accessionable/submission.rb', line 5

def broker
  @broker
end

#contactObject (readonly)

Returns the value of attribute contact.


5
6
7
# File 'app/models/accessionable/submission.rb', line 5

def contact
  @contact
end

#dateObject (readonly)

Returns the value of attribute date.


5
6
7
# File 'app/models/accessionable/submission.rb', line 5

def date
  @date
end

Instance Method Details

#<<(_accessionable) ⇒ Object


20
21
22
# File 'app/models/accessionable/submission.rb', line 20

def <<(_accessionable)
  @accessionables << accesionable
end

#all_accessionablesObject


71
72
73
# File 'app/models/accessionable/submission.rb', line 71

def all_accessionables
  @accessionables + [self]
end

#nameObject


67
68
69
# File 'app/models/accessionable/submission.rb', line 67

def name
  @accessionables.size >= 1 ? @accessionables.first.name : 'empty'
end

#state_action(accessionable) ⇒ Object

rubocop:enable Metrics/MethodLength


59
60
61
62
63
64
65
# File 'app/models/accessionable/submission.rb', line 59

def state_action(accessionable)
  if accessionable.protect?(@service)
    yield 'PROTECT'
  elsif !accessionable.released?
    yield 'HOLD'
  end
end

#update_accession_number!(_user, accession_number) ⇒ Object


75
76
77
# File 'app/models/accessionable/submission.rb', line 75

def update_accession_number!(_user, accession_number)
  @accession_number = accession_number
end

#xmlObject

rubocop:todo Metrics/MethodLength


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
52
53
54
55
# File 'app/models/accessionable/submission.rb', line 25

def xml # rubocop:todo Metrics/AbcSize
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.SUBMISSION(
    'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
    :center_name => center_name,
    :broker_name => broker,
    :alias => self.alias,
    :submission_date => date
  ) do
    xml.CONTACTS { contact.build(xml) }
    xml.ACTIONS do
      # You can only perform additions with protect or hold, or you can do a modification.  So separate the
      # accessionable instances into additions and modifications.
      additions, modifications = accessionables.partition { |accessionable| accessionable.accession_number.blank? }

      additions.each do |accessionable|
        xml.ACTION { xml.ADD(source: accessionable.file_name, schema: accessionable.schema_type) }

        xml.ACTION { xml.tag!(accessionable.protect?(@service) ? 'PROTECT' : 'HOLD') }
      end

      modifications.each do |accessionable|
        xml.ACTION { xml.MODIFY(source: accessionable.file_name, schema: accessionable.schema_type) }

        state_action(accessionable) { |action| xml.ACTION { xml.tag!(action) } }
      end
    end
  end
  xml.target!
end