/// <inheritdoc/> public async Task ProcessMessage(ContractEvent contractEvent) { _logger.LogInformation($"[{nameof(ProcessMessage)}] Processing message for contract event : {contractEvent.BookmarkId}"); var eventType = contractEvent.GetContractEventType(); switch (eventType) { case ContractEventType.Create: var existingContract = await _contractsDataService.TryGetContractAsync(contractEvent.ContractNumber, contractEvent.ContractVersion); if (existingContract is null) { await _contractCreationService.CreateAsync(contractEvent); } else { _logger.LogWarning($"[{nameof(ContractEventProcessor)}] - Ignoring contract event with id [{contractEvent.BookmarkId}] because a contract with contract number [{contractEvent.ContractNumber}], version [{contractEvent.ContractVersion}] and Id [{existingContract.Id}] already exists."); } break; case ContractEventType.Approve: var approveContract = await _contractsDataService.TryGetContractAsync(contractEvent.ContractNumber, contractEvent.ContractVersion); if (approveContract is null) { _logger.LogWarning($"[{nameof(ContractEventProcessor)}] - Ignoring contract event with id [{contractEvent.BookmarkId}] because unable to find a contract with contract number [{contractEvent.ContractNumber}], version [{contractEvent.ContractVersion}]."); } else { await _contractApprovalService.ApproveAsync(contractEvent, approveContract); } break; case ContractEventType.Withdraw: await _contractWithdrawService.WithdrawAsync(contractEvent); break; default: throw new NotImplementedException($"[{nameof(ContractService)}] - [{nameof(ProcessMessage)}] does not have an implementation for event type [{eventType}]."); } }
/// <inheritdoc/> public async Task <bool> ApproveAsync(ContractEvent contractEvent, Contract existingContract) { var approvalRequest = new ApprovalRequest() { ContractNumber = existingContract.ContractNumber, ContractVersion = existingContract.ContractVersion, Id = existingContract.Id, FileName = contractEvent.ContractEventXml }; var eventType = contractEvent.GetContractEventType(); if (eventType != Enums.ContractEventType.Approve) { throw new InvalidOperationException($"[{nameof(ContractApprovalService)}] - [{nameof(ApproveAsync)}] called for event type [{eventType}]."); } switch (existingContract.Status) { case Data.Api.Client.Enumerations.ContractStatus.PublishedToProvider: await _contractsDataService.ManualApproveAsync(approvalRequest); break; case Data.Api.Client.Enumerations.ContractStatus.ApprovedWaitingConfirmation: await _contractsDataService.ConfirmApprovalAsync(approvalRequest); break; default: _logger.LogInformation($"[{nameof(ContractApprovalService)}] - [{nameof(ApproveAsync)}] - No further action taken on [{existingContract.ContractNumber}], version [{existingContract.ContractVersion}], Id [{existingContract.Id}], event parent status [{contractEvent.ParentStatus}], event status [{contractEvent.Status}], event amendment type [{contractEvent.AmendmentType}] and contract status [{existingContract.Status}]."); break; } return(true); }