Module: ADIWG::Mdtranslator::Readers::MdJson::AssociatedResource

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

Class Method Summary collapse

Class Method Details

.unpack(hAssocRes, responseObj) ⇒ Object



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_associatedResource.rb', line 28

def self.unpack(hAssocRes, responseObj)

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

   # return nil object if input is empty
   if hAssocRes.empty?
      @MessagePath.issueWarning(30, responseObj)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intAssocRes = intMetadataClass.newAssociatedResource

   # associated resource - resource type [] (required) {resourceType}
   if hAssocRes.has_key?('resourceType')
      hAssocRes['resourceType'].each do |item|
         unless item.empty?
            hReturn = ResourceType.unpack(item, responseObj)
            unless hReturn.nil?
               intAssocRes[:resourceTypes] << hReturn
            end
         end
      end
   end
   if intAssocRes[:resourceTypes].empty?
      @MessagePath.issueError(31, responseObj)
   end

   # associated resource - association type (required)
   if hAssocRes.has_key?('associationType')
      intAssocRes[:associationType] = hAssocRes['associationType']
   end
   if intAssocRes[:associationType].nil? || intAssocRes[:associationType] == ''
      @MessagePath.issueError(32, responseObj)
   end

   # associated resource - initiative type
   if hAssocRes.has_key?('initiativeType')
      if hAssocRes['initiativeType'] != ''
         intAssocRes[:initiativeType] = hAssocRes['initiativeType']
      end
   end

   # associated resource - resource citation (required) {CI_Citation}
   if hAssocRes.has_key?('resourceCitation')
      hObject = hAssocRes['resourceCitation']
      unless hObject.empty?
         hReturn = Citation.unpack(hObject, responseObj)
         unless hReturn.nil?
            intAssocRes[:resourceCitation] = hReturn
         end
      end
   end
   if intAssocRes[:resourceCitation].empty?
      @MessagePath.issueError(33, responseObj)
   end

   # associated resource - metadata citation
   if hAssocRes.has_key?('metadataCitation')
      hObject = hAssocRes['metadataCitation']
      unless hObject.empty?
         hReturn = Citation.unpack(hObject, responseObj)
         unless hReturn.nil?
            intAssocRes[:metadataCitation] = hReturn
         end
      end
   end

   return intAssocRes

end