diff --git a/avni-server-api/src/main/java/org/avni/server/dao/metabase/DatabaseRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/metabase/DatabaseRepository.java index 395f26180..ef2d70690 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/metabase/DatabaseRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/metabase/DatabaseRepository.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import org.avni.server.domain.metabase.Database; +import org.avni.server.domain.metabase.DatabaseSyncStatus; import org.avni.server.domain.metabase.FieldDetails; import org.avni.server.domain.metabase.MetabaseDatabaseInfo; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -46,9 +47,14 @@ public List getFields(int databaseId) { } } - public JsonNode getInitialSyncStatus(int databaseId) { + public DatabaseSyncStatus getInitialSyncStatus(int databaseId) { String url = metabaseApiUrl + "/database/" + databaseId; - return getForObject(url, JsonNode.class); + String jsonResponse = getForObject(url, String.class); + try { + return objectMapper.readValue(jsonResponse, DatabaseSyncStatus.class); + } catch (Exception e) { + throw new RuntimeException("Failed to parse sync status", e); + } } public JsonNode getDataset(String requestBody) { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatabaseSyncStatus.java b/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatabaseSyncStatus.java new file mode 100644 index 000000000..832efd201 --- /dev/null +++ b/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatabaseSyncStatus.java @@ -0,0 +1,49 @@ +package org.avni.server.domain.metabase; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class DatabaseSyncStatus { + + @JsonProperty("initial_sync_status") + private String initialSyncStatus; + + @JsonProperty("name") + private String name; + + @JsonProperty("is_full_sync") + private boolean isFullSync; + + @JsonProperty("id") + private int id; + + @JsonProperty("engine") + private String engine; + + + public String getInitialSyncStatus() { + return initialSyncStatus; + } + + + public String getName() { + return name; + } + + + public boolean isFullSync() { + return isFullSync; + } + + + public int getId() { + return id; + } + + + public String getEngine() { + return engine; + } + +} diff --git a/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java b/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java index e478394da..e5c7c0ec0 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/metabase/DatabaseService.java @@ -100,11 +100,12 @@ public int getFieldIdByTableNameAndFieldName(String tableName, String fieldName) } public SyncStatus getInitialSyncStatus() { - JsonNode responseBody = databaseRepository.getInitialSyncStatus(getDatabaseId()); - String status = responseBody.path("initial_sync_status").asText(); + DatabaseSyncStatus databaseSyncStatus = databaseRepository.getInitialSyncStatus(getDatabaseId()); + String status = databaseSyncStatus.getInitialSyncStatus(); return SyncStatus.fromString(status); } + private JsonNode getTableMetadata() { int tableMetadataId = getTableIdByName("Table Metadata"); String requestBody = createRequestBodyForDataset(tableMetadataId);