Module: ADIWG::Mdtranslator::Readers::SbJson::MaterialRequest

Defined in:
lib/adiwg/mdtranslator/readers/sbJson/modules/module_materialRequest.rb

Class Method Summary collapse

Class Method Details

.unpack(hSbJson, hResponseObj) ⇒ Object



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
# File 'lib/adiwg/mdtranslator/readers/sbJson/modules/module_materialRequest.rb', line 17

def self.unpack(hSbJson, hResponseObj)

   # instance classes needed in script
   intMetadataClass = .new

   if hSbJson.has_key?('materialRequestInstructions')
      sbRequest = hSbJson['materialRequestInstructions']
      unless sbRequest.nil? || sbRequest == ''

         # make a new request contact
         hContact = intMetadataClass.newContact
         hContact[:contactId] = UUIDTools::UUID.random_create.to_s
         hContact[:name] = 'U.S. Geological Survey ScienceBase'
         hContact[:contactType] = 'materialRequestInstructions'

         # make a new distribution record
         hDistribution = intMetadataClass.newDistribution
         hDistributor = intMetadataClass.newDistributor
         hResponsibility = intMetadataClass.newResponsibility
         hParty = intMetadataClass.newParty
         hProcess = intMetadataClass.newOrderProcess

         # parties [] {party}
         hParty[:contactId] = hContact[:contactId]
         hParty[:contactType] = 'ScienceBase'

         # contact {responsibility}
         hResponsibility[:roleName] = 'distributor'
         hResponsibility[:parties] << hParty

         # orderProcess {orderProcess}
         hProcess[:orderingInstructions] = sbRequest

         # distributor {distributor}
         hDistributor[:contact] = hResponsibility
         hDistributor[:orderProcess] << hProcess

         # distribution {distribution}
         hDistribution[:description] = 'sbJson Material Request distributor generated by ADIwg mdTranslator'
         hDistribution[:distributor] << hDistributor

         return hContact, hDistribution

      end
   end

   return nil

end