module ADIWG::Mdtranslator::Readers::MdJson::Allocation

Public Class Methods

unpack(hAlloc, responseObj) click to toggle source
# 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 = InternalMetadata.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