Skip to content

Commit

Permalink
avniproject#762 | Removed primitive obsession from getDatabaseByName
Browse files Browse the repository at this point in the history
  • Loading branch information
ombhardwajj committed Sep 8, 2024
1 parent 05cf2ed commit 9a185c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Database getDatabaseById(Database database) {
}
}

public Database getDatabaseByName(String name) {
public Database getDatabaseByName(Database database) {
String url = metabaseApiUrl + "/database";

String jsonResponse = getForObject(url, String.class);
Expand All @@ -49,11 +49,11 @@ public Database getDatabaseByName(String name) {

for (JsonNode dbNode : dataArray) {
Database db = objectMapper.treeToValue(dbNode, Database.class);
if (db.getName().equals(name)) {
if (db.getName().equals(database.getName())) {
return db;
}
}
throw new RuntimeException("Database with name " + name + " not found.");
throw new RuntimeException("Database with name " + database.getName() + " not found.");
} catch (Exception e) {
throw new RuntimeException("Failed to retrieve database", e);
}
Expand Down Expand Up @@ -97,13 +97,9 @@ public void createQuestionForTable(Database database, TableDetails tableDetails,
getCollectionByName(database.getName()).getIdAsInt()
);

System.out.println("Final Request Body: " + requestBody.toJson(objectMapper).toPrettyString());

postForObject(metabaseApiUrl + "/card", requestBody.toJson(objectMapper), JsonNode.class);
}



public FieldDetails getFieldDetailsByName(Database database, TableDetails tableDetails, FieldDetails fieldDetails) {
List<FieldDetails> fieldsList = getFields(database);
String snakeCaseTableName = S.toSnakeCase(tableDetails.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void setupMetabase() {
public int getGlobalDatabaseId() {
if (globalDatabase == null) {
Organisation currentOrganisation = organisationService.getCurrentOrganisation();
globalDatabase = databaseRepository.getDatabaseByName(currentOrganisation.getName());
Database database = new Database();
database.setName(currentOrganisation.getName());
globalDatabase = databaseRepository.getDatabaseByName(database);
}
return globalDatabase.getId();
}
Expand Down

0 comments on commit 9a185c4

Please sign in to comment.