-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor usage of users endpoint #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55fe1ce
f95973c
21c4d0d
f8a51f2
2004aa1
4db2439
8fe8997
5ae1ed9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Change Log | ||
|
|
||
| All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). | ||
|
|
||
| ## [1.1.0] - 12-02-2025 | ||
|
|
||
| #### Changed | ||
|
|
||
| - persons.ps1: Changed API endpoint from: /humanresources to: /users for faster processing of data. | ||
|
|
||
| ## [1.0.0] - 26-08-2024 | ||
|
|
||
| This is the first official release of _HelloID-Conn-Prov-Source-Inplanning_. | ||
|
|
||
| ### Added | ||
|
|
||
| ### Changed | ||
|
|
||
| ### Deprecated | ||
|
|
||
| ### Removed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| ################################################## | ||
| # HelloID-Conn-Prov-Source-Inplanning-Persons | ||
| # | ||
| # Version: 1.0.0 | ||
| # Version: 1.1.0 | ||
| ################################################## | ||
| # Initialize default value's | ||
| $config = $configuration | ConvertFrom-Json | ||
|
|
||
| #region functions | ||
| function Resolve-InplanningError { | ||
| [CmdletBinding()] | ||
| param ( | ||
|
|
@@ -32,7 +33,7 @@ function Resolve-InplanningError { | |
| } | ||
| } | ||
|
|
||
| try { | ||
| function Retrieve-AccessToken { | ||
| $pair = "$($config.Username):$($config.Password)" | ||
| $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair) | ||
| $base64 = [System.Convert]::ToBase64String($bytes) | ||
|
|
@@ -49,48 +50,86 @@ try { | |
| Body = 'grant_type=client_credentials' | ||
| } | ||
|
|
||
| $accessToken = (Invoke-RestMethod @splatGetToken).access_token | ||
| $result = (Invoke-RestMethod @splatGetToken) | ||
| $script:expirationTimeAccessToken = (Get-Date).AddSeconds($result.expires_in) | ||
|
|
||
| return $result.access_token | ||
| } | ||
|
|
||
| function Confirm-AccessTokenIsValid { | ||
| if ($null -ne $Script:expirationTimeAccessToken) { | ||
| if ((Get-Date) -le $Script:expirationTimeAccessToken) { | ||
| return $true | ||
| } | ||
| } | ||
| return $false | ||
| } | ||
| #endregion functions | ||
|
|
||
| try { | ||
| $accessToken = Retrieve-AccessToken | ||
| $headers = @{ | ||
| Authorization = "Bearer $($accessToken)" | ||
| Accept = 'application/json; charset=utf-8' | ||
| } | ||
|
|
||
| $splatGetUsers = @{ | ||
| Uri = "$($config.BaseUrl)/humanresources" | ||
| Uri = "$($config.BaseUrl)/users?limit=0" | ||
| Headers = $headers | ||
| Method = 'GET' | ||
| } | ||
|
|
||
| $splatGetUsers = @{ | ||
| Uri = "$($config.BaseUrl)/users?limit=0" | ||
| Headers = $headers | ||
| Method = 'GET' | ||
| } | ||
|
|
||
| $personsWebRequest = Invoke-WebRequest @splatGetUsers | ||
| $personsCorrected = [Text.Encoding]::UTF8.GetString([Text.Encoding]::UTF8.GetBytes($personsWebRequest.content)) | ||
| $persons = $personsCorrected | ConvertFrom-Json | ||
|
|
||
| Write-Information "Retrieved $($persons.count) persons from the source system." | ||
| $personObjects = $personsCorrected | ConvertFrom-Json | ||
| $persons = $personObjects | Where-Object active -eq "True" | ||
| $persons = $persons | Sort-Object resource -Unique | ||
|
|
||
| $today = Get-Date | ||
| $startDate = $today.AddDays( - $($config.HistoricalDays)).ToString('yyyy-MM-dd') | ||
| $endDate = $today.AddDays($($config.FutureDays)).ToString('yyyy-MM-dd') | ||
|
|
||
| foreach ($person in $persons) { | ||
| try { | ||
| If(($person.resource.Length -gt 0) -Or ($null -ne $person.resource)){ | ||
|
|
||
| # Create an empty list that will hold all shifts (contracts) | ||
| $contracts = [System.Collections.Generic.List[object]]::new() | ||
|
|
||
| # Check if token is still valid | ||
| if(-not (Confirm-AccessTokenIsValid)){ | ||
| $accessToken = Retrieve-AccessToken | ||
|
|
||
| $headers = @{ | ||
| Authorization = "Bearer $($accessToken)" | ||
| Accept = 'application/json; charset=utf-8' | ||
| } | ||
| } | ||
|
|
||
| $splatGetUsersShifts = @{ | ||
| Uri = "$($config.BaseUrl)/roster/resourceRoster?resource=$($person.uname)&startDate=$($startDate)&endDate=$($endDate)" | ||
| Uri = "$($config.BaseUrl)/roster/resourceRoster?resource=$($person.resource)&startDate=$($startDate)&endDate=$($endDate)" | ||
| Headers = $headers | ||
| Method = 'GET' | ||
| } | ||
|
|
||
| $personShifts = Invoke-RestMethod @splatGetUsersShifts | ||
|
|
||
| If($personshifts.count -gt 0){ | ||
| $counter = 0 | ||
| foreach ($day in $personShifts.days) { | ||
|
|
||
| # Removes days when person has vacation | ||
| if ((-not($day.parts.count -eq 0)) -and ($null -eq $day.absence)) { | ||
|
|
||
| $rosterDate = $day.rosterDate | ||
| foreach ($part in $day.parts) { | ||
| $counter = ($counter + 1) | ||
| # Define the pattern for hh:mm-hh:mm | ||
| $pattern = '^\d{2}:\d{2}-\d{2}:\d{2}' | ||
| $time = [regex]::Match($part.shift.uname, $pattern) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Als $time.value leeg is (regex matcht niet), dan staat in $time:"System.Text.RegularExpressions.Match" . |
||
|
|
@@ -104,12 +143,22 @@ try { | |
| $endTime = '00:00' | ||
| } | ||
|
|
||
| if($part.prop){ | ||
| $functioncode = $part.prop.uname | ||
| $function = $part.prop.name | ||
| } else { | ||
| $functioncode = "" | ||
| $function = "" | ||
| } | ||
|
|
||
| $ShiftContract = @{ | ||
| externalId = "$($person.uname)$($rosterDate)$($time)$($part.group.externalId)" | ||
| externalId = "$($person.resource)$($rosterDate)$($time)$($counter)$($part.group.externalId)" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is het niet beter om een scheidingsteken tussen de verschillende waarden te plaatsen?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ik heb het connectorteam gevraagd om eens te kijken of ze een betere manier kunnen bedenken om de contract id te maken (zonder counter)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Als je de volgorde van $day.parts verandert (bijvoorbeeld na sortering of filtering), dan verandert ook de waarde van $counter, wat leidt tot een andere externalId voor exact dezelfde shift en daarbij is een counter is betekenisloos bij het terugzoeken van een entry. Je weet niet welke shift met counter 3 bedoeld werd. |
||
| labourHist = $part.labourHist | ||
| labourHistGroup = $part.labourHistGroup | ||
| shift = $part.shift | ||
| group = $part.group | ||
| functioncode = $functioncode | ||
| functionname = $function | ||
| # Add the same fields as for shift. Otherwise, the HelloID mapping will fail | ||
| # The value of both the 'startAt' and 'endAt' cannot be null. If empty, HelloID is unable | ||
| # to determine the start/end date, resulting in the contract marked as 'active'. | ||
|
|
@@ -124,17 +173,16 @@ try { | |
|
|
||
| if ($contracts.Count -gt 0) { | ||
| $personObj = [PSCustomObject]@{ | ||
| ExternalId = $person.uname | ||
| ExternalId = $person.resource | ||
| DisplayName = "$($person.firstName) $($person.lastName)".Trim(' ') | ||
| FirstName = $person.firstName | ||
| LastName = $person.lastName | ||
| Email = $person.email | ||
| PhoneNumber = $person.phone | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Phone number is removed. Is this by accident? |
||
| Contracts = $contracts | ||
| } | ||
| Write-Output $personObj | ConvertTo-Json -Depth 20 | ||
| } | ||
| } catch { | ||
| }} | ||
| }} catch { | ||
| $ex = $PSItem | ||
| if ($($ex.Exception.GetType().FullName -eq 'Microsoft.PowerShell.Commands.HttpResponseException')) { | ||
| $errorObj = Resolve-InplanningError -ErrorObject $ex | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.