Class: LUSI::API::Enrolment::EnrolmentBase Abstract

Inherits:
Object
  • Object
show all
Extended by:
Core::Endpoint
Defined in:
lib/lusi_api/enrolment.rb

Overview

This class is abstract.

Subclasses must define the lusi_ws_* endpoint methods and additional attributes

The abstract base class for enrolment classes

Direct Known Subclasses

Course::CourseEnrolment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Endpoint

lusi_ws_endpoint, lusi_ws_method, lusi_ws_path, lusi_ws_xml_root

Constructor Details

#initialize(xml = nil, lookup = nil, enrolment_role: nil, identity: nil, is_current_enrolment: nil, is_current_identity: nil, username: nil) ⇒ void

Initalises a new Enrolment instance

Parameters:

  • xml (Nokogiri::XML::Document, Nokogiri::XML::Node) (defaults to: nil)

    the parsed XML root of the enrolment

  • lookup (LUSI::API::Core::Lookup::LookupService, nil) (defaults to: nil)

    the lookup service for object resolution

  • enrolment_role (LUSI::API::Enrolment::EnrolmentRole, nil) (defaults to: nil)

    the default enrolment role

  • identity (String, nil) (defaults to: nil)

    the default user identity code

  • is_current_enrolment (Boolean, nil) (defaults to: nil)

    the default current enrolment flag

  • is_current_identity (Boolean, nil) (defaults to: nil)

    the default current identity flag

  • username (String, nil) (defaults to: nil)

    the default username



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lusi_api/enrolment.rb', line 65

def initialize(xml = nil, lookup = nil, enrolment_role: nil, identity: nil, is_current_enrolment: nil,
               is_current_identity: nil, username: nil)
  is_current_enrolment = is_current_enrolment.nil? || is_current_enrolment ? true : false
  is_current_identity = is_current_identity.nil? || is_current_identity ? true : false
  @enrolment_role = EnrolmentRole.new(LUSI::API::Core::XML.xml_at(xml, 'xmlns:EnrolmentRole', enrolment_role),
                                      lookup)
  @identity = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Identity', identity)
  @is_current_enrolment = LUSI::API::Core::XML.xml_boolean_at(xml, 'xmlns:IsCurrentEnrolment',
                                                              is_current_enrolment)
  @is_current_identity = LUSI::API::Core::XML.xml_boolean_at(xml, 'xmlns:IsCurrentIdentity',
                                                             is_current_identity)
  @username = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Username', username)
end

Instance Attribute Details

#enrolment_roleLUSI::API::Enrolment::EnrolmentRole?

Returns the role that members have against this enrolment.

Returns:



38
39
40
# File 'lib/lusi_api/enrolment.rb', line 38

def enrolment_role
  @enrolment_role
end

#identityLUSI::API::Enrolment::EnrolmentIdentity

Returns the identity of the subject (person) of the enrolment.

Returns:

  • (LUSI::API::Enrolment::EnrolmentIdentity)

    the identity of the subject (person) of the enrolment



42
43
44
# File 'lib/lusi_api/enrolment.rb', line 42

def identity
  @identity
end

#is_current_enrolmentBoolean?

Returns true if the enrolment is current, false otherwise.

Returns:

  • (Boolean, nil)

    true if the enrolment is current, false otherwise



46
47
48
# File 'lib/lusi_api/enrolment.rb', line 46

def is_current_enrolment
  @is_current_enrolment
end

#is_current_identityBoolean?

Returns true if the member’s identity is current, false otherwise.

Returns:

  • (Boolean, nil)

    true if the member’s identity is current, false otherwise



50
51
52
# File 'lib/lusi_api/enrolment.rb', line 50

def is_current_identity
  @is_current_identity
end

#usernameString?

Returns the username of the subject (person) of the enrolment.

Returns:

  • (String, nil)

    the username of the subject (person) of the enrolment



54
55
56
# File 'lib/lusi_api/enrolment.rb', line 54

def username
  @username
end

Class Method Details

.get_instance(api, lookup = nil, current_only: nil, **kwargs) {|obj| ... } ⇒ Object

Returns an array of instances matching the specified search criteria

Parameters:

Yields:

  • (obj)

    Passes the instance to the block



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/lusi_api/enrolment.rb', line 84

def self.get_instance(api, lookup = nil, current_only: nil, **kwargs)
  current_only = current_only.nil? || current_only ? true : false
  if current_only
    # Filter nodes which have current enrolments and user identities
    filter = Proc.new do |node|
      LUSI::API::Core::XML.xml_boolean_at(node, 'xmlns:IsCurrentEnrolment', false) &&
          LUSI::API::Core::XML.xml_boolean_at(node, 'xmlns:IsCurrentIdentity', false)
    end
  else
    filter = nil
  end
  params = self.get_instance_params(**kwargs)
  xml = api.call(self.lusi_ws_path, self.lusi_ws_endpoint, self.lusi_ws_method, **params)
  result = LUSI::API::Core::XML.xml(xml, "xmlns:#{self.lusi_ws_xml_root}", filter: filter) do |m|
    obj = self.new(m, lookup)
    yield(obj) if block_given?
    obj
  end
  # Return the array of instances
  result
end

.lusi_ws_pathObject

See Also:

  • (LUSI(LUSI::API(LUSI::API::Core(LUSI::API::Core::Endpoint(LUSI::API::Core::Endpoint#lusi_ws_path)


128
129
130
# File 'lib/lusi_api/enrolment.rb', line 128

def self.lusi_ws_path
  'UserDetails'
end

Instance Method Details

#lookup_indicesArray<Symbol>

Returns the lookup indices supported by this enrolment type

Returns:

  • (Array<Symbol>)

    the supported lookup indices



108
109
110
# File 'lib/lusi_api/enrolment.rb', line 108

def lookup_indices
  [:identity, :role, :username]
end

#lookup_key(index = nil) ⇒ Object

Returns the value to be used as a key for the specified lookup index

Returns:

  • (Object)

    the key value



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/lusi_api/enrolment.rb', line 114

def lookup_key(index = nil)
  case index
    when :identity
      self.identity
    when :role
      self.enrolment_role ? self.enrolment_role.identity : nil
    when :username
      self.username
    else
      nil
  end
end