-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from ConductionNL/development
Development to main
- Loading branch information
Showing
28 changed files
with
1,549 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
use OCA\OpenConnector\Service\ObjectService; | ||
use OCA\OpenConnector\Service\SearchService; | ||
use OCA\OpenConnector\Db\Synchronization; | ||
use OCA\OpenConnector\Service\SynchronizationService; | ||
use OCA\OpenConnector\Db\SynchronizationMapper; | ||
use OCA\OpenConnector\Db\SynchronizationContractMapper; | ||
use OCA\OpenConnector\Db\SynchronizationContractLogMapper; | ||
|
@@ -13,6 +13,8 @@ | |
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IAppConfig; | ||
use OCP\IRequest; | ||
use Exception; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
|
||
class SynchronizationsController extends Controller | ||
{ | ||
|
@@ -29,16 +31,17 @@ public function __construct( | |
private readonly IAppConfig $config, | ||
private readonly SynchronizationMapper $synchronizationMapper, | ||
private readonly SynchronizationContractMapper $synchronizationContractMapper, | ||
private readonly SynchronizationContractLogMapper $synchronizationContractLogMapper | ||
private readonly SynchronizationContractLogMapper $synchronizationContractLogMapper, | ||
private readonly SynchronizationService $synchronizationService | ||
) | ||
{ | ||
parent::__construct($appName, $request); | ||
parent::__construct($appName, $request); | ||
|
||
} | ||
|
||
/** | ||
* Returns the template of the main app's page | ||
* | ||
* | ||
* This method renders the main page of the application, adding any necessary data to the template. | ||
* | ||
* @NoAdminRequired | ||
|
@@ -47,17 +50,17 @@ public function __construct( | |
* @return TemplateResponse The rendered template response | ||
*/ | ||
public function page(): TemplateResponse | ||
{ | ||
{ | ||
return new TemplateResponse( | ||
'openconnector', | ||
'index', | ||
[] | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves a list of all synchronizations | ||
* | ||
* | ||
* This method returns a JSON response containing an array of all synchronizations in the system. | ||
* | ||
* @NoAdminRequired | ||
|
@@ -79,7 +82,7 @@ public function index(ObjectService $objectService, SearchService $searchService | |
|
||
/** | ||
* Retrieves a single synchronization by its ID | ||
* | ||
* | ||
* This method returns a JSON response containing the details of a specific synchronization. | ||
* | ||
* @NoAdminRequired | ||
|
@@ -99,7 +102,7 @@ public function show(string $id): JSONResponse | |
|
||
/** | ||
* Creates a new synchronization | ||
* | ||
* | ||
* This method creates a new synchronization based on POST data. | ||
* | ||
* @NoAdminRequired | ||
|
@@ -116,17 +119,17 @@ public function create(): JSONResponse | |
unset($data[$key]); | ||
} | ||
} | ||
|
||
if (isset($data['id'])) { | ||
unset($data['id']); | ||
} | ||
|
||
return new JSONResponse($this->synchronizationMapper->createFromArray(object: $data)); | ||
} | ||
|
||
/** | ||
* Updates an existing synchronization | ||
* | ||
* | ||
* This method updates an existing synchronization based on its ID. | ||
* | ||
* @NoAdminRequired | ||
|
@@ -152,7 +155,7 @@ public function update(int $id): JSONResponse | |
|
||
/** | ||
* Deletes a synchronization | ||
* | ||
* | ||
* This method deletes a synchronization based on its ID. | ||
* | ||
* @NoAdminRequired | ||
|
@@ -182,7 +185,7 @@ public function destroy(int $id): JSONResponse | |
public function contracts(int $id): JSONResponse | ||
{ | ||
try { | ||
$contracts = $this->synchronizationContractMapper->findAll($null, null, ['synchronization_id' => $id]); | ||
$contracts = $this->synchronizationContractMapper->findAll(null, null, ['synchronization_id' => $id]); | ||
return new JSONResponse($contracts); | ||
} catch (DoesNotExistException $e) { | ||
return new JSONResponse(['error' => 'Contracts not found'], 404); | ||
|
@@ -199,7 +202,7 @@ public function contracts(int $id): JSONResponse | |
* | ||
* @param int $id The ID of the source to retrieve logs for | ||
* @return JSONResponse A JSON response containing the call logs | ||
*/ | ||
*/ | ||
public function logs(int $id): JSONResponse | ||
{ | ||
try { | ||
|
@@ -209,4 +212,55 @@ public function logs(int $id): JSONResponse | |
return new JSONResponse(['error' => 'Logs not found'], 404); | ||
} | ||
} | ||
|
||
/** | ||
* Tests a synchronization | ||
* | ||
* This method tests a synchronization without persisting anything to the database. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param int $id The ID of the synchronization | ||
* | ||
* @return JSONResponse A JSON response containing the test results | ||
* | ||
* @example | ||
* Request: | ||
* empty POST | ||
* | ||
* Response: | ||
* { | ||
* "resultObject": { | ||
* "fullName": "John Doe", | ||
* "userAge": 30, | ||
* "contactEmail": "[email protected]" | ||
* }, | ||
* "isValid": true, | ||
* "validationErrors": [] | ||
* } | ||
*/ | ||
public function test(int $id): JSONResponse | ||
{ | ||
try { | ||
$synchronization = $this->synchronizationMapper->find(id: $id); | ||
} catch (DoesNotExistException $exception) { | ||
return new JSONResponse(data: ['error' => 'Not Found'], statusCode: 404); | ||
} | ||
|
||
// Try to synchronize | ||
try { | ||
$logAndContractArray = $this->synchronizationService->synchronize(synchronization: $synchronization, isTest: true); | ||
// Return the result as a JSON response | ||
return new JSONResponse(data: $logAndContractArray, statusCode: 200); | ||
} catch (Exception $e) { | ||
// If synchronizaiton fails, return an error response | ||
return new JSONResponse([ | ||
'error' => 'Synchronization error', | ||
'message' => $e->getMessage() | ||
], 400); | ||
} | ||
|
||
return new JSONResponse($resultFromTest, 200); | ||
} | ||
} |
Oops, something went wrong.