Skip to content

Commit

Permalink
added localityCode in individual while creation (#1324)
Browse files Browse the repository at this point in the history
* added localityCode in individual while creation

* resolved coderabbit comment
  • Loading branch information
yashita-egov authored Jan 28, 2025
1 parent cd342c6 commit 6301026
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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.
*
Expand Down Expand Up @@ -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 ?
Expand All @@ -270,6 +285,7 @@ private static IndividualRequest mapToIndividualRequest(UserRequest userRequest)
.type(AddressType.CORRESPONDENCE)
.addressLine1(userRequest.getUser().getCorrespondenceAddress())
.clientReferenceId(String.valueOf(UUID.randomUUID()))
.locality((localityCode!=null) ? Boundary.builder().code(localityCode).build() : null)
.isDeleted(Boolean.FALSE)
.build()))
/*
Expand Down

0 comments on commit 6301026

Please sign in to comment.