diff --git a/avni-server-api/src/main/java/org/avni/server/service/DatabaseService.java b/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java similarity index 90% rename from avni-server-api/src/main/java/org/avni/server/service/DatabaseService.java rename to avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java index 1817d8798..86dba4e01 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/DatabaseService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java @@ -1,4 +1,4 @@ -package org.avni.server.service; +package org.avni.server.service.metabase; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -56,21 +56,6 @@ public int getFieldIdByTableNameAndFieldName(int databaseId, String tableName, S return -1; } - public void waitForSyncCompletion(int databaseId) { - while (true) { - String syncStatus = getInitialSyncStatus(databaseId); - if ("complete".equals(syncStatus)) { - return; - } - try { - TimeUnit.SECONDS.sleep(5); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException("Thread was interrupted while waiting for sync completion", e); - } - } - } - public String getInitialSyncStatus(int databaseId) { JsonNode responseBody = databaseRepository.getInitialSyncStatus(databaseId); return responseBody.path("initial_sync_status").asText(); @@ -100,7 +85,10 @@ public void createQuestionsForSubjectTypes() { int databaseId = metabaseService.getGlobalDatabaseId(); int collectionId = metabaseService.getGlobalCollectionId(); - waitForSyncCompletion(databaseId); + String syncStatus = getInitialSyncStatus(databaseId); + if (!"complete".equals(syncStatus)) { + throw new RuntimeException("Database initial sync is not complete."); + } List subjectTypeNames = getSubjectTypeNames(databaseId); diff --git a/avni-server-api/src/main/java/org/avni/server/service/MetabaseService.java b/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java similarity index 97% rename from avni-server-api/src/main/java/org/avni/server/service/MetabaseService.java rename to avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java index 6d8e75997..c1a08c55d 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/MetabaseService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java @@ -1,4 +1,4 @@ -package org.avni.server.service; +package org.avni.server.service.metabase; import org.avni.server.dao.metabase.CollectionPermissionsRepository; import org.avni.server.dao.metabase.CollectionRepository; @@ -6,6 +6,7 @@ import org.avni.server.dao.metabase.GroupPermissionsRepository; import org.avni.server.domain.Organisation; import org.avni.server.domain.metabase.*; +import org.avni.server.service.OrganisationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; diff --git a/avni-server-api/src/main/java/org/avni/server/web/MetabaseController.java b/avni-server-api/src/main/java/org/avni/server/web/MetabaseController.java index 37c8cfcfe..01dc7fde3 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/MetabaseController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/MetabaseController.java @@ -1,9 +1,9 @@ package org.avni.server.web; -import org.avni.server.service.DatabaseService; +import org.avni.server.service.metabase.DatabaseService; import org.avni.server.domain.accessControl.PrivilegeType; import org.avni.server.dao.metabase.MetabaseConnector; import org.avni.server.dao.metabase.DatabaseRepository; -import org.avni.server.service.MetabaseService; +import org.avni.server.service.metabase.MetabaseService; import org.avni.server.service.UserService; import org.avni.server.service.accessControl.AccessControlService; import org.springframework.web.bind.annotation.*; @@ -31,4 +31,9 @@ public void setupMetabase() { public void createQuestions() { databaseService.createQuestionsForSubjectTypes(); } + + @GetMapping("/sync-status") + public String getSyncStatus() { + return databaseService.getInitialSyncStatus(metabaseService.getGlobalDatabaseId()); + } }