From 0a6877ea0a167b4b3df03c9650a4eb68e097bd31 Mon Sep 17 00:00:00 2001 From: yashita-egov Date: Mon, 6 Jan 2025 12:48:08 +0530 Subject: [PATCH 1/2] added localityCode in individual while creation --- .../egov/hrms/service/EmployeeService.java | 13 +++++++++++- .../egov/hrms/service/IndividualService.java | 20 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java index ceb95f160b..0afd18e22e 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java @@ -103,6 +103,9 @@ public class EmployeeService { @Autowired private ObjectMapper objectMapper; + @Autowired + private IndividualService individualService; + /** * Service method for create employee. Does following: * 1. Sets ids to all the objects using idgen service. @@ -264,7 +267,15 @@ private void createUser(Employee employee, RequestInfo requestInfo) { enrichUser(employee); UserRequest request = UserRequest.builder().requestInfo(requestInfo).user(employee.getUser()).build(); try { - UserResponse response = userService.createUser(request); + UserResponse response; + if(userService instanceof IndividualService) { + String localityCode = (employee.getJurisdictions()!=null && !employee.getJurisdictions().isEmpty())? employee.getJurisdictions().get(0).getBoundary() : null; + response = individualService.createUserByLocality(request, localityCode); + } + else{ + response = userService.createUser(request); + } + User user = response.getUser().get(0); employee.setId(UUID.fromString(user.getUuid()).getMostSignificantBits()); employee.setUuid(user.getUuid()); diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java index 37f03382a8..49bba43906 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java @@ -49,7 +49,7 @@ public IndividualService(PropertiesManager propertiesManager, @Override public UserResponse createUser(UserRequest userRequest) { - IndividualRequest request = mapToIndividualRequest(userRequest); + IndividualRequest request = mapToIndividualRequest(userRequest, null); StringBuilder uri = new StringBuilder(); uri.append(propertiesManager.getIndividualHost()); uri.append(propertiesManager.getIndividualCreateEndpoint()); @@ -63,6 +63,21 @@ public UserResponse createUser(UserRequest userRequest) { return userResponse; } + public UserResponse createUserByLocality(UserRequest userRequest, String localityCode) { + IndividualRequest request = mapToIndividualRequest(userRequest,localityCode); + StringBuilder uri = new StringBuilder(); + uri.append(propertiesManager.getIndividualHost()); + uri.append(propertiesManager.getIndividualCreateEndpoint()); + IndividualResponse response = restCallRepository + .fetchResult(uri, request, IndividualResponse.class); + UserResponse userResponse = null; + if (response != null && response.getIndividual() != null) { + log.info("response received from individual service"); + userResponse = mapToUserResponse(response); + } + return userResponse; + } + /** * Updates a user by searching for the corresponding individual and updating their details. * @@ -250,7 +265,7 @@ private static Date convertMillisecondsToDate(long milliseconds) { } } - private static IndividualRequest mapToIndividualRequest(UserRequest userRequest) { + private static IndividualRequest mapToIndividualRequest(UserRequest userRequest, String localityCode) { Individual individual = Individual.builder() .id(userRequest.getUser().getUuid()) .userId(userRequest.getUser().getId() != null ? @@ -270,6 +285,7 @@ private static IndividualRequest mapToIndividualRequest(UserRequest userRequest) .type(AddressType.CORRESPONDENCE) .addressLine1(userRequest.getUser().getCorrespondenceAddress()) .clientReferenceId(String.valueOf(UUID.randomUUID())) + .locality(Boundary.builder().code(localityCode).build()) .isDeleted(Boolean.FALSE) .build())) /* From 60b3d2a28321ec49897ff27e3c4fc6716feac662 Mon Sep 17 00:00:00 2001 From: yashita-egov Date: Mon, 27 Jan 2025 10:48:38 +0530 Subject: [PATCH 2/2] resolved coderabbit comment --- .../src/main/java/org/egov/hrms/service/IndividualService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java index 49bba43906..17302f58b1 100644 --- a/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java +++ b/core-services/egov-hrms/src/main/java/org/egov/hrms/service/IndividualService.java @@ -285,7 +285,7 @@ private static IndividualRequest mapToIndividualRequest(UserRequest userRequest, .type(AddressType.CORRESPONDENCE) .addressLine1(userRequest.getUser().getCorrespondenceAddress()) .clientReferenceId(String.valueOf(UUID.randomUUID())) - .locality(Boundary.builder().code(localityCode).build()) + .locality((localityCode!=null) ? Boundary.builder().code(localityCode).build() : null) .isDeleted(Boolean.FALSE) .build())) /*