puree 1.9.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -12
  3. data/Gemfile +1 -1
  4. data/README.md +106 -75
  5. data/lib/puree/extractor/conference_paper.rb +6 -14
  6. data/lib/puree/extractor/dataset.rb +5 -41
  7. data/lib/puree/extractor/doctoral_thesis.rb +5 -6
  8. data/lib/puree/extractor/event.rb +6 -14
  9. data/lib/puree/extractor/external_organisation.rb +5 -8
  10. data/lib/puree/extractor/extractor.rb +19 -0
  11. data/lib/puree/extractor/journal.rb +5 -9
  12. data/lib/puree/extractor/journal_article.rb +6 -15
  13. data/lib/puree/extractor/masters_thesis.rb +5 -6
  14. data/lib/puree/extractor/organisational_unit.rb +25 -0
  15. data/lib/puree/extractor/paper.rb +6 -11
  16. data/lib/puree/extractor/person.rb +4 -53
  17. data/lib/puree/extractor/project.rb +5 -28
  18. data/lib/puree/extractor/publisher.rb +5 -12
  19. data/lib/puree/extractor/research_output.rb +20 -0
  20. data/lib/puree/extractor/resource.rb +22 -58
  21. data/lib/puree/extractor/thesis.rb +6 -17
  22. data/lib/puree/model/conference_paper.rb +1 -1
  23. data/lib/puree/model/dataset.rb +8 -25
  24. data/lib/puree/model/event.rb +0 -9
  25. data/lib/puree/model/external_organisation.rb +1 -1
  26. data/lib/puree/model/external_organisation_header.rb +2 -19
  27. data/lib/puree/model/identifier.rb +26 -0
  28. data/lib/puree/model/journal.rb +1 -1
  29. data/lib/puree/model/journal_article.rb +1 -4
  30. data/lib/puree/model/model.rb +43 -0
  31. data/lib/puree/model/{organisation_header.rb → organisation_header_base.rb} +2 -2
  32. data/lib/puree/model/{organisation.rb → organisational_unit.rb} +3 -6
  33. data/lib/puree/model/organisational_unit_header.rb +9 -0
  34. data/lib/puree/model/paper.rb +10 -1
  35. data/lib/puree/model/person.rb +3 -9
  36. data/lib/puree/model/project.rb +7 -14
  37. data/lib/puree/model/publication_status.rb +1 -1
  38. data/lib/puree/model/publisher.rb +3 -0
  39. data/lib/puree/model/publisher_header.rb +9 -0
  40. data/lib/puree/model/{publication.rb → research_output.rb} +18 -20
  41. data/lib/puree/model/research_output_scopus_metric.rb +26 -0
  42. data/lib/puree/model/resource.rb +19 -11
  43. data/lib/puree/model/thesis.rb +6 -3
  44. data/lib/puree/rest/activity.rb +24 -0
  45. data/lib/puree/rest/application.rb +24 -0
  46. data/lib/puree/rest/base.rb +131 -0
  47. data/lib/puree/rest/classification_scheme.rb +24 -0
  48. data/lib/puree/rest/client.rb +105 -0
  49. data/lib/puree/rest/curricula_vitae.rb +24 -0
  50. data/lib/puree/rest/dataset.rb +24 -0
  51. data/lib/puree/rest/equipment.rb +24 -0
  52. data/lib/puree/rest/event.rb +24 -0
  53. data/lib/puree/rest/external_organisation.rb +24 -0
  54. data/lib/puree/rest/external_person.rb +24 -0
  55. data/lib/puree/rest/impact.rb +24 -0
  56. data/lib/puree/rest/journal.rb +24 -0
  57. data/lib/puree/rest/mixins/active_mixin.rb +14 -0
  58. data/lib/puree/rest/mixins/activity_mixin.rb +14 -0
  59. data/lib/puree/rest/mixins/application_mixin.rb +15 -0
  60. data/lib/puree/rest/mixins/award_mixin.rb +15 -0
  61. data/lib/puree/rest/mixins/dataset_mixin.rb +15 -0
  62. data/lib/puree/rest/mixins/former_mixin.rb +14 -0
  63. data/lib/puree/rest/mixins/impact_mixin.rb +15 -0
  64. data/lib/puree/rest/mixins/person_mixin.rb +15 -0
  65. data/lib/puree/rest/mixins/press_media_mixin.rb +15 -0
  66. data/lib/puree/rest/mixins/prize_mixin.rb +15 -0
  67. data/lib/puree/rest/mixins/project_mixin.rb +15 -0
  68. data/lib/puree/rest/mixins/research_output_mixin.rb +15 -0
  69. data/lib/puree/rest/mixins/student_thesis_mixin.rb +15 -0
  70. data/lib/puree/rest/organisational_unit.rb +51 -0
  71. data/lib/puree/rest/person.rb +58 -0
  72. data/lib/puree/rest/press_media.rb +24 -0
  73. data/lib/puree/rest/prize.rb +24 -0
  74. data/lib/puree/rest/project.rb +27 -0
  75. data/lib/puree/rest/publisher.rb +31 -0
  76. data/lib/puree/rest/research_output.rb +24 -0
  77. data/lib/puree/rest/rest.rb +30 -0
  78. data/lib/puree/util/util.rb +3 -0
  79. data/lib/puree/version.rb +1 -1
  80. data/lib/puree/xml_extractor/base.rb +6 -6
  81. data/lib/puree/xml_extractor/collection.rb +112 -19
  82. data/lib/puree/xml_extractor/conference_paper.rb +9 -2
  83. data/lib/puree/xml_extractor/dataset.rb +56 -166
  84. data/lib/puree/xml_extractor/doctoral_thesis.rb +1 -1
  85. data/lib/puree/xml_extractor/event.rb +16 -19
  86. data/lib/puree/xml_extractor/external_organisation.rb +14 -5
  87. data/lib/puree/xml_extractor/journal.rb +18 -8
  88. data/lib/puree/xml_extractor/journal_article.rb +24 -11
  89. data/lib/puree/xml_extractor/masters_thesis.rb +1 -1
  90. data/lib/puree/xml_extractor/mixins/abstract_mixin.rb +17 -0
  91. data/lib/puree/xml_extractor/mixins/description_mixin.rb +17 -0
  92. data/lib/puree/xml_extractor/mixins/{external_organisations_mixin.rb → external_organisation_mixin.rb} +2 -2
  93. data/lib/puree/xml_extractor/mixins/identifier_mixin.rb +25 -0
  94. data/lib/puree/xml_extractor/mixins/keyword_mixin.rb +21 -0
  95. data/lib/puree/xml_extractor/mixins/organisational_unit_mixin.rb +18 -0
  96. data/lib/puree/xml_extractor/mixins/owner_mixin.rb +18 -0
  97. data/lib/puree/xml_extractor/mixins/peer_reviewed_mixin.rb +1 -1
  98. data/lib/puree/xml_extractor/mixins/person_mixin.rb +45 -0
  99. data/lib/puree/xml_extractor/mixins/publisher_mixin.rb +22 -0
  100. data/lib/puree/xml_extractor/mixins/{associated_mixin.rb → research_output_mixin.rb} +7 -7
  101. data/lib/puree/xml_extractor/mixins/title_mixin.rb +17 -0
  102. data/lib/puree/xml_extractor/mixins/type_mixin.rb +17 -0
  103. data/lib/puree/xml_extractor/mixins/workflow_mixin.rb +17 -0
  104. data/lib/puree/xml_extractor/organisational_unit.rb +82 -0
  105. data/lib/puree/xml_extractor/paper.rb +17 -3
  106. data/lib/puree/xml_extractor/person.rb +30 -35
  107. data/lib/puree/xml_extractor/project.rb +39 -75
  108. data/lib/puree/xml_extractor/publisher.rb +15 -6
  109. data/lib/puree/xml_extractor/research_output.rb +189 -0
  110. data/lib/puree/xml_extractor/resource.rb +28 -36
  111. data/lib/puree/xml_extractor/shared.rb +12 -9
  112. data/lib/puree/xml_extractor/thesis.rb +29 -15
  113. data/lib/puree/xml_extractor/xml_extractor.rb +43 -0
  114. data/lib/puree.rb +5 -114
  115. data/puree.gemspec +1 -1
  116. data/test/extractor/resource_test.rb +103 -0
  117. data/test/rest/base_test.rb +45 -0
  118. data/test/rest/common_test.rb +44 -0
  119. data/test/test_extractor_helper.rb +1 -0
  120. data/test/test_helper.rb +17 -0
  121. data/test/test_rest_helper.rb +82 -0
  122. data/test/test_xml_extractor_helper.rb +17 -0
  123. data/test/xml_extractor/xml_extractor_collection_test.rb +120 -0
  124. data/test/xml_extractor/xml_extractor_conference_paper_test.rb +69 -0
  125. data/test/xml_extractor/xml_extractor_dataset_test.rb +156 -0
  126. data/test/xml_extractor/xml_extractor_event_test.rb +58 -0
  127. data/test/xml_extractor/xml_extractor_external_organisation_test.rb +49 -0
  128. data/test/xml_extractor/xml_extractor_journal_article_test.rb +66 -0
  129. data/test/xml_extractor/xml_extractor_journal_test.rb +53 -0
  130. data/test/xml_extractor/xml_extractor_organisation_test.rb +80 -0
  131. data/test/xml_extractor/xml_extractor_person_test.rb +88 -0
  132. data/test/xml_extractor/xml_extractor_project_test.rb +136 -0
  133. data/test/xml_extractor/xml_extractor_publisher_test.rb +49 -0
  134. data/test/xml_extractor/xml_extractor_research_output_test.rb +214 -0
  135. data/test/xml_extractor/xml_extractor_thesis_test.rb +80 -0
  136. metadata +105 -68
  137. data/lib/puree/api/api.rb +0 -9
  138. data/lib/puree/api/authentication.rb +0 -33
  139. data/lib/puree/api/configuration.rb +0 -43
  140. data/lib/puree/api/map.rb +0 -80
  141. data/lib/puree/api/person_request.rb +0 -64
  142. data/lib/puree/api/request.rb +0 -119
  143. data/lib/puree/extractor/collection.rb +0 -131
  144. data/lib/puree/extractor/download.rb +0 -71
  145. data/lib/puree/extractor/organisation.rb +0 -34
  146. data/lib/puree/extractor/paper_base.rb +0 -28
  147. data/lib/puree/extractor/publication.rb +0 -53
  148. data/lib/puree/extractor/server.rb +0 -56
  149. data/lib/puree/model/download_header.rb +0 -21
  150. data/lib/puree/model/paper_base.rb +0 -19
  151. data/lib/puree/model/server.rb +0 -13
  152. data/lib/puree/query/funding.rb +0 -54
  153. data/lib/puree/query/person.rb +0 -121
  154. data/lib/puree/query/query.rb +0 -6
  155. data/lib/puree/xml_extractor/download.rb +0 -42
  156. data/lib/puree/xml_extractor/mixins/workflow_state_mixin.rb +0 -18
  157. data/lib/puree/xml_extractor/organisation.rb +0 -75
  158. data/lib/puree/xml_extractor/paper_base.rb +0 -17
  159. data/lib/puree/xml_extractor/publication.rb +0 -257
  160. data/lib/puree/xml_extractor/server.rb +0 -32
  161. data/spec/download_http_spec.rb +0 -31
  162. data/spec/open_api_dataset_http_spec.rb +0 -15
  163. data/spec/query/funding_http_spec.rb +0 -29
  164. data/spec/query/person_http_spec.rb +0 -52
  165. data/spec/resource/collection_all_http_spec.rb +0 -77
  166. data/spec/resource/collection_http_spec.rb +0 -65
  167. data/spec/resource/dataset_http_spec.rb +0 -112
  168. data/spec/resource/event_http_spec.rb +0 -52
  169. data/spec/resource/journal_http_spec.rb +0 -36
  170. data/spec/resource/organisation_http_spec.rb +0 -52
  171. data/spec/resource/person_http_spec.rb +0 -60
  172. data/spec/resource/project_http_spec.rb +0 -89
  173. data/spec/resource/publication_http_spec.rb +0 -126
  174. data/spec/resource/publisher_http_spec.rb +0 -26
  175. data/spec/server_http_spec.rb +0 -26
  176. data/spec/spec_helper.rb +0 -159
@@ -0,0 +1,18 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Owner mixin.
6
+ #
7
+ module OwnerMixin
8
+
9
+ # @return [Puree::Model::OrganisationalUnitHeader, nil]
10
+ def owner
11
+ xpath_result = xpath_query '/managingOrganisationalUnit'
12
+ Puree::XMLExtractor::Shared.organisation_header xpath_result
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -8,7 +8,7 @@ module Puree
8
8
 
9
9
  # @return [Boolean, nil]
10
10
  def peer_reviewed
11
- xpath_result = xpath_query_for_single_value('/peerReview/peerReviewed')
11
+ xpath_result = xpath_query_for_single_value('/peerReview')
12
12
  return true if xpath_result === 'true'
13
13
  return false if xpath_result === 'false'
14
14
  nil
@@ -0,0 +1,45 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Person mixin.
6
+ #
7
+ module PersonMixin
8
+
9
+ private
10
+
11
+ # @return [Array<Puree::Model::EndeavourPerson>]
12
+ def persons(type, xpath_query_path)
13
+ xpath_result = xpath_query xpath_query_path
14
+ arr = []
15
+ xpath_result.each do |i|
16
+ uuid_internal = i.at_xpath('person/@uuid')
17
+ uuid_external = i.at_xpath('externalPerson/@uuid')
18
+ if uuid_internal
19
+ person_type = 'internal'
20
+ uuid = uuid_internal.text.strip
21
+ elsif uuid_external
22
+ person_type = 'external'
23
+ uuid = uuid_external.text.strip
24
+ else
25
+ person_type = 'other'
26
+ uuid = ''
27
+ end
28
+ if person_type === type
29
+ person = Puree::Model::EndeavourPerson.new
30
+ person.uuid = uuid
31
+ name = Puree::Model::PersonName.new
32
+ name.first = i.xpath('name/firstName').text.strip
33
+ name.last = i.xpath('name/lastName').text.strip
34
+ person.name = name if name.data?
35
+ person.role = i.xpath('personRole').text.strip
36
+ arr << person if person.data?
37
+ end
38
+ end
39
+ arr
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Publisher extractor mixin.
6
+ #
7
+ module PublisherMixin
8
+
9
+ # @return [Puree::Model::PublisherHeader, nil]
10
+ def publisher
11
+ xpath_result = xpath_query '/publisher'
12
+ h = Puree::Model::PublisherHeader.new
13
+ h.uuid = xpath_result.xpath('@uuid').text.strip
14
+ h.name = xpath_result.xpath('name').text.strip
15
+ h.type = xpath_result.xpath('type').text.strip
16
+ h.data? ? h : nil
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -2,19 +2,19 @@ module Puree
2
2
 
3
3
  module XMLExtractor
4
4
 
5
- # Associated extractor mixin.
5
+ # Research output extractor mixin.
6
6
  #
7
- module AssociatedMixin
7
+ module ResearchOutputMixin
8
8
 
9
- # Combines projects and publications
9
+ # Related research outputs
10
10
  # @return [Array<Puree::Model::RelatedContentHeader>]
11
- def associated
12
- xpath_result = xpath_query '/associatedContent/relatedContent'
11
+ def research_outputs
12
+ xpath_result = xpath_query '/relatedResearchOutputs/relatedResearchOutput'
13
13
  data_arr = []
14
14
  xpath_result.each { |i|
15
15
  related = Puree::Model::RelatedContentHeader.new
16
- related.type = i.xpath('typeClassification').text.strip
17
- related.title = i.xpath('title').text.strip
16
+ related.type = i.xpath('type').text.strip
17
+ related.title = i.xpath('name').text.strip
18
18
  related.uuid = i.attr('uuid').strip
19
19
  data_arr << related
20
20
  }
@@ -0,0 +1,17 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Title mixin.
6
+ #
7
+ module TitleMixin
8
+
9
+ # @return [String, nil]
10
+ def title
11
+ xpath_query_for_single_value '/title'
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Type mixin.
6
+ #
7
+ module TypeMixin
8
+
9
+ # @return [String, nil]
10
+ def type
11
+ xpath_query_for_single_value '/type'
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Workflow extractor mixin.
6
+ #
7
+ module WorkflowMixin
8
+
9
+ # @return [String, nil]
10
+ def workflow
11
+ xpath_query_for_single_value '/workflow'
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,82 @@
1
+ module Puree
2
+
3
+ module XMLExtractor
4
+
5
+ # Organisational unit XML extractor.
6
+ #
7
+ class OrganisationalUnit < Puree::XMLExtractor::Resource
8
+ include Puree::XMLExtractor::TypeMixin
9
+
10
+ def initialize(xml)
11
+ super
12
+ setup_model :organisational_unit
13
+ end
14
+
15
+ # @return [Puree::Model::Address]
16
+ def address
17
+ xpath_result = xpath_query '/addresses/address'
18
+ if !xpath_result.empty?
19
+ a = Puree::Model::Address.new
20
+ street = xpath_result.xpath('street').text.strip
21
+ a.street = street unless street.empty?
22
+ building = xpath_result.xpath('building').text.strip
23
+ a.building = building unless building.empty?
24
+ postcode = xpath_result.xpath('postalCode').text.strip
25
+ a.postcode = postcode unless building.empty?
26
+ city = xpath_result.xpath('city').text.strip
27
+ a.city = city unless city.empty?
28
+ country = xpath_result.xpath('country').text.strip
29
+ a.country = country unless country.empty?
30
+ a
31
+ end
32
+ end
33
+
34
+ # @return [Array<String>]
35
+ def email_addresses
36
+ xpath_query_for_multi_value '/emails/email'
37
+ end
38
+
39
+ # @return [String, nil]
40
+ def name
41
+ xpath_query_for_single_value '/name'
42
+ end
43
+
44
+ # @return [Puree::Model::OrganisationalUnitHeader, nil]
45
+ def parent
46
+ xpath_result = xpath_query '/parents/parent'
47
+ Puree::XMLExtractor::Shared.organisation_header xpath_result
48
+ end
49
+
50
+ # @return [Array<String>]
51
+ def phone_numbers
52
+ xpath_query_for_multi_value '/phoneNumbers/phoneNumber'
53
+ end
54
+
55
+ # @return [Array<String>]
56
+ def urls
57
+ xpath_query_for_multi_value '/webAddresses/webAddress'
58
+ end
59
+
60
+ private
61
+
62
+ def xpath_root
63
+ '/organisationalUnit'
64
+ end
65
+
66
+ def combine_metadata
67
+ super
68
+ @model.address = address
69
+ @model.email_addresses = email_addresses
70
+ @model.name = name
71
+ @model.parent = parent
72
+ @model.phone_numbers = phone_numbers
73
+ @model.type = type
74
+ @model.urls = urls
75
+ @model
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -1,14 +1,28 @@
1
1
  module Puree
2
2
  module XMLExtractor
3
3
 
4
- # Paper XML extractor.
4
+ # Paper base XML extractor.
5
5
  #
6
- class Paper < Puree::XMLExtractor::PaperBase
6
+ class Paper < Puree::XMLExtractor::ResearchOutput
7
+ include Puree::XMLExtractor::PagesMixin
8
+ include Puree::XMLExtractor::PageRangeMixin
9
+ include Puree::XMLExtractor::PeerReviewedMixin
7
10
 
8
- def initialize(xml:)
11
+ def initialize(xml)
9
12
  super
13
+ setup_model :paper
10
14
  end
11
15
 
16
+ private
17
+
18
+ def combine_metadata
19
+ super
20
+ @model.pages = pages
21
+ @model.page_range = page_range
22
+ @model.peer_reviewed = peer_reviewed
23
+ @model
24
+ end
25
+
12
26
  end
13
27
  end
14
28
  end
@@ -5,47 +5,44 @@ module Puree
5
5
  # Person XML extractor.
6
6
  #
7
7
  class Person < Puree::XMLExtractor::Resource
8
+ include Puree::XMLExtractor::IdentifierMixin
9
+ include Puree::XMLExtractor::KeywordMixin
8
10
 
9
- def initialize(xml:)
11
+ def initialize(xml)
10
12
  super
11
- @resource_type = :person
13
+ setup_model :person
12
14
  end
13
15
 
14
- # @return [Array<Puree::Model::OrganisationHeader>]
16
+ # @return [Array<Puree::Model::OrganisationalUnitHeader>]
15
17
  def affiliations
16
- xpath_result = xpath_query '//organisation'
17
- Puree::XMLExtractor::Shared.organisation_multi_header xpath_result
18
+ xpath_result = xpath_query '/staffOrganisationAssociations/staffOrganisationAssociation/organisationalUnit'
19
+ Puree::XMLExtractor::Shared.organisation_multi_header xpath_result if xpath_result
18
20
  end
19
21
 
20
22
  # @return [Array<String>]
21
23
  def email_addresses
22
- xpath_query_for_multi_value '//emails/classificationDefinedStringFieldExtension/value'
23
- end
24
-
25
- # @return [String, nil]
26
- def employee_id
27
- id '/dk/atira/pure/person/personsources/employee'
28
- end
29
-
30
- # @return [String, nil]
31
- def hesa_id
32
- id '/dk/atira/pure/person/personsources/hesastaff'
24
+ xpath_query_for_multi_value '/staffOrganisationAssociations/staffOrganisationAssociation/emails/email'
33
25
  end
34
26
 
35
27
  # @return [Array<String>]
36
28
  def image_urls
37
- xpath_query_for_multi_value '/photos/file/url'
29
+ xpath_result = xpath_query '/profilePhotos/profilePhoto'
30
+ arr = []
31
+ xpath_result.each do |i|
32
+ arr << i.attr('url').strip
33
+ end
34
+ arr.uniq
38
35
  end
39
36
 
40
37
  # @return [Array<String>]
41
38
  def keywords
42
- xpath_query_for_multi_value '//keywordGroup/keyword/userDefinedKeyword/freeKeyword'
39
+ keyword_group 'userDefinedKeywordContainers'
43
40
  end
44
41
 
45
42
  # @return [Puree::Model::PersonName, nil]
46
43
  def name
47
44
  xpath_result = xpath_query '/name'
48
- if xpath_result
45
+ if !xpath_result.empty?
49
46
  first = xpath_result.xpath('firstName').text.strip
50
47
  last = xpath_result.xpath('lastName').text.strip
51
48
  model = Puree::Model::PersonName.new
@@ -60,26 +57,24 @@ module Puree
60
57
  xpath_query_for_single_value '/orcid'
61
58
  end
62
59
 
63
- # @return [String, nil]
64
- def scopus_id
65
- id '/dk/atira/pure/person/personsources/scopusauthor'
66
- end
67
-
68
60
  private
69
61
 
70
- # @return [String, nil]
71
- def id(uri)
72
- xpath_result = xpath_query '/sources/classificationDefinedStringFieldExtension'
73
- if xpath_result
74
- xpath_result.each do |i|
75
- if i.xpath('classification/uri').text.strip === uri
76
- return i.xpath('value').text.strip
77
- end
78
- end
79
- end
80
- nil
62
+ def xpath_root
63
+ '/person'
81
64
  end
82
65
 
66
+ def combine_metadata
67
+ super
68
+ @model.affiliations = affiliations
69
+ @model.email_addresses = email_addresses
70
+ @model.identifiers = identifiers
71
+ @model.image_urls = image_urls
72
+ @model.keywords = keywords
73
+ @model.name = name
74
+ @model.orcid = orcid
75
+ @model
76
+ end
77
+
83
78
  end
84
79
 
85
80
  end
@@ -5,12 +5,16 @@ module Puree
5
5
  # Project XML extractor.
6
6
  #
7
7
  class Project < Puree::XMLExtractor::Resource
8
- # include Puree::XMLExtractor::AssociatedMixin # not present in stable API
9
- include Puree::XMLExtractor::ExternalOrganisationsMixin
10
-
11
- def initialize(xml:)
8
+ include Puree::XMLExtractor::ExternalOrganisationMixin
9
+ include Puree::XMLExtractor::IdentifierMixin
10
+ include Puree::XMLExtractor::OrganisationalUnitMixin
11
+ include Puree::XMLExtractor::PersonMixin
12
+ include Puree::XMLExtractor::TitleMixin
13
+ include Puree::XMLExtractor::TypeMixin
14
+
15
+ def initialize(xml)
12
16
  super
13
- @resource_type = :project
17
+ setup_model :project
14
18
  end
15
19
 
16
20
  # @return [String, nil]
@@ -20,23 +24,10 @@ module Puree
20
24
 
21
25
  # @return [String, nil]
22
26
  def description
23
- xpath_query_for_single_value '/description/localizedString'
24
- end
25
-
26
- # @return [Boolean]
27
- def funded?
28
- xpath_result = xpath_query_for_single_value '/type'
29
- return false if xpath_result.downcase.include? 'nonfunded'
30
- true
31
- end
32
-
33
- # @return [Array<Puree::Model::OrganisationHeader>]
34
- def organisations
35
- xpath_result = xpath_query '/organisations/association/organisation'
36
- Puree::XMLExtractor::Shared.organisation_multi_header xpath_result
27
+ xpath_query_for_single_value '/descriptions/description'
37
28
  end
38
29
 
39
- # @return [Puree::Model::OrganisationHeader, nil]
30
+ # @return [Puree::Model::OrganisationalUnitHeader, nil]
40
31
  def owner
41
32
  xpath_result = xpath_query '/owner'
42
33
  Puree::XMLExtractor::Shared.organisation_header xpath_result
@@ -44,86 +35,59 @@ module Puree
44
35
 
45
36
  # @return [Array<Puree::Model::EndeavourPerson>]
46
37
  def persons_internal
47
- persons 'internal'
38
+ persons 'internal', '/participants/participant'
48
39
  end
49
40
 
50
41
  # @return [Array<Puree::Model::EndeavourPerson>]
51
42
  def persons_external
52
- persons 'external'
43
+ persons 'external', '/participants/participant'
53
44
  end
54
45
 
55
46
  # @return [Array<Puree::Model::EndeavourPerson>]
56
47
  def persons_other
57
- persons 'other'
48
+ persons 'other', '/participants/participant'
58
49
  end
59
50
 
60
51
  # @return [String, nil]
61
52
  def status
62
- xpath_query_for_single_value '/status/term/localizedString'
53
+ xpath_query_for_single_value '/status'
63
54
  end
64
55
 
65
56
  # @return [Puree::Model::TemporalRange, nil]
66
- def temporal_expected
67
- temporal_range '/expectedStartDate', '/expectedEndDate'
68
- end
69
-
70
- # @return [Puree::Model::TemporalRange, nil]
71
- def temporal_actual
72
- temporal_range '/startFinishDate/startDate', '/startFinishDate/endDate'
73
- end
74
-
75
- # @return [String, nil]
76
- def title
77
- xpath_query_for_single_value '/title/localizedString'
78
- end
79
-
80
- # @return [String, nil]
81
- def type
82
- xpath_query_for_single_value '/typeClassification/term/localizedString'
57
+ def temporal
58
+ temporal_range '/period/startDate', '/period/endDate'
83
59
  end
84
60
 
85
61
  # @return [String, nil]
86
62
  def url
87
- xpath_query_for_single_value '/projectURL'
63
+ xpath_query_for_single_value '/links/link/url'
88
64
  end
89
65
 
90
66
  private
91
67
 
92
- # @return [Array<Endeavour::Person>]
93
- def persons(type)
94
- xpath_result = xpath_query '/persons/participantAssociation'
95
- arr = []
96
- xpath_result.each do |i|
97
- uuid_internal = i.at_xpath('person/@uuid')
98
- uuid_external = i.at_xpath('externalPerson/@uuid')
99
- if uuid_internal
100
- person_type = 'internal'
101
- uuid = uuid_internal.text.strip
102
- elsif uuid_external
103
- person_type = 'external'
104
- uuid = uuid_external.text.strip
105
- else
106
- person_type = 'other'
107
- uuid = ''
108
- end
109
- if person_type === type
110
- person = Puree::Model::EndeavourPerson.new
111
- person.uuid = uuid
112
-
113
- name = Puree::Model::PersonName.new
114
- name.first = i.xpath('person/name/firstName').text.strip
115
- name.last = i.xpath('person/name/lastName').text.strip
116
- person.name = name
117
-
118
- role = i.xpath('personRole/term/localizedString').text.strip
119
- person.role = role
120
-
121
- arr << person if person.data?
122
- end
123
- end
124
- arr.uniq { |d| d.uuid }
68
+ def xpath_root
69
+ '/project'
125
70
  end
126
71
 
72
+ def combine_metadata
73
+ super
74
+ @model.acronym = acronym
75
+ @model.description = description
76
+ @model.external_organisations = external_organisations
77
+ @model.identifiers = identifiers
78
+ @model.organisational_units = organisational_units
79
+ @model.owner = owner
80
+ @model.persons_internal = persons_internal
81
+ @model.persons_external = persons_external
82
+ @model.persons_other = persons_other
83
+ @model.status = status
84
+ @model.temporal = temporal
85
+ @model.title = title
86
+ @model.type = type
87
+ @model.url = url
88
+ @model
89
+ end
90
+
127
91
  # @return [Puree::Model::TemporalRange, nil]
128
92
  def temporal_range(start_path, end_path)
129
93
  range_start = xpath_query_for_single_value start_path
@@ -5,10 +5,11 @@ module Puree
5
5
  # Publisher XML extractor.
6
6
  #
7
7
  class Publisher < Puree::XMLExtractor::Resource
8
+ include Puree::XMLExtractor::TypeMixin
8
9
 
9
- def initialize(xml:)
10
+ def initialize(xml)
10
11
  super
11
- @resource_type = :publisher
12
+ setup_model :publisher
12
13
  end
13
14
 
14
15
  # @return [String, nil]
@@ -16,10 +17,18 @@ module Puree
16
17
  xpath_query_for_single_value '/name'
17
18
  end
18
19
 
19
- # Adds no value as value is Publisher
20
- # def type
21
- # xpath_query_for_single_value '/typeClassification/term/localizedString'
22
- # end
20
+ private
21
+
22
+ def xpath_root
23
+ '/publisher'
24
+ end
25
+
26
+ def combine_metadata
27
+ super
28
+ @model.name = name
29
+ @model.type = type
30
+ @model
31
+ end
23
32
 
24
33
  end
25
34