Skip to content
Merged

Dev #2396

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Unity.Flex.Domain.Scoresheets;
using Unity.Flex.Domain.Settings;
Expand All @@ -25,8 +26,8 @@ public partial class ScoresheetAppService(IUnitOfWorkManager unitOfWorkManager,
IReportingFieldsGeneratorService<Scoresheet> reportingFieldsGeneratorService,
IFeatureChecker featureChecker) : FlexAppService, IScoresheetAppService
{
private readonly static object _sectionLockObject = new();
private readonly static object _questionLockObject = new();
private static readonly SemaphoreSlim _sectionLock = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim _questionLock = new SemaphoreSlim(1, 1);

public async Task<List<ScoresheetDto>> GetListAsync()
{
Expand Down Expand Up @@ -55,32 +56,42 @@ public virtual async Task<QuestionDto> CreateQuestionInHighestOrderSectionAsync(
{
await ValidateChangeableScoresheet(scoresheetId);

lock (_questionLockObject)
await _questionLock.WaitAsync();
try
{
ScoresheetSection highestOrderSection = sectionRepository.GetSectionWithHighestOrderAsync(scoresheetId, true).Result ?? throw new AbpValidationException("Scoresheet has no section.");
ScoresheetSection highestOrderSection = await sectionRepository.GetSectionWithHighestOrderAsync(scoresheetId, true) ?? throw new AbpValidationException("Scoresheet has no section.");
uint highestOrder = (highestOrderSection.Fields != null && highestOrderSection.Fields.Count > 0) ? highestOrderSection.Fields.Max(q => q.Order) : 0;
var order = highestOrder + 1;
var newQuestion = new Question(Guid.NewGuid(), dto.Name.Trim(), dto.Label, (QuestionType)dto.QuestionType, order, dto.Description, highestOrderSection.Id, dto.Definition);
highestOrderSection.AddQuestion(newQuestion);
_ = sectionRepository.UpdateAsync(highestOrderSection).Result;
await sectionRepository.UpdateAsync(highestOrderSection);
return ObjectMapper.Map<Question, QuestionDto>(newQuestion);
}
finally
{
_questionLock.Release();
}
}

public virtual async Task<ScoresheetSectionDto> CreateSectionAsync(Guid scoresheetId, CreateSectionDto dto)
{
await ValidateChangeableScoresheet(scoresheetId);

lock (_sectionLockObject)
await _sectionLock.WaitAsync();
try
{
ScoresheetSection? highestOrderSection = sectionRepository.GetSectionWithHighestOrderAsync(scoresheetId, true).Result;
ScoresheetSection? highestOrderSection = await sectionRepository.GetSectionWithHighestOrderAsync(scoresheetId, true);
var order = highestOrderSection == null ? 0 : highestOrderSection.Order + 1;
var scoresheet = scoresheetRepository.GetAsync(scoresheetId, true).Result;
var scoresheet = await scoresheetRepository.GetAsync(scoresheetId, true);
ScoresheetSection newSection = new(Guid.NewGuid(), dto.Name.Trim(), order);
_ = scoresheet.AddSection(newSection);
_ = scoresheetRepository.UpdateAsync(scoresheet).Result;
await scoresheetRepository.UpdateAsync(scoresheet);
return ObjectMapper.Map<ScoresheetSection, ScoresheetSectionDto>(newSection);
}
finally
{
_sectionLock.Release();
}
}

public async Task UpdateAsync(Guid scoresheetId, EditScoresheetDto dto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private async Task UpdateEmailLogStatus(EmailLog log, HttpResponseMessage respon
{
response.StatusCode,
Headers = response.Headers?.ToString(),
Body = response.Content != null ? response.Content.ReadAsStringAsync().Result : null
Body = response.Content != null ? await response.Content.ReadAsStringAsync() : null
});

log.ChesHttpStatusCode = response.StatusCode.ToString("D");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@ public class PaymentsManager(
private void ConfigureWorkflow(StateMachine<PaymentRequestStatus, PaymentApprovalAction> paymentStateMachine)
{
paymentStateMachine.Configure(PaymentRequestStatus.L1Pending)
.PermitIf(PaymentApprovalAction.L1Approve, PaymentRequestStatus.L2Pending, () => HasPermission(PaymentsPermissions.Payments.L1ApproveOrDecline))
.PermitIf(PaymentApprovalAction.L1Decline, PaymentRequestStatus.L1Declined, () => HasPermission(PaymentsPermissions.Payments.L1ApproveOrDecline));
.PermitIf(PaymentApprovalAction.L1Approve, PaymentRequestStatus.L2Pending, () => HasPermissionAsync(PaymentsPermissions.Payments.L1ApproveOrDecline).GetAwaiter().GetResult())
.PermitIf(PaymentApprovalAction.L1Decline, PaymentRequestStatus.L1Declined, () => HasPermissionAsync(PaymentsPermissions.Payments.L1ApproveOrDecline).GetAwaiter().GetResult());

paymentStateMachine.Configure(PaymentRequestStatus.L1Declined)
.PermitIf(PaymentApprovalAction.L1Approve, PaymentRequestStatus.L2Pending, () => HasPermission(PaymentsPermissions.Payments.L1ApproveOrDecline));
.PermitIf(PaymentApprovalAction.L1Approve, PaymentRequestStatus.L2Pending, () => HasPermissionAsync(PaymentsPermissions.Payments.L1ApproveOrDecline).GetAwaiter().GetResult());

paymentStateMachine.Configure(PaymentRequestStatus.L2Pending)
.PermitIf(PaymentApprovalAction.L2Approve, PaymentRequestStatus.L3Pending, () => HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline))
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline))
.PermitIf(PaymentApprovalAction.L2Decline, PaymentRequestStatus.L2Declined, () => HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline));
.PermitIf(PaymentApprovalAction.L2Approve, PaymentRequestStatus.L3Pending, () => HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline).GetAwaiter().GetResult())
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline).GetAwaiter().GetResult())
.PermitIf(PaymentApprovalAction.L2Decline, PaymentRequestStatus.L2Declined, () => HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline).GetAwaiter().GetResult());

paymentStateMachine.Configure(PaymentRequestStatus.L2Declined)
.PermitIf(PaymentApprovalAction.L2Approve, PaymentRequestStatus.L3Pending, () => HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline))
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline));
.PermitIf(PaymentApprovalAction.L2Approve, PaymentRequestStatus.L3Pending, () => HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline).GetAwaiter().GetResult())
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline).GetAwaiter().GetResult());

paymentStateMachine.Configure(PaymentRequestStatus.L3Pending)
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermission(PaymentsPermissions.Payments.L3ApproveOrDecline))
.PermitIf(PaymentApprovalAction.L3Decline, PaymentRequestStatus.L3Declined, () => HasPermission(PaymentsPermissions.Payments.L3ApproveOrDecline));
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermissionAsync(PaymentsPermissions.Payments.L3ApproveOrDecline).GetAwaiter().GetResult())
.PermitIf(PaymentApprovalAction.L3Decline, PaymentRequestStatus.L3Declined, () => HasPermissionAsync(PaymentsPermissions.Payments.L3ApproveOrDecline).GetAwaiter().GetResult());

paymentStateMachine.Configure(PaymentRequestStatus.L2Declined)
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline));
.PermitIf(PaymentApprovalAction.Submit, PaymentRequestStatus.Submitted, () => HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline).GetAwaiter().GetResult());
}

private bool HasPermission(string permission)
private async Task<bool> HasPermissionAsync(string permission)
{
return permissionChecker.IsGrantedAsync(permission).Result;
return await permissionChecker.IsGrantedAsync(permission);
}

public async Task<List<PaymentActionResultItem>> GetActions(Guid paymentRequestsId)
Expand Down Expand Up @@ -136,12 +136,12 @@ public async Task<PaymentRequest> TriggerAction(Guid paymentRequestsId, PaymentA

else if (triggerAction == PaymentApprovalAction.Submit)
{
if (HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline) && paymentRequest.Status == PaymentRequestStatus.L2Pending)
if (await HasPermissionAsync(PaymentsPermissions.Payments.L2ApproveOrDecline) && paymentRequest.Status == PaymentRequestStatus.L2Pending)
{
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level2);
paymentRequest.ExpenseApprovals[index].Approve(currentUserId);
}
else if (HasPermission(PaymentsPermissions.Payments.L3ApproveOrDecline) && paymentRequest.Status == PaymentRequestStatus.L3Pending)
else if (await HasPermissionAsync(PaymentsPermissions.Payments.L3ApproveOrDecline) && paymentRequest.Status == PaymentRequestStatus.L3Pending)
{
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level3);
paymentRequest.ExpenseApprovals[index].Approve(currentUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task<string> GetAuthTokenAsync(ClientOptions clientOptions)
client.DefaultRequestHeaders.ConnectionClose = true;

HttpResponseMessage response = await client.SendAsync(requestMessage);
var responseBody = response.Content.ReadAsStringAsync();
var responseBody = await response.Content.ReadAsStringAsync();
string responseMessage = response.RequestMessage != null ? response.RequestMessage.ToString() : "";

if (response.Content == null)
Expand All @@ -91,7 +91,7 @@ public async Task<string> GetAuthTokenAsync(ClientOptions clientOptions)
}
}

var tokenResponse = JsonSerializer.Deserialize<TokenValidationResponse>(responseBody.Result)
var tokenResponse = JsonSerializer.Deserialize<TokenValidationResponse>(responseBody)
?? throw new UserFriendlyException($"Error deserializing token response {response.StatusCode} {responseMessage}");

int expiresInSeconds = tokenResponse.ExpiresIn - ONE_MINUTE_SECONDS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Unity.GrantManager.ApplicantProfile;

public class CreateUpdateReportsHistoryDto
{
public Guid? ApplicantId { get; set; }
public string? FiscalYear { get; set; }
public DateTime? ReportDate { get; set; }
public bool? Outstanding { get; set; }
public bool? IncompleteReport { get; set; }
public string? Note { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ public interface IApplicantHistoryAppService : IApplicationService
Task<AuditHistoryDto> UpdateAuditHistoryAsync(Guid id, CreateUpdateAuditHistoryDto input);
Task DeleteAuditHistoryAsync(Guid id);

Task<List<ReportsHistoryDto>> GetReportsHistoryListAsync(Guid applicantId);
Task<ReportsHistoryDto> GetReportsHistoryAsync(Guid id);
Task<ReportsHistoryDto> CreateReportsHistoryAsync(CreateUpdateReportsHistoryDto input);
Task<ReportsHistoryDto> UpdateReportsHistoryAsync(Guid id, CreateUpdateReportsHistoryDto input);
Task DeleteReportsHistoryAsync(Guid id);

Task SaveNotesAsync(Guid applicantId, SaveApplicantHistoryNotesDto input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Volo.Abp.Application.Dtos;

namespace Unity.GrantManager.ApplicantProfile;

public class ReportsHistoryDto : AuditedEntityDto<Guid>
{
public Guid? ApplicantId { get; set; }
public string? FiscalYear { get; set; }
public DateTime? ReportDate { get; set; }
public bool? Outstanding { get; set; }
public bool? IncompleteReport { get; set; }
public string? Note { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class SaveApplicantHistoryNotesDto
public string? FundingHistoryComments { get; set; }
public string? IssueTrackingComments { get; set; }
public string? AuditComments { get; set; }
public string? ReportsComments { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class ApplicantHistoryAppService(
IFundingHistoryRepository fundingHistoryRepository,
IIssueTrackingRepository issueTrackingRepository,
IAuditHistoryRepository auditHistoryRepository,
IReportsHistoryRepository reportsHistoryRepository,
IApplicantRepository applicantRepository) : GrantManagerAppService, IApplicantHistoryAppService
{
public async Task<List<FundingHistoryDto>> GetFundingHistoryListAsync(Guid applicantId)
Expand Down Expand Up @@ -107,12 +108,45 @@ public async Task DeleteAuditHistoryAsync(Guid id)
await auditHistoryRepository.DeleteAsync(id, autoSave: true);
}

public async Task<List<ReportsHistoryDto>> GetReportsHistoryListAsync(Guid applicantId)
{
var items = await reportsHistoryRepository.GetByApplicantIdAsync(applicantId);
return ObjectMapper.Map<List<ReportsHistory>, List<ReportsHistoryDto>>(items);
}

public async Task<ReportsHistoryDto> GetReportsHistoryAsync(Guid id)
{
var entity = await reportsHistoryRepository.GetAsync(id);
return ObjectMapper.Map<ReportsHistory, ReportsHistoryDto>(entity);
}

public async Task<ReportsHistoryDto> CreateReportsHistoryAsync(CreateUpdateReportsHistoryDto input)
{
var entity = ObjectMapper.Map<CreateUpdateReportsHistoryDto, ReportsHistory>(input);
await reportsHistoryRepository.InsertAsync(entity, autoSave: true);
return ObjectMapper.Map<ReportsHistory, ReportsHistoryDto>(entity);
}

public async Task<ReportsHistoryDto> UpdateReportsHistoryAsync(Guid id, CreateUpdateReportsHistoryDto input)
{
var entity = await reportsHistoryRepository.GetAsync(id);
ObjectMapper.Map(input, entity);
await reportsHistoryRepository.UpdateAsync(entity, autoSave: true);
return ObjectMapper.Map<ReportsHistory, ReportsHistoryDto>(entity);
}

public async Task DeleteReportsHistoryAsync(Guid id)
{
await reportsHistoryRepository.DeleteAsync(id, autoSave: true);
}

public async Task SaveNotesAsync(Guid applicantId, SaveApplicantHistoryNotesDto input)
{
var applicant = await applicantRepository.GetAsync(applicantId);
applicant.FundingHistoryComments = input.FundingHistoryComments;
applicant.IssueTrackingComments = input.IssueTrackingComments;
applicant.AuditComments = input.AuditComments;
applicant.ReportsComments = input.ReportsComments;
await applicantRepository.UpdateAsync(applicant, autoSave: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ public async Task<AssessmentDto> CreateAsync(CreateAssessmentDto dto)

public async Task<IList<AssessmentDto>> GetListAsync(Guid applicationId)
{
IQueryable<Assessment> queryableAssessments = _assessmentRepository.GetQueryableAsync().Result;
IQueryable<Assessment> queryableAssessments = await _assessmentRepository.GetQueryableAsync();
var assessments = queryableAssessments.Where(c => c.ApplicationId.Equals(applicationId)).ToList();
return await Task.FromResult<IList<AssessmentDto>>(
ObjectMapper.Map<List<Assessment>, List<AssessmentDto>>(
assessments.OrderByDescending(s => s.IsAiAssessment).ThenByDescending(s => s.CreationTime).ToList()));
return ObjectMapper.Map<List<Assessment>, List<AssessmentDto>>(
assessments.OrderByDescending(s => s.IsAiAssessment).ThenByDescending(s => s.CreationTime).ToList());
}

public async Task<AssessmentDisplayListDto> GetDisplayList(Guid applicationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ await _amazonS3Client.DeleteObjectAsync(new DeleteObjectRequest
{
throw new AbpValidationException("Missing ApplicationId");
}
IQueryable<ApplicationAttachment> queryableAttachment = _applicationAttachmentRepository.GetQueryableAsync().Result;
IQueryable<ApplicationAttachment> queryableAttachment = await _applicationAttachmentRepository.GetQueryableAsync();
ApplicationAttachment? attachment = queryableAttachment.FirstOrDefault(a => a.S3ObjectKey.Equals(s3ObjectKey) && a.ApplicationId.Equals(new Guid(attachmentTypeId.ToString())));
if (attachment != null)
{
Expand All @@ -97,7 +97,7 @@ await _amazonS3Client.DeleteObjectAsync(new DeleteObjectRequest
{
throw new AbpValidationException("Missing AssessmentId");
}
IQueryable<AssessmentAttachment> queryableAttachment = _assessmentAttachmentRepository.GetQueryableAsync().Result;
IQueryable<AssessmentAttachment> queryableAttachment = await _assessmentAttachmentRepository.GetQueryableAsync();
AssessmentAttachment? attachment = queryableAttachment.FirstOrDefault(a => a.S3ObjectKey.Equals(s3ObjectKey) && a.AssessmentId.Equals(new Guid(attachmentTypeId.ToString())));
if (attachment != null)
{
Expand All @@ -110,7 +110,7 @@ await _amazonS3Client.DeleteObjectAsync(new DeleteObjectRequest
{
throw new AbpValidationException("Missing ApplicantId");
}
IQueryable<ApplicantAttachment> queryableAttachment = _applicantAttachmentRepository.GetQueryableAsync().Result;
IQueryable<ApplicantAttachment> queryableAttachment = await _applicantAttachmentRepository.GetQueryableAsync();
ApplicantAttachment? attachment = queryableAttachment.FirstOrDefault(a => a.S3ObjectKey.Equals(s3ObjectKey) && a.ApplicantId.Equals(new Guid(attachmentTypeId.ToString())));
if (attachment != null)
{
Expand Down
Loading
Loading