-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added controller, service layer, validator and enrichment layer for p…
…lan employee assignment
- Loading branch information
1 parent
bb72eeb
commit 293f1d8
Showing
22 changed files
with
938 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ervices/plan-service/src/main/java/digit/repository/PlanEmployeeAssignmentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package digit.repository; | ||
|
||
import digit.web.models.PlanEmployeeAssignmentRequest; | ||
|
||
public interface PlanEmployeeAssignmentRepository { | ||
|
||
public void create(PlanEmployeeAssignmentRequest planEmployeeAssignmentRequest); | ||
|
||
public void update(PlanEmployeeAssignmentRequest planEmployeeAssignmentRequest); | ||
} |
39 changes: 39 additions & 0 deletions
39
...services/plan-service/src/main/java/digit/repository/impl/PlanEmployeeAssignmentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package digit.repository.impl; | ||
|
||
import digit.config.Configuration; | ||
import digit.kafka.Producer; | ||
import digit.repository.PlanEmployeeAssignmentRepository; | ||
import digit.web.models.PlanEmployeeAssignmentRequest; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class PlanEmployeeAssignmentImpl implements PlanEmployeeAssignmentRepository { | ||
|
||
private Producer producer; | ||
|
||
private Configuration config; | ||
|
||
public PlanEmployeeAssignmentImpl(Producer producer, Configuration config) | ||
{ | ||
this.producer = producer; | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Pushes a new plan employee assignment to persister kafka topic. | ||
* @param planEmployeeAssignmentRequest The request containing the plan employee assignment details. | ||
*/ | ||
@Override | ||
public void create(PlanEmployeeAssignmentRequest planEmployeeAssignmentRequest) { | ||
producer.push(config.getPlanEmployeeAssignmentCreateTopic(), planEmployeeAssignmentRequest); | ||
} | ||
|
||
/** | ||
* Pushes an updated existing plan employee assignment to persister kafka topic. | ||
* @param planEmployeeAssignmentRequest The request containing the updated plan employee assignment details. | ||
*/ | ||
@Override | ||
public void update(PlanEmployeeAssignmentRequest planEmployeeAssignmentRequest) { | ||
producer.push(config.getPlanEmployeeAssignmentUpdateTopic(), planEmployeeAssignmentRequest); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
health-services/plan-service/src/main/java/digit/service/PlanEmployeeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package digit.service; | ||
|
||
import digit.config.Configuration; | ||
import digit.kafka.Producer; | ||
import digit.repository.PlanEmployeeAssignmentRepository; | ||
import digit.service.enrichment.PlanEmployeeAssignmentEnricher; | ||
import digit.service.validator.PlanEmployeeAssignmentValidator; | ||
import digit.util.ResponseInfoFactory; | ||
import digit.web.models.*; | ||
import org.egov.common.utils.ResponseInfoUtil; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collections; | ||
|
||
@Service | ||
public class PlanEmployeeService { | ||
|
||
Producer producer; | ||
|
||
Configuration config; | ||
|
||
ResponseInfoFactory responseInfoFactory; | ||
|
||
PlanEmployeeAssignmentRepository repository; | ||
|
||
PlanEmployeeAssignmentEnricher enricher; | ||
|
||
PlanEmployeeAssignmentValidator validator; | ||
|
||
public PlanEmployeeService(Producer producer, Configuration config, ResponseInfoFactory responseInfoFactory, PlanEmployeeAssignmentRepository repository, PlanEmployeeAssignmentEnricher enricher, PlanEmployeeAssignmentValidator validator) | ||
{ | ||
this.producer = producer; | ||
this.config = config; | ||
this.responseInfoFactory = responseInfoFactory; | ||
this.repository = repository; | ||
this.enricher = enricher; | ||
this.validator = validator; | ||
} | ||
|
||
/** | ||
* Creates a new plan employee assignment based on the provided request. | ||
* @param request The request containing the plan employee assignment details. | ||
* @return The response containing the created plan employee assignment. | ||
*/ | ||
public PlanEmployeeAssignmentResponse create(PlanEmployeeAssignmentRequest request) { | ||
|
||
validator.validateCreate(request); | ||
enricher.enrichCreate(request); | ||
repository.create(request); | ||
|
||
return PlanEmployeeAssignmentResponse.builder() | ||
.planEmployeeAssignment(Collections.singletonList(request.getPlanEmployeeAssignment())) | ||
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(request.getRequestInfo(), Boolean.TRUE)) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Searches for plan employee assignment based on the provided search criteria. | ||
* @param request The search request containing the criteria. | ||
* @return A list of plan employee assignments that matches the search criteria. | ||
*/ | ||
public PlanEmployeeAssignmentResponse search(PlanEmployeeAssignmentSearchRequest request) { | ||
|
||
return PlanEmployeeAssignmentResponse.builder(). | ||
responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(request.getRequestInfo(), Boolean.TRUE)) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Updates an existing plan employee assignment based on the provided request. | ||
* @param request The request containing the updated plan employee assignment details. | ||
* @return The response containing the updated plan employee assignment. | ||
*/ | ||
|
||
public PlanEmployeeAssignmentResponse update(PlanEmployeeAssignmentRequest request) { | ||
|
||
validator.validateUpdate(request); | ||
enricher.enrichUpdate(request); | ||
repository.update(request); | ||
|
||
return PlanEmployeeAssignmentResponse.builder() | ||
.responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(request.getRequestInfo(), Boolean.TRUE)) | ||
.planEmployeeAssignment(Collections.singletonList(request.getPlanEmployeeAssignment())) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...s/plan-service/src/main/java/digit/service/enrichment/PlanEmployeeAssignmentEnricher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package digit.service.enrichment; | ||
|
||
import digit.web.models.PlanEmployeeAssignment; | ||
import digit.web.models.PlanEmployeeAssignmentRequest; | ||
import org.egov.common.utils.UUIDEnrichmentUtil; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static org.egov.common.utils.AuditDetailsEnrichmentUtil.prepareAuditDetails; | ||
|
||
@Component | ||
public class PlanEmployeeAssignmentEnricher { | ||
|
||
/** | ||
* Enriches the PlanEmployeeAssignmentRequest with id and audit details. | ||
* @param request The PlanEmployeeAssignmentRequest body to be enriched | ||
*/ | ||
public void enrichCreate(PlanEmployeeAssignmentRequest request) | ||
{ | ||
PlanEmployeeAssignment planEmployeeAssignment = request.getPlanEmployeeAssignment(); | ||
|
||
// Generate id for Plan employee assignment body | ||
UUIDEnrichmentUtil.enrichRandomUuid(planEmployeeAssignment, "id"); | ||
|
||
// Set Audit Details for Plan employee assignment | ||
planEmployeeAssignment.setAuditDetails(prepareAuditDetails(planEmployeeAssignment.getAuditDetails(), | ||
request.getRequestInfo(), | ||
Boolean.TRUE)); | ||
} | ||
|
||
/** | ||
* Enriches the PlanEmployeeAssignmentRequest for updating an existing plan employee assignment with audit details. | ||
* @param request The PlanEmployeeAssignmentRequest body to be enriched | ||
*/ | ||
public void enrichUpdate(PlanEmployeeAssignmentRequest request) | ||
{ | ||
PlanEmployeeAssignment planEmployeeAssignment = request.getPlanEmployeeAssignment(); | ||
|
||
// Set Audit Details for Plan employee assignment update | ||
planEmployeeAssignment.setAuditDetails(prepareAuditDetails(planEmployeeAssignment.getAuditDetails(), | ||
request.getRequestInfo(), | ||
Boolean.FALSE)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
health-services/plan-service/src/main/java/digit/util/HrmsUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package digit.util; | ||
|
||
|
||
import digit.config.Configuration; | ||
import digit.web.models.hrms.*; | ||
import digit.web.models.RequestInfoWrapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.egov.common.contract.request.RequestInfo; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
|
||
import java.util.*; | ||
|
||
import static digit.config.ServiceConstants.*; | ||
|
||
@Slf4j | ||
@Component | ||
public class HrmsUtil { | ||
|
||
private RestTemplate restTemplate; | ||
|
||
private Configuration configs; | ||
|
||
private RequestInfoWrapper requestInfoWrapper; | ||
|
||
public HrmsUtil(RestTemplate restTemplate, Configuration configs, RequestInfoWrapper requestInfoWrapper) | ||
{ | ||
this.restTemplate = restTemplate; | ||
this.configs = configs; | ||
this.requestInfoWrapper = requestInfoWrapper; | ||
} | ||
|
||
public List<Employee> fetchHrmsData(RequestInfo requestInfo, String employeeId, String tenantId) { | ||
|
||
StringBuilder uri = new StringBuilder(); | ||
uri.append(configs.getHrmsHost()).append(configs.getHrmsEndPoint()).append("?limit={limit}&tenantId={tenantId}&offset={offset}&ids={employeeId}"); | ||
|
||
Map<String, String> uriParameters = new HashMap<>(); | ||
uriParameters.put("limit", configs.getDefaultLimit().toString()); | ||
uriParameters.put("tenantId", tenantId); | ||
uriParameters.put("offset", configs.getDefaultOffset().toString()); | ||
uriParameters.put("employeeId", employeeId); | ||
|
||
RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(requestInfo).build(); | ||
EmployeeResponse employeeResponse = new EmployeeResponse(); | ||
|
||
try { | ||
employeeResponse = restTemplate.postForObject(uri.toString(), requestInfoWrapper, EmployeeResponse.class, uriParameters); | ||
} catch (Exception e) { | ||
log.error(ERROR_WHILE_FETCHING_DATA_FROM_HRMS, e); | ||
} | ||
|
||
return employeeResponse.getEmployees(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.