module ADIWG::Mdtranslator::Readers::MdJson::Party

Public Class Methods

unpack(hParty, responseObj, inContext = nil) click to toggle source
# File lib/adiwg/mdtranslator/readers/mdJson/modules/module_party.rb, line 15
def self.unpack(hParty, responseObj, inContext = nil)

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

   # return nil object if input is empty
   if hParty.empty?
      @MessagePath.issueWarning(620, responseObj, inContext)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intParty = intMetadataClass.newParty

   # party - contact ID (required)
   # load party with contact index, contact type, and name
   # return nil if contact ID does not exist in contact array
   if hParty.has_key?('contactId')
      intParty[:contactId] = hParty['contactId']
      unless intParty[:contactId].nil? || intParty[:contactId] == ''
         hContact = @MessagePath.findContact(hParty['contactId'])
         if hContact[0].nil?
            outContext = 'contact ID ' + intParty[:contactId]
            outContext = inContext + ' > ' + outContext unless inContext.nil?
            @MessagePath.issueError(622, responseObj, outContext)
         else
            intParty[:contactIndex] = hContact[0]
            intParty[:contactType] = hContact[1]
            intParty[:contactName] = hContact[2]
         end
      end
   end
   if intParty[:contactId].nil? || intParty[:contactId] == ''
      @MessagePath.issueError(621, responseObj, inContext)
   end

   # party - organization members []
   # organization member contact IDs not found in 'contacts' are reported as warnings
   if intParty[:contactType] == 'organization'
      if hParty.has_key?('organizationMembers')
         hParty['organizationMembers'].each do |contactId|
            intParty[:organizationMembers] << contactId
            hContact = @MessagePath.findContact(contactId)
            if hContact[0].nil?
               outContext = 'contact ID ' + contactId
               outContext = inContext + ' > ' + outContext unless inContext.nil?
               @MessagePath.issueWarning(623, responseObj, outContext)
            end
         end
      end
   end

   return intParty

end