Skip to content

Commit

Permalink
avnirproject#762 | Created DatabaseSyncStatus for getInitialSyncStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
ombhardwajj committed Aug 31, 2024
1 parent b456232 commit e21282d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,9 +47,14 @@ public List<FieldDetails> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e21282d

Please sign in to comment.