From b9dc476beb374a9ac2f9f9987a50b0043bdcada7 Mon Sep 17 00:00:00 2001 From: Om Bhardwaj <115864495+ombhardwajj@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:49:13 +0530 Subject: [PATCH] avniproject#762 | Enums added --- .../server/domain/metabase/TableType.java | 29 +++++++++++++++++++ .../service/metabase/DatabaseService.java | 10 +++++-- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 avni-server-api/src/main/java/org/avni/server/domain/metabase/TableType.java diff --git a/avni-server-api/src/main/java/org/avni/server/domain/metabase/TableType.java b/avni-server-api/src/main/java/org/avni/server/domain/metabase/TableType.java new file mode 100644 index 000000000..f361ed671 --- /dev/null +++ b/avni-server-api/src/main/java/org/avni/server/domain/metabase/TableType.java @@ -0,0 +1,29 @@ +package org.avni.server.domain.metabase; + +public enum TableType { + INDIVIDUAL("Individual"), + HOUSEHOLD("Household"), + GROUP("Group"), + PERSON("Person"), + PROGRAM_ENCOUNTER("ProgramEncounter"), + PROGRAM_ENROLMENT("ProgramEnrolment"); + + private final String typeName; + + TableType(String typeName) { + this.typeName = typeName; + } + + public String getTypeName() { + return typeName; + } + + public static TableType fromString(String typeName) { + for (TableType type : TableType.values()) { + if (type.getTypeName().equalsIgnoreCase(typeName)) { + return type; + } + } + throw new IllegalArgumentException("Unknown table type: " + typeName); + } +} 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 ec72c9a74..d41ee35a5 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 @@ -1,4 +1,4 @@ -package org.avni.server.service.metabase; +ckage org.avni.server.service.metabase; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -129,14 +129,16 @@ public List getSubjectTypeNames() { JsonNode rows = tableMetadata.path("data").path("rows"); for (JsonNode row : rows) { String type = row.get(2).asText(); - if (Arrays.asList("Individual", "Household", "Group", "Person").contains(type)) { + if (Arrays.asList(TableType.INDIVIDUAL.getTypeName(), TableType.HOUSEHOLD.getTypeName(), TableType.GROUP.getTypeName(), TableType.PERSON.getTypeName()).contains(type)) { String rawName = row.get(1).asText(); subjectTypeNames.add(formatName(rawName)); } } + System.out.println("The subject type names::" + subjectTypeNames); return subjectTypeNames; } + public List getProgramAndEncounterNames() { JsonNode tableMetadata = getTableMetadata(); List programNames = new ArrayList<>(); @@ -144,14 +146,16 @@ public List getProgramAndEncounterNames() { JsonNode rows = tableMetadata.path("data").path("rows"); for (JsonNode row : rows) { String type = row.get(2).asText(); - if (Arrays.asList("ProgramEncounter", "ProgramEnrolment").contains(type)) { + if (Arrays.asList(TableType.PROGRAM_ENCOUNTER.getTypeName(), TableType.PROGRAM_ENROLMENT.getTypeName()).contains(type)) { String rawName = row.get(1).asText(); programNames.add(formatName(rawName)); } } + System.out.println("The program and encounter::" + programNames); return programNames; } + private List extractTableNames(JsonNode databaseDetails) { List tableNames = new ArrayList<>(); JsonNode tablesArray = databaseDetails.path("tables");