Class: Puree::Query::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/openaccess/apc.rb

Overview

Add the creation and modification dates to the selection criteria for publications

Constant Summary collapse

OPTS =

Maps keyword arguments to Pure query parameters The query parameter is either a String (the name of the parameter) or a Proc which accepts the keyword argument name, value and query parameter hash and modifies the query hash as required.

{
  created_end: 'createdDate.toDate',
  created_start: 'createdDate.fromDate',
  modified_end: 'modifiedDate.toDate',
  modified_start: 'modifiedDate.fromDate',
  order_by: proc do |_opt, values, query|
    values = [values] unless values.is_a?(Array)
    values.each_index do |i|
      value = values[i]
      if '+-'.include?(value[0])
        descending = value[0] == '-' ? 'true' : 'false'
        value = value[1..-1]
      else
        descending = 'false'
      end
      param = format('orderBy.property[%d]', i)
      query[param] = value
      param = format('orderBy.property[%d].descending', i)
      query[param] = descending
    end
  end,
  published_end: 'publicationDate.toDate',
  published_start: 'publicationDate.fromDate',
  workflow_states: proc do |_opt, values, query|
    values = [values] unless value.is_a?(Array)
    values.each_index do |i|
      param = format('workflowStates.workflowState[%d].workflowName', i)
      query[param] = 'publication'
      param = format('workflowStates.workflowState[%d]', i)
      query[param] = values[i].to_s
    end
  end
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.query_params(params, **opts) ⇒ void

This method returns an undefined value.

Adds whitelisted keyword arguments to the supplied query parameter hash

Parameters:

  • params (Hash)

    the query parameters hash



101
102
103
104
105
106
107
108
109
110
# File 'lib/openaccess/apc.rb', line 101

def self.query_params(params, **opts)
  OPTS.each do |opt, param|
    next unless opts[opt]
    if param.is_a?(Proc)
      param.call(opt, opts[opt], params)
    else
      params[param] = opts[opt]
    end
  end
end

Instance Method Details

#publication_uuids_extended(uuid:, limit:, **opts) ⇒ Array<String>

Returns an array of publication UUIDs for the given person’s UUID

Parameters:

  • uuid (String)

    the person UUID

  • limit (Integer)

    the number of results to return

  • opts (Hash)

    the options hash

Returns:

  • (Array<String>)

    the array of publication UUIDs



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/openaccess/apc.rb', line 85

def publication_uuids_extended(uuid:, limit:, **opts)
  params = {
    'associatedPersonUuids.uuid' => uuid,
    'rendering' => :system,
    'window.size' => limit.to_s,
    'window.offset' => (opts[:offset] || 0).to_s
  }
  self.class.query_params(params, **opts)
  headers
  response = @req.get(build_publication_url, params: params)
  extract_publication_uuids(make_doc(response.body))
end

#publications_extended(uuid:, limit:, **opts) ⇒ Array<Puree::Model::Publication] the array of publications

Returns an array of publications for the given person’s UUID

Parameters:

  • uuid (String)

    the person UUID

  • limit (Integer)

    the number of results to return

  • opts (Hash)

    the options hash

Options Hash (**opts):

  • :uuid (String)

    the person UUID owning the publications

  • :limit (Numeric)

    the maximum number of results to return

  • :offset (Numeric)

    the start of the result set

  • :created_start (String)

    the creation start date

  • :created_end (String)

    the creation end date

  • :modified_start (String)

    the modification start date

  • :modified_end (String)

    the modification end date

  • :order_by (Array<String>)

    the list of fields to sort the result set. Each field can be prefixed by ‘+’ (ascending sort) or ‘-’ (descending sort); the default is ascending.

  • :published_start (String)

    the publication start date

  • :published_end (String)

    the publication end date

  • :workflow_states (Array<String>)

    the valid workflow states (:approved|:entryInProgress|:forApproval|:forRevalidation)

Returns:

  • (Array<Puree::Model::Publication] the array of publications)

    Array<Puree::Model::Publication] the array of publications



71
72
73
74
75
76
77
78
79
80
# File 'lib/openaccess/apc.rb', line 71

def publications_extended(uuid:, limit:, **opts)
  uuids = publication_uuids_extended(uuid: uuid, limit: limit, **opts)
  publications = []
  uuids.each do |u|
    publication_extractor = Puree::Extractor::Publication.new(@config)
    publication = publication_extractor.find uuid: u
    publications << publication if publication
  end
  publications
end