Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.iemr.admin.controller.bulkRegistration;

import com.iemr.admin.repo.employeemaster.EmployeeMasterRepoo;
import com.iemr.admin.service.bulkRegistration.BulkRegistrationService;
import com.iemr.admin.service.bulkRegistration.BulkRegistrationServiceImpl;
import com.iemr.admin.service.bulkRegistration.EmployeeXmlService;
import com.iemr.admin.service.locationmaster.LocationMasterServiceInter;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController

public class BulkRegistrationController {
@Autowired
private EmployeeXmlService employeeXmlService;
@Autowired
BulkRegistrationServiceImpl bulkRegistrationServiceimpl;
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());


@Autowired
BulkRegistrationService bulkRegistrationService;
Comment on lines +24 to +32
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ› ๏ธ Refactor suggestion

Avoid injecting both interface and implementation directly.

Having both bulkRegistrationService and bulkRegistrationServiceimpl fields may lead to confusion or inconsistent usage. Typically, you should stick to injecting the interface for a cleaner design.

-@Autowired
-BulkRegistrationServiceImpl bulkRegistrationServiceimpl;
 ...
 @Autowired
 BulkRegistrationService bulkRegistrationService;
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Autowired
private EmployeeXmlService employeeXmlService;
@Autowired
BulkRegistrationServiceImpl bulkRegistrationServiceimpl;
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
@Autowired
BulkRegistrationService bulkRegistrationService;
@Autowired
private EmployeeXmlService employeeXmlService;
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
@Autowired
BulkRegistrationService bulkRegistrationService;


@Autowired
private EmployeeMasterRepoo employeeMasterRepoo;
private Map<String, Object> errorResponse = new HashMap<>();
@Autowired
private LocationMasterServiceInter locationMasterServiceInter;
private Map<String, Object> response = new HashMap<>();


@RequestMapping(value = "/bulkRegistration",method = RequestMethod.POST,headers = "Authorization")
public ResponseEntity<Map<String, Object>> registerBulkUser(@RequestBody String m_user,@RequestHeader String authorization) throws Exception {
logger.info("Bulk registration request received. Request payload is omitted from logs.");
try {
bulkRegistrationService.registerBulkUser(m_user,authorization);
response.put("status","Success");
response.put("statusCode",200);
response.put("totalUser",bulkRegistrationServiceimpl.totalEmployeeListSize);
response.put("registeredUser",bulkRegistrationServiceimpl.m_bulkUser.size());
response.put("error",bulkRegistrationServiceimpl.errorLogs.toString());

bulkRegistrationServiceimpl.m_bulkUser.clear();
bulkRegistrationServiceimpl.m_UserDemographics.clear();
bulkRegistrationServiceimpl.errorLogs.clear();
bulkRegistrationServiceimpl.validationErrors.clear();

} catch (Exception e) {
response.put("status","Fail");
response.put("statusCode",500);
throw new RuntimeException(e);
}
return ResponseEntity.ok(response);

}
@Operation(description = "Download formatted Excel sheet")
@RequestMapping(value = {"/downloadExcelSheet"},method = {RequestMethod.GET},consumes = {"application/octet-stream"})
public ResponseEntity<?> exportIntoExcelFile(){

// Load the Excel file from resources
ClassPathResource excelFile = new ClassPathResource("xlsxfile/bulkuser_excel_sheet.xlsx");

// Return the Excel file as a response with proper headers
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + excelFile.getFilename() + "\"")
.body(excelFile);
}



}
94 changes: 94 additions & 0 deletions src/main/java/com/iemr/admin/data/bulkuser/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.iemr.admin.data.bulkuser;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Data;

@Data
@JacksonXmlRootElement(localName = "Employee")
public class Employee {

@JacksonXmlProperty(localName = "Title")
private String title;

@JacksonXmlProperty(localName = "FirstName")
private String firstName;

@JacksonXmlProperty(localName = "MiddleName")
private String middleName;

@JacksonXmlProperty(localName = "LastName")
private String lastName;

@JacksonXmlProperty(localName = "Gender")
private String gender;

@JacksonXmlProperty(localName = "ContactNo")
private String contactNo;

@JacksonXmlProperty(localName = "Designation")
private String designation;

@JacksonXmlProperty(localName = "EmergencyContactNo")
private String emergencyContactNo;

@JacksonXmlProperty(localName = "DOB")
private String dob;

@JacksonXmlProperty(localName = "Age")
private int age;

@JacksonXmlProperty(localName = "Email")
private String email;

@JacksonXmlProperty(localName = "MaritalStatus")
private String maritalStatus;

@JacksonXmlProperty(localName = "AadhaarNo")
private String aadhaarNo;

@JacksonXmlProperty(localName = "PAN")
private String pan;

@JacksonXmlProperty(localName = "Qualification")
private String qualification;

@JacksonXmlProperty(localName = "FatherName")
private String fatherName;

@JacksonXmlProperty(localName = "MotherName")
private String motherName;

@JacksonXmlProperty(localName = "Community")
private String community;

@JacksonXmlProperty(localName = "Religion")
private String religion;

@JacksonXmlProperty(localName = "AddressLine1")
private String addressLine1;

@JacksonXmlProperty(localName = "State")
private String state;

@JacksonXmlProperty(localName = "District")
private String district;

@JacksonXmlProperty(localName = "Pincode")
private String pincode;

@JacksonXmlProperty(localName = "PermanentAddressLine1")
private String permanentAddressLine1;

@JacksonXmlProperty(localName = "PermanentState")
private String permanentState;

@JacksonXmlProperty(localName = "PermanentDistrict")
private String permanentDistrict;

@JacksonXmlProperty(localName = "PermanentPincode")
private String permanentPincode;

@JacksonXmlProperty(localName = "DateOfJoining")
private String dateOfJoining;
}
17 changes: 17 additions & 0 deletions src/main/java/com/iemr/admin/data/bulkuser/EmployeeList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.iemr.admin.data.bulkuser;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Data;

import java.util.List;

@Data
@JacksonXmlRootElement(localName = "Employees")
public class EmployeeList {

@JsonProperty("Employee")
@JacksonXmlElementWrapper(useWrapping = false) // To avoid extra nested array in XML
private List<Employee> employees;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.iemr.admin.service.bulkRegistration;

public interface BulkRegistrationService {
void registerBulkUser(String user,String authorization);
}
Loading