Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
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
74 changes: 61 additions & 13 deletions persons.ps1
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 (
Expand All @@ -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)
Expand All @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Gaat dit werken met afgelopen en toekomstige regels?
  2. Is het nodig dat dit gaat werken?
  3. Is dit gedocumenteerd in de readme?

$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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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" .

Expand All @@ -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)"
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The 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'.
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# HelloID-Conn-Prov-Source-Inplanning

[![Workflow Status](https://github.com/Tools4everBV/HelloID-Conn-Prov-Source-Inplanning/actions/workflows/createRelease.yaml/badge.svg)](https://github.com/Tools4everBV/HelloID-Conn-Prov-Source-Inplanning/actions/workflows/createRelease.yaml)
![Release](https://img.shields.io/github/v/release/Tools4everBV/HelloID-Conn-Prov-Source-Inplanning?label=Release)


| :information_source: Information |
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -34,7 +37,7 @@ Currently the following endpoints are being used..
| Endpoint |
| ---------------------------- |
| api/token |
| api/humanresources |
| api/users |
| api/roster/resourceRoster |


Expand Down