Commit 2b080106 authored by Saroj Singh's avatar Saroj Singh
Browse files

resolve master conflict

1 merge request!9Cvs download
Showing with 777 additions and 118 deletions
+777 -118
......@@ -12,7 +12,11 @@ import org.apache.tomcat.util.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -290,6 +294,9 @@ public class FormsController {
String validation = validationService.validateInspectionObject(incomingData);
if (validation.equals(Constants.ResponseCodes.SUCCESS)) {
IncomingData inspectionData = new IncomingData();
inspectionData.setInspectionCompleted(incomingData.getInspectionCompleted());
inspectionData.setLatitude(incomingData.getLatitude());
inspectionData.setLongitude(incomingData.getLongitude());
inspectionData.setInspectorDataObject(incomingData);
inspectionData.setApplicationId(incomingData.getApplicationId());
inspectionData.setInspectorSummaryDataObject(incomingData.getInspectorSummaryDataObject());
......@@ -487,4 +494,17 @@ public class FormsController {
}
return ResponseGenerator.failureResponse(Constants.ResponseMessages.ERROR_MESSAGE);
}
@GetMapping(value = PathRoutes.FormServiceApi.GET_INSTITUTE_FORM_DATA_EXCEL)
public ResponseEntity<Resource> getFile(@RequestParam(value = Constants.ORG_ID, required = true) Long orgId) {
String filename = "institute.xlsx";
InputStreamResource file = new InputStreamResource(formsService.getInstituteFormData(orgId));
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.body(file);
}
}
package com.tarento.formservice.dao;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.tarento.formservice.models.InstituteCourses;
import com.tarento.formservice.models.InstitueFormExcelDto;
@Repository
public interface InstituteCoursesDao extends CrudRepository<InstituteCourses, Long>{
@Query(value = "select distinct ic.district_name, ic.center_code, u.username,ic.degree, ic.course from institute_courses ic "
+ " inner join user u on (u.id = ic.profile_id) where u.org_id = :orgId" ,
nativeQuery=true )
List<Object[]> findInstituteForm(Long orgId);
}
......@@ -12,6 +12,7 @@ public class IncomingData {
private Long id;
private Long formId;
private String title;
private String districtName;
private String applicationId;
private String recordId;
private int version;
......@@ -33,5 +34,8 @@ public class IncomingData {
private String reviewedDate;
private String inspectionDate;
private String inspectionCompletedDate;
private Boolean inspectionCompleted = Boolean.FALSE;
private Double latitude;
private Double longitude;
}
package com.tarento.formservice.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Data
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class InstituteFormDataDto {
private String districtCode;
private String centerCode;
private String instituteName;
private String degree;
private String course;
private String formsSavedAsDraft;
private String formsSubmitted;
private String formsSubmittedTimestamp;
}
package com.tarento.formservice.models;
import lombok.Data;
@Data
public class InstitueFormExcelDto {
private String districtName;
private String centerCode;
private String firstName;
}
package com.tarento.formservice.models;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@AllArgsConstructor
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@Setter
@ToString
@Entity
@Table(name = "institute_courses")
public class InstituteCourses {
@Id @GeneratedValue
@Column(name = "id")
private Long id;
@Column(name = "district_name")
private String districtName;
@Column(name = "center_code")
private String centerCode;
@Column(name = "degree")
private String degree;
@Column(name = "course")
private String course;
@Column(name = "applied_year")
private String appliedYear;
@Column(name = "sector")
private String sector;
@Column(name = "profile_id")
private Long profileId; //Fk UserProfile
@Column(name = "created_date")
private Date createdDate;
@Column(name = "created_by")
private Long createdBy;
@Column(name = "updated_date")
private Date updatedDate;
@Column(name = "updated_by")
private Long updatedBy;
}
package com.tarento.formservice.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonProperty;
@Entity
@Table(name = "role")
public class Role {
@Id @GeneratedValue
@Column(name = "id")
private Long id;
private String description;
private String code;
private String name;
private Long orgId;
private boolean isSuperAdmin;
@JsonProperty("isAdmin")
private boolean isAdmin;
private Long createdBy;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public boolean isAdmin() {
return isAdmin;
}
public void setAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
public Long getOrgId() {
return orgId;
}
public void setOrgId(Long orgId) {
this.orgId = orgId;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isSuperAdmin() {
return isSuperAdmin;
}
public void setSuperAdmin(boolean isSuperAdmin) {
this.isSuperAdmin = isSuperAdmin;
}
}
package com.tarento.formservice.models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* This class holds the information about the User's basic authentication along
* with Mail ID.
*
* @author Darshan Nagesh
*
*/
@Entity
@Table(name = "user")
public class User {
@Id @GeneratedValue
@Column(name = "id")
private Long id;
private String username;
private String password;
private String emailId;
private String phoneNo;
private String orgId;
private String countryCode;
private String timeZone;
private String avatarUrl;
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getTimeZone() {
return timeZone;
}
public void setTimeZone(String timeZone) {
this.timeZone = timeZone;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
private Boolean isActive;
private Boolean isDeleted;
@JsonProperty("authToken")
private String authToken;
public String getOrgId() {
return orgId;
}
public void setOrgId(String orgId) {
this.orgId = orgId;
}
public String getAuthToken() {
return authToken;
}
public void setAuthToken(String authToken) {
this.authToken = authToken;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
public Boolean getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
}
package com.tarento.formservice.models;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* This model contains the User Profile Information for a User
*
* @author Darshan Nagesh
*
*/
@Data
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "user_profile")
public class UserProfile {
@Id @GeneratedValue
@Column(name = "id")
private Long profileId;
@Column(name = "user_id")
private Long userId;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
@Column(name = "age")
private int age;
@Column(name = "phone_number")
private String phoneNo;
@Column(name = "dob")
private String dob;
@Column(name = "gender")
private String gender;
@Column(name = "avatar_url")
private String avatarUrl;
@Column(name = "user_profilecol")
private String userProfilecol;
@Column(name = "work_start_date")
private Date startDate;
@Column(name = "work_end_date")
private Date endDate;
@Column(name = "salary")
private Long salary;
@Column(name = "country")
private String country;
@Column(name = "registration_date")
private Date registrationDate;
@Column(name = "employment_type")
private String employmentType;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "created_by")
private Long createdBy;
@Column(name = "updated_date")
private Date updatedDate;
@Column(name = "updated_by")
private Long updatedBy;
}
package com.tarento.formservice.service;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
......@@ -69,4 +70,6 @@ public interface FormsService {
public void consentBulkApplication(List<Consent> consentList, UserInfo userInfo);
public ByteArrayInputStream getInstituteFormData(Long orgId);
}
package com.tarento.formservice.service.impl;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
......@@ -14,6 +15,18 @@ import java.util.stream.Collectors;
import com.opencsv.CSVWriter;
import com.tarento.formservice.model.*;
import org.apache.commons.io.FileUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;
......@@ -46,14 +59,36 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponentsBuilder;
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;
import com.tarento.formservice.model.Assignee;
import com.tarento.formservice.model.Consent;
import com.tarento.formservice.model.IncomingData;
import com.tarento.formservice.model.InstituteFormDataDto;
import com.tarento.formservice.model.KeyValue;
import com.tarento.formservice.model.KeyValueList;
import com.tarento.formservice.model.ResponseData;
import com.tarento.formservice.model.Result;
import com.tarento.formservice.model.Role;
import com.tarento.formservice.model.Roles;
import com.tarento.formservice.model.SearchObject;
import com.tarento.formservice.model.SearchRequestDto;
import com.tarento.formservice.model.State;
import com.tarento.formservice.model.StateMatrix;
import com.tarento.formservice.model.Status;
import com.tarento.formservice.model.UserInfo;
import com.tarento.formservice.model.WorkflowDto;
import com.tarento.formservice.models.Field;
import com.tarento.formservice.models.Form;
import com.tarento.formservice.models.FormDetail;
import com.tarento.formservice.models.InstitueFormExcelDto;
import com.tarento.formservice.repository.ElasticSearchRepository;
import com.tarento.formservice.repository.RestService;
import com.tarento.formservice.service.ActivityService;
......@@ -62,6 +97,7 @@ import com.tarento.formservice.utils.AppConfiguration;
import com.tarento.formservice.utils.CloudStorage;
import com.tarento.formservice.utils.Constants;
import com.tarento.formservice.utils.DateUtils;
import com.tarento.formservice.utils.ExcelHelper;
import com.tarento.formservice.utils.WorkflowUtil;
import com.tarento.formservice.utils.NotificationService.NotificationUtil;
......@@ -84,6 +120,9 @@ public class FormsServiceImpl implements FormsService {
@Autowired
private ActivityService activityService;
@Autowired
InstituteCoursesDao instituteCoursesDao;
@Override
public Form createForm(FormDetail newForm) throws IOException {
......@@ -298,73 +337,75 @@ public class FormsServiceImpl implements FormsService {
return formsDao.updateFormData(jsonMap, id);
}
@Override
public List<Map<String, Object>> getApplications(UserInfo userInfo, SearchRequestDto searchRequestDto) {
try {
// query builder
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
setRoleBasedSearchObject(userInfo, searchRequestDto);
setRoleBasedExcludeSearchObject(userInfo, searchRequestDto);
if (searchRequestDto != null) {
if (searchRequestDto.getSearchObjects() != null) {
for (SearchObject objects : searchRequestDto.getSearchObjects()) {
String key = objects.getKey();
Object values = objects.getValues();
if (Constants.ElasticSearchFields.MAPPING.containsKey(key)) {
boolBuilder.must().add(
QueryBuilders.termsQuery(Constants.ElasticSearchFields.MAPPING.get(key), values));
/*
* boolBuilder.must()
* .add(QueryBuilders.matchQuery(Constants.ElasticSearchFields.MAPPING.get(key),
* values));
*/
} else {
// In the case where UI tries to send random values which are not configured in
// our ES Mapping, the API should send empty set as a response.
// So here, we just query as empty set and we know that we will get empty set as
// a response
boolBuilder.must().add(QueryBuilders.matchQuery(Constants.EMPTY_SET, Constants.EMPTY_SET));
}
}
}
if (searchRequestDto.getExcludeObject() != null) {
for (SearchObject objects : searchRequestDto.getExcludeObject()) {
String key = objects.getKey();
Object values = objects.getValues();
if (Constants.ElasticSearchFields.MAPPING.containsKey(key)) {
boolBuilder.mustNot().add(
QueryBuilders.termsQuery(Constants.ElasticSearchFields.MAPPING.get(key), values));
/*
* boolBuilder.must()
* .add(QueryBuilders.matchQuery(Constants.ElasticSearchFields.MAPPING.get(key),
* values));
*/
} else {
// In the case where UI tries to send random values which are not configured in
// our ES Mapping, the API should send empty set as a response.
// So here, we just query as empty set and we know that we will get empty set as
// a response
boolBuilder.must().add(QueryBuilders.matchQuery(Constants.EMPTY_SET, Constants.EMPTY_SET));
}
}
}
}
searchSourceBuilder.query(boolBuilder).sort(Constants.TIMESTAMP, SortOrder.DESC);
// es call
SearchRequest searchRequest = new SearchRequest(appConfig.getFormDataIndex()).source(searchSourceBuilder);
LOGGER.info("Search Request : " + searchRequest);
List<Map<String, Object>> response = formsDao.searchResponse(searchRequest);
if (searchRequestDto != null && searchRequestDto.getFilterObjects() != null) {
return filterSearchResults(response, searchRequestDto.getFilterObjects(), userInfo);
}
return response;
} catch (Exception e) {
LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
}
return null;
}
@Override
public List<Map<String, Object>> getApplications(UserInfo userInfo, SearchRequestDto searchRequestDto) {
try {
// query builder
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
setRoleBasedSearchObject(userInfo, searchRequestDto);
setRoleBasedExcludeSearchObject(userInfo, searchRequestDto);
if (searchRequestDto != null) {
if (searchRequestDto.getSearchObjects() != null) {
for (SearchObject objects : searchRequestDto.getSearchObjects()) {
String key = objects.getKey();
Object values = objects.getValues();
if (Constants.ElasticSearchFields.MAPPING.containsKey(key)) {
boolBuilder.must().add(
QueryBuilders.termsQuery(Constants.ElasticSearchFields.MAPPING.get(key), values));
/*
* boolBuilder.must()
* .add(QueryBuilders.matchQuery(Constants.ElasticSearchFields.MAPPING.get(key),
* values));
*/
} else {
// In the case where UI tries to send random values which are not configured in
// our ES Mapping, the API should send empty set as a response.
// So here, we just query as empty set and we know that we will get empty set as
// a response
boolBuilder.must().add(QueryBuilders.matchQuery(Constants.EMPTY_SET, Constants.EMPTY_SET));
}
}
}
if (searchRequestDto.getExcludeObject() != null) {
for (SearchObject objects : searchRequestDto.getExcludeObject()) {
String key = objects.getKey();
Object values = objects.getValues();
if (Constants.ElasticSearchFields.MAPPING.containsKey(key)) {
boolBuilder.mustNot().add(
QueryBuilders.termsQuery(Constants.ElasticSearchFields.MAPPING.get(key), values));
/*
* boolBuilder.must()
* .add(QueryBuilders.matchQuery(Constants.ElasticSearchFields.MAPPING.get(key),
* values));
*/
} else {
// In the case where UI tries to send random values which are not configured in
// our ES Mapping, the API should send empty set as a response.
// So here, we just query as empty set and we know that we will get empty set as
// a response
boolBuilder.must().add(QueryBuilders.matchQuery(Constants.EMPTY_SET, Constants.EMPTY_SET));
}
}
}
}
searchSourceBuilder.query(boolBuilder).sort(Constants.TIMESTAMP, SortOrder.DESC);
// es call
SearchRequest searchRequest = new SearchRequest(appConfig.getFormDataIndex()).source(searchSourceBuilder);
LOGGER.info("Search Request : " + searchRequest);
List<Map<String, Object>> response = formsDao.searchResponse(searchRequest);
if (searchRequestDto != null && searchRequestDto.getFilterObjects() != null) {
return filterSearchResults(response, searchRequestDto.getFilterObjects(), userInfo);
}
return response;
} catch (Exception e) {
LOGGER.error(String.format(Constants.EXCEPTION, "getApplications", e.getMessage()));
}
return null;
}
@Override
public String getInstitutesData(UserInfo userInfo, InstituteDownloadRequestDto instituteDownloadRequestDto) {
......@@ -986,6 +1027,7 @@ public class FormsServiceImpl implements FormsService {
}
return null;
}
public ConcurrentMap<Long, State> fetchAllStates() {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000);
......@@ -1004,7 +1046,7 @@ public class FormsServiceImpl implements FormsService {
LOGGER.info("Search Request : " + searchRequest);
return formsDao.fetchAllStateMatrix(searchRequest);
}
@Override
public Boolean updateApplicationStatus(IncomingData incomingData, UserInfo userInfo, String status) {
try {
......@@ -1049,57 +1091,72 @@ public class FormsServiceImpl implements FormsService {
}
@Override
public Boolean submitInspection(IncomingData incomingData, UserInfo userInfo) {
try {
Map<String, Object> applicationMap = getApplicationById(incomingData.getApplicationId(), userInfo);
if (applicationMap != null) {
IncomingData applicationData = objectMapper.convertValue(applicationMap, IncomingData.class);
// get workflow next status
WorkflowDto workflowDto = new WorkflowDto(applicationData, userInfo,
Constants.WorkflowActions.COMPLETED_INSPECTION);
WorkflowUtil.getNextStateForMyRequest(workflowDto);
// update assignee inspection status in data object
Boolean isLeadIns = Boolean.FALSE;
Boolean inspectionCompleted = Boolean.TRUE;
if (applicationData != null && applicationData.getInspection() != null
&& applicationData.getInspection().getAssignedTo() != null) {
for (Assignee assignee : applicationData.getInspection().getAssignedTo()) {
if (assignee.getId().equals(userInfo.getId()) && assignee.getLeadInspector() != null
&& assignee.getLeadInspector()) {
isLeadIns = Boolean.TRUE;
assignee.setStatus(workflowDto.getNextState());
assignee.setConsentDate(DateUtils.getYyyyMmDdInUTC());
} else if (StringUtils.isBlank(assignee.getStatus())) {
inspectionCompleted = Boolean.FALSE;
}
}
}
// allow only lead inspector to submit inspection details
if (isLeadIns) {
incomingData.setInspection(applicationData.getInspection());
incomingData.setInspectionDate(DateUtils.getYyyyMmDdInUTC());
incomingData.getInspection().setInspectionDate(DateUtils.getYyyyMmDdInUTC());
String nextStatus = inspectionCompleted ? workflowDto.getNextState()
: Status.LEADINSCOMPLETED.name();
incomingData.getInspection().setStatus(nextStatus);
if (inspectionCompleted) {
incomingData.setStatus(workflowDto.getNextState());
incomingData.setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
incomingData.getInspection().setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
}
Boolean response = saveFormSubmitv1(incomingData, userInfo,
inspectionCompleted ? Constants.WorkflowActions.COMPLETED_INSPECTION
: Constants.WorkflowActions.LEAD_INSPECTION_COMPLETED);
return response;
}
}
} catch (Exception e) {
LOGGER.error(String.format(Constants.EXCEPTION, "submitInspection", e.getMessage()));
}
return Boolean.FALSE;
}
@Override
public Boolean submitInspection(IncomingData incomingData, UserInfo userInfo) {
try {
Boolean inspectionCompleted = incomingData.getInspectionCompleted();
Map<String, Object> applicationMap = getApplicationById(incomingData.getApplicationId(), userInfo);
if (applicationMap != null) {
IncomingData applicationData = objectMapper.convertValue(applicationMap, IncomingData.class);
// get workflow next status
WorkflowDto workflowDto = new WorkflowDto(applicationData, userInfo,
Constants.WorkflowActions.COMPLETED_INSPECTION);
WorkflowUtil.getNextStateForMyRequest(workflowDto);
// update assignee inspection status in data object
Boolean isLeadIns = Boolean.FALSE;
if (applicationData != null && applicationData.getInspection() != null
&& applicationData.getInspection().getAssignedTo() != null) {
for (Assignee assignee : applicationData.getInspection().getAssignedTo()) {
if (assignee.getId().equals(userInfo.getId()) && assignee.getLeadInspector() != null
&& assignee.getLeadInspector()) {
isLeadIns = Boolean.TRUE;
assignee.setStatus(workflowDto.getNextState());
if(incomingData.getInspectionCompleted()) {
assignee.setStatus(Constants.WorkflowActions.COMPLETED_INSPECTION);
}
assignee.setConsentDate(DateUtils.getYyyyMmDdInUTC());
} /*else if (StringUtils.isBlank(assignee.getStatus())) {
inspectionCompleted = Boolean.FALSE;
}*/
}
}
// allow only lead inspector to submit inspection details
//if (isLeadIns) {
incomingData.setInspection(applicationData.getInspection());
incomingData.setInspectionDate(DateUtils.getYyyyMmDdInUTC());
incomingData.getInspection().setInspectionDate(DateUtils.getYyyyMmDdInUTC());
/*
String nextStatus = inspectionCompleted ? workflowDto.getNextState()
: Status.LEADINSCOMPLETED.name();
*/
String nextStatus = inspectionCompleted ? Status.INSCOMPLETED.name()
: Status.LEADINSCOMPLETED.name();
incomingData.getInspection().setStatus(nextStatus);
if (inspectionCompleted) {
incomingData.setStatus(workflowDto.getNextState());
incomingData.setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
incomingData.getInspection().setInspectionCompletedDate(DateUtils.getYyyyMmDdInUTC());
}
Boolean response = saveFormSubmitv1(incomingData, userInfo,
inspectionCompleted ? Constants.WorkflowActions.COMPLETED_INSPECTION
: Constants.WorkflowActions.LEAD_INSPECTION_COMPLETED);
return response;
//}
}
} catch (Exception e) {
LOGGER.error(String.format(Constants.EXCEPTION, "submitInspection", e.getMessage()));
}
return Boolean.FALSE;
}
/**
* Creates an async operation to send notification & update activity logs on
......@@ -1159,6 +1216,7 @@ public class FormsServiceImpl implements FormsService {
return null;
}
}
@Override
public Boolean consentApplication(Consent consent, UserInfo userInfo) {
......@@ -1206,7 +1264,7 @@ public class FormsServiceImpl implements FormsService {
}
return Boolean.FALSE;
}
@Override
public void submitBulkInspection(List<IncomingData> inspectionDataList, UserInfo userInfo) {
new Thread(() -> {
......@@ -1232,6 +1290,7 @@ public class FormsServiceImpl implements FormsService {
}
}).start();
}
@Override
public List<Map<String, Object>> getAllPlainForms() {
......@@ -1252,6 +1311,8 @@ public class FormsServiceImpl implements FormsService {
}
return null;
}
@Override
public List<Map<String, Object>> getPlainFormsById(String id) {
......@@ -1274,4 +1335,67 @@ public class FormsServiceImpl implements FormsService {
return null;
}
@Override
public ByteArrayInputStream getInstituteFormData(Long orgId) {
List<InstituteFormDataDto> dataList = new ArrayList<InstituteFormDataDto>();
List<Object[]> dataListDto = instituteCoursesDao.findInstituteForm(orgId);
for(Object[] dto : dataListDto) {
InstituteFormDataDto data = new InstituteFormDataDto();
data.setCenterCode(String.valueOf(dto[0]));
data.setDistrictCode(String.valueOf(dto[1]));
String emailId = String.valueOf(dto[2]);
data.setInstituteName(emailId);
data.setDegree(String.valueOf(dto[3]));
data.setCourse(String.valueOf(dto[4]));
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);
}
}
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;
}
}
......@@ -103,6 +103,7 @@ public interface Constants {
public static final String UP_SMF = "up-smf";
public static final String _ID = "_id";
public static final String ID = "id";
public static final String ORG_ID = "orgId";
public static final String FORM_ID = "formId";
public static final String APPLICATION_ID = "applicationId";
public static final String STATUS = "status";
......
package com.tarento.formservice.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.tarento.formservice.model.InstituteFormDataDto;
public class ExcelHelper {
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";
public static ByteArrayInputStream instituteToExcel(List<InstituteFormDataDto> dataList) {
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream();) {
Sheet sheet = workbook.createSheet(SHEET);
// Header
Row headerRow = sheet.createRow(0);
for (int col = 0; col < HEADERs.length; col++) {
Cell cell = headerRow.createCell(col);
cell.setCellValue(HEADERs[col]);
}
int rowIdx = 1;
for (InstituteFormDataDto data : dataList) {
Row row = sheet.createRow(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(6).setCellValue(data.getFormsSavedAsDraft());
row.createCell(7).setCellValue(data.getFormsSubmitted());
row.createCell(8).setCellValue(data.getFormsSubmittedTimestamp());
}
workbook.write(out);
return new ByteArrayInputStream(out.toByteArray());
} catch (IOException e) {
throw new RuntimeException("fail to import data to Excel file: " + e.getMessage());
}
}
}
......@@ -31,6 +31,7 @@ public interface PathRoutes {
final String SAVE_PLAIN_FORM = "/v1/savePlainForm";
final String GET_ALL_PLAIN_FORMS = "/getAllPlainForms";
final String GET_PLAIN_FORM_BY_ID = "/getPlainFormById";
final String GET_INSTITUTE_FORM_DATA_EXCEL="/getInstituteFormDataInExcel";
}
public interface JsonFormServiceApi {
......
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