diff --git a/src/main/java/com/tarento/formservice/controllers/FormsController.java b/src/main/java/com/tarento/formservice/controllers/FormsController.java index 7beed6941ed5361b4edb60edb5ce8123751558a2..aba07d5655738ac31dea2917d9e16b1b9703c8c7 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 ea37cc92b62bfd9a3259521c572167d7897e2e5e..fdea2eb2e7bcdfb1bde1a1b09c0445e1a50a28e3 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 f38c5036c1c7e72334bed3f25d3055940223e058..a7c51c12de30e9a6ea0c487424a8e04d5d5bf9f2 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 2a8546f72b5b3690ab9681c908d97ca03ec8d9b1..fc459b16803c0400b8516068d2b8e2adc069a59c 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);