22to the KMD Nova api."""
33
44import uuid
5- import base64
65import urllib .parse
76
87import requests
98
109from itk_dev_shared_components .kmd_nova .authentication import NovaAccess
11- from itk_dev_shared_components .kmd_nova .nova_objects import NovaCase , CaseParty , JournalNote , Caseworker , Department
12- from itk_dev_shared_components .kmd_nova .util import datetime_from_iso_string
10+ from itk_dev_shared_components .kmd_nova .nova_objects import NovaCase , CaseParty , Department
11+ from itk_dev_shared_components .kmd_nova .util import datetime_from_iso_string , extract_caseworker
1312
1413
1514def get_case (case_uuid : str , nova_access : NovaAccess ) -> NovaCase :
@@ -125,7 +124,7 @@ def _get_nova_cases(nova_access: NovaAccess, payload: dict) -> list[NovaCase]:
125124 kle_number = case_dict ['caseClassification' ]['kleNumber' ]['code' ],
126125 proceeding_facet = case_dict ['caseClassification' ]['proceedingFacet' ]['code' ],
127126 sensitivity = case_dict ["sensitivity" ]["sensitivity" ],
128- caseworker = _extract_case_worker (case_dict ),
127+ caseworker = extract_caseworker (case_dict ),
129128 security_unit = security_unit ,
130129 responsible_department = responsible_department
131130 )
@@ -189,6 +188,11 @@ def _create_payload(*, case_uuid: str = None, identification: str = None, identi
189188 "novaUserId" : True ,
190189 "fullName" : True ,
191190 "racfId" : True
191+ },
192+ "losIdentity" : {
193+ "novaUnitId" : True ,
194+ "fullName" : True ,
195+ "administrativeUnitId" : True
192196 }
193197 },
194198 "responsibleDepartment" : {
@@ -235,29 +239,6 @@ def _extract_departments(case_dict: dict) -> tuple[Department, Department]:
235239 return security_unit , responsible_department
236240
237241
238- def _extract_case_worker (case_dict : dict ) -> Caseworker | None :
239- """Extract the case worker from a HTTP request response.
240- If the case worker is in a unexpected format, None is returned.
241-
242- Args:
243- case_dict: The dictionary describing the case.
244-
245- Returns:
246- A case worker object describing the case worker if any.
247- """
248- if 'caseworker' in case_dict :
249- try :
250- return Caseworker (
251- uuid = case_dict ['caseworker' ]['kspIdentity' ]['novaUserId' ],
252- name = case_dict ['caseworker' ]['kspIdentity' ]['fullName' ],
253- ident = case_dict ['caseworker' ]['kspIdentity' ]['racfId' ]
254- )
255- except KeyError :
256- return None
257-
258- return None
259-
260-
261242def _extract_case_parties (case_dict : dict ) -> list [CaseParty ]:
262243 """Extract the case parties from a HTTP request response.
263244
@@ -281,29 +262,6 @@ def _extract_case_parties(case_dict: dict) -> list[CaseParty]:
281262 return parties
282263
283264
284- def _extract_journal_notes (case_dict : dict ) -> list :
285- """Extract the journal notes from a HTTP request response.
286-
287- Args:
288- case_dict: The dictionary describing the journal note.
289-
290- Returns:
291- A journal note object describing the journal note.
292- """
293- notes = []
294- for note_dict in case_dict ['journalNotes' ]['journalNotes' ]:
295- note = JournalNote (
296- uuid = note_dict ['uuid' ],
297- title = note_dict ['journalNoteAttributes' ]['title' ],
298- journal_date = note_dict ['journalNoteAttributes' ]['journalNoteDate' ],
299- note_format = note_dict ['journalNoteAttributes' ]['format' ],
300- note = base64 .b64decode (note_dict ['journalNoteAttributes' ]['note' ]),
301- approved = note_dict ['journalNoteAttributes' ].get ('approved' , False )
302- )
303- notes .append (note )
304- return notes
305-
306-
307265def add_case (case : NovaCase , nova_access : NovaAccess ):
308266 """Add a case to KMD Nova. The case will be created as 'Active'.
309267
@@ -371,12 +329,20 @@ def add_case(case: NovaCase, nova_access: NovaAccess):
371329 }
372330
373331 if case .caseworker :
374- payload ['caseworker' ] = {
375- "kspIdentity" : {
376- "racfId" : case .caseworker .ident ,
377- "fullName" : case .caseworker .name
332+ if case .caseworker .type == 'user' :
333+ payload ['caseworker' ] = {
334+ "kspIdentity" : {
335+ "racfId" : case .caseworker .ident ,
336+ "fullName" : case .caseworker .name
337+ }
338+ }
339+ elif case .caseworker .type == 'group' :
340+ payload ['caseworker' ] = {
341+ "losIdentity" : {
342+ "administrativeUnitId" : case .caseworker .ident ,
343+ "fullName" : case .caseworker .name
344+ }
378345 }
379- }
380346
381347 headers = {'Content-Type' : 'application/json' , 'Authorization' : f"Bearer { nova_access .get_bearer_token ()} " }
382348
0 commit comments