Module: ADIWG::Mdtranslator::Readers::MdJson::EntityAttribute

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

Class Method Summary collapse

Class Method Details

.unpack(hAttribute, responseObj, inContext = nil) ⇒ 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_entityAttribute.rb', line 27

def self.unpack(hAttribute, responseObj, inContext = nil)

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

   # return nil object if input is empty
   if hAttribute.empty?
      @MessagePath.issueWarning(240, responseObj, inContext)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = .new
   intAttribute = intMetadataClass.newEntityAttribute

   outContext = nil

   # attribute - common name
   if hAttribute.has_key?('commonName')
      unless hAttribute['commonName'] == ''
         intAttribute[:attributeName] = hAttribute['commonName']
      end
   end

   # attribute - code name (required)
   if hAttribute.has_key?('codeName')
      intAttribute[:attributeCode] = hAttribute['codeName']
   end
   if intAttribute[:attributeCode].nil? || intAttribute[:attributeCode] == ''
      @MessagePath.issueError(241, responseObj, inContext)
   else
      if inContext.nil?
         outContext = 'attribute code name ' + hAttribute['codeName']
      else
         outContext = inContext + ' attribute code name ' + hAttribute['codeName']
      end
   end

   # attribute - alias []
   if hAttribute.has_key?('alias')
      hAttribute['alias'].each do |item|
         unless item == ''
            intAttribute[:attributeAlias] << item
         end
      end
   end

   # attribute - definition (required)
   if hAttribute.has_key?('definition')
      intAttribute[:attributeDefinition] = hAttribute['definition']
   end
   if intAttribute[:attributeDefinition].nil? || intAttribute[:attributeDefinition] == ''
      @MessagePath.issueError(242, responseObj, outContext)
   end

   # attribute - attribute reference
   if hAttribute.has_key?('attributeReference')
      hCitation = hAttribute['attributeReference']
      unless hCitation.empty?
         hReturn = Citation.unpack(hCitation, responseObj, outContext)
         unless hReturn.nil?
            intAttribute[:attributeReference] = hReturn
         end
      end
   end

   # attribute - data type (required)
   if hAttribute.has_key?('dataType')
      intAttribute[:dataType] = hAttribute['dataType']
   end
   if intAttribute[:dataType].nil? || intAttribute[:dataType] == ''
      @MessagePath.issueError(243, responseObj, outContext)
   end

   # attribute - allow nulls (required)
   if hAttribute.has_key?('allowNull')
      if hAttribute['allowNull'] === true
         intAttribute[:allowNull] = hAttribute['allowNull']
      end
   end

   # attribute - require value to be unique (required)
   # ... allowMany deprecated
   if hAttribute.has_key?('allowMany')
      if hAttribute['allowMany'] === false
         intAttribute[:mustBeUnique] = hAttribute['allowMany']
         @MessagePath.issueNotice(244, responseObj, outContext)
      end
   end
   if hAttribute.has_key?('mustBeUnique')
      if hAttribute['mustBeUnique'] === false
         intAttribute[:mustBeUnique] = hAttribute['mustBeUnique']
      end
   end

   # attribute - units of measure
   if hAttribute.has_key?('units')
      unless hAttribute['units'] == ''
         intAttribute[:unitOfMeasure] = hAttribute['units']
      end
   end

   # attribute - units of measure resolution
   if hAttribute.has_key?('unitsResolution')
      unless hAttribute['unitsResolution'] == ''
         intAttribute[:measureResolution] = hAttribute['unitsResolution']
      end
   end

   # attribute - case sensitive {Boolean} (default = false)
   if hAttribute.has_key?('isCaseSensitive')
      unless hAttribute['unitsResolution'] == ''
         intAttribute[:isCaseSensitive] = hAttribute['isCaseSensitive']
      end
   end

   # attribute - field width
   if hAttribute.has_key?('fieldWidth')
      unless hAttribute['fieldWidth'] == ''
         intAttribute[:fieldWidth] = hAttribute['fieldWidth']
      end
   end

   # attribute - missing value
   if hAttribute.has_key?('missingValue')
      unless hAttribute['missingValue'] == ''
         intAttribute[:missingValue] = hAttribute['missingValue']
      end
   end

   # attribute - domain ID
   if hAttribute.has_key?('domainId')
      unless hAttribute['domainId'] == ''
         intAttribute[:domainId] = hAttribute['domainId']
      end
   end

   # attribute - minimum value
   if hAttribute.has_key?('minValue')
      unless hAttribute['minValue'] == ''
         intAttribute[:minValue] = hAttribute['minValue']
      end
   end

   # attribute - maximum value
   if hAttribute.has_key?('maxValue')
      unless hAttribute['maxValue'] == ''
         intAttribute[:maxValue] = hAttribute['maxValue']
      end
   end

   # attribute - domain range of values [] {valueRange}
   if hAttribute.has_key?('valueRange')
      aValueRange = hAttribute['valueRange']
      aValueRange.each do |hRange|
         unless hRange.empty?
            hReturn = ValueRange.unpack(hRange, responseObj, outContext)
            unless hReturn.nil?
               intAttribute[:valueRange] << hReturn
            end
         end
      end
   end

   # attribute - time period of values [] {timePeriod}
   if hAttribute.has_key?('timePeriod')
      aTimePeriods = hAttribute['timePeriod']
      aTimePeriods.each do |hTimePeriod|
         unless hTimePeriod.empty?
            hReturn = TimePeriod.unpack(hTimePeriod, responseObj, outContext)
            unless hReturn.nil?
               intAttribute[:timePeriod] << hReturn
            end
         end
      end
   end

   return intAttribute

end