From f2e749f32d28d9a763ba74e8fdd29ff51ec33915 Mon Sep 17 00:00:00 2001 From: himeshr Date: Wed, 11 Dec 2024 12:28:18 +0530 Subject: [PATCH] avniproject/avni-webapp#1337 | Filter table names by org_schema_name --- .../server/domain/metabase/DatasetColumn.java | 3 ++- .../service/metabase/DatabaseService.java | 27 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java b/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java index 48509b4c7..773587a30 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/metabase/DatasetColumn.java @@ -2,7 +2,8 @@ public enum DatasetColumn { NAME(1), - TYPE(2); + TYPE(2), + SCHEMA_NAME(3); private final int index; 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 98fc49f82..f59fece5a 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 @@ -4,8 +4,9 @@ import org.avni.server.domain.metabase.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Arrays; + import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -81,10 +82,12 @@ public List getSubjectTypeNames() { for (List row : rows) { String type = row.get(DatasetColumn.TYPE.getIndex()); - if (type.equalsIgnoreCase(TableType.INDIVIDUAL.getTypeName()) || - type.equalsIgnoreCase(TableType.HOUSEHOLD.getTypeName()) || - type.equalsIgnoreCase(TableType.GROUP.getTypeName()) || - type.equalsIgnoreCase(TableType.PERSON.getTypeName())) { + String schemaName = row.get(DatasetColumn.SCHEMA_NAME.getIndex()); + if (schemaName.equalsIgnoreCase(getGlobalDatabase().getName()) && + (type.equalsIgnoreCase(TableType.INDIVIDUAL.getTypeName()) || + type.equalsIgnoreCase(TableType.HOUSEHOLD.getTypeName()) || + type.equalsIgnoreCase(TableType.GROUP.getTypeName()) || + type.equalsIgnoreCase(TableType.PERSON.getTypeName()))) { subjectTypeNames.add(row.get(DatasetColumn.NAME.getIndex())); } } @@ -98,18 +101,20 @@ public List getProgramAndEncounterNames() { DatasetResponse datasetResponse = databaseRepository.findAll(fetchedMetadataTable, getGlobalDatabase()); List> rows = datasetResponse.getData().getRows(); - List programNames = new ArrayList<>(); + List programAndEncounterNames = new ArrayList<>(); for (List row : rows) { String type = row.get(DatasetColumn.TYPE.getIndex()); - if (type.equalsIgnoreCase(TableType.PROGRAM_ENCOUNTER.getTypeName()) || - type.equalsIgnoreCase(TableType.ENCOUNTER.getTypeName()) || - type.equalsIgnoreCase(TableType.PROGRAM_ENROLMENT.getTypeName())) { - programNames.add(row.get(DatasetColumn.NAME.getIndex())); + String schemaName = row.get(DatasetColumn.SCHEMA_NAME.getIndex()); + if (schemaName.equalsIgnoreCase(getGlobalDatabase().getName()) && + (type.equalsIgnoreCase(TableType.PROGRAM_ENCOUNTER.getTypeName()) || + type.equalsIgnoreCase(TableType.ENCOUNTER.getTypeName()) || + type.equalsIgnoreCase(TableType.PROGRAM_ENROLMENT.getTypeName()))) { + programAndEncounterNames.add(row.get(DatasetColumn.NAME.getIndex())); } } - return programNames; + return programAndEncounterNames; } private void createQuestionsForEntities(List entityNames, FieldDetails addressFieldDetails, FieldDetails entityFieldDetails) {