Skip to content
GitLab
    • Explore Projects Groups Topics Snippets
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • fusiondirectory-orchestrator fusiondirectory-orchestrator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 25
    • Issues 25
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • fusiondirectoryfusiondirectory
  • fusiondirectory-orchestratorfusiondirectory-orchestrator
  • Merge requests
  • !85
An error occurred while fetching the assigned milestone of the selected merge_request.

:art: refactor(archive) - improve method structure and enhance supann status...

  • Review changes

  • Download
  • Patches
  • Plain diff
Closed Alexa Oana eliza requested to merge 73-orchestrator-create-a-librabry-in-core-orchestrator into dev 1 month ago
  • Overview 0
  • Commits 4
  • Pipelines 1
  • Changes 1

:art: refactor(archive) - improve method structure and enhance supann status handling in archiving process

Related to #73

Viewing commit 7e5cb8ee
Prev Next
Show latest version
1 file
+ 133
− 117

    Preferences

    File browser
    Compare changes
  • 7e5cb8ee
    dockx thibault
    :art: refactor(archive) - improve method structure and enhance supann status... · 7e5cb8ee
    dockx thibault authored 1 month ago
    :art: refactor(archive) - improve method structure and enhance supann status handling in archiving process
plugins/tasks/Archive.php
+ 133
− 117
  • View file @ 7e5cb8ee

  • Edit in single-file editor

  • Open in Web IDE


Conflict: This file was modified in both the source and target branches. Ask someone with write access to resolve it.
@@ -4,134 +4,150 @@ use FusionDirectory\Rest\WebServiceCall;
class Archive implements EndpointInterface
{
private TaskGateway $gateway;
public function __construct (TaskGateway $gateway)
{
$this->gateway = $gateway;
}
/**
* @return array
* Part of the interface of orchestrator plugin to treat GET method
*/
public function processEndPointGet (): array
{
// Retrieve tasks of type 'archive'
return $this->gateway->getObjectTypeTask('archive');
}
/**
* @param array|null $data
* @return array
* @throws Exception
* Note: Part of the interface of orchestrator plugin to treat PATCH method
*/
public function processEndPointPatch (array $data = NULL): array
{
$result = [];
$archiveTasks = $this->gateway->getObjectTypeTask('archive');
// Initialize the WebServiceCall object for login
$webServiceCall = new WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/login', 'POST');
$webServiceCall->setCurlSettings(); // Perform login and set the token
foreach ($archiveTasks as $task) {
try {
if (!$this->gateway->statusAndScheduleCheck($task)) {
// Skip this task if it does not meet the status and schedule criteria
continue;
}
private TaskGateway $gateway;
// Receive null or 'toBeArchived'
$supannState = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
public function __construct(TaskGateway $gateway)
{
$this->gateway = $gateway;
}
if ($supannState !== 'toBeArchived') {
// The task does not meet the criteria for archiving and can therefore be suppressed
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
$this->gateway->removeSubTask($task['dn']);
continue;
}
/**
* @return array
* Part of the interface of orchestrator plugin to treat GET method
*/
public function processEndPointGet(): array
{
// Retrieve tasks of type 'archive'
return $this->gateway->getObjectTypeTask('archive');
}
// Set the archive endpoint and method using the same WebServiceCall object
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
$webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request
$response = $webServiceCall->execute();
// Check if the HTTP status code is 204
if ($webServiceCall->getHttpStatusCode() === 204) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2');
} else {
throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode());
/**
* @param array|null $data
* @return array
* @throws Exception
* Note: Part of the interface of orchestrator plugin to treat PATCH method
*/
public function processEndPointPatch(array $data = null): array
{
$result = [];
$archiveTasks = $this->gateway->getObjectTypeTask('archive');
// Initialize the WebServiceCall object for login
$webServiceCall = new WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/login', 'POST');
$webServiceCall->setCurlSettings(); // Perform login and set the token
foreach ($archiveTasks as $task) {
try {
if (!$this->gateway->statusAndScheduleCheck($task)) {
// Skip this task if it does not meet the status and schedule criteria
continue;
}
// Retrieve the desired supann status from the main task
$desiredSupannStatus = $this->getArchiveTaskBehaviorFromMainTask($task['fdtasksgranularmaster'][0]);
// Retrieve the current supann status of the user
$currentSupannStatus = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
// Check if the current supann status matches the desired status
if (!$this->isSupannStatusMatching($desiredSupannStatus, $currentSupannStatus)) {
// The task does not meet the criteria for archiving and can therefore be suppressed
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
$this->gateway->removeSubTask($task['dn']);
continue;
}
// Set the archive endpoint and method using the same WebServiceCall object
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
$webServiceCall->setCurlSettings($archiveUrl, null, 'POST'); // Update settings for the archive request
$response = $webServiceCall->execute();
// Check if the HTTP status code is 204
if ($webServiceCall->getHttpStatusCode() === 204) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2');
} else {
throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode());
}
} catch (Exception $e) {
$result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage());
}
}
} catch (Exception $e) {
$result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage());
}
}
return $result;
}
/**
* @param array|null $data
* @return array
* Note: Part of the interface of orchestrator plugin to treat POST method
*/
public function processEndPointPost (array $data = NULL): array
{
return [];
}
/**
* @param array|null $data
* @return array
* Note: Part of the interface of orchestrator plugin to treat DELETE method
*/
public function processEndPointDelete (array $data = NULL): array
{
return [];
}
/**
* Retrieve the supannAccountStatus of a user
* @param string $userDn
* @return string|null
*/
private function getUserSupannAccountStatus (string $userDn): ?string
{
$supannState = $this->gateway->getLdapTasks(
'(objectClass=supannPerson)',
['supannRessourceEtatDate'],
'',
$userDn
);
if ($this->hasToBeArchived($supannState)) {
return 'toBeArchived';
return $result;
}
return NULL;
}
/**
* @param array|null $data
* @return array
* Note: Part of the interface of orchestrator plugin to treat POST method
*/
public function processEndPointPost(array $data = null): array
{
return [];
}
private function hasToBeArchived (array $supannState): bool
{
if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) {
return FALSE;
/**
* @param array|null $data
* @return array
* Note: Part of the interface of orchestrator plugin to treat DELETE method
*/
public function processEndPointDelete(array $data = null): array
{
return [];
}
foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) {
// Skip non-numeric keys (e.g., 'count')
if (!is_numeric($key)) {
continue;
}
/**
* Retrieve the supannAccountStatus of a user
* @param string $userDn
* @return array|null
*/
private function getUserSupannAccountStatus(string $userDn): ?array
{
return $this->gateway->getLdapTasks(
'(objectClass=supannPerson)',
['supannRessourceEtatDate'],
'',
$userDn
);
}
if (strpos($value, '{COMPTE}I:toBeArchived') !== FALSE) {
return TRUE;
}
/**
* @param string $taskDN
* @return array
* Note: Retrieve the desired supann status from the main task attributes.
*/
private function getArchiveTaskBehaviorFromMainTask(string $taskDN): array
{
return $this->gateway->getLdapTasks(
'(objectClass=*)',
['fdArchiveTaskResource', 'fdArchiveTaskState', 'fdArchiveTaskSubState'],
'',
$taskDN
);
}
return FALSE;
}
/**
* @param array $desiredStatus
* @param array $currentStatus
* @return bool
* Note: Compare the desired supann status with the current status to determine if they match.
*/
private function isSupannStatusMatching(array $desiredStatus, array $currentStatus): bool
{
if (empty($currentStatus[0]['supannressourceetatdate'])) {
return false;
}
foreach ($currentStatus[0]['supannressourceetatdate'] as $resource) {
if (strpos($resource, '{' . $desiredStatus[0]['fdarchivetaskresource'][0] . '}') !== false &&
strpos($resource, ':' . $desiredStatus[0]['fdarchivetaskstate'][0]) !== false &&
(empty($desiredStatus[0]['fdarchivetasksubstate'][0]) || strpos($resource, ':' . $desiredStatus[0]['fdarchivetasksubstate'][0]) !== false)) {
return true;
}
}
return false;
}
}
\ No newline at end of file
Assignee
Alexa Oana eliza's avatar
Alexa Oana eliza
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 Participants
Reference:
Source branch: 73-orchestrator-create-a-librabry-in-core-orchestrator

Menu

Explore Projects Groups Topics Snippets