Module: ADIWG::Mdtranslator::Readers::MdJson::Entity

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

Class Method Summary collapse

Class Method Details

.unpack(hEntity, responseObj) ⇒ Object



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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_entity.rb', line 27

def self.unpack(hEntity, responseObj)

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

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

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intEntity = intMetadataClass.newEntity

   outContext = nil

   # entity - id
   if hEntity.has_key?('entityId')
      s = hEntity['entityId']
      unless s == ''
         intEntity[:entityId] = s
      end
   end

   # entity - name
   if hEntity.has_key?('commonName')
      unless hEntity['commonName'] == ''
         intEntity[:entityName] = hEntity['commonName']
      end
   end

   # entity - code (required)
   if hEntity.has_key?('codeName')
      intEntity[:entityCode] = hEntity['codeName']
   end
   if intEntity[:entityCode].nil? || intEntity[:entityCode] == ''
      @MessagePath.issueError(231, responseObj)
   else
      outContext = 'entity code name ' + hEntity['codeName']
   end

   # entity - alias []
   if hEntity.has_key?('alias')
      hEntity['alias'].each do |item|
         unless item == ''
            intEntity[:entityAlias] << item
         end
      end
   end

   # entity - definition (required)
   if hEntity.has_key?('definition')
      intEntity[:entityDefinition] = hEntity['definition']
   end
   if intEntity[:entityDefinition].nil? || intEntity[:entityDefinition] == ''
      @MessagePath.issueError(232, responseObj, outContext)
   end

   # entity - entity reference [] {citation}
   if hEntity.has_key?('entityReference')
      hEntity['entityReference'].each do |hCitation|
         unless hCitation.empty?
            hReturn = Citation.unpack(hCitation, responseObj, outContext)
            unless hReturn.nil?
               intEntity[:entityReferences] << hReturn
            end
         end
      end
   end

   # data entity - primary key (NOT required)
   if hEntity.has_key?('primaryKeyAttributeCodeName')
      hEntity['primaryKeyAttributeCodeName'].each do |item|
         unless item == ''
            intEntity[:primaryKey] << item
         end
      end
   end

   # entity - indexes []
   if hEntity.has_key?('index')
      hEntity['index'].each do |hIndex|
         unless hIndex.empty?
            index = EntityIndex.unpack(hIndex, responseObj, outContext)
            unless index.nil?
               intEntity[:indexes] << index
            end
         end
      end
   end

   # entity - attributes []
   if hEntity.has_key?('attribute')
      hEntity['attribute'].each do |hAttribute|
         unless hAttribute.empty?
            attribute = EntityAttribute.unpack(hAttribute, responseObj, outContext)
            unless attribute.nil?
               intEntity[:attributes] << attribute
            end
         end
      end
   end

   # entity - foreign keys []
   if hEntity.has_key?('foreignKey')
      hEntity['foreignKey'].each do |hFKey|
         unless hFKey.empty?
            fKey = EntityForeignKey.unpack(hFKey, responseObj, outContext)
            unless fKey.nil?
               intEntity[:foreignKeys] << fKey
            end
         end
      end
   end

   # entity - field separator
   if hEntity.has_key?('fieldSeparatorCharacter')
      unless hEntity['fieldSeparatorCharacter'] == ''
         intEntity[:fieldSeparatorCharacter] = hEntity['fieldSeparatorCharacter']
      end
   end

   # entity - number of header lines
   if hEntity.has_key?('numberOfHeaderLines')
      unless hEntity['numberOfHeaderLines'] == ''
         intEntity[:numberOfHeaderLines] = hEntity['numberOfHeaderLines'].to_i
      end
   end

   # entity - quote character
   if hEntity.has_key?('quoteCharacter')
      unless hEntity['quoteCharacter'] == ''
         intEntity[:quoteCharacter] = hEntity['quoteCharacter']
      end
   end

   return intEntity

end