diff --git a/src/main/java/com/tarento/formservice/controllers/FormsController.java b/src/main/java/com/tarento/formservice/controllers/FormsController.java index 2e6b9262f5ce89d5a6e70aecc041a6df29e7f9ba..7beed6941ed5361b4edb60edb5ce8123751558a2 100644 --- a/src/main/java/com/tarento/formservice/controllers/FormsController.java +++ b/src/main/java/com/tarento/formservice/controllers/FormsController.java @@ -11,7 +11,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; @@ -36,6 +40,7 @@ import com.tarento.formservice.model.Status; import com.tarento.formservice.model.UserInfo; import com.tarento.formservice.models.Form; import com.tarento.formservice.models.FormDetail; +import com.tarento.formservice.models.InstituteFormDataRequest; import com.tarento.formservice.service.FormsService; import com.tarento.formservice.utils.Constants; import com.tarento.formservice.utils.PathRoutes; @@ -481,4 +486,16 @@ 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"; + InputStreamResource file = new InputStreamResource(formsService.getInstituteFormData(instituteFormDataRequest.getOrgId())); + + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename) + .contentType(MediaType.parseMediaType("application/vnd.ms-excel")) + .body(file); + } + + } diff --git a/src/main/java/com/tarento/formservice/dao/InstituteCoursesDao.java b/src/main/java/com/tarento/formservice/dao/InstituteCoursesDao.java new file mode 100644 index 0000000000000000000000000000000000000000..5aa2898db233258b1664170836d28afe6d207c88 --- /dev/null +++ b/src/main/java/com/tarento/formservice/dao/InstituteCoursesDao.java @@ -0,0 +1,21 @@ +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); + +} diff --git a/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java b/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java new file mode 100644 index 0000000000000000000000000000000000000000..ea37cc92b62bfd9a3259521c572167d7897e2e5e --- /dev/null +++ b/src/main/java/com/tarento/formservice/model/InstituteFormDataDto.java @@ -0,0 +1,27 @@ +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 nursingCouseOffered; + //private String paramedicalCourseOffered; + private String formsSavedAsDraft; + private String formsSubmitted; + private String formsSubmittedTimestamp; +} diff --git a/src/main/java/com/tarento/formservice/models/InstitueFormExcelDto.java b/src/main/java/com/tarento/formservice/models/InstitueFormExcelDto.java new file mode 100644 index 0000000000000000000000000000000000000000..948393ba13625cc822fc303ab6b5fea5eada83b8 --- /dev/null +++ b/src/main/java/com/tarento/formservice/models/InstitueFormExcelDto.java @@ -0,0 +1,12 @@ +package com.tarento.formservice.models; + +import lombok.Data; + +@Data +public class InstitueFormExcelDto { + + private String districtName; + private String centerCode; + private String firstName; + +} diff --git a/src/main/java/com/tarento/formservice/models/InstituteCourses.java b/src/main/java/com/tarento/formservice/models/InstituteCourses.java new file mode 100644 index 0000000000000000000000000000000000000000..7e0921c86e14bfc4efdbcabdaf1a6b8734629099 --- /dev/null +++ b/src/main/java/com/tarento/formservice/models/InstituteCourses.java @@ -0,0 +1,55 @@ +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; + +} diff --git a/src/main/java/com/tarento/formservice/models/InstituteFormDataRequest.java b/src/main/java/com/tarento/formservice/models/InstituteFormDataRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..43b19c0fc326b982c91eeea1c5c460837510b74b --- /dev/null +++ b/src/main/java/com/tarento/formservice/models/InstituteFormDataRequest.java @@ -0,0 +1,10 @@ +package com.tarento.formservice.models; + +import lombok.Data; + +@Data +public class InstituteFormDataRequest { + + private Long orgId; + +} diff --git a/src/main/java/com/tarento/formservice/models/Role.java b/src/main/java/com/tarento/formservice/models/Role.java new file mode 100644 index 0000000000000000000000000000000000000000..ad5c419b05c846a75be9e69f0ee85c7e13d87333 --- /dev/null +++ b/src/main/java/com/tarento/formservice/models/Role.java @@ -0,0 +1,97 @@ +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; + } +} diff --git a/src/main/java/com/tarento/formservice/models/User.java b/src/main/java/com/tarento/formservice/models/User.java new file mode 100644 index 0000000000000000000000000000000000000000..6ad6f328098e6c64d289dcf54d777ee9ebfd1089 --- /dev/null +++ b/src/main/java/com/tarento/formservice/models/User.java @@ -0,0 +1,144 @@ +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; + } + +} diff --git a/src/main/java/com/tarento/formservice/models/UserProfile.java b/src/main/java/com/tarento/formservice/models/UserProfile.java new file mode 100644 index 0000000000000000000000000000000000000000..e089a9d0f26e44abfdecd2510e0ed6fcc19a5685 --- /dev/null +++ b/src/main/java/com/tarento/formservice/models/UserProfile.java @@ -0,0 +1,96 @@ +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; + + + +} diff --git a/src/main/java/com/tarento/formservice/service/FormsService.java b/src/main/java/com/tarento/formservice/service/FormsService.java index e87ef79e666fd34e6719e6cead21136887db5630..34b5a6e615a904115180aae3fa440dbec34a38a7 100644 --- a/src/main/java/com/tarento/formservice/service/FormsService.java +++ b/src/main/java/com/tarento/formservice/service/FormsService.java @@ -1,5 +1,6 @@ package com.tarento.formservice.service; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List; import java.util.Map; @@ -75,4 +76,6 @@ public interface FormsService { public void consentBulkApplication(List<Consent> consentList, UserInfo userInfo); + public ByteArrayInputStream getInstituteFormData(Long orgId); + } 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 3d667c798794048f6df45bbde3b7e8145a50ba47..f38c5036c1c7e72334bed3f25d3055940223e058 100644 --- a/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java +++ b/src/main/java/com/tarento/formservice/service/impl/FormsServiceImpl.java @@ -1,5 +1,6 @@ package com.tarento.formservice.service.impl; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -43,15 +44,18 @@ 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.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; @@ -68,6 +72,7 @@ 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; @@ -76,6 +81,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; @@ -98,6 +104,9 @@ public class FormsServiceImpl implements FormsService { @Autowired private ActivityService activityService; + + @Autowired + InstituteCoursesDao instituteCoursesDao; @Override public Form createForm(FormDetail newForm) throws IOException { @@ -1101,5 +1110,30 @@ 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])); + data.setInstituteName(String.valueOf(dto[2])); + data.setDegree(String.valueOf(dto[3])); + data.setCourse(String.valueOf(dto[4])); + dataList.add(data); + } + + System.out.println("************************"); + System.out.println(dataList.size()); + System.out.println("***********************"); + + ByteArrayInputStream in = ExcelHelper.instituteToExcel(dataList); + return in; + } } diff --git a/src/main/java/com/tarento/formservice/utils/ExcelHelper.java b/src/main/java/com/tarento/formservice/utils/ExcelHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..2a8546f72b5b3690ab9681c908d97ca03ec8d9b1 --- /dev/null +++ b/src/main/java/com/tarento/formservice/utils/ExcelHelper.java @@ -0,0 +1,60 @@ +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", "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"; + + + 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); + 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()); + } + + workbook.write(out); + return new ByteArrayInputStream(out.toByteArray()); + } catch (IOException e) { + throw new RuntimeException("fail to import data to Excel file: " + e.getMessage()); + } + } +} diff --git a/src/main/java/com/tarento/formservice/utils/PathRoutes.java b/src/main/java/com/tarento/formservice/utils/PathRoutes.java index 162a218e2a4ed17487981fea171f6c1ead74c375..12a44a8d57cbee8a2701a10bda4edcf6ef89945e 100644 --- a/src/main/java/com/tarento/formservice/utils/PathRoutes.java +++ b/src/main/java/com/tarento/formservice/utils/PathRoutes.java @@ -30,6 +30,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 {