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
3 changes: 2 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ public function register(IRegistrationContext $context): void
$container->get('OCP\App\IAppManager'),
$container,
$container->get('Psr\Log\LoggerInterface'),
$container->get(SettingsService::class)
$container->get(SettingsService::class),
$container->get(\OCA\OpenRegister\Service\OrganisationService::class)
);
});

Expand Down
37 changes: 28 additions & 9 deletions lib/Service/ArchiMateImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace OCA\SoftwareCatalog\Service;

use OCA\OpenRegister\Service\ObjectService;
use OCA\OpenRegister\Service\OrganisationService;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\IUserSession;
Expand Down Expand Up @@ -142,7 +143,8 @@ public function __construct(
private readonly IAppManager $appManager,
private readonly ContainerInterface $container,
private readonly LoggerInterface $logger,
private readonly SettingsService $settingsService
private readonly SettingsService $settingsService,
private readonly OrganisationService $organisationService
) {
}

Expand Down Expand Up @@ -269,6 +271,7 @@ public function importArchiMateFileFromPathOptimized(array $options = []): array
// DEBUG: Verify that the optimized import method is being called
$this->logger->info('GEMMA IMPORT DEBUG: Starting optimized import', $options);


// Starting OPTIMIZED ArchiMate XML import

try {
Expand Down Expand Up @@ -1063,6 +1066,7 @@ private function saveObjectsToDatabase(array $objects): array
'object_sections' => array_count_values(array_column($objects, 'section'))
]);


$serviceInitStartTime = microtime(true);
$objectService = $this->getObjectService();
if (!$objectService) {
Expand Down Expand Up @@ -1415,13 +1419,26 @@ private function getCurrentUserId(): ?string
}

/**
* Get current organisation from cache
* Get current organisation UUID from OrganisationService
*
* @return string Default organisation
* @return string Organisation UUID
*/
private function getCurrentOrganisation(): string
{
return $this->cachedConfig['organisation'] ?? 'default';
try {
$this->logger->info('Getting default organisation from OrganisationService');
$defaultOrganisation = $this->organisationService->ensureDefaultOrganisation();
$uuid = $defaultOrganisation->getUuid();


$this->logger->info('Got default organisation UUID: ' . $uuid);
return $uuid;
} catch (\Exception $e) {
$this->logger->error('Failed to get default organisation: ' . $e->getMessage());
$this->logger->error('Exception trace: ' . $e->getTraceAsString());
// Fallback to cached value or 'default' string
return $this->cachedConfig['organisation'] ?? 'default';
}
}

/**
Expand Down Expand Up @@ -3364,7 +3381,7 @@ private function transformViewsOptimized(
'schema' => $this->getSchemaIdForSection('view'),
'id' => $identifier,
'owner' => $this->cachedConfig['userId'],
'organisation' => $this->cachedConfig['organisation'],
'organisation' => $this->getCurrentOrganisation(),

],
'identifier' => $identifier,
Expand Down Expand Up @@ -3578,13 +3595,15 @@ private function buildElementsLookupFromRawData(
*/
private function createModelObjectDirect(array $metadata, string $modelIdentifier): array
{
$organisation = $this->getCurrentOrganisation();

return [
'@self' => [
'register' => $this->cachedConfig['registerId'] ?? throw new \RuntimeException("Register ID not found in cached configuration. Please ensure AMEF configuration is properly initialized."),
'schema' => $this->cachedConfig['schemaIds']['model'] ?? throw new \RuntimeException("Schema ID for 'model' not found in cached configuration. Please ensure AMEF configuration is properly initialized."),
'id' => $modelIdentifier,
'owner' => $this->cachedConfig['userId'],
'organisation' => $this->cachedConfig['organisation'],
'organisation' => $organisation, // Use the method instead of cached value
'published' => date('Y-m-d\TH:i:s\Z')
],
'identifier' => $modelIdentifier,
Expand Down Expand Up @@ -3671,7 +3690,7 @@ private function transformSectionObjectsBatch(
'schema' => $this->cachedConfig['schemaIds'][$schemaType] ?? throw new \RuntimeException("Schema ID for '{$schemaType}' not found in cached configuration. Please ensure AMEF configuration is properly initialized."),
'id' => $identifier,
'owner' => $this->cachedConfig['userId'],
'organisation' => $this->cachedConfig['organisation'],
'organisation' => $this->getCurrentOrganisation(),
'published' => date('Y-m-d\TH:i:s\Z')
],
'identifier' => $identifier,
Expand Down Expand Up @@ -4016,7 +4035,7 @@ private function bulkTransformSection(
'schema' => $this->cachedConfig['schemaIds'][$schemaType] ?? throw new \RuntimeException("Schema ID for '{$schemaType}' not found in cached configuration. Please ensure AMEF configuration is properly initialized."),
'id' => $identifier,
'owner' => $this->cachedConfig['userId'],
'organisation' => $this->cachedConfig['organisation'],
'organisation' => $this->getCurrentOrganisation(),
'published' => date('Y-m-d\TH:i:s\Z')
],
'identifier' => $identifier,
Expand Down Expand Up @@ -4136,7 +4155,7 @@ private function bulkTransformViews(
'schema' => $this->getSchemaIdForSection('view'),
'id' => $identifier,
'owner' => $this->cachedConfig['userId'],
'organisation' => $this->cachedConfig['organisation'],
'organisation' => $this->getCurrentOrganisation(),
'published' => date('Y-m-d\TH:i:s\Z')
],
'identifier' => $identifier,
Expand Down