Skip to content

Commit

Permalink
Move greg-uio logic to custom uio mappers
Browse files Browse the repository at this point in the history
- Moves greg role -> affiliation mappings to custom uio mappers
- Adds legacy_stedkode (NO_SKO) to custom uio orgunit mapper

Issue: CRB-3975
  • Loading branch information
fredrikhl committed Jan 20, 2023
1 parent f4682ad commit dc426b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
20 changes: 8 additions & 12 deletions Cerebrum/modules/greg/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
Import/update utils should use a py:class:`.GregMapper` to extract relevant
Cerebrum data from a (sanitized) Greg object.
Future changes
--------------
The Greg mappers are not configurable. If diverging business logic is required
in the future, we may opt to either:
- Subclass GregMapper
- Add a mapper config, which we feed to the GregMapper on init.
"""
from __future__ import (
absolute_import,
Expand Down Expand Up @@ -286,6 +278,11 @@ class GregConsents(object):
Extract consent data from greg person data.
"""

# Map Greg consent type to internal import consent name.
#
# TODO: Do we really nedd to map this, or could this maybe just be a
# passlist of known consent types?
#
# TODO: Is this a generic consent? Or should this be moved to
# `Cerebrum.modules.no.uio.greg_import`?
type_map = {
Expand Down Expand Up @@ -353,10 +350,9 @@ class GregRoles(object):

# Greg role name -> AFFILIATION/status
type_map = {
'emeritus': 'TILKNYTTET/emeritus',
'external-consultant': 'TILKNYTTET/ekst_partner',
'external-partner': 'TILKNYTTET/ekst_partner',
'guest-researcher': 'TILKNYTTET/gjesteforsker',
# example:
#
# 'emeritus': 'TILKNYTTET/emeritus',
}

get_orgunit_ids = GregOrgunitIds()
Expand Down
27 changes: 24 additions & 3 deletions Cerebrum/modules/no/uio/greg_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,29 @@
sync_greg_consent = GroupMembershipSetter(GREG_CONSENT_GROUP)


class UioGregMapper(mapper.GregMapper):
pass
class _UioGregOrgunitIds(mapper.GregOrgunitIds):

type_map = {
('orgreg', 'orgreg_id'): 'ORGREG_OU_ID',
('sapuio', 'legacy_stedkode'): 'NO_SKO',
}


class _UioGregRoles(mapper.GregRoles):

type_map = {
'emeritus': 'TILKNYTTET/emeritus',
'external-consultant': 'TILKNYTTET/ekst_partner',
'external-partner': 'TILKNYTTET/ekst_partner',
'guest-researcher': 'TILKNYTTET/gjesteforsker',
}

get_orgunit_ids = _UioGregOrgunitIds()


class _UioGregMapper(mapper.GregMapper):

get_affiliations = _UioGregRoles()


class UioGregImporter(importer.GregImporter):
Expand All @@ -46,4 +67,4 @@ class UioGregImporter(importer.GregImporter):
'greg-publish': sync_greg_consent,
}

mapper = UioGregMapper()
mapper = _UioGregMapper()

0 comments on commit dc426b2

Please sign in to comment.