-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#837 | Added a metabase dashboard and advanced questions in it
- Loading branch information
1 parent
568a05d
commit 52a1f6d
Showing
13 changed files
with
353 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
avni-server-api/src/main/java/org/avni/server/dao/metabase/MetabaseDashboardRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.avni.server.dao.metabase; | ||
|
||
import org.avni.server.domain.metabase.*; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Repository | ||
public class MetabaseDashboardRepository extends MetabaseConnector { | ||
private final DatabaseRepository databaseRepository; | ||
|
||
public MetabaseDashboardRepository(RestTemplateBuilder restTemplateBuilder , DatabaseRepository databaseRepository) { | ||
super(restTemplateBuilder); | ||
this.databaseRepository = databaseRepository; | ||
} | ||
|
||
public Dashboard save(CreateDashboardRequest createDashboardRequest) { | ||
String url = metabaseApiUrl + "/dashboard"; | ||
return postForObject(url, createDashboardRequest, Dashboard.class); | ||
} | ||
|
||
|
||
public CollectionItem getDashboardByName(CollectionInfoResponse globalCollection) { | ||
List<CollectionItem> items = databaseRepository.getExistingCollectionItems(globalCollection.getIdAsInt()); | ||
|
||
return items.stream() | ||
.filter(item -> item.getName().equals(globalCollection.getName())) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
public void updateDashboard(int dashboardId, DashboardUpdateRequest request) { | ||
String url = metabaseApiUrl + "/dashboard/" + dashboardId; | ||
sendPutRequest(url, request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
avni-server-api/src/main/java/org/avni/server/domain/metabase/CreateDashboardRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
public class CreateDashboardRequest { | ||
private final String name; | ||
private final String description; | ||
private final Integer collection_id; | ||
|
||
public CreateDashboardRequest(String name, String description, Integer collection_id) { | ||
this.name = name; | ||
this.description = description; | ||
this.collection_id = collection_id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public Integer getCollection_id() { | ||
return collection_id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + | ||
"name='" + name + '\'' + | ||
", description='" + description + '\'' + | ||
", collectionId=" + collection_id + | ||
'}'; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
avni-server-api/src/main/java/org/avni/server/domain/metabase/Dashboard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class Dashboard { | ||
private int id; | ||
private String name; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Dashboard{" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||
'}'; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
avni-server-api/src/main/java/org/avni/server/domain/metabase/DashboardResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class DashboardResponse { | ||
|
||
private String name; | ||
private String id; | ||
|
||
public DashboardResponse() { | ||
} | ||
|
||
public DashboardResponse(@JsonProperty("name") String name, | ||
@JsonProperty("id") Object id) { | ||
this.name = name; | ||
|
||
if (id instanceof Integer) { | ||
this.id = String.valueOf(id); | ||
} else { | ||
this.id = id.toString(); | ||
} | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public int getIdAsInt() { | ||
try { | ||
return Integer.parseInt(id); | ||
} catch (NumberFormatException e) { | ||
throw new RuntimeException("Failed to convert id to integer: " + id, e); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
avni-server-api/src/main/java/org/avni/server/domain/metabase/DashboardUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
import java.util.List; | ||
|
||
public class DashboardUpdateRequest { | ||
private final List<Dashcard> dashcards; | ||
|
||
public DashboardUpdateRequest(List<Dashcard> dashcards) { | ||
this.dashcards = dashcards; | ||
} | ||
|
||
|
||
public List<Dashcard> getDashcards() { | ||
return dashcards; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
avni-server-api/src/main/java/org/avni/server/domain/metabase/Dashcard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Dashcard { | ||
@JsonProperty("id") | ||
private int dashboardId; | ||
|
||
@JsonProperty("card_id") | ||
private int cardId; | ||
|
||
@JsonProperty("dashboard_tab_id") | ||
private Integer dashboardTabId; | ||
|
||
private int row; | ||
private int col; | ||
|
||
@JsonProperty("size_x") | ||
private int sizeX; | ||
|
||
@JsonProperty("size_y") | ||
private int sizeY; | ||
|
||
@JsonProperty("visualization_settings") | ||
private Object visualizationSettings; | ||
|
||
@JsonProperty("parameter_mappings") | ||
private List<Object> parameterMappings; | ||
|
||
public Dashcard(int dashboardId, int cardId, Integer dashboardTabId, int row, int col, int sizeX, int sizeY) { | ||
this.dashboardId = dashboardId; | ||
this.cardId = cardId; | ||
this.dashboardTabId = dashboardTabId; | ||
this.row = row; | ||
this.col = col; | ||
this.sizeX = sizeX; | ||
this.sizeY = sizeY; | ||
this.visualizationSettings = Collections.emptyMap(); | ||
this.parameterMappings = Collections.emptyList(); | ||
} | ||
|
||
public int getDashboardId() { | ||
return dashboardId; | ||
} | ||
|
||
public int getCardId() { | ||
return cardId; | ||
} | ||
|
||
public Integer getDashboardTabId() { | ||
return dashboardTabId; | ||
} | ||
|
||
public int getRow() { | ||
return row; | ||
} | ||
|
||
public int getCol() { | ||
return col; | ||
} | ||
|
||
public int getSizeX() { | ||
return sizeX; | ||
} | ||
|
||
public int getSizeY() { | ||
return sizeY; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + | ||
"dashboardId=" + dashboardId + | ||
", cardId=" + cardId + | ||
", dashboardTabId=" + dashboardTabId + | ||
", row=" + row + | ||
", col=" + col + | ||
", sizeX=" + sizeX + | ||
", sizeY=" + sizeY + | ||
", visualizationSettings=" + visualizationSettings + | ||
", parameterMappings=" + parameterMappings + | ||
'}'; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
avni-server-api/src/main/java/org/avni/server/domain/metabase/QuestionName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.avni.server.domain.metabase; | ||
|
||
public enum QuestionName { | ||
QUESTION_1("Pie Chart : Count of Non Voided Individuals - Non Voided Subject Type"), | ||
QUESTION_2("Pie Chart : Number of Non exited and Non voided Enrollments for Non Voided Program"); | ||
|
||
private final String questionName; | ||
|
||
QuestionName(String questionName) { | ||
this.questionName = questionName; | ||
} | ||
|
||
public String getQuestionName() { | ||
return questionName; | ||
} | ||
} |
Oops, something went wrong.