puree 0.20.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/PITCHME.md +43 -21
- data/README.md +72 -18
- data/lib/puree.rb +66 -21
- data/lib/puree/api/api.rb +9 -0
- data/lib/puree/api/authentication.rb +33 -0
- data/lib/puree/api/configuration.rb +43 -0
- data/lib/puree/api/map.rb +76 -0
- data/lib/puree/api/request.rb +116 -0
- data/lib/puree/extractor/collection.rb +131 -0
- data/lib/puree/extractor/dataset.rb +48 -0
- data/lib/puree/extractor/download.rb +71 -0
- data/lib/puree/extractor/event.rb +33 -0
- data/lib/puree/extractor/extractor.rb +10 -0
- data/lib/puree/extractor/journal.rb +29 -0
- data/lib/puree/extractor/organisation.rb +34 -0
- data/lib/puree/extractor/person.rb +32 -0
- data/lib/puree/extractor/project.rb +40 -0
- data/lib/puree/extractor/publication.rb +40 -0
- data/lib/puree/extractor/publisher.rb +27 -0
- data/lib/puree/extractor/resource.rb +69 -0
- data/lib/puree/extractor/server.rb +56 -0
- data/lib/puree/model/address.rb +50 -0
- data/lib/puree/model/copyright_license.rb +26 -0
- data/lib/puree/model/dataset.rb +84 -0
- data/lib/puree/model/download_header.rb +21 -0
- data/lib/puree/model/endeavour_person.rb +34 -0
- data/lib/puree/model/event.rb +31 -0
- data/lib/puree/model/event_header.rb +26 -0
- data/lib/puree/model/file.rb +45 -0
- data/lib/puree/model/helper/validation.rb +15 -0
- data/lib/puree/model/journal.rb +20 -0
- data/lib/puree/model/legal_condition.rb +26 -0
- data/lib/puree/model/link.rb +26 -0
- data/lib/puree/model/model.rb +7 -0
- data/lib/puree/model/organisation.rb +34 -0
- data/lib/puree/model/organisation_header.rb +34 -0
- data/lib/puree/model/person.rb +28 -0
- data/lib/puree/model/person_name.rb +52 -0
- data/lib/puree/model/project.rb +49 -0
- data/lib/puree/model/publication.rb +53 -0
- data/lib/puree/model/publication_status.rb +21 -0
- data/lib/puree/model/publisher.rb +13 -0
- data/lib/puree/model/related_content_header.rb +34 -0
- data/lib/puree/model/resource.rb +42 -0
- data/lib/puree/model/server.rb +13 -0
- data/lib/puree/model/spatial_point.rb +16 -0
- data/lib/puree/model/structure.rb +18 -0
- data/lib/puree/model/temporal_range.rb +15 -0
- data/lib/puree/util/date.rb +86 -0
- data/lib/puree/util/util.rb +8 -0
- data/lib/puree/version.rb +1 -1
- data/lib/puree/xml_extractor/base.rb +47 -0
- data/lib/puree/xml_extractor/collection.rb +40 -0
- data/lib/puree/xml_extractor/dataset.rb +305 -0
- data/lib/puree/xml_extractor/download.rb +42 -0
- data/lib/puree/xml_extractor/event.rb +63 -0
- data/lib/puree/xml_extractor/journal.rb +33 -0
- data/lib/puree/xml_extractor/organisation.rb +75 -0
- data/lib/puree/xml_extractor/person.rb +57 -0
- data/lib/puree/xml_extractor/project.rb +135 -0
- data/lib/puree/xml_extractor/publication.rb +189 -0
- data/lib/puree/xml_extractor/publisher.rb +28 -0
- data/lib/puree/xml_extractor/resource.rb +71 -0
- data/lib/puree/xml_extractor/server.rb +32 -0
- data/lib/puree/xml_extractor/shared.rb +31 -0
- data/lib/puree/xml_extractor/xml_extractor.rb +10 -0
- data/puree.gemspec +11 -8
- data/spec/download_http_spec.rb +31 -0
- data/spec/open_api_dataset_http_spec.rb +15 -0
- data/spec/resource/collection_all_http_spec.rb +77 -0
- data/spec/resource/collection_http_spec.rb +65 -0
- data/spec/resource/dataset_http_spec.rb +104 -0
- data/spec/resource/event_http_spec.rb +52 -0
- data/spec/resource/journal_http_spec.rb +36 -0
- data/spec/resource/organisation_http_spec.rb +52 -0
- data/spec/resource/person_http_spec.rb +48 -0
- data/spec/resource/project_http_spec.rb +76 -0
- data/spec/resource/publication_http_spec.rb +78 -0
- data/spec/resource/publisher_http_spec.rb +26 -0
- data/spec/server_http_spec.rb +26 -0
- data/spec/spec_helper.rb +106 -21
- metadata +110 -46
- data/lib/puree/collection.rb +0 -285
- data/lib/puree/configuration.rb +0 -15
- data/lib/puree/dataset.rb +0 -483
- data/lib/puree/date.rb +0 -63
- data/lib/puree/download.rb +0 -189
- data/lib/puree/event.rb +0 -133
- data/lib/puree/journal.rb +0 -75
- data/lib/puree/map.rb +0 -68
- data/lib/puree/organisation.rb +0 -177
- data/lib/puree/person.rb +0 -136
- data/lib/puree/project.rb +0 -231
- data/lib/puree/publication.rb +0 -258
- data/lib/puree/publisher.rb +0 -64
- data/lib/puree/resource.rb +0 -261
- data/lib/puree/server.rb +0 -156
- data/spec/collection_spec.rb +0 -62
- data/spec/dataset_spec.rb +0 -148
- data/spec/download_spec.rb +0 -33
- data/spec/event_spec.rb +0 -108
- data/spec/journal_spec.rb +0 -92
- data/spec/organisation_spec.rb +0 -112
- data/spec/person_spec.rb +0 -104
- data/spec/project_spec.rb +0 -120
- data/spec/publication_spec.rb +0 -128
- data/spec/publisher_spec.rb +0 -89
- data/spec/server_spec.rb +0 -36
@@ -0,0 +1,53 @@
|
|
1
|
+
module Puree
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# A publication.
|
5
|
+
#
|
6
|
+
class Publication < Resource
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_accessor :category
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_accessor :description
|
13
|
+
|
14
|
+
# @return [String, nil]
|
15
|
+
attr_accessor :doi
|
16
|
+
|
17
|
+
# @return [Puree::Model::EventHeader, nil]
|
18
|
+
attr_accessor :event
|
19
|
+
|
20
|
+
# @return [Array<Puree::Model::File>]
|
21
|
+
attr_accessor :files
|
22
|
+
|
23
|
+
# @return [Array<Puree::Model::OrganisationHeader>]
|
24
|
+
attr_accessor :organisations
|
25
|
+
|
26
|
+
# @return [Fixnum, nil]
|
27
|
+
attr_accessor :pages
|
28
|
+
|
29
|
+
# @return [Array<Puree::Model::EndeavourPerson>]
|
30
|
+
attr_accessor :persons_internal
|
31
|
+
|
32
|
+
# @return [Array<Puree::Model::EndeavourPerson>]
|
33
|
+
attr_accessor :persons_external
|
34
|
+
|
35
|
+
# @return [Array<Puree::Model::EndeavourPerson>]
|
36
|
+
attr_accessor :persons_other
|
37
|
+
|
38
|
+
# @return [Array<Puree::Model::PublicationStatus>]
|
39
|
+
attr_accessor :statuses
|
40
|
+
|
41
|
+
# @return [String, nil]
|
42
|
+
attr_accessor :subtitle
|
43
|
+
|
44
|
+
# @return [String, nil]
|
45
|
+
attr_accessor :title
|
46
|
+
|
47
|
+
# @return [String, nil]
|
48
|
+
attr_accessor :type
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Puree
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# Status of a publication.
|
5
|
+
#
|
6
|
+
class PublicationStatus < Puree::Model::Structure
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :stage
|
10
|
+
|
11
|
+
# @return [Time, nil]
|
12
|
+
attr_accessor :date
|
13
|
+
|
14
|
+
# @param v [String]
|
15
|
+
def stage=(v)
|
16
|
+
@stage = v if v && !v.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Puree
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# A minimal representation of related content.
|
5
|
+
#
|
6
|
+
class RelatedContentHeader < Puree::Model::Structure
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :uuid
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_reader :title
|
13
|
+
|
14
|
+
# @return [String, nil]
|
15
|
+
attr_reader :type
|
16
|
+
|
17
|
+
# @param v [String]
|
18
|
+
def uuid=(v)
|
19
|
+
@uuid = v if v && !v.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param v [String]
|
23
|
+
def title=(v)
|
24
|
+
@title = v if v && !v.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param v [String]
|
28
|
+
def type=(v)
|
29
|
+
@type = v if v && !v.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Puree
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# A resource.
|
5
|
+
#
|
6
|
+
class Resource
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :uuid
|
10
|
+
|
11
|
+
# @return [Time, nil]
|
12
|
+
attr_reader :created
|
13
|
+
|
14
|
+
# @return [Time, nil]
|
15
|
+
attr_reader :modified
|
16
|
+
|
17
|
+
# @return [String, nil]
|
18
|
+
attr_reader :locale
|
19
|
+
|
20
|
+
# @param v [String]
|
21
|
+
def uuid=(v)
|
22
|
+
@uuid = v if v && !v.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param v [Time]
|
26
|
+
def created=(v)
|
27
|
+
@created = v
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param v [Time]
|
31
|
+
def modified=(v)
|
32
|
+
@modified = v
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param v [String]
|
36
|
+
def locale=(v)
|
37
|
+
@locale = v if v && !v.empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Puree
|
2
|
+
module Model
|
3
|
+
|
4
|
+
# One or two dates which are part of a date range.
|
5
|
+
class TemporalRange < Puree::Model::Structure
|
6
|
+
|
7
|
+
# @return [Time, nil]
|
8
|
+
attr_accessor :start
|
9
|
+
|
10
|
+
# @return [Time, nil]
|
11
|
+
attr_accessor :end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Puree
|
2
|
+
|
3
|
+
module Util
|
4
|
+
|
5
|
+
# Date transformations
|
6
|
+
#
|
7
|
+
module Date
|
8
|
+
|
9
|
+
# Converts a date with variable components present (year, month, day) to Time format.
|
10
|
+
#
|
11
|
+
# @param data [Hash]
|
12
|
+
# @return [Time]
|
13
|
+
def self.hash_to_time(data)
|
14
|
+
h = normalise data
|
15
|
+
if !h['year'].empty? && !h['month'].empty? && !h['day'].empty?
|
16
|
+
return Time.new h['year'].to_i,
|
17
|
+
h['month'].to_i,
|
18
|
+
h['day'].to_i
|
19
|
+
end
|
20
|
+
if !h['year'].empty? && !h['month'].empty?
|
21
|
+
return Time.new h['year'].to_i,
|
22
|
+
h['month'].to_i
|
23
|
+
end
|
24
|
+
if !h['year'].empty?
|
25
|
+
return Time.new h['year'].to_i
|
26
|
+
end
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
# Converts a date with three components (year, month, day) to ISO 8601 date format.
|
31
|
+
#
|
32
|
+
# @param data [Hash]
|
33
|
+
# @return [String]
|
34
|
+
def self.iso(data)
|
35
|
+
iso_date = ''
|
36
|
+
year = data['year']
|
37
|
+
month = data['month']
|
38
|
+
day = data['day']
|
39
|
+
if !year.empty?
|
40
|
+
iso_date << year
|
41
|
+
else
|
42
|
+
iso_date
|
43
|
+
end
|
44
|
+
if !month.empty?
|
45
|
+
# Add leading zero to convert to ISO 8601 date component
|
46
|
+
if month.length < 2
|
47
|
+
month.insert(0, '0')
|
48
|
+
end
|
49
|
+
iso_date << '-' + month
|
50
|
+
else
|
51
|
+
iso_date
|
52
|
+
end
|
53
|
+
if !day.empty?
|
54
|
+
# Add leading zero to convert to ISO 8601 date component
|
55
|
+
if day.length < 2
|
56
|
+
day.insert(0, '0')
|
57
|
+
end
|
58
|
+
iso_date << '-' + day
|
59
|
+
end
|
60
|
+
iso_date
|
61
|
+
end
|
62
|
+
|
63
|
+
# Forces a date to have three components (year, month, day).
|
64
|
+
#
|
65
|
+
# @param data [Hash]
|
66
|
+
# @return [Hash]
|
67
|
+
def self.normalise(data)
|
68
|
+
if !data.nil? && !data.empty?
|
69
|
+
date = {}
|
70
|
+
year = data['year']
|
71
|
+
month = data['month']
|
72
|
+
day = data['day']
|
73
|
+
date['year'] = year ? year : ''
|
74
|
+
date['month'] = month ? month : ''
|
75
|
+
date['day'] = day ? day : ''
|
76
|
+
date
|
77
|
+
else
|
78
|
+
{}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/lib/puree/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Puree
|
2
|
+
|
3
|
+
module XMLExtractor
|
4
|
+
|
5
|
+
# Base XML extractor.
|
6
|
+
#
|
7
|
+
class Base
|
8
|
+
|
9
|
+
def initialize(xml:)
|
10
|
+
@api_map = Puree::API::Map.new.get
|
11
|
+
make_doc xml
|
12
|
+
end
|
13
|
+
|
14
|
+
# XPath search for a single value, at a given path.
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
17
|
+
def xpath_query_for_single_value(path)
|
18
|
+
xpath_result = xpath_query(path).text.strip
|
19
|
+
xpath_result.empty? ? nil : xpath_result
|
20
|
+
end
|
21
|
+
|
22
|
+
# XPath search for multiple values, at a given path.
|
23
|
+
#
|
24
|
+
# @return [Array<String>]
|
25
|
+
def xpath_query_for_multi_value(path)
|
26
|
+
xpath_result = xpath_query path
|
27
|
+
arr = []
|
28
|
+
xpath_result.each { |i| arr << i.text.strip }
|
29
|
+
arr.uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def make_doc(xml)
|
35
|
+
@doc = Nokogiri::XML xml
|
36
|
+
@doc.remove_namespaces!
|
37
|
+
end
|
38
|
+
|
39
|
+
def service_response_name
|
40
|
+
@api_map[:resource_type][@resource_type][:response]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Puree
|
2
|
+
|
3
|
+
module XMLExtractor
|
4
|
+
|
5
|
+
# Collection XML extractor.
|
6
|
+
#
|
7
|
+
class Collection < Puree::XMLExtractor::Base
|
8
|
+
|
9
|
+
def initialize(xml:)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
# Records available in collection.
|
14
|
+
#
|
15
|
+
# @return [Fixnum]
|
16
|
+
def count
|
17
|
+
@doc.xpath('//count').text.strip.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
# Resource UUIDs in collection response.
|
21
|
+
#
|
22
|
+
# @return [Array<String>]
|
23
|
+
def uuids
|
24
|
+
arr = []
|
25
|
+
xpath_result = @doc.xpath '//renderedItem/@renderedContentUUID'
|
26
|
+
xpath_result.each { |i| arr << i.text.strip }
|
27
|
+
arr
|
28
|
+
end
|
29
|
+
|
30
|
+
# Is there any data after get?
|
31
|
+
# @return [Boolean]
|
32
|
+
def get_data?
|
33
|
+
count >= 1 ? true : false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,305 @@
|
|
1
|
+
module Puree
|
2
|
+
|
3
|
+
module XMLExtractor
|
4
|
+
|
5
|
+
# Dataset XML extractor.
|
6
|
+
#
|
7
|
+
class Dataset < Puree::XMLExtractor::Resource
|
8
|
+
|
9
|
+
def initialize(xml:)
|
10
|
+
super
|
11
|
+
@resource_type = :dataset
|
12
|
+
end
|
13
|
+
|
14
|
+
# Open access permission
|
15
|
+
# @return [String, nil]
|
16
|
+
def access
|
17
|
+
xpath_query_for_single_value '/openAccessPermission/term/localizedString'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Combines projects and publications
|
21
|
+
# @return [Array<Puree::Model::RelatedContentHeader>]
|
22
|
+
def associated
|
23
|
+
xpath_result = xpath_query '/associatedContent/relatedContent'
|
24
|
+
data_arr = []
|
25
|
+
xpath_result.each { |i|
|
26
|
+
related = Puree::Model::RelatedContentHeader.new
|
27
|
+
related.type = i.xpath('typeClassification').text.strip
|
28
|
+
related.title = i.xpath('title').text.strip
|
29
|
+
related.uuid = i.attr('uuid').strip
|
30
|
+
data_arr << related
|
31
|
+
}
|
32
|
+
data_arr.uniq { |d| d.uuid }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Date made available
|
36
|
+
# @return [Time, nil]
|
37
|
+
def available
|
38
|
+
Puree::Util::Date.hash_to_time temporal_date('dateMadeAvailable')
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String, nil]
|
42
|
+
def description
|
43
|
+
xpath_query_for_single_value '/descriptions/classificationDefinedField/value/localizedString'
|
44
|
+
end
|
45
|
+
|
46
|
+
# Digital Object Identifier
|
47
|
+
# @return [String, nil]
|
48
|
+
def doi
|
49
|
+
xpath_query_for_single_value '/doi'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Supporting files
|
53
|
+
# @return [Array<Puree::Model::File>]
|
54
|
+
def files
|
55
|
+
xpath_result = xpath_query '/documents/document'
|
56
|
+
docs = []
|
57
|
+
xpath_result.each do |d|
|
58
|
+
doc = Puree::Model::File.new
|
59
|
+
doc.name = d.xpath('fileName').text.strip
|
60
|
+
doc.mime = d.xpath('mimeType').text.strip
|
61
|
+
doc.size = d.xpath('size').text.strip.to_i
|
62
|
+
doc.url = d.xpath('url').text.strip
|
63
|
+
# doc['createdDate'] = d.xpath('createdDate').text.strip
|
64
|
+
# doc['visibleOnPortalDate'] = d.xpath('visibleOnPortalDate').text.strip
|
65
|
+
# doc['limitedVisibility'] = d.xpath('limitedVisibility').text.strip
|
66
|
+
document_license = d.xpath('documentLicense')
|
67
|
+
if !document_license.empty?
|
68
|
+
license = Puree::Model::CopyrightLicense.new
|
69
|
+
license.name = document_license.xpath('term/localizedString').text.strip
|
70
|
+
license.url = document_license.xpath('description/localizedString').text.strip
|
71
|
+
doc.license = license if license.data?
|
72
|
+
end
|
73
|
+
docs << doc
|
74
|
+
end
|
75
|
+
docs.uniq { |d| d.url }
|
76
|
+
end
|
77
|
+
|
78
|
+
# @return [Array<String>]
|
79
|
+
def keywords
|
80
|
+
xpath_result = xpath_query '/keywordGroups/keywordGroup/keyword/userDefinedKeyword/freeKeyword'
|
81
|
+
data_arr = xpath_result.map { |i| i.text.strip }
|
82
|
+
data_arr.uniq
|
83
|
+
end
|
84
|
+
|
85
|
+
# @return [Array<Puree::Model::LegalCondition>]
|
86
|
+
def legal_conditions
|
87
|
+
xpath_result = xpath_query '/legalConditions/legalCondition'
|
88
|
+
data = []
|
89
|
+
xpath_result.each { |i|
|
90
|
+
model = Puree::Model::LegalCondition.new
|
91
|
+
model.name = i.xpath('typeClassification/term/localizedString').text.strip
|
92
|
+
model.description = i.xpath('description').text.strip
|
93
|
+
data << model
|
94
|
+
}
|
95
|
+
data.uniq { |d| d.name }
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [Array<Puree::Model::Link>]
|
99
|
+
def links
|
100
|
+
xpath_result = xpath_query '/links/link'
|
101
|
+
data = []
|
102
|
+
xpath_result.each { |i|
|
103
|
+
model = Puree::Model::Link.new
|
104
|
+
model.description = i.xpath('description').text.strip
|
105
|
+
model.url = i.xpath('url').text.strip
|
106
|
+
data << model
|
107
|
+
}
|
108
|
+
data.uniq { |d| d.url }
|
109
|
+
end
|
110
|
+
|
111
|
+
# @return [Array<Puree::Model::OrganisationHeader>]
|
112
|
+
def organisations
|
113
|
+
xpath_result = xpath_query '/organisations/organisation'
|
114
|
+
Puree::XMLExtractor::Shared.organisation_multi_header xpath_result
|
115
|
+
end
|
116
|
+
|
117
|
+
# @return [Puree::Model::OrganisationHeader, nil]
|
118
|
+
def owner
|
119
|
+
xpath_result = xpath_query '/managedBy'
|
120
|
+
Puree::XMLExtractor::Shared.organisation_header xpath_result
|
121
|
+
end
|
122
|
+
|
123
|
+
# @return [Array<Puree::Model::EndeavourPerson>]
|
124
|
+
def persons_internal
|
125
|
+
persons 'internal'
|
126
|
+
end
|
127
|
+
|
128
|
+
# @return [Array<Puree::Model::EndeavourPerson>]
|
129
|
+
def persons_external
|
130
|
+
persons 'external'
|
131
|
+
end
|
132
|
+
|
133
|
+
# @return [Array<Puree::Model::EndeavourPerson>]
|
134
|
+
def persons_other
|
135
|
+
persons 'other'
|
136
|
+
end
|
137
|
+
|
138
|
+
# Date of data production
|
139
|
+
# @return [Puree::Model::TemporalRange, nil]
|
140
|
+
def production
|
141
|
+
temporal_range 'dateOfDataProduction', 'endDateOfDataProduction'
|
142
|
+
end
|
143
|
+
|
144
|
+
# @return [Array<Puree::Model::RelatedContentHeader>]
|
145
|
+
def projects
|
146
|
+
associated_type('Research').uniq
|
147
|
+
end
|
148
|
+
|
149
|
+
# @return [Array<Puree::Model::RelatedContentHeader>]
|
150
|
+
def publications
|
151
|
+
data_arr = []
|
152
|
+
associated.each do |i|
|
153
|
+
if i.type != 'Research'
|
154
|
+
data_arr << i
|
155
|
+
end
|
156
|
+
end
|
157
|
+
data_arr
|
158
|
+
end
|
159
|
+
|
160
|
+
# @return [String, nil]
|
161
|
+
def publisher
|
162
|
+
xpath_query_for_single_value '/publisher/name'
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [Array<String>]
|
166
|
+
def spatial_places
|
167
|
+
# Data from free-form text box
|
168
|
+
xpath_result = xpath_query '/geographicalCoverage/localizedString'
|
169
|
+
data = []
|
170
|
+
xpath_result.each do |i|
|
171
|
+
data << i.text.strip
|
172
|
+
end
|
173
|
+
data.uniq
|
174
|
+
end
|
175
|
+
|
176
|
+
# Spatial coverage point
|
177
|
+
# @return [Puree::Model::SpatialPoint, nil]
|
178
|
+
def spatial_point
|
179
|
+
xpath_result = xpath_query '/geoLocation/point'
|
180
|
+
point = Puree::Model::SpatialPoint.new
|
181
|
+
if !xpath_result[0].nil?
|
182
|
+
arr = xpath_result.text.split(',')
|
183
|
+
point.latitude = arr[0].strip.to_f
|
184
|
+
point.longitude = arr[1].strip.to_f
|
185
|
+
point
|
186
|
+
end
|
187
|
+
nil
|
188
|
+
end
|
189
|
+
|
190
|
+
# def state
|
191
|
+
# # useful?
|
192
|
+
# /startedWorkflow/state
|
193
|
+
# end
|
194
|
+
|
195
|
+
# Temporal coverage
|
196
|
+
# @return [Puree::Model::TemporalRange, nil]
|
197
|
+
def temporal
|
198
|
+
temporal_range 'temporalCoverageStartDate', 'temporalCoverageEndDate'
|
199
|
+
end
|
200
|
+
|
201
|
+
# @return [String, nil]
|
202
|
+
def title
|
203
|
+
xpath_query_for_single_value '/title/localizedString'
|
204
|
+
end
|
205
|
+
|
206
|
+
private
|
207
|
+
|
208
|
+
def associated_type(type)
|
209
|
+
data_arr = []
|
210
|
+
associated.each do |i|
|
211
|
+
if i.type === type
|
212
|
+
related = Puree::Model::RelatedContentHeader.new
|
213
|
+
related.type = i.type
|
214
|
+
related.title = i.title
|
215
|
+
related.uuid = i.uuid
|
216
|
+
data_arr << related
|
217
|
+
end
|
218
|
+
end
|
219
|
+
data_arr.uniq
|
220
|
+
end
|
221
|
+
|
222
|
+
# @return [Array<Endeavour::Person>]
|
223
|
+
def persons(type)
|
224
|
+
xpath_result = xpath_query '/persons/dataSetPersonAssociation'
|
225
|
+
arr = []
|
226
|
+
xpath_result.each do |i|
|
227
|
+
uuid_internal = i.at_xpath('person/@uuid')
|
228
|
+
uuid_external = i.at_xpath('externalPerson/@uuid')
|
229
|
+
if uuid_internal
|
230
|
+
person_type = 'internal'
|
231
|
+
uuid = uuid_internal.text.strip
|
232
|
+
elsif uuid_external
|
233
|
+
person_type = 'external'
|
234
|
+
uuid = uuid_external.text.strip
|
235
|
+
else
|
236
|
+
person_type = 'other'
|
237
|
+
uuid = ''
|
238
|
+
end
|
239
|
+
if person_type === type
|
240
|
+
person = Puree::Model::EndeavourPerson.new
|
241
|
+
person.uuid = uuid
|
242
|
+
|
243
|
+
name = Puree::Model::PersonName.new
|
244
|
+
name.first = i.xpath('name/firstName').text.strip
|
245
|
+
name.last = i.xpath('name/lastName').text.strip
|
246
|
+
person.name = name
|
247
|
+
|
248
|
+
role_uri = i.xpath('personRole/uri').text.strip
|
249
|
+
person.role = roles[role_uri]
|
250
|
+
|
251
|
+
arr << person if person.data?
|
252
|
+
end
|
253
|
+
end
|
254
|
+
arr.uniq { |d| d.uuid }
|
255
|
+
end
|
256
|
+
|
257
|
+
# Temporal range
|
258
|
+
# @return [Puree::Model::TemporalRange, nil]
|
259
|
+
def temporal_range(start_path, end_path)
|
260
|
+
range_start = Puree::Util::Date.hash_to_time temporal_date(start_path)
|
261
|
+
range_end = Puree::Util::Date.hash_to_time temporal_date(end_path)
|
262
|
+
if range_start || range_end
|
263
|
+
range = Puree::Model::TemporalRange.new
|
264
|
+
range.start = range_start if range_start
|
265
|
+
range.end = range_end if range_end
|
266
|
+
return range
|
267
|
+
end
|
268
|
+
nil
|
269
|
+
end
|
270
|
+
|
271
|
+
# Temporal coverage date
|
272
|
+
# @return [Hash]
|
273
|
+
def temporal_date(date_path)
|
274
|
+
path = "/#{date_path}"
|
275
|
+
xpath_result = xpath_query path
|
276
|
+
o = {}
|
277
|
+
o['year'] = xpath_result.xpath('year').text.strip
|
278
|
+
o['month'] = xpath_result.xpath('month').text.strip
|
279
|
+
o['day'] = xpath_result.xpath('day').text.strip
|
280
|
+
Puree::Util::Date.normalise o
|
281
|
+
end
|
282
|
+
|
283
|
+
def roles
|
284
|
+
{
|
285
|
+
'/dk/atira/pure/dataset/roles/dataset/contributor' => 'Contributor',
|
286
|
+
'/dk/atira/pure/dataset/roles/dataset/creator' => 'Creator',
|
287
|
+
'/dk/atira/pure/dataset/roles/dataset/datacollector' => 'Data Collector',
|
288
|
+
'/dk/atira/pure/dataset/roles/dataset/datamanager' => 'Data Manager',
|
289
|
+
'/dk/atira/pure/dataset/roles/dataset/distributor' => 'Distributor',
|
290
|
+
'/dk/atira/pure/dataset/roles/dataset/editor' => 'Editor',
|
291
|
+
'/dk/atira/pure/dataset/roles/dataset/funder' => 'Funder',
|
292
|
+
'/dk/atira/pure/dataset/roles/dataset/owner' => 'Owner',
|
293
|
+
'/dk/atira/pure/dataset/roles/dataset/other' => 'Other',
|
294
|
+
'/dk/atira/pure/dataset/roles/dataset/producer' => 'Producer',
|
295
|
+
'/dk/atira/pure/dataset/roles/dataset/rightsholder' => 'Rights Holder',
|
296
|
+
'/dk/atira/pure/dataset/roles/dataset/sponsor' => 'Sponsor',
|
297
|
+
'/dk/atira/pure/dataset/roles/dataset/supervisor' => 'Supervisor'
|
298
|
+
}
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|