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 7aacd1eb7..066860a6e 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 @@ -59,7 +59,7 @@ public Database getDatabaseByName(Database database) { } } - public CollectionInfoResponse getCollectionByName(String collectionName) { + public CollectionInfoResponse getCollectionByName(Database database) { String url = metabaseApiUrl + "/collection"; try { String jsonResponse = getForObject(url, String.class); @@ -70,9 +70,9 @@ public CollectionInfoResponse getCollectionByName(String collectionName) { ); return collections.stream() - .filter(collection -> collection.getName().equals(collectionName)) + .filter(collection -> collection.getName().equals(database.getName())) .findFirst() - .orElseThrow(() -> new RuntimeException("Collection with name " + collectionName + " not found.")); + .orElseThrow(() -> new RuntimeException("Collection with name " + database.getName() + " not found.")); } catch (Exception e) { throw new RuntimeException("Failed to retrieve collection", e); } @@ -94,7 +94,7 @@ public void createQuestionForTable(Database database, TableDetails tableDetails, VisualizationType.TABLE, null, objectMapper.createObjectNode(), - getCollectionByName(database.getName()).getIdAsInt() + getCollectionByName(database).getIdAsInt() ); postForObject(metabaseApiUrl + "/card", requestBody.toJson(objectMapper), JsonNode.class); 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 5bc128e8f..20f9e2e63 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 @@ -202,7 +202,7 @@ public void createQuestionsForIndividualTables() { VisualizationType.TABLE, null, objectMapper.createObjectNode(), - databaseRepository.getCollectionByName(database.getName()).getIdAsInt() + databaseRepository.getCollectionByName(database).getIdAsInt() ); databaseRepository.postForObject(metabaseApiUrl + "/card", requestBody.toJson(objectMapper), JsonNode.class); 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 96a03efdf..429e7ad3c 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 @@ -77,7 +77,9 @@ public int getGlobalDatabaseId() { public int getGlobalCollectionId() { if (globalCollection == null) { Organisation currentOrganisation = organisationService.getCurrentOrganisation(); - globalCollection = databaseRepository.getCollectionByName(currentOrganisation.getName()); + Database database = new Database(); + database.setName(currentOrganisation.getName()); + globalCollection = databaseRepository.getCollectionByName(database); } return globalCollection.getIdAsInt(); }