Module: ADIWG::Mdtranslator::Readers::MdJson::Allocation

Defined in:
lib/adiwg/mdtranslator/readers/mdJson/modules/module_allocation.rb

Class Method Summary collapse

Class Method Details

.unpack(hAlloc, responseObj) ⇒ Object



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_allocation.rb', line 21

def self.unpack(hAlloc, responseObj)

   @MessagePath = ADIWG::Mdtranslator::Readers::MdJson::MdJson

   # return nil object if input is empty
   if hAlloc.empty?
      @MessagePath.issueWarning(20, responseObj)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = .new
   intAlloc = intMetadataClass.newAllocation

   # allocation - id
   if hAlloc.has_key?('sourceAllocationId')
      unless hAlloc['sourceAllocationId'] == ''
         intAlloc[:id] = hAlloc['sourceAllocationId']
      end
   end

   # allocation - amount (required)
   if hAlloc.has_key?('amount')
      intAlloc[:amount] = hAlloc['amount']
   end
   if intAlloc[:amount].nil? || intAlloc[:amount] == ''
      @MessagePath.issueError(21, responseObj)
   end

   # allocation - currency (required)
   if hAlloc.has_key?('currency')
      intAlloc[:currency] = hAlloc['currency']
   end
   if intAlloc[:currency].nil? || intAlloc[:currency] == ''
      @MessagePath.issueError(22, responseObj)
   end

   # allocation - source ID {contactId}
   if hAlloc.has_key?('sourceId')
      unless hAlloc['sourceId'] == ''
         intAlloc[:sourceId] = hAlloc['sourceId']
      end
   end

   # allocation - recipient ID {contactId}
   if hAlloc.has_key?('recipientId')
      unless hAlloc['recipientId'] == ''
         intAlloc[:recipientId] = hAlloc['recipientId']
      end
   end

   # allocation - responsible party [] {responsibility}
   if hAlloc.has_key?('responsibleParty')
      aRParties = hAlloc['responsibleParty']
      aRParties.each do |hRParty|
         hReturn = ResponsibleParty.unpack(hRParty, responseObj)
         unless hReturn.nil?
            intAlloc[:responsibleParties] << hReturn
         end
      end
   end

   # allocation - matching {Boolean}
   if hAlloc.has_key?('matching')
      if hAlloc['matching'] === true
         intAlloc[:matching] = hAlloc['matching']
      end
   end

   # allocation - online resource [] {onlineResource}
   if hAlloc.has_key?('onlineResource')
      aOnlines = hAlloc['onlineResource']
      aOnlines.each do |hOnline|
         hReturn = OnlineResource.unpack(hOnline, responseObj)
         unless hReturn.nil?
            intAlloc[:onlineResources] << hReturn
         end
      end
   end

   # allocation - comment
   if hAlloc.has_key?('comment')
      unless hAlloc['comment'] == ''
         intAlloc[:comment] = hAlloc['comment']
      end
   end

   return intAlloc

end