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 3686e78c9..7aacd1eb7 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 @@ -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); @@ -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); } @@ -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 fieldsList = getFields(database); String snakeCaseTableName = S.toSnakeCase(tableDetails.getName()); diff --git a/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java b/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java index cdd3677b9..96a03efdf 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/metabase/MetabaseService.java @@ -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(); }