From 4db6bd5430852a0dfcf6b1b2642e28da3a6d8b2f Mon Sep 17 00:00:00 2001 From: sarojsingh2021 <saroj.kumarsingh@tarento.com> Date: Tue, 6 Dec 2022 19:14:20 +0530 Subject: [PATCH] clean code --- .../controllers/FormsController.java | 1 + .../model/InstituteFormDataDto.java | 3 -- .../service/impl/FormsServiceImpl.java | 47 ++++++++++++++++--- .../formservice/utils/ExcelHelper.java | 11 ++--- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/tarento/formservice/controllers/FormsController.java b/src/main/java/com/tarento/formservice/controllers/FormsController.java index 7beed69..aba07d5 100644 --- a/src/main/java/com/tarento/formservice/controllers/FormsController.java +++ b/src/main/java/com/tarento/formservice/controllers/FormsController.java @@ -486,6 +486,7 @@ public class FormsController { } return ResponseGenerator.failureResponse(Constants.ResponseMessages.ERROR_MESSAGE); } + @GetMapping(value = PathRoutes.FormServiceApi.GET_INSTITUTE_FORM_DATA_EXCEL) public ResponseEntity<Resource> getFile(@RequestBody InstituteFormDataRequest instituteFormDataRequest) { String filename = "institute.xlsx"; diff --git a/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java b/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java index ea37cc9..fdea2eb 100644 --- a/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java +++ b/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java @@ -11,7 +11,6 @@ import lombok.Setter; @Setter @NoArgsConstructor @AllArgsConstructor - public class InstituteFormDataDto { private String districtCode; @@ -19,8 +18,6 @@ public class InstituteFormDataDto { private String instituteName; private String degree; private String course; - //private String nursingCouseOffered; - //private String paramedicalCourseOffered; private String formsSavedAsDraft; private String formsSubmitted; private String formsSubmittedTimestamp; diff --git a/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java b/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java index f38c503..a7c51c1 100644 --- a/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java +++ b/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java @@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -14,6 +15,7 @@ import java.util.Random; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.lang3.StringUtils; import org.elasticsearch.action.search.MultiSearchResponse; import org.elasticsearch.action.search.SearchRequest; @@ -49,6 +51,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; +import com.mchange.v2.codegen.bean.BeangenUtils; import com.tarento.formservice.dao.FormsDao; import com.tarento.formservice.dao.InstituteCoursesDao; import com.tarento.formservice.model.AssignApplication; @@ -1122,18 +1125,50 @@ public class FormsServiceImpl implements FormsService { InstituteFormDataDto data = new InstituteFormDataDto(); data.setCenterCode(String.valueOf(dto[0])); data.setDistrictCode(String.valueOf(dto[1])); - data.setInstituteName(String.valueOf(dto[2])); + String emailId = String.valueOf(dto[2]); + + data.setInstituteName(emailId); data.setDegree(String.valueOf(dto[3])); data.setCourse(String.valueOf(dto[4])); - dataList.add(data); + List<Map<String, Object>> responseData = this.getApplicationForInstitues(emailId); + if(responseData != null && responseData.size()>0) { + for(Map<String, Object> mp : responseData) { + InstituteFormDataDto dInnernal = new InstituteFormDataDto(); + try { + BeanUtils.copyProperties(dInnernal, data); + dInnernal.setFormsSubmitted(String.valueOf(mp.get("title"))); + dInnernal.setFormsSavedAsDraft(String.valueOf(mp.get("status"))); + dInnernal.setFormsSubmittedTimestamp(String.valueOf(mp.get("timestamp"))); + dataList.add(dInnernal); + + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + }else { + dataList.add(data); + } + + } - System.out.println("************************"); - System.out.println(dataList.size()); - System.out.println("***********************"); - ByteArrayInputStream in = ExcelHelper.instituteToExcel(dataList); return in; } + + public List<Map<String, Object>> getApplicationForInstitues(String emailId){ + SearchRequestDto searchRequestDto = new SearchRequestDto(); + SearchObject searchObject = new SearchObject(); + searchObject.setKey("createdBy"); + searchObject.setValues(emailId); + + List<SearchObject> searchObjects = new ArrayList<>(); + searchObjects.add(searchObject); + + searchRequestDto.setSearchObjects(searchObjects); + List<Map<String, Object>> responseData = this.getApplications(null, searchRequestDto); + + return responseData; + } } diff --git a/src/main/java/com/tarento/formservice/utils/ExcelHelper.java b/src/main/java/com/tarento/formservice/utils/ExcelHelper.java index 2a8546f..fc459b1 100644 --- a/src/main/java/com/tarento/formservice/utils/ExcelHelper.java +++ b/src/main/java/com/tarento/formservice/utils/ExcelHelper.java @@ -15,7 +15,6 @@ import com.tarento.formservice.model.InstituteFormDataDto; public class ExcelHelper { - //static String[] HEADERs = { "SI","District Name", "Parent Training Center Code", "Name of Institution", "Nursing course offered(Y/N)", "Paramedical course offered(Y/N)", "Forms(s) saved as draft", "Forms(s) submitted", "Timestamp of forms(s) submission" }; static String[] HEADERs = { "SI","District Name", "Parent Training Center Code", "Name of Institution", "Degree", "Course", "Forms(s) saved as draft", "Forms(s) submitted", "Timestamp of forms(s) submission" }; static String SHEET = "Institute and forms Details"; @@ -38,17 +37,15 @@ public class ExcelHelper { for (InstituteFormDataDto data : dataList) { Row row = sheet.createRow(rowIdx++); - row.createCell(0).setCellValue(rowIdx); + row.createCell(0).setCellValue(rowIdx-1); row.createCell(1).setCellValue(data.getDistrictCode()); row.createCell(2).setCellValue(data.getCenterCode()); row.createCell(3).setCellValue(data.getInstituteName()); row.createCell(4).setCellValue(data.getDegree()); row.createCell(5).setCellValue(data.getCourse()); - //row.createCell(4).setCellValue(data.getNursingCouseOffered()); - //row.createCell(5).setCellValue(data.getParamedicalCourseOffered()); - //row.createCell(6).setCellValue(data.getFormsSavedAsDraft()); - //row.createCell(7).setCellValue(data.getFormsSubmitted()); - //row.createCell(8).setCellValue(data.getFormsSubmittedTimestamp()); + row.createCell(6).setCellValue(data.getFormsSavedAsDraft()); + row.createCell(7).setCellValue(data.getFormsSubmitted()); + row.createCell(8).setCellValue(data.getFormsSubmittedTimestamp()); } workbook.write(out); -- GitLab