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
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
// ArchiMate import/export routes
['name' => 'settings#importArchiMate', 'url' => '/api/archimate/import', 'verb' => 'POST'],
['name' => 'settings#exportArchiMate', 'url' => '/api/archimate/export', 'verb' => 'POST'],
['name' => 'settings#exportOrgArchiMate', 'url' => '/api/archimate/export/organization', 'verb' => 'POST'],
['name' => 'settings#downloadArchiMate', 'url' => '/api/archimate/download/{fileName}', 'verb' => 'GET'],

// ArchiMate status management routes (status reading is via main settings endpoint)
Expand Down
86 changes: 84 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1288,14 +1288,96 @@ public function render(): string {
}
}

/**
* Export organization-specific ArchiMate file with enriched views
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return Response File download response or JSON error response
*/
public function exportOrgArchiMate(): Response
{
try {
$rawInput = file_get_contents('php://input');
$data = json_decode($rawInput, true);

if (json_last_error() !== JSON_ERROR_NONE) {
$data = [
'organization' => $this->request->getParam('organization', null)
];
}

$organizationUuid = $data['organization'] ?? null;

if (empty($organizationUuid)) {
return new JSONResponse([
'success' => false,
'message' => 'Organization UUID is required',
'error' => 'MISSING_ORGANIZATION'
], 400);
}

$result = $this->archiMateService->exportOrgArchiMate($organizationUuid);

if (!$result['success']) {
$statusCode = 500;
if (str_contains($result['error'] ?? '', 'not found')) {
$statusCode = 404;
}

return new JSONResponse([
'success' => false,
'message' => $result['error'] ?? 'Export failed',
'error' => $result['error'] ?? 'EXPORT_FAILED'
], $statusCode);
}

$fileName = $result['file_name'] ?? 'archimate_org_export_' . date('Y-m-d_H-i-s') . '.xml';
$xmlContent = $result['xml'] ?? '<?xml version="1.0" encoding="UTF-8"?><model></model>';

$response = new class($xmlContent) extends Response {
public function __construct(private string $content) {
parent::__construct();
}

public function render(): string {
return $this->content;
}
};

$response->setStatus(200);
$response->addHeader('Content-Type', 'application/xml');
$response->addHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"');
$response->addHeader('Content-Length', (string)strlen($xmlContent));
$response->addHeader('Cache-Control', 'no-cache');

return $response;

} catch (\Exception $e) {
$this->logger->error('Organization ArchiMate export failed', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);

$statusCode = $this->getHttpStatusForException($e);

return new JSONResponse([
'success' => false,
'message' => 'Export failed: ' . $e->getMessage(),
'error' => $e->getMessage()
], $statusCode);
}
}

/**
* Download ArchiMate file
*
* @NoAdminRequired
* @NoCSRFRequired
*
*
* @param string $fileName The filename to download
*
*
* @return Response File download response
*/
public function downloadArchiMate(string $fileName): Response
Expand Down
Loading
Loading