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
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
<org.projectlombok.version>1.16.18</org.projectlombok.version>
<environment>${ENV_VAR}</environment>
<!-- <environment>test</environment>-->
Copy link
Member

Choose a reason for hiding this comment

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

remove comments

<target-properties>target/classes/application.properties</target-properties>
<source-properties>target/classes/admin_${environment}.properties</source-properties>

Expand All @@ -54,6 +55,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 All @@ -73,6 +78,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -181,12 +191,7 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</exclusion>
</exclusions>

</dependency>

<!-- start newly added dependencies -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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 jakarta.servlet.http.HttpServletRequest;
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.lang.reflect.Method;
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;

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

@CrossOrigin()
@PostMapping(value = "/bulkRegistration", headers = "Authorization")
public ResponseEntity<Map<String, Object>> registerBulkUser(@RequestBody String m_user, @RequestHeader String authorization) {
bulkRegistrationServiceimpl.bulkRegistrationErrors.clear();
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());
Comment on lines +51 to +53
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Improve encapsulation by avoiding direct field access.

The controller directly accesses service implementation fields, violating encapsulation principles.

Add getter methods to the service interface and implementation:

-response.put("totalUser", bulkRegistrationServiceimpl.totalEmployeeListSize);
-response.put("registeredUser", bulkRegistrationServiceimpl.m_bulkUser.size());
-response.put("error", bulkRegistrationServiceimpl.errorLogs.toString());
+response.put("totalUser", bulkRegistrationService.getTotalEmployeeCount());
+response.put("registeredUser", bulkRegistrationService.getRegisteredUserCount());
+response.put("error", bulkRegistrationService.getErrorLogs());

Committable suggestion skipped: line range outside the PR's diff.

πŸ€– Prompt for AI Agents
In
src/main/java/com/iemr/admin/controller/bulkRegistration/BulkRegistrationController.java
around lines 51 to 53, the controller directly accesses fields of
bulkRegistrationServiceimpl, breaking encapsulation. To fix this, add
appropriate getter methods in the service interface and implement them in the
service class to expose totalEmployeeListSize, m_bulkUser size, and errorLogs
safely. Then update the controller to call these getters instead of accessing
fields directly.


bulkRegistrationServiceimpl.m_bulkUser.clear();
bulkRegistrationServiceimpl.m_UserDemographics.clear();
bulkRegistrationServiceimpl.errorLogs.clear();
bulkRegistrationServiceimpl.totalEmployeeListSize=0;

} catch (Exception e) {
response.put("message", e.getMessage());
response.put("statusCode", 500);

}
return ResponseEntity.ok(response);

}

@CrossOrigin()
@GetMapping("/download-error-sheet")
public ResponseEntity<byte[]> downloadErrorSheet() {
try {
byte[] fileContent = bulkRegistrationServiceimpl.insertErrorLog();

HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment; filename=error_log.xlsx");

if(!bulkRegistrationServiceimpl.bulkRegistrationErrors.isEmpty()){
bulkRegistrationServiceimpl.bulkRegistrationErrors.clear();
}
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(fileContent);

} catch (Exception e) {
return ResponseEntity.status(500).body(null);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.iemr.admin.data.bulkuser;

import lombok.Data;

import java.util.List;

@Data
public class BulkRegistrationError {
String userName;
Integer rowNumber;
List<String> error;
}
102 changes: 102 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,102 @@
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 = "DateOfBirth")
private String dob="";

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

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

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

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

@JacksonXmlProperty(localName = "PAN")
private String pan="";
Comment on lines +47 to +51
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Add validation for sensitive data fields.

The Aadhaar and PAN fields should include validation annotations to ensure data integrity and security.

Consider adding validation annotations:

 @JacksonXmlProperty(localName = "AadhaarNo")
+@Pattern(regexp = "\\d{12}", message = "Aadhaar number must be 12 digits")
 private String aadhaarNo="";

 @JacksonXmlProperty(localName = "PAN")
+@Pattern(regexp = "^[A-Z]{5}[0-9]{4}[A-Z]{1}$", message = "Invalid PAN format")
 private String pan="";
πŸ“ 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
@JacksonXmlProperty(localName = "AadhaarNo")
private String aadhaarNo="";
@JacksonXmlProperty(localName = "PAN")
private String pan="";
@JacksonXmlProperty(localName = "AadhaarNo")
@Pattern(regexp = "\\d{12}", message = "Aadhaar number must be 12 digits")
private String aadhaarNo="";
@JacksonXmlProperty(localName = "PAN")
@Pattern(regexp = "^[A-Z]{5}[0-9]{4}[A-Z]{1}$", message = "Invalid PAN format")
private String pan="";
πŸ€– Prompt for AI Agents
In src/main/java/com/iemr/admin/data/bulkuser/Employee.java around lines 47 to
51, the AadhaarNo and PAN fields lack validation annotations. Add appropriate
validation annotations such as @NotBlank and pattern-based constraints (e.g.,
@Pattern) to enforce correct formats and ensure data integrity and security for
these sensitive fields.


@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 = "CurrentAddressLine1")
private String addressLine1="";

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

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

@JacksonXmlProperty(localName = "CurrentPincode")
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="";

@JacksonXmlProperty(localName = "UserName")
private String UserName="";

@JacksonXmlProperty(localName = "Password")
private String Password="";
Comment on lines +95 to +99
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix field naming convention violations.

Fields UserName and Password should follow Java camelCase convention.

Apply this diff to fix the naming:

-    @JacksonXmlProperty(localName = "UserName")
-    private String UserName="";
+    @JacksonXmlProperty(localName = "UserName")
+    private String userName="";

-    @JacksonXmlProperty(localName = "Password")
-    private String Password="";
+    @JacksonXmlProperty(localName = "Password")
+    private String password="";
πŸ“ 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
@JacksonXmlProperty(localName = "UserName")
private String UserName="";
@JacksonXmlProperty(localName = "Password")
private String Password="";
@JacksonXmlProperty(localName = "UserName")
private String userName="";
@JacksonXmlProperty(localName = "Password")
private String password="";
πŸ€– Prompt for AI Agents
In src/main/java/com/iemr/admin/data/bulkuser/Employee.java around lines 95 to
99, the field names UserName and Password violate Java camelCase naming
conventions. Rename these fields to userName and password respectively, updating
all references accordingly to maintain consistency and adhere to standard Java
naming practices.



}
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
Expand Up @@ -36,8 +36,7 @@

@Entity
@Table(name = "m_Religion")
public class M_Religion
{
public class M_Religion {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ public interface EmployeeMasterRepoo extends CrudRepository<M_User1, Integer>
@Query("SELECT u FROM M_User1 u WHERE u.userID=:userID AND deleted=false")
M_User1 editEmployee(@Param("userID") Integer userID);

@Query("SELECT u FROM M_User1 u WHERE u.aadhaarNo=:aadhaar AND deleted=false ")
M_User1 findEmployeeAadhaarNo(@Param("aadhaar") String userName);
Comment on lines +43 to +44
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Ensure proper handling of sensitive Aadhaar data.

The method handles Aadhaar numbers which are sensitive personal information. Ensure that:

  1. Input validation is performed at the service layer
  2. Audit logging is implemented for Aadhaar number queries
  3. Database column for aadhaarNo is properly indexed for performance
πŸ€– Prompt for AI Agents
In src/main/java/com/iemr/admin/repo/employeemaster/EmployeeMasterRepoo.java
around lines 43 to 44, the method querying Aadhaar numbers needs enhanced
handling for sensitive data. Ensure input validation for the Aadhaar number is
done in the service layer before calling this repository method. Implement audit
logging in the service layer to record queries involving Aadhaar numbers for
traceability. Verify that the database column for aadhaarNo is indexed to
optimize query performance.


@Query("SELECT u FROM M_User1 u WHERE u.userName=:userName AND deleted=false ")
M_User1 findEmployeeByName(@Param("userName") String userName);


@Query("SELECT u FROM M_User1 u WHERE u.contactNo=:contactNo AND deleted=false ")
M_User1 findEmployeeByContact(@Param("contactNo") String userName);

@Query("SELECT u FROM M_User1 u WHERE u.userName=:userName OR u.aadhaarNo=:aadhaarNo OR u.pAN=:getpAN OR u.employeeID=:employeeID OR u.healthProfessionalID=:healthProfessionalID AND deleted=false ")
M_User1 checkingEmpDetails(@Param("userName") String userName, @Param("aadhaarNo") String aadhaarNo,
@Param("getpAN") String getpAN,@Param("employeeID") String employeeID, @Param("healthProfessionalID") String healthProfessionalID);
Expand Down
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
Loading