Skip to content

Commit

Permalink
avniproject/avni-product#1334 | summaryTable endpoint added in Activi…
Browse files Browse the repository at this point in the history
…ties tab

Signed-off-by: ak2502 <akanksha.feb25@gmail.com>
  • Loading branch information
ak2502 committed Aug 23, 2023
1 parent 75be325 commit f0f40aa
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/avniproject/etl/controller/ReportController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public ReportController(ReportRepository reportRepository, ReportUtil reportUtil
this.reportUtil = reportUtil;
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/aggregate/summaryTable", method = RequestMethod.GET)
public List<UserActivityDTO> getSummaryTable(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds){
return reportRepository.generateSummaryTable(
OrgIdentityContextHolder.getDbSchema()
);
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "report/hr/userActivity", method = RequestMethod.GET)
public List<UserActivityDTO> getUserActivity(@RequestParam(value = "startDate", required = false) String startDate,
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/avniproject/etl/dto/UserActivityDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class UserActivityDTO {

private String tableName;
private String tableType;
private String userName;
private Long id;
private Long registrationCount;
Expand All @@ -20,6 +22,22 @@ public class UserActivityDTO {
private DateTime syncEnd;
private DateTime lastSuccessfulSync;

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getTableType() {
return tableType;
}

public void setTableType(String tableType) {
this.tableType = tableType;
}

public String getUserName() {
return userName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public ReportRepository(NamedParameterJdbcTemplate jdbcTemplate, SchemaMetadataR
this.schemaMetadataRepository = schemaMetadataRepository;
}

public List<UserActivityDTO> generateSummaryTable(String orgSchemaName){
String baseQuery = "select name, type \n" +
"from public.table_metadata\n" +
"where schema_name = '${schemaName}'\n" +
"order by type;";
String query= baseQuery.replace("${schemaName}", orgSchemaName);
return jdbcTemplate.query(query, new SummaryTableMapper());
}

public List<UserActivityDTO> generateUserActivity(String orgSchemaName, String subjectWhere, String encounterWhere, String enrolmentWhere, String userWhere) {
SchemaMetadata schema = schemaMetadataRepository.getExistingSchemaMetadata();
List<String> subjectTableNames = schema.getAllSubjectTableNames().stream().toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.avniproject.etl.repository.rowMappers.reports;

import org.avniproject.etl.dto.UserActivityDTO;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class SummaryTableMapper implements RowMapper<UserActivityDTO> {
@Override
public UserActivityDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
UserActivityDTO userActivityDTO = new UserActivityDTO();
userActivityDTO.setTableName(rs.getString("name"));
userActivityDTO.setTableType(rs.getString("type"));
return userActivityDTO;
}
}

0 comments on commit f0f40aa

Please sign in to comment.