Module: ADIWG::Mdtranslator::Readers::MdJson::Party

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

Class Method Summary collapse

Class Method Details

.unpack(hParty, responseObj, inContext = nil) ⇒ Object



15
16
17
18
19
20
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
# 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