-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRosettaAPIWorker.cs
More file actions
1064 lines (842 loc) · 38.4 KB
/
Copy pathRosettaAPIWorker.cs
File metadata and controls
1064 lines (842 loc) · 38.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Text.Json;
using DotNetEnv;
namespace UCDRosettaAPI;
public class RosettaAPIWorker
{
public string? Base_Url {get;set;}
private string? Token_Url {get;set;}
private string? _Client_ID {get;set;}
private string? _Client_Secret {get;set;}
private string? _OAuth_Token {get;set;}
private string? _OAuth_Scopes {get;set;}
public string? Test_ID {get;set;}
public long Expires_in_Ticks {get;set;}
public RosettaAPIWorker()
{
//Load Environment Variables File
Env.Load();
//Load API Information
_Client_ID = Environment.GetEnvironmentVariable("ROSETTA_CLIENT_ID");
_Client_Secret = Environment.GetEnvironmentVariable("ROSETTA_CLIENT_SECRET");
_OAuth_Scopes = Environment.GetEnvironmentVariable("ROSETTA_SCOPES");
Base_Url = Environment.GetEnvironmentVariable("ROSETTA_BASE_URL");
Token_Url = Environment.GetEnvironmentVariable("ROSETTA_OAUTH_URL");
Test_ID = Environment.GetEnvironmentVariable("ROSETTA_TEST_ID");
//Configure Inital Ticks Value
Expires_in_Ticks = 0;
}
public enum PeopleSearchBy
{
iamid,
loginid,
email,
employeeid,
studentid,
mailid,
department
}
public enum EmployeeSearchBy
{
iamid,
departmentid,
divisionid,
subdivisionid,
subdivisionl4id,
organizationid
}
public bool CheckOAuthToken()
{
//Var for Return Value
bool bTokenStatus = true;
//Check Ticks
if(DateTime.Now.AddMinutes(1).Ticks >= Expires_in_Ticks)
{
//Initiate Http Client to Get OAuth Token
using(var client = new HttpClient())
{
//Add Required Header Values
client.DefaultRequestHeaders.Add("client_id",_Client_ID);
client.DefaultRequestHeaders.Add("client_secret",_Client_Secret);
client.DefaultRequestHeaders.Add("grant_type","CLIENT_CREDENTIALS");
client.DefaultRequestHeaders.Add("scope",_OAuth_Scopes);
//Post Sent to Token Url
HttpResponseMessage response = client.PostAsync(Token_Url, null).Result;
if(response.StatusCode == System.Net.HttpStatusCode.OK)
{
//Read Response Body
string responsebody = response.Content.ReadAsStringAsync().Result;
//Parse Response Body Json
var jnOAuthPayload = JsonDocument.Parse(responsebody);
//Get Root Json Element
var jnOAuthRoot = jnOAuthPayload.RootElement;
//Make Sure Access Token and Expires Values are Included in Payload
if(jnOAuthRoot.TryGetProperty("access_token", out JsonElement accessTokenElement) &&
jnOAuthRoot.TryGetProperty("expires_in", out JsonElement expiresInElement))
{
//Load OAuth Token
_OAuth_Token = accessTokenElement.GetString();
//Determine When It Expires
if(expiresInElement.TryGetDouble(out double dblExpiresIn))
{
Expires_in_Ticks = DateTime.Now.AddSeconds(dblExpiresIn).Ticks;
}
else
{
Expires_in_Ticks = 0;
bTokenStatus = false;
}
}
else
{
Expires_in_Ticks = 0;
bTokenStatus = false;
}//End of Access_Token and Expires_In Checks
}
else
{
Expires_in_Ticks = 0;
bTokenStatus = false;
}//End of Status Code Check
}//End of HttpClient
}//End of Ticks Check
return bTokenStatus;
}
public RosettaStudentAssociationShort ParseRosettaStudentAssocShortJson(JsonElement jeStudentAssocShrt)
{
//Initialize Student Association to Return
RosettaStudentAssociationShort rosettaStudentAssoc = new();
//Retrieve College Code
if(jeStudentAssocShrt.TryGetProperty("college_code",out JsonElement jeCollegeCode))
{
rosettaStudentAssoc.College_Code = jeCollegeCode.GetString() ?? "";
}
//Retrieve College Title
if(jeStudentAssocShrt.TryGetProperty("college_title",out JsonElement jeCollegeTitle))
{
rosettaStudentAssoc.College_Title = jeCollegeTitle.GetString() ?? "";
}
//Retrieve Major Code
if(jeStudentAssocShrt.TryGetProperty("major_code",out JsonElement jeMajorCode))
{
rosettaStudentAssoc.Major_Code = jeMajorCode.GetString() ?? "";
}
//Retrieve Major Title
if(jeStudentAssocShrt.TryGetProperty("major_title",out JsonElement jeMajorTitle))
{
rosettaStudentAssoc.Major_Title = jeMajorTitle.GetString() ?? "";
}
//Retrieve Academic Level
if(jeStudentAssocShrt.TryGetProperty("academic_level",out JsonElement jeAcademicLvl))
{
rosettaStudentAssoc.Academic_Level = jeAcademicLvl.GetString() ?? "";
}
//Retrieve Class Level
if(jeStudentAssocShrt.TryGetProperty("class_level",out JsonElement jeClassLvl))
{
rosettaStudentAssoc.Class_Level = jeClassLvl.GetString() ?? "";
}
return rosettaStudentAssoc;
}
public RosettaStudentAssociation ParseRosettaStudentAssocJson(JsonElement jeStudentAssoc)
{
//Initialize Student Association to Return
RosettaStudentAssociation rosettaStudentAssoc = new();
//Retrieve IAM ID
if(jeStudentAssoc.TryGetProperty("iam_id",out JsonElement jeIAMID))
{
rosettaStudentAssoc.IAM_ID = jeIAMID.GetString() ?? "";
}
//Retrieve Student ID
if(jeStudentAssoc.TryGetProperty("student_id",out JsonElement jeStudentID))
{
rosettaStudentAssoc.Student_ID = jeStudentID.GetString() ?? "";
}
//Retrieve PIDM
if(jeStudentAssoc.TryGetProperty("pidm",out JsonElement jePIDM))
{
rosettaStudentAssoc.PIDM = jePIDM.GetString() ?? "";
}
//Retrieve College Code
if(jeStudentAssoc.TryGetProperty("college_code",out JsonElement jeCollegeCode))
{
rosettaStudentAssoc.College_Code = jeCollegeCode.GetString() ?? "";
}
//Retrieve College Title
if(jeStudentAssoc.TryGetProperty("college_title",out JsonElement jeCollegeTitle))
{
rosettaStudentAssoc.College_Title = jeCollegeTitle.GetString() ?? "";
}
//Retrieve Major Code
if(jeStudentAssoc.TryGetProperty("major_code",out JsonElement jeMajorCode))
{
rosettaStudentAssoc.Major_Code = jeMajorCode.GetString() ?? "";
}
//Retrieve Major Title
if(jeStudentAssoc.TryGetProperty("major_title",out JsonElement jeMajorTitle))
{
rosettaStudentAssoc.Major_Title = jeMajorTitle.GetString() ?? "";
}
//Retrieve Level Affiliation Code
if(jeStudentAssoc.TryGetProperty("lvl_affiliation_code",out JsonElement jeLvlAfflCode))
{
rosettaStudentAssoc.Level_Affiliation_Code = jeLvlAfflCode.GetString() ?? "";
}
//Retrieve Class Affiliation Code
if(jeStudentAssoc.TryGetProperty("cls_affiliation_code",out JsonElement jeClsAfflCode))
{
rosettaStudentAssoc.Class_Affiliation_Code = jeClsAfflCode.GetString() ?? "";
}
//Retrieve Rank
if(jeStudentAssoc.TryGetProperty("rank",out JsonElement jeRank))
{
rosettaStudentAssoc.Rank = jeRank.GetString() ?? "";
}
return rosettaStudentAssoc;
}
public RosettaEmployeeAssociation ParseRosettaEmployeeAssocJson(JsonElement jeEmploymentAssoc)
{
//Initialize Employee Association to Return
RosettaEmployeeAssociation rosettaEmplAssoc = new();
//Retrieve IAM ID
if(jeEmploymentAssoc.TryGetProperty("iam_id",out JsonElement jeIAMID))
{
rosettaEmplAssoc.IAM_ID = jeIAMID.GetString() ?? "";
}
//Retrieve Employee Record
if(jeEmploymentAssoc.TryGetProperty("employee_record",out JsonElement jeEmployeeRecord))
{
rosettaEmplAssoc.Employee_Record = jeEmployeeRecord.GetString() ?? "";
}
//Retrieve Employee ID
if(jeEmploymentAssoc.TryGetProperty("employee_id",out JsonElement jeEmployeeID))
{
rosettaEmplAssoc.Employee_ID = jeEmployeeID.GetString() ?? "";
}
//Retrieve Position Number
if(jeEmploymentAssoc.TryGetProperty("position_number",out JsonElement jePositionNumber))
{
rosettaEmplAssoc.Position_Number = jePositionNumber.GetString() ?? "";
}
//Retrieve Position Title
if(jeEmploymentAssoc.TryGetProperty("position_title",out JsonElement jePositionTitle))
{
rosettaEmplAssoc.Position_Title = jePositionTitle.GetString() ?? "";
}
//Retrieve Relationship to Organization
if(jeEmploymentAssoc.TryGetProperty("relationship_to_organization",out JsonElement jeRelationToOrg))
{
rosettaEmplAssoc.Relationship_To_Organization = jeRelationToOrg.GetString() ?? "";
}
//Retrieve Employee Classification
if(jeEmploymentAssoc.TryGetProperty("employee_classification",out JsonElement jeEmplClassifction))
{
rosettaEmplAssoc.Employee_Classification = jeEmplClassifction.GetString() ?? "";
}
//Retrieve Employee Classification Description
if(jeEmploymentAssoc.TryGetProperty("employee_classification_description",out JsonElement jeEmplClassifctionDescp))
{
rosettaEmplAssoc.Employee_Classification_Description = jeEmplClassifctionDescp.GetString() ?? "";
}
//Retrieve Status
if(jeEmploymentAssoc.TryGetProperty("status",out JsonElement jeStatus))
{
rosettaEmplAssoc.Status = jeStatus.GetString() ?? "";
}
//Retrieve Hire Date
if(jeEmploymentAssoc.TryGetProperty("hire_date",out JsonElement jeHireDate))
{
rosettaEmplAssoc.Hire_Date = jeHireDate.GetString() ?? "";
}
//Retrieve Start Date
if(jeEmploymentAssoc.TryGetProperty("start_date",out JsonElement jeStartDate))
{
rosettaEmplAssoc.Start_Date = jeStartDate.GetString() ?? "";
}
//Retrieve FTE Percentage
if(jeEmploymentAssoc.TryGetProperty("fte_percentage",out JsonElement jeFTEPercentage))
{
rosettaEmplAssoc.FTE_Percentage = jeFTEPercentage.GetString() ?? "";
}
//Retrieve Joy Type ID
if(jeEmploymentAssoc.TryGetProperty("job_type_id",out JsonElement jeJobTypeID))
{
rosettaEmplAssoc.Job_Type_ID = jeJobTypeID.GetString() ?? "";
}
//Retrieve Job Type Description
if(jeEmploymentAssoc.TryGetProperty("job_type_description",out JsonElement jeJobTypeDesc))
{
rosettaEmplAssoc.Job_Type_Description = jeJobTypeDesc.GetString() ?? "";
}
//Retrieve Organization ID
if(jeEmploymentAssoc.TryGetProperty("organization_id",out JsonElement jeOrganizationID))
{
rosettaEmplAssoc.Organization_ID = jeOrganizationID.GetString() ?? "";
}
//Retrieve Organization Title
if(jeEmploymentAssoc.TryGetProperty("organization_title",out JsonElement jeOrgTitle))
{
rosettaEmplAssoc.Organization_Title = jeOrgTitle.GetString() ?? "";
}
//Retrieve Division ID
if(jeEmploymentAssoc.TryGetProperty("division_id",out JsonElement jeDivisionID))
{
rosettaEmplAssoc.Division_ID = jeDivisionID.GetString() ?? "";
}
//Retrieve Division Title
if(jeEmploymentAssoc.TryGetProperty("division_title",out JsonElement jeDivisionTitle))
{
rosettaEmplAssoc.Division_Title = jeDivisionTitle.GetString() ?? "";
}
//Retrieve Subdivision ID
if(jeEmploymentAssoc.TryGetProperty("subdivision_id",out JsonElement jeSubDivID))
{
rosettaEmplAssoc.Subdivision_ID = jeSubDivID.GetString() ?? "";
}
//Retrieve Subdivision Title
if(jeEmploymentAssoc.TryGetProperty("subdivision_title",out JsonElement jeSudDivTitle))
{
rosettaEmplAssoc.Subdivision_Title = jeSudDivTitle.GetString() ?? "";
}
//Retrieve Subdivision L4 ID
if(jeEmploymentAssoc.TryGetProperty("subdivision_l4_id",out JsonElement jeSubDivL4ID))
{
rosettaEmplAssoc.Subdivision_L4_ID = jeSubDivL4ID.GetString() ?? "";
}
//Retrieve Subdivision L4 Title
if(jeEmploymentAssoc.TryGetProperty("subdivision_l4_title",out JsonElement jeSubDivL4Title))
{
rosettaEmplAssoc.Subdivision_L4_Title = jeSubDivL4Title.GetString() ?? "";
}
//Retrieve Business Unit ID
if(jeEmploymentAssoc.TryGetProperty("business_unit_id",out JsonElement jeBusinessUnitID))
{
rosettaEmplAssoc.Business_Unit_ID = jeBusinessUnitID.GetString() ?? "";
}
//Retrieve Business Unit Title
if(jeEmploymentAssoc.TryGetProperty("business_unit_title",out JsonElement jeBusinessUnitTitle))
{
rosettaEmplAssoc.Business_Unit_Title = jeBusinessUnitTitle.GetString() ?? "";
}
//Retrieve Department ID
if(jeEmploymentAssoc.TryGetProperty("department_id",out JsonElement jeDepartmentID))
{
rosettaEmplAssoc.Department_ID = jeDepartmentID.GetString() ?? "";
}
//Retrieve Department Title
if(jeEmploymentAssoc.TryGetProperty("department_title",out JsonElement jeDepartmentTitle))
{
rosettaEmplAssoc.Department_Title = jeDepartmentTitle.GetString() ?? "";
}
//Retrieve Department Short Title
if(jeEmploymentAssoc.TryGetProperty("department_short_title",out JsonElement jeDepartmentShortTitle))
{
rosettaEmplAssoc.Department_Short_Title = jeDepartmentShortTitle.GetString() ?? "";
}
//Retrieve Reports to Position
if(jeEmploymentAssoc.TryGetProperty("reports_to_position",out JsonElement jeReportsToPosition))
{
rosettaEmplAssoc.Reports_To_Position = jeReportsToPosition.GetString() ?? "";
}
//Retrieve Reports To IAM ID
if(jeEmploymentAssoc.TryGetProperty("reports_to_iam_id",out JsonElement jeReportsToIAMID))
{
rosettaEmplAssoc.Reports_To_IAM_ID = jeReportsToIAMID.GetString() ?? "";
}
//Retrieve Reports to Employee ID
if(jeEmploymentAssoc.TryGetProperty("reports_to_employee_id",out JsonElement jeReportsToEmpID))
{
rosettaEmplAssoc.Reports_To_Employee_ID = jeReportsToEmpID.GetString() ?? "";
}
//Retrieve Is Health Position
if(jeEmploymentAssoc.TryGetProperty("is_health_position",out JsonElement jeIsHealthPos))
{
rosettaEmplAssoc.Is_Health_Position = jeIsHealthPos.GetString() ?? "";
}
//Retrieve Is Campus Position
if(jeEmploymentAssoc.TryGetProperty("is_campus_position",out JsonElement jeIsCampusPos))
{
rosettaEmplAssoc.Is_Campus_Position = jeIsCampusPos.GetString() ?? "";
}
return rosettaEmplAssoc;
}
public RosettaPerson ParseRosettaPersonJson(JsonElement jePeople)
{
//Initialize Person to Return
RosettaPerson rosettaPerson = new();
//Retrieve Display Name
if(jePeople.TryGetProperty("displayname",out JsonElement jeDisplayName))
{
rosettaPerson.DisplayName = jeDisplayName.GetString() ?? "";
}
//Retrieve IAM ID
if(jePeople.TryGetProperty("iam_id",out JsonElement jeIAMID))
{
rosettaPerson.IAM_ID = jeIAMID.GetString() ?? "";
}
//Retrieve IDs
if(jePeople.TryGetProperty("id",out JsonElement jeIDs))
{
//Retrieve IAM ID
if(jeIDs.TryGetProperty("iam_id",out JsonElement jeIDsIAM))
{
rosettaPerson.IAM_ID = jeIDsIAM.GetString() ?? "";
}
//Retrieve Login ID
if(jeIDs.TryGetProperty("login_id",out JsonElement jeIDsLogin))
{
rosettaPerson.Login_ID = jeIDsLogin.GetString() ?? "";
}
//Retrieve Mothra ID
if(jeIDs.TryGetProperty("mothra_id",out JsonElement jeIDsMothra))
{
rosettaPerson.Mothra_ID = jeIDsMothra.GetString() ?? "";
}
//Retrieve Employee ID
if(jeIDs.TryGetProperty("employee_id",out JsonElement jeIDsEmployee))
{
rosettaPerson.Employee_ID = jeIDsEmployee.GetString() ?? "";
}
//Retrieve Mail IDs
if(jeIDs.TryGetProperty("mail_id",out JsonElement jeIDsMail))
{
//Check for Campus Mail ID
if(jeIDsMail.TryGetProperty("campus",out JsonElement jeIDsMailCampus))
{
rosettaPerson.Mail_ID_Campus = jeIDsMailCampus.GetString() ?? "";
}
//Check for Health Mail ID
if(jeIDsMail.TryGetProperty("health",out JsonElement jeIDsMailHealth))
{
rosettaPerson.Mail_ID_Health = jeIDsMailHealth.GetString() ?? "";
}
}
}//End of IDs
//Retrieve Names
if(jePeople.TryGetProperty("name",out JsonElement jeNames))
{
//Check for Lived First Name
if(jeNames.TryGetProperty("lived_first_name",out JsonElement jeNamesLivedFirst))
{
rosettaPerson.Lived_First_Name = jeNamesLivedFirst.GetString() ?? "";
}
//Check for Lived Last Name
if(jeNames.TryGetProperty("lived_last_name",out JsonElement jeNamesLivedLast))
{
rosettaPerson.Lived_Last_Name = jeNamesLivedLast.GetString() ?? "";
}
}//End of Names Checks
//Retrieve Email Addresses
if(jePeople.TryGetProperty("email",out JsonElement jeEmailAddress))
{
//Check for Campus Email Address
if(jeEmailAddress.TryGetProperty("campus",out JsonElement jeEmailAddressCampus))
{
rosettaPerson.Email_Address_Campus = jeEmailAddressCampus.GetString() ?? "";
}
//Check for Health Email Address
if(jeEmailAddress.TryGetProperty("health",out JsonElement jeEmailAddressHealth))
{
rosettaPerson.Email_Address_Health = jeEmailAddressHealth.GetString() ?? "";
}
}
//Retrieve Provisioning Statuses
if(jePeople.TryGetProperty("provisioning_status",out JsonElement jeProvisioningStatus))
{
//Retrieve Primary Provisioning Status
if(jeProvisioningStatus.TryGetProperty("primary",out JsonElement jeProvisioningStatusPrimary))
{
rosettaPerson.Provisioning_Status_Primary = jeProvisioningStatusPrimary.GetString() ?? "";
}
//Retrieve Employee Provisioning Status
if(jeProvisioningStatus.TryGetProperty("employee",out JsonElement jeProvisioningStatusEmployee))
{
rosettaPerson.Provisioning_Status_Employee = jeProvisioningStatusEmployee.GetString() ?? "";
}
//Retrieve Faculty Provisioning Status
if(jeProvisioningStatus.TryGetProperty("faculty",out JsonElement jeProvisioningStatusFaculty))
{
rosettaPerson.Provisioning_Status_Faculty = jeProvisioningStatusFaculty.GetString() ?? "";
}
//Retrieve Student Provisioning Status
if(jeProvisioningStatus.TryGetProperty("student",out JsonElement jeProvisioningStatusStudent))
{
rosettaPerson.Provisioning_Status_Student = jeProvisioningStatusStudent.GetString() ?? "";
}
}//End of Provisioning Status
//Retrieve Affiliation
if(jePeople.TryGetProperty("affiliation",out JsonElement jeAffiliation))
{
//Loop Through Each Affiliation
foreach(JsonElement jeAffil in jeAffiliation.EnumerateArray())
{
switch(jeAffil.GetString())
{
case "employee":
rosettaPerson.Affiliation_Employee = true;
break;
case "faculty":
rosettaPerson.Affiliation_Faculty = true;
break;
case "temporary_affiliate":
rosettaPerson.Affiliation_Temporary_Affiliate = true;
break;
case "student":
rosettaPerson.Affiliation_Student = true;
break;
case "student_applicant":
rosettaPerson.Affiliation_Student_Applicant = true;
break;
case "health_affiliate":
rosettaPerson.Affiliation_Health_Affiliate = true;
break;
}//End of jeAffil Switch Statement
}//End of Affiliation Enumerate Array
}//End of Affiliations
//Retrieve Employment Status
if(jePeople.TryGetProperty("employment_status",out JsonElement jeEmploymentStatus))
{
//Loop Through Each Employment Status
foreach(JsonElement jeEmplStatus in jeEmploymentStatus.EnumerateArray())
{
switch(jeEmplStatus.GetString())
{
case "is_academic":
rosettaPerson.Employment_Is_Academic = true;
break;
case "is_academic_senate":
rosettaPerson.Employment_Is_Academic_Senate = true;
break;
case "is_academic_federation":
rosettaPerson.Employment_Is_Academic_Federation = true;
break;
case "is_faculty":
rosettaPerson.Employment_Is_Faculty = true;
break;
case "is_teaching_faculty":
rosettaPerson.Employment_Is_Teaching_Faculty = true;
break;
case "is_ladder_rank":
rosettaPerson.Employment_Is_Ladder_Rank = true;
break;
case "is_without_salary":
rosettaPerson.Employment_Is_Without_Salary = true;
break;
case "is_msp":
rosettaPerson.Employment_Is_MSP = true;
break;
case "is_ssp":
rosettaPerson.Employment_Is_SSP = true;
break;
case "is_manager":
rosettaPerson.Employment_Is_Manager = true;
break;
case "is_campus_employee":
rosettaPerson.Employment_Is_Campus_Employee = true;
break;
case "is_health_employee":
rosettaPerson.Employment_Is_Health_Employee = true;
break;
}//End of jeEmplStatus Switch Statement
}//End of Employment Status Enumerate Array
}//End of Employment Statuses
//Check for Employment Associations
if(jePeople.TryGetProperty("employee_association",out JsonElement jeEmploymentAssociations))
{
//Loop Through Each Employment Association
foreach(JsonElement jeEmplAssociation in jeEmploymentAssociations.EnumerateArray())
{
rosettaPerson.lEmployeeAssociations.Add(ParseRosettaEmployeeAssocJson(jeEmplAssociation));
}
//Update Employee Associations with IAM ID
if(string.IsNullOrEmpty(rosettaPerson.IAM_ID) == false && rosettaPerson.lEmployeeAssociations.Count > 0)
{
foreach(RosettaEmployeeAssociation rea in rosettaPerson.lEmployeeAssociations)
{
rea.IAM_ID = rosettaPerson.IAM_ID;
}
}
}//End of Employment Associations
//Check for Student Associations
if(jePeople.TryGetProperty("student_association",out JsonElement jeStudentAssociations))
{
//Loop Through Each Student Association
foreach(JsonElement jeStdtAssociation in jeStudentAssociations.EnumerateArray())
{
rosettaPerson.lStudentAssociations.Add(ParseRosettaStudentAssocShortJson(jeStdtAssociation));
}
}//End of Student Associations
return rosettaPerson;
}
public List<RosettaPerson> GetPeopleBySearchTerm(PeopleSearchBy searchBy, string searchTerm)
{
//Var for Return List
List<RosettaPerson> lRosettaPeople = new();
//Var for Search Result Limit
int nSrchRsltLimit = 100;
//Var for Search Result Offset
int nSrchRsltOffset = 0;
//Var for Retrieve More Search Results
bool bRetrMoreSrchRslts = true;
do
{
//Check OAuth Token
if(CheckOAuthToken() == true)
{
//Initiate Http Client to Get People Information
using(var client = new HttpClient())
{
//Var for Bearer Token
string bearerToken = "Bearer " + _OAuth_Token;
//Add Required Header Values
client.DefaultRequestHeaders.Add("Authorization",bearerToken);
//Var for People Url
string peopleURL = Base_Url + "people?"+ searchBy.ToString() + "=" + searchTerm + "&offset=" + nSrchRsltOffset.ToString() + "&limit=" + nSrchRsltLimit.ToString() + "&count=true";
//Get to People Endpoint
HttpResponseMessage response = client.GetAsync(peopleURL).Result;
//Check Response Status Code
if(response.StatusCode == System.Net.HttpStatusCode.OK)
{
//Pull X-Total-Count and x-response-count
if(response.Headers.TryGetValues("x-total-count", out var xtcount)
&& response.Headers.TryGetValues("x-response-count", out var xrpcount)
&& int.TryParse(xtcount.First(),out int nTotalCnt)
&& int.TryParse(xrpcount.First(),out int nRspnCnt))
{
//Check Total and Response Counts are Not Empty
if(nTotalCnt > 0 && nRspnCnt > 0)
{
//Read Response Body
string responsebody = response.Content.ReadAsStringAsync().Result;
//Parse the Response Body
using(JsonDocument jdPeople = JsonDocument.Parse(responsebody))
{
//Access the Array at the Root
JsonElement root = jdPeople.RootElement;
//Iterate Through the Array
foreach(JsonElement element in root.EnumerateArray())
{
//Add Rosetta Person to Returned People List
lRosettaPeople.Add(ParseRosettaPersonJson(element));
}//End of Root Enumerate Array
}//End Parse Response Body
//Increment Offset
nSrchRsltOffset += nSrchRsltLimit;
//Check Offset to Total Count
if(nSrchRsltOffset >= nTotalCnt)
{
bRetrMoreSrchRslts = false;
}
}
else
{
bRetrMoreSrchRslts = false;
}//End of nTotalCnt and nRspnCnt Empty Checks
}
else
{
bRetrMoreSrchRslts = false;
}//End of Return Header Counts Checks
}
else
{
bRetrMoreSrchRslts = false;
}//End of Status Code Check
}//End of HttpClient
}
else
{
bRetrMoreSrchRslts = false;
}//End of CheckOAuthToken
}
while(bRetrMoreSrchRslts == true);
//Return Person
return lRosettaPeople;
}
public List<RosettaEmployeeAssociation> GetEmployeeAssociationsBySearchTerm(EmployeeSearchBy searchBy, string searchTerm)
{
//Var for List to Return
List<RosettaEmployeeAssociation> lEmployeeAssociations = new();
//Var for Search Result Limit
int nSrchRsltLimit = 100;
//Var for Search Result Offset
int nSrchRsltOffset = 0;
//Var for Retrieve More Search Results
bool bRetrMoreSrchRslts = true;
do
{
//Check OAuth Token
if(CheckOAuthToken() == true)
{
//Initiate Http Client to Get Employee Association Information
using(var client = new HttpClient())
{
//Var for Bearer Token
string bearerToken = "Bearer " + _OAuth_Token;
//Add Required Header Values
client.DefaultRequestHeaders.Add("Authorization",bearerToken);
//Var for Employee Association Url
string employeeURL = Base_Url + "employee-association?"+ searchBy.ToString() + "=" + searchTerm + "&offset=" + nSrchRsltOffset.ToString() + "&limit=" + nSrchRsltLimit.ToString() + "&count=true";
//Get to People Endpoint
HttpResponseMessage response = client.GetAsync(employeeURL).Result;
//Check Response Status Code
if(response.StatusCode == System.Net.HttpStatusCode.OK)
{
//Pull X-Total-Count and x-response-count
if(response.Headers.TryGetValues("x-total-count", out var xtcount)
&& response.Headers.TryGetValues("x-response-count", out var xrpcount)
&& int.TryParse(xtcount.First(),out int nTotalCnt)
&& int.TryParse(xrpcount.First(),out int nRspnCnt))
{
//Check Total and Response Counts are Not Empty
if(nTotalCnt > 0 && nRspnCnt > 0)
{
//Read Response Body
string responsebody = response.Content.ReadAsStringAsync().Result;
//Parse the Response Body
using(JsonDocument jdEmplAssoc = JsonDocument.Parse(responsebody))
{
//Access the Array at the Root
JsonElement root = jdEmplAssoc.RootElement;
//Iterate Through the Array
foreach(JsonElement element in root.EnumerateArray())
{
//Add Rosetta Person to Returned People List
lEmployeeAssociations.Add(ParseRosettaEmployeeAssocJson(element));
}//End of Root Enumerate Array
}//End Parse Response Body
//Increment Offset
nSrchRsltOffset += nSrchRsltLimit;
//Check Offset to Total Count
if(nSrchRsltOffset >= nTotalCnt)
{
bRetrMoreSrchRslts = false;
}
}
else
{
bRetrMoreSrchRslts = false;
}//End of nTotalCnt and nRspnCnt Empty Checks
}
else
{
bRetrMoreSrchRslts = false;
}//End of Return Header Counts Checks
}
else
{
bRetrMoreSrchRslts = false;
}//End of Status Code Check
}//End of HttpClient
}
else
{
bRetrMoreSrchRslts = false;
}//End of CheckOAuthToken
}
while(bRetrMoreSrchRslts == true);
return lEmployeeAssociations;
}
public RosettaDepartment ParseRosettaDepartmentJson(JsonElement jeDept)
{
//Intialize Rosetta Department to Return
RosettaDepartment rosettaDept = new();
//Retrieve Department ID
if(jeDept.TryGetProperty("department_id",out JsonElement jeDepartmentID))
{
rosettaDept.Department_ID = jeDepartmentID.GetString() ?? "";
}
//Retrieve Department Title
if(jeDept.TryGetProperty("department_title",out JsonElement jeDepartmentTitle))
{
rosettaDept.Department_Title = jeDepartmentTitle.GetString() ?? "";
}
//Retrieve Department Short Title
if(jeDept.TryGetProperty("department_short_title",out JsonElement jeDepartmentShortTitle))
{
rosettaDept.Department_Short_Title = jeDepartmentShortTitle.GetString() ?? "";
}
//Retrieve Subdivision ID
if(jeDept.TryGetProperty("subdivision_id",out JsonElement jeSubdivID))
{
rosettaDept.Subdivision_ID = jeSubdivID.GetString() ?? "";
}
//Retrieve Subdivision Title
if(jeDept.TryGetProperty("subdivision_title",out JsonElement jeSubdivTitle))
{
rosettaDept.Subdivision_Title = jeSubdivTitle.GetString() ?? "";
}
//Retrieve Subdivision L4 ID
if(jeDept.TryGetProperty("subdivision_l4_id",out JsonElement jeSubdivL4ID))
{
rosettaDept.Subdivision_L4_ID = jeSubdivL4ID.GetString() ?? "";
}
//Retrieve Subdivision L4 Title
if(jeDept.TryGetProperty("subdivision_l4_title",out JsonElement jeSubdivL4Title))
{
rosettaDept.Subdivision_L4_Title = jeSubdivL4Title.GetString() ?? "";
}
//Retrieve Division ID
if(jeDept.TryGetProperty("division_id",out JsonElement jeDivisionID))
{
rosettaDept.Division_ID = jeDivisionID.GetString() ?? "";
}
//Retrieve Division Title
if(jeDept.TryGetProperty("division_title",out JsonElement jeDivisionTitle))
{
rosettaDept.Division_Title = jeDivisionTitle.GetString() ?? "";
}
//Retrieve Organization ID
if(jeDept.TryGetProperty("organization_id",out JsonElement jeOrgID))
{
rosettaDept.Organization_ID = jeOrgID.GetString() ?? "";
}
//Retrieve Organization Title
if(jeDept.TryGetProperty("organization_title",out JsonElement jeOrgTitle))
{
rosettaDept.Organization_Title = jeOrgTitle.GetString() ?? "";
}