puree 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +49 -3
- data/lib/puree/api/map.rb +4 -0
- data/lib/puree/extractor/collection.rb +1 -1
- data/lib/puree/extractor/external_organisation.rb +28 -0
- data/lib/puree/extractor/person.rb +1 -0
- data/lib/puree/extractor/resource.rb +4 -4
- data/lib/puree/model/external_organisation.rb +16 -0
- data/lib/puree/model/person.rb +3 -0
- data/lib/puree/query/funding.rb +69 -0
- data/lib/puree/query/person.rb +121 -0
- data/lib/puree/query/query.rb +6 -0
- data/lib/puree/version.rb +1 -1
- data/lib/puree/xml_extractor/external_organisation.rb +28 -0
- data/lib/puree/xml_extractor/person.rb +12 -0
- data/lib/puree.rb +6 -0
- data/spec/query/funding_http_spec.rb +29 -0
- data/spec/query/person_http_spec.rb +30 -0
- data/spec/resource/person_http_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -0
- metadata +12 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a5f9f37e95e788189e6f4acb7a066e5732e157e8
         | 
| 4 | 
            +
              data.tar.gz: b1f37ec7f78e5adef5d0443f565b5526bc2f85c9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7356834acf18066281420d8794360b747828f684fe7a709f22b01a38f4cc2c67768a66aa7f72f4b3b7c7b227014115a8eae66d22e1f77221e892b5ecfc56b33d
         | 
| 7 | 
            +
              data.tar.gz: 499e3b30bedd4b2d08c957f041fd070488a63af104f5bcc06689f3df2a0086e6b290d35c2e39370c9c43aafbe5785f43439e6eacaf6aa2aabfea2e92de803560
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -5,6 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |
| 5 5 | 
             
            ## Unreleased
         | 
| 6 6 | 
             
            - Metadata: activity?, clipping?, externalPerson?
         | 
| 7 7 |  | 
| 8 | 
            +
            ## 1.6.0 - 2017-10-24
         | 
| 9 | 
            +
            ### Added
         | 
| 10 | 
            +
            - ExternalOrganisation.
         | 
| 11 | 
            +
            - Person - employee_id.
         | 
| 12 | 
            +
            - Query - Person - publication_count, publications.
         | 
| 13 | 
            +
            - Query - Funding - project_funders, publication_funders.
         | 
| 14 | 
            +
             | 
| 8 15 | 
             
            ## 1.5.0 - 2017-10-03
         | 
| 9 16 | 
             
            ### Added
         | 
| 10 17 | 
             
            - Dataset, Publication - workflow_state.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            # Purée
         | 
| 1 | 
            +
                 # Purée
         | 
| 2 2 |  | 
| 3 3 | 
             
            Metadata extraction from the Pure Research Information System.
         | 
| 4 4 |  | 
| @@ -92,7 +92,7 @@ collection_extractor = Puree::Extractor::Collection.new config:   config, | |
| 92 92 | 
             
            Fetch a bunch of resources.
         | 
| 93 93 |  | 
| 94 94 | 
             
            ```ruby
         | 
| 95 | 
            -
             | 
| 95 | 
            +
            collection_extractor.find limit: 2
         | 
| 96 96 | 
             
            # =>
         | 
| 97 97 | 
             
            #<Puree::Model::Dataset:0xa62fd90>
         | 
| 98 98 | 
             
            #<Puree::Model::Dataset:0xa5e8c24>
         | 
| @@ -101,7 +101,53 @@ dataset_collection = collection_extractor.find limit: 2 | |
| 101 101 | 
             
            Fetch a random resource from the entire collection.
         | 
| 102 102 |  | 
| 103 103 | 
             
            ```ruby
         | 
| 104 | 
            -
             | 
| 104 | 
            +
            collection_extractor.random_resource
         | 
| 105 105 | 
             
            # =>
         | 
| 106 106 | 
             
            #<Puree::Model::Dataset:0x97998bc>
         | 
| 107 | 
            +
            ```
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            ### Query
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            Get answers to important questions.
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            #### Funding
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            Configure a funding query to retrieve data from a Pure host.
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            ```ruby
         | 
| 118 | 
            +
            funding_query = Puree::Query::Funding.new config
         | 
| 119 | 
            +
            ```
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            Who are the funders (if any) for a project?
         | 
| 122 | 
            +
             | 
| 123 | 
            +
            ```ruby
         | 
| 124 | 
            +
            funding_query.project_funders uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
         | 
| 125 | 
            +
            # =>
         | 
| 126 | 
            +
            #<Puree::Model::ExternalOrganisation:0x98986f0>
         | 
| 127 | 
            +
            ```
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            Who are the funders (if any) for a publication, via a project?
         | 
| 130 | 
            +
             | 
| 131 | 
            +
            ```ruby
         | 
| 132 | 
            +
            funding_query.publication_funders uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
         | 
| 133 | 
            +
            ```
         | 
| 134 | 
            +
             | 
| 135 | 
            +
            #### Person
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            Configure a person query to retrieve data from a Pure host.
         | 
| 138 | 
            +
             | 
| 139 | 
            +
            ```ruby
         | 
| 140 | 
            +
            person_query = Puree::Query::Person.new config
         | 
| 141 | 
            +
            ```
         | 
| 142 | 
            +
             | 
| 143 | 
            +
            Get at most ten publications published by a person during the first six months of 2017.
         | 
| 144 | 
            +
             | 
| 145 | 
            +
            ```ruby
         | 
| 146 | 
            +
            person_query.publications uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',
         | 
| 147 | 
            +
                                      limit: 10,
         | 
| 148 | 
            +
                                      published_start: '2017-01-01',
         | 
| 149 | 
            +
                                      published_end: '2017-06-30'
         | 
| 150 | 
            +
            # =>
         | 
| 151 | 
            +
            #<Puree::Model::Publication:0x9d2c004>
         | 
| 152 | 
            +
            #<Puree::Model::Publication:0xa285028>
         | 
| 107 153 | 
             
            ```
         | 
    
        data/lib/puree/api/map.rb
    CHANGED
    
    
| @@ -86,7 +86,7 @@ module Puree | |
| 86 86 |  | 
| 87 87 | 
             
                  def collect_resources
         | 
| 88 88 | 
             
                    data = []
         | 
| 89 | 
            -
                    resource_class = "Puree::Extractor::#{@resource_type | 
| 89 | 
            +
                    resource_class = "Puree::Extractor::#{Puree::Util::String.titleize(@resource_type)}"
         | 
| 90 90 |  | 
| 91 91 | 
             
                    # whitelist symbol
         | 
| 92 92 | 
             
                    if @api_map[:resource_type].has_key?(@resource_type)
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module Puree
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Extractor
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # External organisation extractor.
         | 
| 6 | 
            +
                #
         | 
| 7 | 
            +
                class ExternalOrganisation < Puree::Extractor::Resource
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  # @option (see Puree::Extractor::Resource#initialize)
         | 
| 10 | 
            +
                  def initialize(config)
         | 
| 11 | 
            +
                    super
         | 
| 12 | 
            +
                    setup :external_organisation
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  private
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def combine_metadata
         | 
| 18 | 
            +
                    super
         | 
| 19 | 
            +
                    @model.name = @extractor.name
         | 
| 20 | 
            +
                    @model.type = @extractor.type
         | 
| 21 | 
            +
                    @model
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            end
         | 
| @@ -18,6 +18,7 @@ module Puree | |
| 18 18 | 
             
                    super
         | 
| 19 19 | 
             
                    @model.affiliations = @extractor.affiliations
         | 
| 20 20 | 
             
                    @model.email_addresses = @extractor.email_addresses
         | 
| 21 | 
            +
                    @model.employee_id = @extractor.employee_id
         | 
| 21 22 | 
             
                    @model.image_urls = @extractor.image_urls
         | 
| 22 23 | 
             
                    @model.keywords = @extractor.keywords
         | 
| 23 24 | 
             
                    @model.name = @extractor.name
         | 
| @@ -48,18 +48,18 @@ module Puree | |
| 48 48 | 
             
                  def setup(resource)
         | 
| 49 49 | 
             
                    @resource_type = resource
         | 
| 50 50 | 
             
                    if @model_type
         | 
| 51 | 
            -
                      resource_class = "Puree::Model::#{Puree::Util::String.titleize(@model_type | 
| 51 | 
            +
                      resource_class = "Puree::Model::#{Puree::Util::String.titleize(@model_type)}"
         | 
| 52 52 | 
             
                    else
         | 
| 53 | 
            -
                      resource_class = "Puree::Model::#{resource | 
| 53 | 
            +
                      resource_class = "Puree::Model::#{Puree::Util::String.titleize(resource)}"
         | 
| 54 54 | 
             
                    end
         | 
| 55 55 | 
             
                    @model = Object.const_get(resource_class).new
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 |  | 
| 58 58 | 
             
                  def make_xml_extractor xml
         | 
| 59 59 | 
             
                    if @model_type
         | 
| 60 | 
            -
                      resource_class = "Puree::XMLExtractor::#{Puree::Util::String.titleize(@model_type | 
| 60 | 
            +
                      resource_class = "Puree::XMLExtractor::#{Puree::Util::String.titleize(@model_type)}"
         | 
| 61 61 | 
             
                    else
         | 
| 62 | 
            -
                      resource_class = "Puree::XMLExtractor::#{@resource_type | 
| 62 | 
            +
                      resource_class = "Puree::XMLExtractor::#{Puree::Util::String.titleize(@resource_type)}"
         | 
| 63 63 | 
             
                    end
         | 
| 64 64 | 
             
                    @extractor = Object.const_get(resource_class).new xml: xml
         | 
| 65 65 | 
             
                  end
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            module Puree
         | 
| 2 | 
            +
              module Model
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                # An external organisational unit as defined by the institution.
         | 
| 5 | 
            +
                #
         | 
| 6 | 
            +
                class ExternalOrganisation < Resource
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  # @return [String, nil]
         | 
| 9 | 
            +
                  attr_accessor :name
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # @return [String, nil]
         | 
| 12 | 
            +
                  attr_accessor :type
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
    
        data/lib/puree/model/person.rb
    CHANGED
    
    
| @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            module Puree
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Query
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # For querying information about funding.
         | 
| 6 | 
            +
                #
         | 
| 7 | 
            +
                class Funding
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def initialize(config)
         | 
| 10 | 
            +
                    @config = config
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  # Project funders
         | 
| 14 | 
            +
                  # @param uuid [String] Project UUID.
         | 
| 15 | 
            +
                  # @return [Array<Puree::Model::ExternalOrganisation>] List of funders which have funded this project.
         | 
| 16 | 
            +
                  def project_funders(uuid:)
         | 
| 17 | 
            +
                    funders = []
         | 
| 18 | 
            +
                    project_extractor = Puree::Extractor::Project.new @config
         | 
| 19 | 
            +
                    project = project_extractor.find uuid: uuid
         | 
| 20 | 
            +
                    if project
         | 
| 21 | 
            +
                      if project.funded
         | 
| 22 | 
            +
                        project.external_organisations.each do |org|
         | 
| 23 | 
            +
                          external_organisation_extractor = Puree::Extractor::ExternalOrganisation.new @config
         | 
| 24 | 
            +
                          external_organisation = external_organisation_extractor.find uuid: org.uuid
         | 
| 25 | 
            +
                          funders << external_organisation if external_organisation.type == '/dk/atira/pure/ueoexternalorganisation/ueoexternalorganisationtypes/ueoexternalorganisation/researchFundingBody'
         | 
| 26 | 
            +
                        end
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                    deduplicate_funders funders
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  # Publication funders
         | 
| 33 | 
            +
                  # @param uuid [String] Publication UUID.
         | 
| 34 | 
            +
                  # @return [Array<Puree::Model::ExternalOrganisation>] List of funders which have funded this publication via a project.
         | 
| 35 | 
            +
                  def publication_funders(uuid:)
         | 
| 36 | 
            +
                    funders = []
         | 
| 37 | 
            +
                    publication_extractor = Puree::Extractor::Publication.new @config
         | 
| 38 | 
            +
                    publication = publication_extractor.find uuid: uuid
         | 
| 39 | 
            +
                    if publication
         | 
| 40 | 
            +
                      publication.associated.each do |associated|
         | 
| 41 | 
            +
                        if associated.type == 'Research'
         | 
| 42 | 
            +
                          single_project_funders = project_funders uuid: associated.uuid
         | 
| 43 | 
            +
                          funders += single_project_funders
         | 
| 44 | 
            +
                        end
         | 
| 45 | 
            +
                      end
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
                    deduplicate_funders funders
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  private
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  def deduplicate_funders(funders)
         | 
| 53 | 
            +
                    uuids_in_list = []
         | 
| 54 | 
            +
                    funder_list = []
         | 
| 55 | 
            +
                    funders.each do |funder|
         | 
| 56 | 
            +
                      uuid = funder.uuid
         | 
| 57 | 
            +
                      unless uuids_in_list.include? uuid
         | 
| 58 | 
            +
                        funder_list << funder
         | 
| 59 | 
            +
                        uuids_in_list << uuid
         | 
| 60 | 
            +
                      end
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                    funder_list
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            end
         | 
| @@ -0,0 +1,121 @@ | |
| 1 | 
            +
            module Puree
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Query
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # For querying information about a person.
         | 
| 6 | 
            +
                #
         | 
| 7 | 
            +
                class Person
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def initialize(config)
         | 
| 10 | 
            +
                    @url = config[:url]
         | 
| 11 | 
            +
                    @headers = {}
         | 
| 12 | 
            +
                    basic_auth username: config[:username],
         | 
| 13 | 
            +
                               password: config[:password]
         | 
| 14 | 
            +
                    @config = config
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  # Count of publications available for a person.
         | 
| 18 | 
            +
                  #
         | 
| 19 | 
            +
                  # @param uuid [String] person UUID.
         | 
| 20 | 
            +
                  # @return [Fixnum]
         | 
| 21 | 
            +
                  def publication_count(uuid:)
         | 
| 22 | 
            +
                    params = {}
         | 
| 23 | 
            +
                    params['associatedPersonUuids.uuid'] = uuid
         | 
| 24 | 
            +
                    params['rendering'] = :system
         | 
| 25 | 
            +
                    params['window.size'] = 0
         | 
| 26 | 
            +
                    headers
         | 
| 27 | 
            +
                    response = @req.get(build_publication_url, params: params)
         | 
| 28 | 
            +
                    doc = make_doc response.body
         | 
| 29 | 
            +
                    extract_publication_count doc
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  # Publications for a person.
         | 
| 33 | 
            +
                  #
         | 
| 34 | 
            +
                  # @param uuid [String] person UUID.
         | 
| 35 | 
            +
                  # @param limit [Fixnum]
         | 
| 36 | 
            +
                  # @param offset [Fixnum]
         | 
| 37 | 
            +
                  # @param published_start [String] using format YYYY-MM-DD
         | 
| 38 | 
            +
                  # @param published_end [String] using format YYYY-MM-DD
         | 
| 39 | 
            +
                  # @return [Array<Puree::Model::Publication>]
         | 
| 40 | 
            +
                  def publications(uuid:, limit:, offset: 0, published_start: nil, published_end: nil)
         | 
| 41 | 
            +
                    uuids = publication_uuids(uuid: uuid,
         | 
| 42 | 
            +
                                              limit: limit,
         | 
| 43 | 
            +
                                              offset: offset,
         | 
| 44 | 
            +
                                              published_start: published_start,
         | 
| 45 | 
            +
                                              published_end: published_end)
         | 
| 46 | 
            +
                    publications = []
         | 
| 47 | 
            +
                    uuids.each do |uuid|
         | 
| 48 | 
            +
                      publication_extractor = Puree::Extractor::Publication.new @config
         | 
| 49 | 
            +
                      publication = publication_extractor.find uuid: uuid
         | 
| 50 | 
            +
                      publications << publication if publication
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
                    publications
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
             | 
| 56 | 
            +
                  private
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def publication_uuids(uuid:, limit:, offset: 0, published_start: nil, published_end: nil)
         | 
| 59 | 
            +
                    params = {}
         | 
| 60 | 
            +
                    params['associatedPersonUuids.uuid'] = uuid
         | 
| 61 | 
            +
                    params['rendering'] = :system
         | 
| 62 | 
            +
                    params['window.size'] = limit.to_s
         | 
| 63 | 
            +
                    params['window.offset'] = offset if limit > 0
         | 
| 64 | 
            +
                    params['publicationDate.fromDate'] = published_start if published_start
         | 
| 65 | 
            +
                    params['publicationDate.toDate'] = published_end if published_end
         | 
| 66 | 
            +
                    headers
         | 
| 67 | 
            +
                    response = @req.get(build_publication_url, params: params)
         | 
| 68 | 
            +
                    doc = make_doc response.body
         | 
| 69 | 
            +
                    extract_publication_uuids doc
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  def make_doc(xml)
         | 
| 73 | 
            +
                    doc = Nokogiri::XML xml
         | 
| 74 | 
            +
                    doc.remove_namespaces!
         | 
| 75 | 
            +
                    doc
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  def extract_publication_count(doc)
         | 
| 79 | 
            +
                    doc.xpath('/GetPublicationResponse/count').text.strip.to_i
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  def extract_publication_uuids(doc)
         | 
| 83 | 
            +
                    records = doc.xpath('/GetPublicationResponse/result/renderedItem')
         | 
| 84 | 
            +
                    uuids = []
         | 
| 85 | 
            +
                    records.each do |record|
         | 
| 86 | 
            +
                      uuid = extract_publication_uuid record
         | 
| 87 | 
            +
                      uuids << uuid
         | 
| 88 | 
            +
                    end
         | 
| 89 | 
            +
                    uuids
         | 
| 90 | 
            +
                  end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                  def extract_publication_uuid(doc)
         | 
| 93 | 
            +
                    doc.xpath('@renderedContentUUID').text.strip
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                  def build_publication_url
         | 
| 97 | 
            +
                    "#{@url}/publication.current"
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  # Provide credentials if necessary
         | 
| 101 | 
            +
                  #
         | 
| 102 | 
            +
                  # @param username [String]
         | 
| 103 | 
            +
                  # @param password [String]
         | 
| 104 | 
            +
                  def basic_auth(username:, password:)
         | 
| 105 | 
            +
                    auth = Base64::strict_encode64("#{username}:#{password}")
         | 
| 106 | 
            +
                    @headers['Authorization'] = 'Basic ' + auth
         | 
| 107 | 
            +
                  end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                  def headers
         | 
| 110 | 
            +
                    @headers['Accept'] = 'application/xml'
         | 
| 111 | 
            +
                    @req = HTTP.headers accept: @headers['Accept']
         | 
| 112 | 
            +
                    if @headers['Authorization']
         | 
| 113 | 
            +
                      @req = @req.auth @headers['Authorization']
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            end
         | 
    
        data/lib/puree/version.rb
    CHANGED
    
    
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module Puree
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module XMLExtractor
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # External organisation XML extractor.
         | 
| 6 | 
            +
                #
         | 
| 7 | 
            +
                class ExternalOrganisation < Puree::XMLExtractor::Resource
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def initialize(xml:)
         | 
| 10 | 
            +
                    super
         | 
| 11 | 
            +
                    @resource_type = :external_organisation
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  # @return [String, nil]
         | 
| 15 | 
            +
                  def name
         | 
| 16 | 
            +
                    xpath_query_for_single_value '/name'
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  # @return [String, nil]
         | 
| 20 | 
            +
                  def type
         | 
| 21 | 
            +
                    xpath_query_for_single_value '/typeClassification/uri'
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            end
         | 
| @@ -22,6 +22,18 @@ module Puree | |
| 22 22 | 
             
                    xpath_query_for_multi_value '//emails/classificationDefinedStringFieldExtension/value'
         | 
| 23 23 | 
             
                  end
         | 
| 24 24 |  | 
| 25 | 
            +
                  # @return [String, nil]
         | 
| 26 | 
            +
                  def employee_id
         | 
| 27 | 
            +
                    xpath_result = xpath_query '/sources/classificationDefinedStringFieldExtension'
         | 
| 28 | 
            +
                    if xpath_result
         | 
| 29 | 
            +
                      xpath_result.each do |i|
         | 
| 30 | 
            +
                        if i.xpath('classification/uri').text.strip === '/dk/atira/pure/person/personsources/employee'
         | 
| 31 | 
            +
                          return i.xpath('value').text.strip
         | 
| 32 | 
            +
                        end
         | 
| 33 | 
            +
                      end
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 25 37 | 
             
                  # @return [Array<String>]
         | 
| 26 38 | 
             
                  def image_urls
         | 
| 27 39 | 
             
                    xpath_query_for_multi_value '/photos/file/url'
         | 
    
        data/lib/puree.rb
    CHANGED
    
    | @@ -24,6 +24,7 @@ require 'puree/xml_extractor/download' | |
| 24 24 | 
             
            require 'puree/xml_extractor/event'
         | 
| 25 25 | 
             
            require 'puree/xml_extractor/journal'
         | 
| 26 26 | 
             
            require 'puree/xml_extractor/organisation'
         | 
| 27 | 
            +
            require 'puree/xml_extractor/external_organisation'
         | 
| 27 28 | 
             
            require 'puree/xml_extractor/person'
         | 
| 28 29 | 
             
            require 'puree/xml_extractor/project'
         | 
| 29 30 |  | 
| @@ -52,6 +53,7 @@ require 'puree/model/dataset' | |
| 52 53 | 
             
            require 'puree/model/download_header'
         | 
| 53 54 | 
             
            require 'puree/model/event'
         | 
| 54 55 | 
             
            require 'puree/model/event_header'
         | 
| 56 | 
            +
            require 'puree/model/external_organisation'
         | 
| 55 57 | 
             
            require 'puree/model/journal'
         | 
| 56 58 | 
             
            require 'puree/model/journal_header'
         | 
| 57 59 | 
             
            require 'puree/model/link'
         | 
| @@ -88,6 +90,7 @@ require 'puree/model/temporal_range' | |
| 88 90 | 
             
            require 'puree/extractor/resource'
         | 
| 89 91 | 
             
            require 'puree/extractor/dataset'
         | 
| 90 92 | 
             
            require 'puree/extractor/event'
         | 
| 93 | 
            +
            require 'puree/extractor/external_organisation'
         | 
| 91 94 | 
             
            require 'puree/extractor/journal'
         | 
| 92 95 | 
             
            require 'puree/extractor/organisation'
         | 
| 93 96 | 
             
            require 'puree/extractor/person'
         | 
| @@ -107,6 +110,9 @@ require 'puree/extractor/collection' | |
| 107 110 | 
             
            require 'puree/extractor/download'
         | 
| 108 111 | 
             
            require 'puree/extractor/server'
         | 
| 109 112 |  | 
| 113 | 
            +
            require 'puree/query/funding'
         | 
| 114 | 
            +
            require 'puree/query/person'
         | 
| 115 | 
            +
             | 
| 110 116 | 
             
            # Metadata extraction from the Pure Research Information System.
         | 
| 111 117 | 
             
            #
         | 
| 112 118 | 
             
            module Puree
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe 'Funding' do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              it '#new' do
         | 
| 6 | 
            +
                q = Puree::Query::Funding.new config
         | 
| 7 | 
            +
                expect(q).to be_a Puree::Query::Funding
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              describe 'project data retrieval' do
         | 
| 11 | 
            +
                before(:all) do
         | 
| 12 | 
            +
                  request :project
         | 
| 13 | 
            +
                  @project_uuid = @p.uuid
         | 
| 14 | 
            +
                  @q = Puree::Query::Funding.new config
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                it '#project_funders' do
         | 
| 18 | 
            +
                  funders = @q.project_funders uuid: @project_uuid
         | 
| 19 | 
            +
                  expect(funders).to all( be_a Puree::Model::ExternalOrganisation )
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                it '#publication_funders' do
         | 
| 23 | 
            +
                  funders = @q.publication_funders uuid: @project_uuid
         | 
| 24 | 
            +
                  expect(funders).to all( be_a Puree::Model::ExternalOrganisation )
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe 'Person' do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              it '#new' do
         | 
| 6 | 
            +
                q = Puree::Query::Person.new config
         | 
| 7 | 
            +
                expect(q).to be_a Puree::Query::Person
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              before(:all) do
         | 
| 11 | 
            +
                request :person
         | 
| 12 | 
            +
                @person_uuid = @p.uuid
         | 
| 13 | 
            +
                @q = Puree::Query::Person.new config
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              describe 'data retrieval' do
         | 
| 17 | 
            +
                it '#publication_count' do
         | 
| 18 | 
            +
                  publication_count = @q.publication_count uuid: @person_uuid
         | 
| 19 | 
            +
                  expect(publication_count).to be_a Fixnum if publication_count
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                it '#publications' do
         | 
| 23 | 
            +
                  publications = @q.publications uuid: @person_uuid,
         | 
| 24 | 
            +
                                                 limit: 3
         | 
| 25 | 
            +
                  expect(publications).to all( be_a Puree::Model::Publication )
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -24,6 +24,7 @@ require 'puree/xml_extractor/download' | |
| 24 24 | 
             
            require 'puree/xml_extractor/event'
         | 
| 25 25 | 
             
            require 'puree/xml_extractor/journal'
         | 
| 26 26 | 
             
            require 'puree/xml_extractor/organisation'
         | 
| 27 | 
            +
            require 'puree/xml_extractor/external_organisation'
         | 
| 27 28 | 
             
            require 'puree/xml_extractor/person'
         | 
| 28 29 | 
             
            require 'puree/xml_extractor/project'
         | 
| 29 30 |  | 
| @@ -52,6 +53,7 @@ require 'puree/model/dataset' | |
| 52 53 | 
             
            require 'puree/model/download_header'
         | 
| 53 54 | 
             
            require 'puree/model/event'
         | 
| 54 55 | 
             
            require 'puree/model/event_header'
         | 
| 56 | 
            +
            require 'puree/model/external_organisation'
         | 
| 55 57 | 
             
            require 'puree/model/journal'
         | 
| 56 58 | 
             
            require 'puree/model/journal_header'
         | 
| 57 59 | 
             
            require 'puree/model/link'
         | 
| @@ -88,6 +90,7 @@ require 'puree/model/temporal_range' | |
| 88 90 | 
             
            require 'puree/extractor/resource'
         | 
| 89 91 | 
             
            require 'puree/extractor/dataset'
         | 
| 90 92 | 
             
            require 'puree/extractor/event'
         | 
| 93 | 
            +
            require 'puree/extractor/external_organisation'
         | 
| 91 94 | 
             
            require 'puree/extractor/journal'
         | 
| 92 95 | 
             
            require 'puree/extractor/organisation'
         | 
| 93 96 | 
             
            require 'puree/extractor/person'
         | 
| @@ -107,6 +110,9 @@ require 'puree/extractor/collection' | |
| 107 110 | 
             
            require 'puree/extractor/download'
         | 
| 108 111 | 
             
            require 'puree/extractor/server'
         | 
| 109 112 |  | 
| 113 | 
            +
            require 'puree/query/funding'
         | 
| 114 | 
            +
            require 'puree/query/person'
         | 
| 115 | 
            +
             | 
| 110 116 | 
             
            def config
         | 
| 111 117 | 
             
              {
         | 
| 112 118 | 
             
                url:      ENV['PURE_URL'],
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: puree
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.6.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Adrian Albin-Clark
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-10- | 
| 11 | 
            +
            date: 2017-10-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: http
         | 
| @@ -77,6 +77,7 @@ files: | |
| 77 77 | 
             
            - lib/puree/extractor/doctoral_thesis.rb
         | 
| 78 78 | 
             
            - lib/puree/extractor/download.rb
         | 
| 79 79 | 
             
            - lib/puree/extractor/event.rb
         | 
| 80 | 
            +
            - lib/puree/extractor/external_organisation.rb
         | 
| 80 81 | 
             
            - lib/puree/extractor/extractor.rb
         | 
| 81 82 | 
             
            - lib/puree/extractor/journal.rb
         | 
| 82 83 | 
             
            - lib/puree/extractor/journal_article.rb
         | 
| @@ -100,6 +101,7 @@ files: | |
| 100 101 | 
             
            - lib/puree/model/endeavour_person.rb
         | 
| 101 102 | 
             
            - lib/puree/model/event.rb
         | 
| 102 103 | 
             
            - lib/puree/model/event_header.rb
         | 
| 104 | 
            +
            - lib/puree/model/external_organisation.rb
         | 
| 103 105 | 
             
            - lib/puree/model/external_organisation_header.rb
         | 
| 104 106 | 
             
            - lib/puree/model/file.rb
         | 
| 105 107 | 
             
            - lib/puree/model/helper/validation.rb
         | 
| @@ -127,6 +129,9 @@ files: | |
| 127 129 | 
             
            - lib/puree/model/structure.rb
         | 
| 128 130 | 
             
            - lib/puree/model/temporal_range.rb
         | 
| 129 131 | 
             
            - lib/puree/model/thesis.rb
         | 
| 132 | 
            +
            - lib/puree/query/funding.rb
         | 
| 133 | 
            +
            - lib/puree/query/person.rb
         | 
| 134 | 
            +
            - lib/puree/query/query.rb
         | 
| 130 135 | 
             
            - lib/puree/util/date.rb
         | 
| 131 136 | 
             
            - lib/puree/util/string.rb
         | 
| 132 137 | 
             
            - lib/puree/util/util.rb
         | 
| @@ -138,6 +143,7 @@ files: | |
| 138 143 | 
             
            - lib/puree/xml_extractor/doctoral_thesis.rb
         | 
| 139 144 | 
             
            - lib/puree/xml_extractor/download.rb
         | 
| 140 145 | 
             
            - lib/puree/xml_extractor/event.rb
         | 
| 146 | 
            +
            - lib/puree/xml_extractor/external_organisation.rb
         | 
| 141 147 | 
             
            - lib/puree/xml_extractor/journal.rb
         | 
| 142 148 | 
             
            - lib/puree/xml_extractor/journal_article.rb
         | 
| 143 149 | 
             
            - lib/puree/xml_extractor/masters_thesis.rb
         | 
| @@ -164,6 +170,8 @@ files: | |
| 164 170 | 
             
            - puree.gemspec
         | 
| 165 171 | 
             
            - spec/download_http_spec.rb
         | 
| 166 172 | 
             
            - spec/open_api_dataset_http_spec.rb
         | 
| 173 | 
            +
            - spec/query/funding_http_spec.rb
         | 
| 174 | 
            +
            - spec/query/person_http_spec.rb
         | 
| 167 175 | 
             
            - spec/resource/collection_all_http_spec.rb
         | 
| 168 176 | 
             
            - spec/resource/collection_http_spec.rb
         | 
| 169 177 | 
             
            - spec/resource/dataset_http_spec.rb
         | 
| @@ -203,6 +211,8 @@ summary: Metadata extraction from the Pure Research Information System. | |
| 203 211 | 
             
            test_files:
         | 
| 204 212 | 
             
            - spec/download_http_spec.rb
         | 
| 205 213 | 
             
            - spec/open_api_dataset_http_spec.rb
         | 
| 214 | 
            +
            - spec/query/funding_http_spec.rb
         | 
| 215 | 
            +
            - spec/query/person_http_spec.rb
         | 
| 206 216 | 
             
            - spec/resource/collection_all_http_spec.rb
         | 
| 207 217 | 
             
            - spec/resource/collection_http_spec.rb
         | 
| 208 218 | 
             
            - spec/resource/dataset_http_spec.rb
         |