module ADIWG::Mdtranslator::Writers::SbJson::Contact

Public Class Methods

build(hParty) click to toggle source
# File lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb, line 70
def self.build(hParty)

   Jbuilder.new do |json|

      role = hParty[:role]
      hContact = @Namespace.get_contact_by_index(hParty[:index])

      unless hContact.empty?

         type = hContact[:isOrganization] ? 'organization' : 'person'

         orgName = nil
         unless hContact[:memberOfOrgs].empty?
            orgContact = @Namespace.get_contact_by_id(hContact[:memberOfOrgs][0])
            orgName = orgContact[:name]
         end
         logoUrl = nil
         unless hContact[:logos].empty?
            logo0 = hContact[:logos][0]
            unless logo0[:graphicURI].empty?
               logoUrl = logo0[:graphicURI][0][:olResURI]
            end
         end

         json.name hContact[:name]
         json.contactType type
         json.personalTitle hContact[:positionName] if type == 'person'
         json.type role
         json.email hContact[:eMailList][0] unless hContact[:eMailList].empty?
         json.hours Hours.build(hContact[:hoursOfService]) unless hContact[:hoursOfService].empty?
         json.instructions hContact[:contactInstructions]
         json.officePhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
            ph[:phoneServiceTypes].include?('voice')}.reject(&:nil?).first
         json.faxPhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
            ph[:phoneServiceTypes].include?('fax')}.reject(&:nil?).first
         json.ttyPhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
            ph[:phoneServiceTypes].include?('tty')}.reject(&:nil?).first
         json.organization {json.displayText orgName} unless orgName.nil?
         json.logoUrl logoUrl unless logoUrl.nil?

         if !hContact[:addresses].empty? || !hContact[:phones].empty?
            json.primaryLocation do
               unless hContact[:phones].empty?
                  json.officePhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
                     ph[:phoneServiceTypes].include?('voice')}.reject(&:nil?).first
                  json.faxPhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
                     ph[:phoneServiceTypes].include?('fax')}.reject(&:nil?).first
                  json.ttyPhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
                     ph[:phoneServiceTypes].include?('tty')}.reject(&:nil?).first
               end
               unless hContact[:addresses].empty?
                  aAddress = hContact[:addresses]
                  json.description aAddress[0][:description]
                  aAddress.each do |hAddress|
                     if hAddress[:addressTypes].include?('physical')
                        json.streetAddress do
                           unless hAddress[:deliveryPoints].empty?
                              json.line1 hAddress[:deliveryPoints][0]
                              json.line2 hAddress[:deliveryPoints][1]
                           end
                           json.city hAddress[:city]
                           json.state hAddress[:adminArea]
                           json.zip hAddress[:postalCode]
                           json.country hAddress[:country]
                        end
                     end
                     if hAddress[:addressTypes].include?('mailing')
                        json.mailAddress do
                           unless hAddress[:deliveryPoints].empty?
                              json.line1 hAddress[:deliveryPoints][0]
                              json.line2 hAddress[:deliveryPoints][1]
                           end
                           json.city hAddress[:city]
                           json.state hAddress[:adminArea]
                           json.zip hAddress[:postalCode]
                           json.country hAddress[:country]
                        end
                     end
                  end
               end
            end
         end
      end
   end

end
get_contact_list(intObj) click to toggle source
# File lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb, line 22
def self.get_contact_list(intObj)

   # gather all responsibility objects in intObj
   # skip those in associatedResources[]
   aResponsibility = @Namespace.nested_objs_by_element(intObj, 'roleName', ['associatedResources'])

   # set an additional 'Material Request Contact' for each distributor contact
   aMRContacts = @Namespace.nested_objs_by_element(intObj[:metadata][:distributorInfo], 'roleName')
   aMRContactsDup = Marshal::load(Marshal.dump(aMRContacts))
   aMRContactsDup.each do |hResponsibility|
      hResponsibility[:roleName] = 'Material Request Contact'
      aResponsibility << hResponsibility
   end

   # make a list of unique role/party contacts
   aContactList = []
   aResponsibility.each do |hResponsibility|
      role = hResponsibility[:roleName]
      sbRole = Codelists.codelist_adiwg2sb('role_adiwg2sb', role)
      sbRole = sbRole.nil? ? role : sbRole
      hResponsibility[:parties].each do |hParty|
         aContactList << { :role => sbRole, :index => hParty[:contactIndex] }
      end
   end

   # add sourceId and recipientId contacts
   unless intObj[:metadata][:funding].empty?
      aFunding = intObj[:metadata][:funding]
      aFunding.each do |hFunding|
         hFunding[:allocations].each do |hAllocation|
            unless hAllocation[:sourceId].nil?
               contactId = hAllocation[:sourceId]
               sourceIndex = @Namespace.get_contact_index_by_id(contactId)
               aContactList << { :role => 'funder', :index => sourceIndex }
            end
            unless hAllocation[:recipientId].nil?
               contactId = hAllocation[:recipientId]
               recipientIndex = @Namespace.get_contact_index_by_id(contactId)
               aContactList << { :role => '', :index => recipientIndex }
            end
         end
      end
   end

   aContactList = aContactList.uniq

end