Commit 4db6bd54 authored by sarojsingh2021's avatar sarojsingh2021
Browse files

clean code

Showing with 46 additions and 16 deletions
+46 -16
......@@ -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";
......
......@@ -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;
......
......@@ -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;
}
}
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment