adiwg-mdtranslator 2.0.0rc2 → 2.0.0rc3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,18 @@
1
1
  # adiwg mdTranslator
2
2
 
3
3
  # version 2 history
4
- # 2016-10-01 start of version 2
4
+ # 2.0.0rc3 2017-05-16 removed topicCategory from schema and manage as keyword
5
+ # 2.0.0rc2 2017-04-21 removed inline CSS option from CLI
6
+ # 2.0.0rc1 2017-04-09 release candidate 1
7
+ # 2.0.0 2016-10-01 start of version 2
5
8
 
6
9
  module ADIWG
7
- module Mdtranslator
8
- # current mdtranslator version
9
- VERSION = "2.0.0rc2"
10
- end
10
+ module Mdtranslator
11
+ # current mdtranslator version
12
+ VERSION = "2.0.0rc3"
13
+ end
11
14
  end
12
15
 
13
- # version 2 history
14
- # 2.0.0rc2 2017-04-21 removed inline CSS option from CLI
15
- # 2.0.0rc1 2017-04-09 release candidate 1
16
-
17
16
  # version 1 history
18
17
  # 1.0.0rc1 2015-02-27 schema 1.0 support
19
18
  # 1.1.0 2015-04-13 added html writer
@@ -1,6 +1,7 @@
1
1
  # mdJson 2.0 writer - resource information
2
2
 
3
3
  # History:
4
+ # Stan Smith 2017-05-16 deprecated topicCategory
4
5
  # Stan Smith 2017-03-11 refactored for mdJson/mdTranslator 2.0
5
6
  # Josh Bradley original script
6
7
 
@@ -43,7 +44,6 @@ module ADIWG
43
44
  json.credit hResInfo[:credits] unless hResInfo[:credits].empty?
44
45
  json.timePeriod TimePeriod.build(hResInfo[:timePeriod]) unless hResInfo[:timePeriod].empty?
45
46
  json.status hResInfo[:status] unless hResInfo[:status].empty?
46
- json.topicCategory hResInfo[:topicCategories] unless hResInfo[:topicCategories].empty?
47
47
  json.pointOfContact @Namespace.json_map(hResInfo[:pointOfContacts], ResponsibleParty)
48
48
  json.spatialReferenceSystem @Namespace.json_map(hResInfo[:spatialReferenceSystems], SpatialReference)
49
49
  json.spatialRepresentationType hResInfo[:spatialRepresentationTypes] unless hResInfo[:spatialRepresentationTypes].empty?
@@ -1,135 +1,57 @@
1
+ # sbJson 1.0 writer
2
+
3
+ # History:
4
+ # Stan Smith 2017-05-12 refactored for mdJson/mdTranslator 2.0
5
+ # Josh Bradley original script
6
+
1
7
  require 'jbuilder'
2
8
  require_relative 'version'
3
- require_relative 'sections/sbJson_base'
4
- require_relative 'sections/sbJson_contact'
5
- require_relative 'sections/sbJson_identifier'
6
- require_relative 'sections/sbJson_spatial'
7
- require_relative 'sections/sbJson_facet'
9
+ require_relative 'sections/sbJson_sbJson'
8
10
 
9
11
  module ADIWG
10
- module Mdtranslator
11
- module Writers
12
- module SbJson
13
- extend SbJson::Base
14
- def self.startWriter(_intObj, responseObj, _paramsObj)
15
- @intObj = _intObj
16
-
17
- # set output flag for null properties
18
- Jbuilder.ignore_nil(!responseObj[:writerShowTags])
19
- # set the format of the output file based on the writer specified
20
- responseObj[:writerFormat] = 'json'
21
- responseObj[:writerVersion] = ADIWG::Mdtranslator::Writers::SbJson::VERSION
22
-
23
- rInfo = _intObj[:metadata][:resourceInfo]
24
- mInfo = _intObj[:metadata][:metadataInfo]
25
- dInfo = _intObj[:metadata][:distributorInfo]
26
- cite = rInfo[:citation]
27
- ids = cite[:citResourceIds]
12
+ module Mdtranslator
13
+ module Writers
14
+ module SbJson
28
15
 
29
- metadata = Jbuilder.new do |json|
30
- parentId = mInfo[:parentMetadata][:citResourceIds].find {
31
- |i| i[:identifierType] == 'scienceBase'
32
- } unless mInfo[:parentMetadata].nil? || mInfo[:parentMetadata][:citResourceIds].nil?
33
- json.parentId parentId.nil? ? '' : parentId[:identifier]
34
-
35
- json.identifiers json_map(ids, Identifier)
36
- json.title cite[:citTitle]
37
- json.alternateTitles([cite[:citAltTitle]]) unless cite[:citAltTitle].nil?
38
- json.body rInfo[:abstract]
39
- json.citation do
40
- names = cite[:citResponsibleParty].map do |rp|
41
- cnt = getContact(rp[:contactId])
42
- cnt[:indName]
43
- end
44
- names = names.select! { |s| s }.nil? ? 'Unknown' : names.join(', ')
45
- dates = cite[:citDate].map { |dt| dt[:dateTime].strftime('%F') + '(' + dt[:dateType] + ')' }
46
- url = cite[:citOlResources].map { |ol| ol[:olResURI] }
47
- json.merge! sprintf('%s, %s, %s, %s', names, dates.join(', '), cite[:citTitle], url.join(', '))
48
- end
49
- json.purpose rInfo[:purpose]
50
-
51
- legal = []
52
- rInfo[:legalConstraints].each do |lc|
53
- legal += lc[:accessCodes] += lc[:useCodes] += lc[:otherCons]
54
- end
55
- json.rights legal.empty? ? nil : legal.join('; ')
56
- json.provenance do
57
- json.annotation 'Generated using the ADIwg mdTranslator, http://mdtranslator.adiwg.org'
58
- end
16
+ def self.startWriter(intObj, responseObj)
17
+ @contacts = intObj[:contacts]
59
18
 
60
- mri = []
61
- dInfo.each { |di| di[:distOrderProcs].each { |dop| mri << dop[:orderInstructions] } }
62
- json.materialRequestInstructions mri.empty? ? nil : mri.join('; ')
19
+ # set output flag for null properties
20
+ Jbuilder.ignore_nil(!responseObj[:writerShowTags])
63
21
 
64
- json.contacts json_map(_intObj[:contacts].select! { |c| !(c[:internal]) }, Contact)
22
+ # set the format of the output file based on the writer specified
23
+ responseObj[:writerFormat] = 'json'
24
+ responseObj[:writerVersion] = ADIWG::Mdtranslator::Writers::SbJson::VERSION
65
25
 
66
- # grab links from citation, additionalDocumentation, distributionInfo
67
- wl = []
68
- wl += cite[:citOlResources]
69
- dInfo.each { |di| di[:distTransOptions].each { |dto| wl += dto[:online] } }
70
- _intObj[:metadata][:additionalDocuments].each { |ad| wl += ad[:citation][:citOlResources] }
26
+ # write the sbJson metadata record
27
+ metadata = SbJson.build(intObj, responseObj)
71
28
 
72
- json.webLinks(wl) do |lnk|
73
- json.type 'webLink'
74
- json.typeLabel 'Web Link'
75
- json.uri lnk[:olResURI]
76
- json.title lnk[:olResName]
77
- end unless wl.empty?
29
+ # set writer pass to true if no messages
30
+ # false or warning state will be set by writer code
31
+ responseObj[:writerPass] = true if responseObj[:writerMessages].empty?
78
32
 
79
- tags = []
80
- rInfo[:topicCategories].each do |tc|
81
- tags << { type: 'Label',
82
- scheme: 'ISO 19115 Topic Categories',
83
- name: tc }
84
- end
85
- rInfo[:descriptiveKeywords].each do |kw|
86
- type = kw[:keyTheCitation].fetch(:citTitle, kw[:keywordType]) || 'Theme'
87
- scheme = kw[:keyTheCitation].fetch(:citOlResources, [])
88
- kw[:keyword].each do |_k|
89
- tags << { type: type,
90
- scheme: scheme.empty? ? 'None' : scheme.first[:olResURI],
91
- name: _k }
92
- end
33
+ # encode the metadata target as JSON
34
+ metadata.target!
93
35
  end
94
- json.tags(tags)
95
36
 
96
- dates = cite[:citDate]
97
- tp = rInfo[:timePeriod]
98
- unless tp.empty?
99
- dates << { dateType: 'Start', dateTime: tp[:beginTime][:dateTime].to_datetime
100
- } unless tp[:beginTime].empty?
101
- dates << { dateType: 'End', dateTime: tp[:endTime][:dateTime].to_datetime
102
- } unless tp[:endTime].empty?
103
-
104
- end
105
- json.dates(dates) do |dt|
106
- json.type dt[:dateType]
107
- json.dateString dt[:dateTime].strftime('%F')
108
- json.label dt[:dateType].split(/(?=[A-Z])/).join(' ').capitalize
37
+ # find contact in contact array and return the contact hash
38
+ def self.getContact(contactIndex)
39
+ if @contacts[contactIndex]
40
+ return @contacts[contactIndex]
41
+ end
42
+ {}
109
43
  end
110
44
 
111
- json.spatial Spatial.build(rInfo[:extents])
112
- json.facets Facet.build(rInfo)
113
- end
114
-
115
- # set writer pass to true if no messages
116
- # false or warning will be set by code that places the message
117
- responseObj[:writerPass] = true if responseObj[:writerMessages].empty?
118
-
119
- # j = JSON.parse(metadata.target!)
120
- # puts JSON.pretty_generate(j)
121
-
122
- metadata.target!
123
- end
45
+ # ignore jBuilder object mapping when array is empty
46
+ def self.json_map(collection = [], _class)
47
+ if collection.nil? || collection.empty?
48
+ return nil
49
+ else
50
+ collection.map { |item| _class.build(item).attributes! }
51
+ end
52
+ end
124
53
 
125
- # find contact in contact array and return the contact hash
126
- def self.getContact(contactID)
127
- @intObj[:contacts].each do |hContact|
128
- return hContact if hContact[:contactId] == contactID
129
- end
130
- {}
131
- end
54
+ end
132
55
  end
133
- end
134
- end
56
+ end
135
57
  end
@@ -0,0 +1,79 @@
1
+ # sbJson 1.0 writer
2
+
3
+ # History:
4
+ # Stan Smith 2017-05-16 original script
5
+
6
+ module ADIWG
7
+ module Mdtranslator
8
+ module Writers
9
+ module SbJson
10
+
11
+ module Citation
12
+
13
+ # build from citation as follows ...
14
+ # names, [] {citation.responsibleParty[]}
15
+ # dates(type), [] {citation.dates[]}
16
+ # title, {citation.title}
17
+ # uri, [] {citation.onlineResource[]}
18
+ def self.build(hCitation)
19
+
20
+ citation = ''
21
+
22
+ # names
23
+ indexes = []
24
+ hCitation[:responsibleParties].each do |hResponsibility|
25
+ hResponsibility[:parties].each do |hParty|
26
+ indexes << hParty[:contactIndex]
27
+ hParty[:organizationMembers].each do |hMember|
28
+ indexes << hMember[:contactIndex]
29
+ end
30
+ end
31
+ end
32
+ indexes.uniq!
33
+ indexes.each do |index|
34
+ hContact = ADIWG::Mdtranslator::Writers::SbJson.getContact(index)
35
+ unless hContact.empty?
36
+ unless hContact[:name].nil?
37
+ citation += hContact[:name] + ', '
38
+ end
39
+ end
40
+ end
41
+
42
+ # dates
43
+ hCitation[:dates].each do |hDate|
44
+ date = hDate[:date]
45
+ dateRes = hDate[:dateResolution]
46
+ unless date.nil?
47
+ case dateRes
48
+ when 'Y', 'YM', 'YMD'
49
+ dateStr = AdiwgDateTimeFun.stringDateFromDateTime(date, dateRes)
50
+ else
51
+ dateStr = AdiwgDateTimeFun.stringDateTimeFromDateTime(date, dateRes)
52
+ end
53
+ citation += dateStr.to_s + '(' + hDate[:dateType] + '), '
54
+ end
55
+ end
56
+
57
+ # title
58
+ citation += hCitation[:title] + ', '
59
+
60
+ # uri
61
+ hCitation[:onlineResources].each do |hOnline|
62
+ citation += hOnline[:olResURI] + ', '
63
+ end
64
+
65
+ # clean off last comma
66
+ if citation.length > 0
67
+ citation = citation[0...-2]
68
+ end
69
+
70
+ citation
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,54 @@
1
+ # sbJson 1.0 writer
2
+
3
+ # History:
4
+ # Stan Smith 2017-05-15 refactored for mdJson/mdTranslator 2.0
5
+ # Josh Bradley original script
6
+
7
+ require 'uuidtools'
8
+
9
+ module ADIWG
10
+ module Mdtranslator
11
+ module Writers
12
+ module SbJson
13
+
14
+ module Id
15
+
16
+ # use metadataInfo identifier
17
+ # else use citation identifier [0]
18
+ # else use generated UUID
19
+ def self.build(intObj)
20
+
21
+ metadataInfo = intObj[:metadata][:metadataInfo]
22
+ resourceInfo = intObj[:metadata][:resourceInfo]
23
+ hIdentifier = metadataInfo[:metadataIdentifier]
24
+ hCitation = resourceInfo[:citation]
25
+
26
+ id = nil
27
+ metadataId = nil
28
+ citationId = nil
29
+ unless hIdentifier.empty?
30
+ metadataId = hIdentifier[:identifier]
31
+ end
32
+
33
+ unless hCitation.empty?
34
+ unless hCitation[:identifiers].empty?
35
+ citationId = hCitation[:identifiers][0][:identifier]
36
+ end
37
+ end
38
+
39
+ if !metadataId.nil?
40
+ id = metadataId
41
+ elsif !citationId.nil?
42
+ id = citationId
43
+ else
44
+ id = UUIDTools::UUID.random_create.to_s
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,23 +1,30 @@
1
+ # sbJson 1.0 writer
2
+
3
+ # History:
4
+ # Stan Smith 2017-05-16 refactored for mdTranslator 2.0
5
+ # Json Bradley original script
6
+
1
7
  require 'jbuilder'
2
8
 
3
9
  module ADIWG
4
- module Mdtranslator
5
- module Writers
6
- module SbJson
7
- module Identifier
8
- def self.build(intObj)
9
- Jbuilder.new do |json|
10
- json.type intObj[:identifierType]
11
- json.scheme intObj[:identifierNamespace] ||
12
- unless intObj[:identifierCitation].empty?
13
- intObj[:identifierCitation][:citOlResources][0][:olResURI] unless intObj[:identifierCitation][:citOlResources].empty?
14
- end ||
15
- 'https://www.sciencebase.gov/vocab/category/item/identifier'
16
- json.key intObj[:identifier]
10
+ module Mdtranslator
11
+ module Writers
12
+ module SbJson
13
+
14
+ module Identifier
15
+
16
+ def self.build(hIdentifier)
17
+
18
+ Jbuilder.new do |json|
19
+ json.key hIdentifier[:identifier]
20
+ json.scheme hIdentifier[:namespace]
21
+ json.type hIdentifier[:description]
22
+ end
23
+ end
24
+
17
25
  end
18
- end
19
- end
26
+
27
+ end
20
28
  end
21
- end
22
- end
29
+ end
23
30
  end
@@ -0,0 +1,57 @@
1
+ # sbJson 1.0 writer
2
+
3
+ # History:
4
+ # Stan Smith 2017-05-12 refactored for mdJson/mdTranslator 2.0
5
+ # Josh Bradley original script
6
+
7
+ require 'jbuilder'
8
+ require_relative 'sbJson_id'
9
+ require_relative 'sbJson_citation'
10
+ require_relative 'sbJson_identifier'
11
+
12
+ module ADIWG
13
+ module Mdtranslator
14
+ module Writers
15
+ module SbJson
16
+
17
+ def self.build(intObj, responseObj)
18
+
19
+ resourceInfo = intObj[:metadata][:resourceInfo]
20
+ hCitation = resourceInfo[:citation]
21
+
22
+ @Namespace = ADIWG::Mdtranslator::Writers::SbJson
23
+
24
+ Jbuilder.new do |json|
25
+
26
+ # id
27
+ json.id Id.build(intObj)
28
+
29
+ # title / alternateTitles (incorporates subTitle)
30
+ unless hCitation.empty?
31
+ json.title hCitation[:title]
32
+ json.alternateTitles hCitation[:alternateTitles] unless hCitation[:alternateTitles].empty?
33
+ end
34
+
35
+ # body / summary
36
+ json.body resourceInfo[:abstract]
37
+ json.summary resourceInfo[:shortAbstract]
38
+
39
+ # citation / identifier
40
+ unless hCitation.empty?
41
+ json.citation Citation.build(hCitation)
42
+ json.identifiers @Namespace.json_map(hCitation[:identifiers], Identifier)
43
+ end
44
+
45
+ # purpose
46
+ json.purpose resourceInfo[:purpose]
47
+
48
+ # rights
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,13 +1,17 @@
1
+ # History version 1
2
+ # Stan Smith 2017-05-12 refactored for mdJson/mdTranslator 2.0
3
+
4
+ # History version 0
5
+ # Josh Bradley
6
+
1
7
  module ADIWG
2
- module Mdtranslator
3
- module Writers
4
- module SbJson
8
+ module Mdtranslator
9
+ module Writers
10
+ module SbJson
5
11
 
6
- # current version of mdJson writer,
7
- # corresponds to mdJson output
8
- VERSION = '0.0.0'
12
+ VERSION = '1.0.0'
9
13
 
10
- end
11
- end
12
- end
14
+ end
15
+ end
16
+ end
13
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adiwg-mdtranslator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0rc2
4
+ version: 2.0.0rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stan Smith
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-01 00:00:00.000000000 Z
12
+ date: 2017-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -129,14 +129,14 @@ dependencies:
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: '2.0'
132
+ version: 2.1.1
133
133
  type: :runtime
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: '2.0'
139
+ version: 2.1.1
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: adiwg-mdcodes
142
142
  requirement: !ruby/object:Gem::Requirement
@@ -165,34 +165,6 @@ dependencies:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
167
  version: '2.5'
168
- - !ruby/object:Gem::Dependency
169
- name: rgeo
170
- requirement: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - "~>"
173
- - !ruby/object:Gem::Version
174
- version: '0.5'
175
- type: :runtime
176
- prerelease: false
177
- version_requirements: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - "~>"
180
- - !ruby/object:Gem::Version
181
- version: '0.5'
182
- - !ruby/object:Gem::Dependency
183
- name: activesupport
184
- requirement: !ruby/object:Gem::Requirement
185
- requirements:
186
- - - "<"
187
- - !ruby/object:Gem::Version
188
- version: '5'
189
- type: :runtime
190
- prerelease: false
191
- version_requirements: !ruby/object:Gem::Requirement
192
- requirements:
193
- - - "<"
194
- - !ruby/object:Gem::Version
195
- version: '5'
196
168
  description: The mdtranslator was written by the Alaska Data Integration Working Group
197
169
  (ADIwg) to assist with creating ISO 19139 metadata records. Input to the mdtranslator
198
170
  is JSON conforming to the mdJson-schema. The mdtranslator architecture allows developers
@@ -609,9 +581,12 @@ files:
609
581
  - lib/adiwg/mdtranslator/writers/sbJson/readme.md
610
582
  - lib/adiwg/mdtranslator/writers/sbJson/sbJson_writer.rb
611
583
  - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_base.rb
584
+ - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_citation.rb
612
585
  - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb
613
586
  - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_facet.rb
587
+ - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_id.rb
614
588
  - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_identifier.rb
589
+ - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_sbJson.rb
615
590
  - lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_spatial.rb
616
591
  - lib/adiwg/mdtranslator/writers/sbJson/version.rb
617
592
  - lib/adiwg/mdtranslator_cli.rb