Skip to content

Commit 1a633a5

Browse files
committed
state, district and fileTpe AjaxController
1 parent bc862e7 commit 1a633a5

4 files changed

Lines changed: 301 additions & 7 deletions

File tree

src/main/java/com/health/config/SecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public static BCryptPasswordEncoder passwordEncoder() {
6060
"/downloadHealthTutorials/**", "/Training-Resource/**", "/Training-Resources/**",
6161
"/loadLanAndFileTypeByTopic/**", "/loadTopicAndFileTypeByLan/**", "/loadTopicAndLanByFileType/**",
6262
"/downloadTrainingResource/**", "/shared-Training-Resource/**", "/shared-training-resource-file/**",
63-
"/check-deployment", "/training-resources/view-share/**" };
63+
"/check-deployment", "/training-resources/view-share/**", "/loadDistrictAndFileTypeByState/**",
64+
"/loadStateAndFileTypeByDistrict/**", "/loadStateAndDistrictByFileType/**", "/Project-Reports/**" };
6465

6566
/**
6667
* url matcher for SUPERADMIN

src/main/java/com/health/controller/AjaxController.java

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.health.model.PromoVideo;
7979
import com.health.model.ResearchPaper;
8080
import com.health.model.State;
81+
import com.health.model.StateDistrictMapping;
8182
import com.health.model.Testimonial;
8283
import com.health.model.Topic;
8384
import com.health.model.TopicCategoryMapping;
@@ -117,6 +118,7 @@
117118
import com.health.service.PromoVideoService;
118119
import com.health.service.ResearchPaperService;
119120
import com.health.service.RoleService;
121+
import com.health.service.StateDistrictMappingService;
120122
import com.health.service.StateService;
121123
import com.health.service.TestimonialService;
122124
import com.health.service.TopicCategoryMappingService;
@@ -300,6 +302,9 @@ public class AjaxController {
300302
@Autowired
301303
private ProjectReportService projectReportService;
302304

305+
@Autowired
306+
private StateDistrictMappingService stateDistrictMappingService;
307+
303308
@Value("${downloadLimit}")
304309
private int downloadLimit;
305310

@@ -2444,6 +2449,227 @@ public ResponseEntity<String> deleteProjectReport(@RequestParam("projectReportId
24442449
}
24452450
}
24462451

2452+
/*
2453+
* Function to load District and FileType by State Author: Alok Kumar
2454+
*/
2455+
2456+
@RequestMapping("/loadDistrictAndFileTypeByState")
2457+
public @ResponseBody ArrayList<Map<String, Integer>> getDistrictAndFileTypeByState(
2458+
@RequestParam(value = "stateId") int stateId, @RequestParam(value = "districtId") int districtId,
2459+
@RequestParam(value = "fileTypeId") int fileTypeId) {
2460+
2461+
ArrayList<Map<String, Integer>> arlist = new ArrayList<>();
2462+
2463+
Map<String, Integer> fileTypes = new TreeMap<>();
2464+
2465+
Map<String, Integer> districts = new TreeMap<>();
2466+
2467+
State state = stateId != 0 ? stateService.findById(stateId) : null;
2468+
District district = districtId != 0 ? disService.findById(districtId) : null;
2469+
Map<Integer, String> fileTypeIdAndValue = fileTypeId != 0 ? ServiceUtility.getFileTypeIdAndValue(fileTypeId)
2470+
: null;
2471+
2472+
List<StateDistrictMapping> localStateDistrictList = new ArrayList<>();
2473+
2474+
// To find FileTypes
2475+
if (state != null && district != null) {
2476+
StateDistrictMapping sdm = stateDistrictMappingService.findByStateAndDistrict(state, district);
2477+
if (sdm != null)
2478+
localStateDistrictList.add(sdm);
2479+
} else if (state != null) {
2480+
localStateDistrictList = stateDistrictMappingService.findByState(state);
2481+
} else {
2482+
localStateDistrictList = stateDistrictMappingService.findAll();
2483+
}
2484+
2485+
List<ProjectReport> prList = projectReportService
2486+
.findByStateDistrictMappingInAndStatusTrue(localStateDistrictList);
2487+
2488+
if (!prList.isEmpty()) {
2489+
2490+
for (ProjectReport temp : prList) {
2491+
2492+
ServiceUtility.getFileTypeIdAndValueforProjectReport(temp)
2493+
.forEach((id, type) -> fileTypes.put(type, id));
2494+
2495+
}
2496+
}
2497+
2498+
// to find districts
2499+
if (state != null) {
2500+
localStateDistrictList = stateDistrictMappingService.findByState(state);
2501+
} else {
2502+
localStateDistrictList = stateDistrictMappingService.findAll();
2503+
}
2504+
2505+
prList = projectReportService.findByStateDistrictMappingInAndStatusTrue(localStateDistrictList);
2506+
List<ProjectReport> newprList1 = new ArrayList<>();
2507+
if (fileTypeIdAndValue != null && !fileTypeIdAndValue.isEmpty()) {
2508+
Map.Entry<Integer, String> entry = fileTypeIdAndValue.entrySet().iterator().next();
2509+
int id = entry.getKey();
2510+
for (ProjectReport temp : prList) {
2511+
if (ServiceUtility.isProjectReportFilePresent(temp, id)) {
2512+
newprList1.add(temp);
2513+
}
2514+
}
2515+
}
2516+
if (!newprList1.isEmpty())
2517+
prList = newprList1;
2518+
2519+
for (ProjectReport pr : prList) {
2520+
2521+
District dis = pr.getStateDistrictMapping().getDistrict();
2522+
districts.put(dis.getDistrictName(), dis.getId());
2523+
2524+
}
2525+
2526+
arlist.add(districts);
2527+
arlist.add(fileTypes);
2528+
2529+
return arlist;
2530+
2531+
}
2532+
2533+
/*
2534+
* Function to load State and FileType by District Author: Alok Kumar
2535+
*/
2536+
2537+
@RequestMapping("/loadStateAndFileTypeByDistrict")
2538+
public @ResponseBody ArrayList<Map<String, Integer>> getStateAndFileTypeByDistrict(
2539+
@RequestParam(value = "stateId") int stateId, @RequestParam(value = "districtId") int districtId,
2540+
@RequestParam(value = "fileTypeId") int fileTypeId) {
2541+
ArrayList<Map<String, Integer>> arlist = new ArrayList<>();
2542+
2543+
Map<String, Integer> states = new TreeMap<>();
2544+
Map<String, Integer> fileTypes = new TreeMap<>();
2545+
2546+
State state = stateId != 0 ? stateService.findById(stateId) : null;
2547+
District district = districtId != 0 ? disService.findById(districtId) : null;
2548+
Map<Integer, String> fileTypeIdAndValue = fileTypeId != 0 ? ServiceUtility.getFileTypeIdAndValue(fileTypeId)
2549+
: null;
2550+
2551+
List<StateDistrictMapping> sdm = district != null ? stateDistrictMappingService.findByDistrict(district)
2552+
: stateDistrictMappingService.findAll();
2553+
List<ProjectReport> prList = projectReportService.findByStateDistrictMappingInAndStatusTrue(sdm);
2554+
List<ProjectReport> newprList = new ArrayList<>();
2555+
if (fileTypeIdAndValue != null && !fileTypeIdAndValue.isEmpty()) {
2556+
Map.Entry<Integer, String> entry = fileTypeIdAndValue.entrySet().iterator().next();
2557+
int id = entry.getKey();
2558+
for (ProjectReport temp : prList) {
2559+
if (ServiceUtility.isProjectReportFilePresent(temp, id)) {
2560+
newprList.add(temp);
2561+
}
2562+
}
2563+
}
2564+
2565+
if (!newprList.isEmpty())
2566+
prList = newprList;
2567+
2568+
for (ProjectReport pr : prList) {
2569+
// To find State
2570+
State stateTemp = pr.getStateDistrictMapping().getState();
2571+
int prStateId = stateTemp.getId();
2572+
states.put(stateTemp.getStateName(), stateTemp.getId());
2573+
2574+
// To find FileType
2575+
if (stateId == 0 || prStateId == stateId) {
2576+
ServiceUtility.getFileTypeIdAndValueforProjectReport(pr).forEach((id, type) -> fileTypes.put(type, id));
2577+
}
2578+
2579+
}
2580+
2581+
arlist.add(states);
2582+
arlist.add(fileTypes);
2583+
2584+
return arlist;
2585+
2586+
}
2587+
2588+
/*
2589+
* Function to load State and District by FileType Author: Alok Kumar
2590+
*/
2591+
2592+
@RequestMapping("/loadStateAndDistrictByFileType")
2593+
public @ResponseBody ArrayList<Map<String, Integer>> getStateAndDistrictByFileType(
2594+
@RequestParam(value = "stateId") int stateId, @RequestParam(value = "districtId") int districtId,
2595+
@RequestParam(value = "fileTypeId") int fileTypeId) {
2596+
2597+
ArrayList<Map<String, Integer>> arlist = new ArrayList<>();
2598+
Map<String, Integer> states = new TreeMap<>();
2599+
Map<String, Integer> districts = new TreeMap<>();
2600+
2601+
State state = stateId != 0 ? stateService.findById(stateId) : null;
2602+
District district = districtId != 0 ? disService.findById(districtId) : null;
2603+
2604+
Map<Integer, String> fileTypeIdAndValue = fileTypeId != 0 ? ServiceUtility.getFileTypeIdAndValue(fileTypeId)
2605+
: null;
2606+
2607+
List<StateDistrictMapping> localstateDistrictList = new ArrayList<>();
2608+
if (district != null) {
2609+
localstateDistrictList = stateDistrictMappingService.findByDistrict(district);
2610+
} else {
2611+
localstateDistrictList = stateDistrictMappingService.findAll();
2612+
}
2613+
2614+
List<ProjectReport> prList = projectReportService
2615+
.findByStateDistrictMappingInAndStatusTrue(localstateDistrictList);
2616+
List<ProjectReport> newprList = new ArrayList<>();
2617+
if (fileTypeIdAndValue != null && !fileTypeIdAndValue.isEmpty()) {
2618+
Map.Entry<Integer, String> entry = fileTypeIdAndValue.entrySet().iterator().next();
2619+
int id = entry.getKey();
2620+
for (ProjectReport temp : prList) {
2621+
if (ServiceUtility.isProjectReportFilePresent(temp, id)) {
2622+
newprList.add(temp);
2623+
}
2624+
}
2625+
}
2626+
2627+
if (!newprList.isEmpty())
2628+
prList = newprList;
2629+
2630+
for (ProjectReport pr : prList) {
2631+
// To find State
2632+
State stateTemp = pr.getStateDistrictMapping().getState();
2633+
states.put(stateTemp.getStateName(), stateTemp.getId());
2634+
2635+
}
2636+
2637+
// to find districts
2638+
2639+
if (state != null) {
2640+
localstateDistrictList = stateDistrictMappingService.findByState(state);
2641+
} else {
2642+
localstateDistrictList = stateDistrictMappingService.findAll();
2643+
}
2644+
2645+
prList = projectReportService.findByStateDistrictMappingInAndStatusTrue(localstateDistrictList);
2646+
List<ProjectReport> newprList1 = new ArrayList<>();
2647+
if (fileTypeIdAndValue != null && !fileTypeIdAndValue.isEmpty()) {
2648+
Map.Entry<Integer, String> entry = fileTypeIdAndValue.entrySet().iterator().next();
2649+
int id = entry.getKey();
2650+
for (ProjectReport temp : prList) {
2651+
if (ServiceUtility.isProjectReportFilePresent(temp, id)) {
2652+
newprList1.add(temp);
2653+
}
2654+
}
2655+
}
2656+
if (!newprList1.isEmpty())
2657+
prList = newprList1;
2658+
2659+
for (ProjectReport pr : prList) {
2660+
2661+
District dis = pr.getStateDistrictMapping().getDistrict();
2662+
districts.put(dis.getDistrictName(), dis.getId());
2663+
2664+
}
2665+
2666+
arlist.add(states);
2667+
arlist.add(districts);
2668+
2669+
return arlist;
2670+
2671+
}
2672+
24472673
/********************************** Projet Report End *************************/
24482674

24492675
@RequestMapping("/loadTopicByCategoryInAssignContri")

src/main/java/com/health/controller/HomeController.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,31 @@ private void getModelTrainingResource(Model model) {
921921
getModelTrainingResource(model, 0, 0, 0);
922922
}
923923

924+
private void getModelProjectReport(Model model, int stateId, int districtId, int fileTypeId) {
925+
926+
ArrayList<Map<String, Integer>> arlist = ajaxController.getDistrictAndFileTypeByState(stateId, districtId,
927+
fileTypeId);
928+
ArrayList<Map<String, Integer>> arlist1 = ajaxController.getStateAndFileTypeByDistrict(stateId, districtId,
929+
fileTypeId);
930+
Map<String, Integer> states = arlist1.get(0);
931+
Map<String, Integer> fileType = arlist1.get(1);
932+
Map<String, Integer> districts = arlist.get(0);
933+
934+
model.addAttribute("states", states);
935+
model.addAttribute("districts", districts);
936+
model.addAttribute("fileTypes", fileType);
937+
938+
model.addAttribute("localState", stateId);
939+
model.addAttribute("localDistrict", districtId);
940+
model.addAttribute("localFile", fileTypeId);
941+
model.addAttribute("districtCount", districts.size());
942+
943+
}
944+
945+
private void getModelProjectReport(Model model) {
946+
getModelProjectReport(model, 0, 0, 0);
947+
}
948+
924949
@RequestMapping("/")
925950
public String index(Model model) {
926951

@@ -7591,7 +7616,7 @@ public String viewAndDownloadProjectReport(HttpServletRequest req,
75917616
State state = stateId != 0 ? stateService.findById(stateId) : null;
75927617
District district = districtId != 0 ? districtService.findById(districtId) : null;
75937618
if (state == null || district == null || inputFileType == 0) {
7594-
// getModelTrainingResource(model);
7619+
getModelProjectReport(model);
75957620

75967621
model.addAttribute("error_msg", "Please select all fields");
75977622
return "projectReports";
@@ -7611,7 +7636,7 @@ public String viewAndDownloadProjectReport(HttpServletRequest req,
76117636
StateDistrictMapping sdm = stateDistrictMappingService.findByStateAndDistrict(state, district);
76127637
List<ProjectReport> prList = projectReportService.findByStateDistrictMapping(sdm);
76137638
if (prList.isEmpty() || prList.size() > 1) {
7614-
// getModelTrainingResource(model);
7639+
getModelProjectReport(model);
76157640
model.addAttribute("error_msg", "Invalid Data");
76167641
return "projectReports";
76177642
}
@@ -7633,7 +7658,7 @@ public String viewAndDownloadProjectReport(HttpServletRequest req,
76337658

76347659
String filePath = ServiceUtility.getProjectReportFilePath(pr, inputFileType);
76357660
if (filePath.isEmpty()) {
7636-
// getModelTrainingResource(model);
7661+
getModelProjectReport(model);
76377662
model.addAttribute("error_msg", "No File Found");
76387663
return "projectReports";
76397664
}
@@ -7726,7 +7751,7 @@ public String viewAndDownloadProjectReport(HttpServletRequest req,
77267751

77277752
if (allowed) {
77287753
model.addAttribute("pageIndexes", pageIndexes);
7729-
// model.addAttribute("filePaths", filePaths);
7754+
77307755
model.addAttribute("fileNames", fileNames);
77317756
}
77327757

@@ -7745,7 +7770,7 @@ public String viewAndDownloadProjectReport(HttpServletRequest req,
77457770
District localDistrict = null;
77467771
String localFile = null;
77477772

7748-
// getModelTrainingResource(model, topicId, lanId, inputFileType);
7773+
getModelProjectReport(model, stateId, districtId, inputFileType);
77497774

77507775
if (stateId != 0) {
77517776
localState = stateService.findById(stateId);
@@ -7760,7 +7785,7 @@ public String viewAndDownloadProjectReport(HttpServletRequest req,
77607785
model.addAttribute("fileTypeQuery", localFile);
77617786
}
77627787

7763-
return "trainingResources";
7788+
return "projectReports";
77647789
}
77657790

77667791
/************************ Project Report End ********************************/

0 commit comments

Comments
 (0)