Verified Commit 03572c0b authored by dockx thibault's avatar dockx thibault
Browse files

:sparkles: Feat(Orchestrator) - logic of end date

Adds better logic of endate but requires refactoring.
2 merge requests!72Releasing Fusiondirectory Orchestrator 1.1,!66Resolve "[Orchestrator] - lifeCycle prolongation adds time from date of process and not from resource end date"
Pipeline #30587 passed with stages
in 1 minute and 11 seconds
Showing with 44 additions and 17 deletions
+44 -17
...@@ -181,6 +181,9 @@ class LifeCycle implements EndpointInterface ...@@ -181,6 +181,9 @@ class LifeCycle implements EndpointInterface
*/ */
protected function updateLifeCycle (array $lifeCycleBehavior, string $userDN, array $currentUserLifeCycle) protected function updateLifeCycle (array $lifeCycleBehavior, string $userDN, array $currentUserLifeCycle)
{ {
// Will contain the supann resource to be updated
$matchedResource = '';
// Only keep the supann state from the received array and removing the count key // Only keep the supann state from the received array and removing the count key
$userStateHistory = $currentUserLifeCycle[0]['supannressourceetatdate']; $userStateHistory = $currentUserLifeCycle[0]['supannressourceetatdate'];
$this->gateway->unsetCountKeys($userStateHistory); $this->gateway->unsetCountKeys($userStateHistory);
...@@ -194,26 +197,38 @@ class LifeCycle implements EndpointInterface ...@@ -194,26 +197,38 @@ class LifeCycle implements EndpointInterface
$newEntry['SubState'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostsubstate'][0] ?? ''; //SubState is optional $newEntry['SubState'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostsubstate'][0] ?? ''; //SubState is optional
$newEntry['EndDate'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostenddate'][0] ?? 0; //EndDate is optional $newEntry['EndDate'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostenddate'][0] ?? 0; //EndDate is optional
// Require the date of today to update the start of the new resources (If change of status).
$currentDate = new DateTime();
// Date of today + numbers of days to add for end date.
$newEndDate = new DateTime();
$newEndDate->modify("+" . $newEntry['EndDate'] . " days");
// Prepare the ldap entry to be modified // Prepare the ldap entry to be modified
$newEntry = "{" . $newEntry['Resource'] . "}" . $newEntry['State'] . ":" . $newEntry['SubState'] . ":" $newResource = "{" . $newEntry['Resource'] . "}" . $newEntry['State'] . ":" . $newEntry['SubState'];
. $currentDate->format('Ymd') . ":" . $newEndDate->format('Ymd');
// Used to compare if the resource exists in history // Used to compare if the resource exists in history
$newResource = $this->returnSupannResourceBetweenBrackets($newEntry); $newResourceName = $this->returnSupannResourceBetweenBrackets($newResource);
// Iterate through the supann state and get a match
foreach ($userStateHistory as $value) {
// Extract resource in curly braces (brackets) from the current supannRessourceEtatDate
$currentResource = $this->returnSupannResourceBetweenBrackets($value);
// Iterate through the supann state and update the array of new entry while keeping history untouched // Get the resource matched
if ($currentResource === $newResourceName) {
$matchedResource = $value;
break;
}
}
// Fetch the end date of the matched resource.
$currentEndDate = $this->extractCurrentEndDate($matchedResource);
// Create a DateTime object from the string
$currentEndDateObject = DateTime::createFromFormat("Ymd", $currentEndDate);
$currentEndDateObject->modify("+" . $newEntry['EndDate'] . " days");
$finalRessourceEtatDate = $newResource . ':' . $currentEndDate . ':' . $currentEndDateObject->format('Ymd');
// Iterate again through the supann state and get a match
foreach ($userStateHistory as $userState => $value) { foreach ($userStateHistory as $userState => $value) {
// Extract resource in curly braces (brackets) from the current supannRessourceEtatDate // Extract resource in curly braces (brackets) from the current supannRessourceEtatDate
$currentResource = $this->returnSupannResourceBetweenBrackets($value); $currentResource = $this->returnSupannResourceBetweenBrackets($value);
// If resources matches, replace the resource with the new one. // Get the resource matched
if ($currentResource === $newResource) { if ($currentResource === $newResourceName) {
$userStateHistory[$userState] = $newEntry; $userStateHistory[$userState] = $finalRessourceEtatDate;
break; break;
} }
} }
...@@ -230,12 +245,24 @@ class LifeCycle implements EndpointInterface ...@@ -230,12 +245,24 @@ class LifeCycle implements EndpointInterface
return $result; return $result;
} }
/**
* @param string|null $matchedResource
* @return string
* Note : Simply return the end date of a supann ressource etat date
*/
private function extractCurrentEndDate (?string $matchedResource): string
{
$parts = explode(":", $matchedResource);
// Get the last element, which is the date
return end($parts);
}
/** /**
* @param string $supannRessourceEtatDate * @param string $supannRessourceEtatDate
* @return string|null * @return string|null
* Note : Simple method to return the content between {} of a supannRessourceEtatDate. * Note : Simple method to return the content between {} of a supannRessourceEtatDate.
*/ */
private function returnSupannResourceBetweenBrackets (string $supannRessourceEtatDate) : ?string private function returnSupannResourceBetweenBrackets (string $supannRessourceEtatDate): ?string
{ {
preg_match('/\{(.*?)\}/', $supannRessourceEtatDate, $matches); preg_match('/\{(.*?)\}/', $supannRessourceEtatDate, $matches);
return $matches[1] ?? NULL; return $matches[1] ?? NULL;
...@@ -246,12 +273,12 @@ class LifeCycle implements EndpointInterface ...@@ -246,12 +273,12 @@ class LifeCycle implements EndpointInterface
* @return array * @return array
* Note : Simply return attributes from main task, here supann desired behavior * Note : Simply return attributes from main task, here supann desired behavior
*/ */
private function getLifeCycleBehaviorFromMainTask (string $taskDN) : array private function getLifeCycleBehaviorFromMainTask (string $taskDN): array
{ {
return $this->gateway->getLdapTasks('(objectClass=*)', ['fdTasksLifeCyclePreResource', return $this->gateway->getLdapTasks('(objectClass=*)', ['fdTasksLifeCyclePreResource',
'fdTasksLifeCyclePreState', 'fdTasksLifeCyclePreSubState', 'fdTasksLifeCyclePreState', 'fdTasksLifeCyclePreSubState',
'fdTasksLifeCyclePostResource', 'fdTasksLifeCyclePostState', 'fdTasksLifeCyclePostSubState', 'fdTasksLifeCyclePostEndDate'], 'fdTasksLifeCyclePostResource', 'fdTasksLifeCyclePostState', 'fdTasksLifeCyclePostSubState', 'fdTasksLifeCyclePostEndDate'],
'', $taskDN); '', $taskDN);
} }
/** /**
...@@ -259,7 +286,7 @@ class LifeCycle implements EndpointInterface ...@@ -259,7 +286,7 @@ class LifeCycle implements EndpointInterface
* @return array * @return array
* Note : simply return the current values of supannRessourceEtatDate of the specified user. * Note : simply return the current values of supannRessourceEtatDate of the specified user.
*/ */
private function getUserSupannHistory ($userDN) : array private function getUserSupannHistory ($userDN): array
{ {
return $this->gateway->getLdapTasks('(objectClass=supannPerson)', ['supannRessourceEtatDate'], return $this->gateway->getLdapTasks('(objectClass=supannPerson)', ['supannRessourceEtatDate'],
'', $userDN); '', $userDN);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment