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


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

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


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

def accessionables
  @accessionables
end

#aliasObject (readonly)

Returns the value of attribute alias


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

def alias
  @alias
end

#brokerObject (readonly)

Returns the value of attribute broker


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

def broker
  @broker
end

#contactObject (readonly)

Returns the value of attribute contact


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

def contact
  @contact
end

#dateObject (readonly)

Returns the value of attribute date


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

def date
  @date
end

Instance Method Details

#<<(_accessionable) ⇒ Object


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

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

#all_accessionablesObject


84
85
86
# File 'app/models/accessionable/submission.rb', line 84

def all_accessionables
  @accessionables + [self]
end

#nameObject


76
77
78
79
80
81
82
# File 'app/models/accessionable/submission.rb', line 76

def name
  if @accessionables.size >= 1
    @accessionables.first.name
  else
    'empty'
  end
end

#state_action(accessionable) ⇒ Object


68
69
70
71
72
73
74
# File 'app/models/accessionable/submission.rb', line 68

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

#update_accession_number!(_user, accession_number) ⇒ Object


88
89
90
# File 'app/models/accessionable/submission.rb', line 88

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

#xmlObject


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/accessionable/submission.rb', line 23

def xml
  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
  ) {
    xml.CONTACTS { contact.build(xml) }
    xml.ACTIONS {
      # 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) do |action|
          xml.ACTION {
            xml.tag!(action)
          }
        end
      end
    }
  }
  xml.target!
end