Skip to content

Commit

Permalink
added header timestamp and setting type (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhang-eGov authored Mar 26, 2024
1 parent 2fee0d0 commit 5d3dc84
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AllocationRequest createAllocation(AllocationRequest allocationRequest) {
allocationValidator.validateAllocation(allocationRequest.getAllocation().getChildren(), true);
// Validates if receiver id is same as configured in mdms
commonValidator.validateReply(allocationRequest.getHeader(), allocationRequest.getAllocation().getChildren().get(0).getLocationCode());
enrichmentService.enrichAllocationCreate(allocationRequest.getAllocation().getChildren(), allocationRequest.getHeader());
enrichmentService.enrichAllocationCreate(allocationRequest.getAllocation(), allocationRequest.getHeader());
// Calculates the allocated and available amount for each sanction in the list of allocation and returns the sanctions
List<Sanction> sanctions = calculationUtil.calculateAndReturnSanctionForAllocation(allocationRequest.getAllocation().getChildren());
// Saves allocations and sanctions in transactional manner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void enrichProgramForCreate(RequestHeader header, Program program) {
program.setStatus(org.digit.program.models.Status.builder().statusCode(Status.ACTIVE).build());
program.setAuditDetails(getAuditDetails(header.getSenderId(), null));
header.setMessageId(program.getId());
header.setMessageTs(System.currentTimeMillis());
log.info("Enrichment for create completed for id: {}", program.getId());
}

Expand All @@ -68,23 +69,28 @@ public void enrichProgramForUpdateOrOnProgram(Program program, RequestHeader hea
log.info("Enrich Program for Update/OnProgram");
program.setAuditDetails(getAuditDetails(header.getSenderId(), program.getAuditDetails()));
header.setMessageId(program.getId());
header.setMessageTs(System.currentTimeMillis());
log.info("Enrichment for update/on-program completed for id: {}", program.getId());
}

/**
* Set audit details and id if not present for sanction create
* @param sanctions
* @param sanction
* @param header
*/
public void enrichSanctionCreate(List<Sanction> sanctions, RequestHeader header) {
public void enrichSanctionCreate(Sanction sanction, RequestHeader header) {
log.info("Enrich sanction create");
for (Sanction sanction : sanctions) {
if (sanction.getId() == null || StringUtils.isEmpty(sanction.getId()))
sanction.setId(UUID.randomUUID().toString());
sanction.setType(MessageType.SANCTION);
sanction.setAuditDetails(getAuditDetails(header.getSenderId(), null));
for (Sanction childSanctions : sanction.getChildren()) {
if (childSanctions.getId() == null || StringUtils.isEmpty(childSanctions.getId()))
childSanctions.setId(UUID.randomUUID().toString());
childSanctions.setType(MessageType.SANCTION);
childSanctions.setAuditDetails(getAuditDetails(header.getSenderId(), null));
}
header.setMessageId(sanctions.get(0).getId());
sanction.setId(UUID.randomUUID().toString());
sanction.setType(MessageType.SANCTION);
sanction.setAuditDetails(getAuditDetails(header.getSenderId(), null));
header.setMessageId(sanction.getId());
header.setMessageTs(System.currentTimeMillis());
log.info("Enrichment for create sanction completed");
}

Expand All @@ -102,17 +108,21 @@ public void enrichSanctionUpdate(List<Sanction> sanctions, String senderId) {

/**
* Setting audit details and id if not present for allocation create
* @param allocations
* @param allocation
* @param header
*/
public void enrichAllocationCreate(List<Allocation> allocations, RequestHeader header) {
for (Allocation allocation : allocations) {
if (allocation.getId() == null || StringUtils.isEmpty(allocation.getId()))
allocation.setId(UUID.randomUUID().toString());
allocation.setType(MessageType.ALLOCATION);
allocation.setAuditDetails(getAuditDetails(header.getSenderId(), null));
public void enrichAllocationCreate(Allocation allocation, RequestHeader header) {
for (Allocation childAllocations : allocation.getChildren()) {
if (childAllocations.getId() == null || StringUtils.isEmpty(childAllocations.getId()))
childAllocations.setId(UUID.randomUUID().toString());
childAllocations.setType(MessageType.ALLOCATION);
childAllocations.setAuditDetails(getAuditDetails(header.getSenderId(), null));
}
header.setMessageId(allocations.get(0).getId());
allocation.setId(UUID.randomUUID().toString());
allocation.setType(MessageType.ALLOCATION);
allocation.setAuditDetails(getAuditDetails(header.getSenderId(), null));
header.setMessageId(allocation.getId());
header.setMessageTs(System.currentTimeMillis());
log.info("Enrichment for create allocation completed");
}

Expand Down Expand Up @@ -142,6 +152,7 @@ public void enrichDisburseCreate(Disbursement disbursement, RequestHeader header
disbursement.setStatus(org.digit.program.models.Status.builder().statusCode(Status.INITIATED).build());
disbursement.setType(MessageType.DISBURSE);
header.setMessageId(disbursement.getId());
header.setMessageTs(System.currentTimeMillis());
for (Disbursement childDisbursement : disbursement.getDisbursements()) {
if (childDisbursement.getId() == null || StringUtils.isEmpty(childDisbursement.getId()))
childDisbursement.setId(UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SanctionRequest createSanction(SanctionRequest sanctionRequest) {
sanctionValidator.validateSanction(sanctionRequest.getSanction().getChildren(), true);
// Validates if receiver id is same as configured in mdms
commonValidator.validateReply(sanctionRequest.getHeader(), sanctionRequest.getSanction().getChildren().get(0).getLocationCode());
enrichmentService.enrichSanctionCreate(sanctionRequest.getSanction().getChildren(), sanctionRequest.getHeader());
enrichmentService.enrichSanctionCreate(sanctionRequest.getSanction(), sanctionRequest.getHeader());
sanctionRepository.saveSanction(sanctionRequest.getSanction().getChildren());
// Forwards on sanction message to exchange service if sender and current domains are same
dispatcherUtil.dispatchOnSanction(sanctionRequest);
Expand Down

0 comments on commit 5d3dc84

Please sign in to comment.