Module: ADIWG::Mdtranslator::Readers::Fgdc::Attribute

Defined in:
lib/adiwg/mdtranslator/readers/fgdc/modules/module_attribute.rb

Class Method Summary collapse

Class Method Details

.unpack(xAttribute, hDictionary, hResponseObj) ⇒ Object



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
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
# File 'lib/adiwg/mdtranslator/readers/fgdc/modules/module_attribute.rb', line 22

def self.unpack(xAttribute, hDictionary, hResponseObj)

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

   # entity attribute 5.1.2.1 (attrlabl) - attribute name (required)
   # -> dataDictionary.entities.attributes.attributeCode
   code = xAttribute.xpath('./attrlabl').text
   unless code.empty?
      hAttribute[:attributeName] = code
      hAttribute[:attributeCode] = code
   end
   if code.empty?
      hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: attribute label is missing'
   end

   # entity attribute 5.1.2.2 (attrdef) - attribute definition (required)
   # -> dataDictionary.entities.attributes.attributeDefinition
   definition = xAttribute.xpath('./attrdef').text
   unless definition.empty?
      hAttribute[:attributeDefinition] = definition
   end
   if definition.empty?
      hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: attribute definition is missing'
   end

   # entity attribute 5.1.2.3 (attrdefs) - attribute definition source (required)
   # -> dataDictionary.entities.attributes.attributeReference.title
   reference = xAttribute.xpath('./attrdefs').text
   unless reference.empty?
      hCitation = intMetadataClass.newCitation
      hCitation[:title] = reference
      hAttribute[:attributeReference] = hCitation
   end
   if reference.empty?
      hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: attribute reference source is missing'
   end

   # entity attribute 5.1.2.4 (attrdomv) - attribute domain value (required)
   domainLength = hDictionary[:domains].length
   axDomain = xAttribute.xpath('./attrdomv')
   unless axDomain.empty?

      # entity attribute 5.1.2.4.1 (edom) - enumerated domain
      unless axDomain.empty?
         hDomain = Enumerated.unpack(axDomain, code, hResponseObj)
         unless hDomain.nil?
            hDictionary[:domains] << hDomain
         end
      end

      # entity attribute 5.1.2.4.2 (rdom) - range domain
      unless axDomain.empty?
         Range.unpack(axDomain, hAttribute, hResponseObj)
      end

      # entity attribute 5.1.2.4.3 (codesetd) - codeset domain
      unless axDomain.empty?
         aDomains = CodeSet.unpack(axDomain, code, hResponseObj)
         hDictionary[:domains].concat aDomains
      end

      # entity attribute 5.1.2.4.4 (udom) - unrepresentable domain
      # -> dataDictionary.domains.domainDescription
      axUnRep = axDomain.xpath('./udom')
      axUnRep.each do |xUnRep|
         unRep = xUnRep.text
         unless unRep.empty?
            hDomain = intMetadataClass.newDictionaryDomain
            hDomain[:domainId] = UUIDTools::UUID.random_create.to_s
            hDomain[:domainName] = code
            hDomain[:domainCode] = code
            hDomain[:domainDescription] = unRep
            hDictionary[:domains] << hDomain
         end
      end

   end
   if axDomain.empty?
      hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: attribute domain is missing'
   end

   # add domainId to attribute
   # fgdc allows multiple domain definitions
   # mdJson allows only one domain definition for an attribute
   # take the first domain that is assigned to the attribute,
   # if this is a problem the user will need to fix in the editor
   unless hDictionary[:domains].empty?
     if hDictionary[:domains].length > domainLength
       hAttribute[:domainId] = hDictionary[:domains][domainLength][:domainId]
     end
   end

   axBegin = xAttribute.xpath('./begdatea')
   # entity attribute 5.1.2.5 (begdatea) - beginning date of attribute values
   # entity attribute 5.1.2.6 (enddatea) - ending date of attribute values
   # -> dataDictionary.entities.attributes.timePeriod.startDateTime
   # -> dataDictionary.entities.attributes.timePeriod.endDateTime
   axBegin.each_with_index do |xBegin, index|
      beginDate = xBegin.text
      unless beginDate.empty?
         hTimePeriod = intMetadataClass.newTimePeriod
         hDateTime = DateTime.unpack(beginDate, nil, hResponseObj)
         unless hDateTime.nil?
            hTimePeriod[:startDateTime] = hDateTime
         end
         endDate = xAttribute.xpath("./enddatea[#{index+1}]").text
         hDateTime = DateTime.unpack(endDate, nil, hResponseObj)
         unless hDateTime.nil?
            hTimePeriod[:endDateTime] = hDateTime
         end
         hTimePeriod[:description] = 'attribute date range'
         hAttribute[:timePeriod] << hTimePeriod
      end
   end

   # entity attribute 5.1.2.7 (attrvai) - attribute value accuracy information
   # -> not mapped

   # entity attribute 5.1.2.7.1 (attrva) - attribute value accuracy
   # -> not mapped

   # entity attribute 5.1.2.7.2 (attrvae) - attribute value accuracy explanation
   # -> not mapped

   # entity attribute 5.1.2.8 (attrmfrq) - attribute measurement frequency
   # -> not mapped; same as resource maintenance but at attribute level

   hAttribute

end