remymumoh

Untitled

Oct 5th, 2020
859
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package edu.umd.aims.scheduler;
  2.  
  3. import com.google.gson.Gson;
  4. import com.microsoft.azure.documentdb.Document;
  5. import edu.umd.aims.Application;
  6. import edu.umd.aims.model.AimsReports;
  7. import edu.umd.aims.service.DatabaseService;
  8. import edu.umd.aims.service.EAreportService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.boot.SpringApplication;
  11. import org.springframework.scheduling.annotation.Scheduled;
  12. import org.springframework.stereotype.Component;
  13.  
  14. import java.text.SimpleDateFormat;
  15. import java.util.*;
  16.  
  17. @Component
  18. public class ReportsScheduler {
  19.     private static final String STR_AIMS_REPORTS = "reports";
  20.     private static Gson gson = new Gson();
  21.     @Autowired
  22.     private EAreportService eaReportService;
  23.     @Autowired
  24.     private DatabaseService databaseService;
  25.     private List<String> projects= Arrays.asList(new String[]{ "BAISV","ZAMPHIA2020"});
  26.     //private List<String> projects= Arrays.asList("ZAMPHIA2020","BAISV");
  27.  
  28.  
  29.     @Scheduled(fixedDelay = 5*60*60*1000)
  30.     public void reportScheduler(){
  31.         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  32.         Date now = new Date();
  33.         String strDate = sdf.format(now);
  34.         System.out.println("reports cron job expression(report_scheduler):: " + strDate);
  35.         projects.forEach(project->{
  36.             String country=null;
  37.             if(project.equalsIgnoreCase("ZAMPHIA2020")){
  38.                 country = "ZAMBIA";
  39.             }
  40.             else if(project.equalsIgnoreCase("BAISV")){
  41.                 country = "BOTSWANA";
  42.             }
  43.             if(project.equalsIgnoreCase("ZAMPHIA2020")){
  44.                 genZambiaReport(project, country);
  45.             }
  46.             else if(project.equalsIgnoreCase("BAISV")){
  47.                 genBAISVReport(project, country);
  48.             }
  49.         });
  50.     }
  51.  
  52.     private void genZambiaReport(String project, String country){
  53.         List<LinkedHashMap<String, String>> hhsumByTeam= eaReportService.getHHSummaryByTeamEAAndProjectIdBAISV(project);
  54.  
  55.         List<LinkedHashMap<String, String>> ResponseRateByProvince= eaReportService.getResponseByArea(project, "YPROVINCEN");
  56.         //System.out.println("looping  1" );
  57.         List<LinkedHashMap<String, String>> ResponseRateByDistrict= eaReportService.getResponseByArea(project, "YDISTRICTN");
  58.         //System.out.println("looping  2" );
  59.         List<LinkedHashMap<String, String>> ResponseRateByEA= eaReportService.getResponseByEAList(project);
  60.         //System.out.println("looping  3" );
  61.         List<LinkedHashMap<String, String>> BiomarkerByEA= eaReportService.getBiomarkerByEA(project);
  62.         //System.out.println("looping  4" );
  63.         List<LinkedHashMap<String, String>> ConsenttoLinkagetoCare= eaReportService.getConsenttoLinkagetoCareByEA(project);
  64.         //System.out.println("looping  5" );
  65.         List<LinkedHashMap<String, String>> DMValidatedByHHno= eaReportService.getDMValidatedbyHHno(project);
  66. //        //System.out.println("looping  6" );
  67.         List<LinkedHashMap<String, String>> PTIDbyCaseNumber= eaReportService.getPTIDbyCaseNumber(project);
  68.  
  69.         List<LinkedHashMap<String, String>> eligibilityByTeam= eaReportService.getEliblityByGenderByTeam(project);
  70.         //System.out.println("looping  9" );
  71.         List<LinkedHashMap<String, String>> HouseholdByGenderByTeam= eaReportService.getHouseholdByGenderByTeam(project);
  72.         //System.out.println("looping  10" );
  73.         List<LinkedHashMap<String, String>> ageMissmatchByTeam= eaReportService.ageMissmatchByTeam(project);
  74.         //System.out.println("looping  11" );
  75.         List<LinkedHashMap<String, String>> durationByTeam= eaReportService.durationByTeam(project);
  76.         //System.out.println("looping  12" );
  77.         List<LinkedHashMap<String, String>> DailyAchievementSummary = eaReportService.getDailyAchievementZASummary(project);
  78.  
  79.         //List<String> reportTypes = Arrays.asList("PTIDbyCaseNumber");
  80.         List<String> reportTypes = Arrays.asList("hhsumByTeam", "eligibilityByTeam", "HouseholdByGenderByTeam", "ageMissmatchByTeam", "durationByTeam", "ResponseRateByProvince","ResponseRateByDistrict","ResponseRateByEA","BiomarkerByEA","ConsenttoLinkagetoCare","DMValidatedByHHno","PTIDbyCaseNumber","DailyAchievementSummary");
  81.         String finalCountry = country;
  82.         reportTypes.forEach(reportType->{
  83.             Document existing = databaseService.getEAReportByProjectIdAndReportType(project,reportType,STR_AIMS_REPORTS);
  84.             if(existing!=null) {
  85.                 AimsReports aimsReport = gson.fromJson(existing.toString(), AimsReports.class);
  86.                 if (reportType.equalsIgnoreCase("hhsumByTeam")) {
  87.                     aimsReport.setReport(hhsumByTeam);
  88.                 }else if(reportType.equalsIgnoreCase("eligibilityByTeam")){
  89.                     aimsReport.setReport(eligibilityByTeam);
  90.                 }else if(reportType.equalsIgnoreCase("HouseholdByGenderByTeam")){
  91.                     aimsReport.setReport(HouseholdByGenderByTeam);
  92.                 }else if(reportType.equalsIgnoreCase("ageMissmatchByTeam")){
  93.                     aimsReport.setReport(ageMissmatchByTeam);
  94.                 }else if(reportType.equalsIgnoreCase("durationByTeam")){
  95.                     aimsReport.setReport(durationByTeam);
  96.                 }else if(reportType.equalsIgnoreCase("ResponseRateByProvince")){
  97.                     aimsReport.setReport(ResponseRateByProvince);
  98.                 }else if(reportType.equalsIgnoreCase("ResponseRateByDistrict")){
  99.                     aimsReport.setReport(ResponseRateByDistrict);
  100.                 }else if(reportType.equalsIgnoreCase("ResponseRateByEA")){
  101.                     aimsReport.setReport(ResponseRateByEA);
  102.                 }else if(reportType.equalsIgnoreCase("BiomarkerByEA")){
  103.                     aimsReport.setReport(BiomarkerByEA);
  104.                 }else if(reportType.equalsIgnoreCase("ConsenttoLinkagetoCare")){
  105.                     aimsReport.setReport(ConsenttoLinkagetoCare);
  106.                 }else if(reportType.equalsIgnoreCase("DMValidatedByHHno")){
  107.                     aimsReport.setReport(DMValidatedByHHno);
  108.                 }else if(reportType.equalsIgnoreCase("PTIDbyCaseNumber")){
  109.                     aimsReport.setReport(PTIDbyCaseNumber);
  110.                 }else if(reportType.equalsIgnoreCase("DailyAchievementSummary")){
  111.                     aimsReport.setReport(DailyAchievementSummary);
  112.                 }
  113.                 databaseService.updateAimsReport(aimsReport, STR_AIMS_REPORTS);
  114.                 // System.out.println("update" );
  115.  
  116.             } else {
  117.                 if (reportType.equalsIgnoreCase("hhsumByTeam")) {
  118.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, PTIDbyCaseNumber);
  119.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  120.                 }else if(reportType.equalsIgnoreCase("eligibilityByTeam")){
  121.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, eligibilityByTeam);
  122.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  123.                 }else if(reportType.equalsIgnoreCase("HouseholdByGenderByTeam")){
  124.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, HouseholdByGenderByTeam);
  125.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  126.                 }else if(reportType.equalsIgnoreCase("ageMissmatchByTeam")){
  127.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ageMissmatchByTeam);
  128.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  129.                 }else if(reportType.equalsIgnoreCase("durationByTeam")){
  130.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, durationByTeam);
  131.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  132.                 }else if(reportType.equalsIgnoreCase("ResponseRateByProvince")){
  133.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ResponseRateByProvince);
  134.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  135.                 }else if(reportType.equalsIgnoreCase("ResponseRateByDistrict")){
  136.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ResponseRateByDistrict);
  137.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  138.                 }else if(reportType.equalsIgnoreCase("ResponseRateByEA")){
  139.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ResponseRateByEA);
  140.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  141.                 }else if(reportType.equalsIgnoreCase("BiomarkerByEA")){
  142.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, BiomarkerByEA);
  143.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  144.                 }else if(reportType.equalsIgnoreCase("ConsenttoLinkagetoCare")){
  145.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ConsenttoLinkagetoCare);
  146.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  147.                 }else if(reportType.equalsIgnoreCase("DMValidatedByHHno")){
  148.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, DMValidatedByHHno);
  149.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  150.                 }else if(reportType.equalsIgnoreCase("PTIDbyCaseNumber")){
  151.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, PTIDbyCaseNumber);
  152.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  153.                 }else if(reportType.equalsIgnoreCase("DailyAchievementSummary")){
  154.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, DailyAchievementSummary);
  155.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  156.                 }
  157.             }
  158.         });
  159.  
  160.     }
  161.  
  162.  
  163.     private void genBAISVReport(String project, String country) {
  164.  
  165.         List<LinkedHashMap<String, String>> ResponseRateByDistrict= eaReportService.getResponseByArea(project, "YDISTRICTN");
  166.         List<LinkedHashMap<String, String>> PTIDbyCaseNumber= eaReportService.getBAISVPTIDbyCaseNumber(project);
  167.         List<LinkedHashMap<String, String>> DMValidatedByHHno= eaReportService.getDMValidatedbyHHno(project);
  168.         List<LinkedHashMap<String, String>> durationByTeam= eaReportService.durationByTeam(project);
  169.         List<LinkedHashMap<String, String>> eligibilityByTeam= eaReportService.getEliblityByGenderByTeam(project);
  170.         List<LinkedHashMap<String, String>> DailyAchievementSummary = eaReportService.getDailyAchievementSummary(project);
  171.         List<LinkedHashMap<String, String>> hhsumByTeam= eaReportService.getHHSummaryByTeamEAAndProjectIdBAISV(project);
  172. //        //System.out.println("looping  2" );
  173.         List<LinkedHashMap<String, String>> ResponseRateByEA= eaReportService.getResponseByEAList(project);
  174.         //System.out.println("looping  3" );
  175.         List<LinkedHashMap<String, String>> BiomarkerByEA= eaReportService.getBiomarkerByEA(project);
  176.         //System.out.println("looping  6" );
  177.         List<LinkedHashMap<String, String>> HouseholdByGenderByTeam= eaReportService.getHouseholdByGenderByTeamBAISV(project);
  178.         //System.out.println("looping  6" );
  179.         List<LinkedHashMap<String, String>> ageMissmatchByTeam= eaReportService.ageMissmatchByTeam(project);
  180.         //System.out.println("looping  4" );
  181.         List<LinkedHashMap<String, String>> ConsenttoLinkagetoCare= eaReportService.getConsenttoLinkagetoCareByEA(project);
  182.  
  183.         //List<String> reportTypes = Arrays.asList("durationByTeam");
  184.         List<String> reportTypes = Arrays.asList("hhsumByTeam", "ResponseRateByEA","BiomarkerByEA","durationByTeam", "eligibilityByTeam","HouseholdByGenderByTeam","ageMissmatchByTeam","ConsenttoLinkagetoCare","DMValidatedByHHno","ResponseRateByDistrict","DailyAchievementSummary" );
  185.         String finalCountry = country;
  186.         reportTypes.forEach(reportType -> {
  187.             Document existing = databaseService.getEAReportByProjectIdAndReportType(project, reportType, STR_AIMS_REPORTS);
  188.             if (existing != null) {
  189.                 AimsReports aimsReport = gson.fromJson(existing.toString(), AimsReports.class);
  190.                 if (reportType.equalsIgnoreCase("hhsumByTeam")) {
  191.                     aimsReport.setReport(hhsumByTeam);
  192.                 }else if(reportType.equalsIgnoreCase("eligibilityByTeam")){
  193.                     aimsReport.setReport(eligibilityByTeam);
  194.                 }else if(reportType.equalsIgnoreCase("HouseholdByGenderByTeam")){
  195.                     aimsReport.setReport(HouseholdByGenderByTeam);
  196.                 }else if(reportType.equalsIgnoreCase("ageMissmatchByTeam")){
  197.                     aimsReport.setReport(ageMissmatchByTeam);
  198.                 }else if(reportType.equalsIgnoreCase("durationByTeam")){
  199.                     aimsReport.setReport(durationByTeam);
  200.                 }else if(reportType.equalsIgnoreCase("ResponseRateByDistrict")){
  201.                     aimsReport.setReport(ResponseRateByDistrict);
  202.                 }else if(reportType.equalsIgnoreCase("ResponseRateByEA")){
  203.                     aimsReport.setReport(ResponseRateByEA);
  204.                 }else if(reportType.equalsIgnoreCase("BiomarkerByEA")){
  205.                     aimsReport.setReport(BiomarkerByEA);
  206.                 }else if(reportType.equalsIgnoreCase("ConsenttoLinkagetoCare")){
  207.                     aimsReport.setReport(ConsenttoLinkagetoCare);
  208.                 }else if(reportType.equalsIgnoreCase("DMValidatedByHHno")){
  209.                     aimsReport.setReport(DMValidatedByHHno);
  210.                 }else if(reportType.equalsIgnoreCase("PTIDbyCaseNumber")){
  211.                     aimsReport.setReport(PTIDbyCaseNumber);
  212.                 }else if(reportType.equalsIgnoreCase("DailyAchievementSummary")){
  213.                     aimsReport.setReport(DailyAchievementSummary);
  214.                 }
  215.                 databaseService.updateAimsReport(aimsReport, STR_AIMS_REPORTS);
  216.                 // System.out.println("update" );
  217.  
  218.             } else {
  219.                 if (reportType.equalsIgnoreCase("hhsumByTeam")) {
  220.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, durationByTeam);
  221.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  222.                 } else if (reportType.equalsIgnoreCase("ResponseRateByEA")) {
  223.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ResponseRateByEA);
  224.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  225.                 } else if (reportType.equalsIgnoreCase("BiomarkerByEA")) {
  226.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, BiomarkerByEA);
  227.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  228.                 } else if (reportType.equalsIgnoreCase("durationByTeam")) {
  229.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, durationByTeam);
  230.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  231.                 } else if (reportType.equalsIgnoreCase("eligibilityByTeam")) {
  232.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, eligibilityByTeam);
  233.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  234.                 } else if (reportType.equalsIgnoreCase("HouseholdByGenderByTeam")) {
  235.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, HouseholdByGenderByTeam);
  236.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  237.                 } else if (reportType.equalsIgnoreCase("ageMissmatchByTeam")) {
  238.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ageMissmatchByTeam);
  239.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  240.                 } else if (reportType.equalsIgnoreCase("PTIDbyCaseNumber")) {
  241.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, PTIDbyCaseNumber);
  242.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  243.                 } else if (reportType.equalsIgnoreCase("DMValidatedByHHno")) {
  244.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, DMValidatedByHHno);
  245.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  246.                 } else if (reportType.equalsIgnoreCase("ResponseRateByDistrict")) {
  247.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, ResponseRateByDistrict);
  248.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  249.                 } else if (reportType.equalsIgnoreCase("DailyAchievementSummary")) {
  250.                     AimsReports hhsumByTeam1 = new AimsReports(UUID.randomUUID().toString(), finalCountry, project, reportType, DailyAchievementSummary);
  251.                     databaseService.updateAimsReport(hhsumByTeam1, STR_AIMS_REPORTS);
  252.  
  253.                 }
  254.             }
  255.         });
  256.  
  257.     }
  258. }
  259.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×