Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor with remove of contracts reference project and sonar cleanup… #193

Merged
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 @@ -7,5 +7,6 @@ namespace Unity.GrantManager.Intakes.Integration
public interface IFormIntService : IApplicationService
{
Task<dynamic?> GetFormDataAsync(Guid chefsFormId, Guid chefsFormVersionId);
Task<object> GetForm(Guid? formId);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Unity.GrantManager.Applications;
Expand All @@ -7,7 +8,6 @@
using Volo.Abp;
using Volo.Abp.Domain.Entities;


namespace Unity.GrantManager.Events
{
[RemoteService(false)]
Expand Down Expand Up @@ -54,14 +54,20 @@ public async Task<bool> PublishedFormAsync(EventSubscriptionDto eventSubscriptio
.OrderBy(s => s.CreationTime)
.FirstOrDefault();

if (applicationForm != null && applicationForm.ApiKey != null) {
// Go grab the new name/description/version and map the new available fields
if (applicationForm != null
&& applicationForm.ApiKey != null
&& applicationForm.ChefsApplicationFormGuid != null)
{
// Go grab the new name/description/version and map the new available fields
var formVersion = await _formIntService.GetFormDataAsync(eventSubscriptionDto.FormId, eventSubscriptionDto.FormVersion);
applicationForm = await _applicationFormManager.SynchronizePublishedForm(applicationForm, formVersion);
dynamic form = await _formIntService.GetForm(Guid.Parse(applicationForm.ChefsApplicationFormGuid));
applicationForm = await _applicationFormManager.SynchronizePublishedForm(applicationForm, formVersion, form);
applicationForm.AvailableChefsFields = _intakeFormSubmissionMapper.InitializeAvailableFormFields(applicationForm, formVersion);
applicationForm = await _applicationFormRepository.UpdateAsync(applicationForm);
} else {
applicationForm = await _applicationFormManager.InitializeApplicationForm(eventSubscriptionDto);
}
else
{
applicationForm = await _applicationFormManager.InitializeApplicationForm(ObjectMapper.Map<EventSubscriptionDto, EventSubscription>(eventSubscriptionDto));
}

return applicationForm != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FormIntService(RestClient intakeClient,

var request = new RestRequest($"/forms/{chefsFormId}/versions/{chefsFormVersionId}")
{
Authenticator = new HttpBasicAuthenticator(applicationForm.ChefsApplicationFormGuid!, _stringEncryptionService.Decrypt(applicationForm.ApiKey!))
Authenticator = new HttpBasicAuthenticator(applicationForm.ChefsApplicationFormGuid!, _stringEncryptionService.Decrypt(applicationForm.ApiKey!) ?? string.Empty)
};

var response = await _intakeClient.GetAsync(request);
Expand All @@ -53,6 +53,14 @@ public FormIntService(RestClient intakeClient,

return null;
}

public async Task<object> GetForm(Guid? formId)
{
var request = new RestRequest($"/forms/{formId}");
var response = await _intakeClient.GetAsync(request);

return response.Content ?? "Error";
}
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using Unity.GrantManager.Events;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
using Unity.GrantManager.Intakes;
using Volo.Abp.Domain.Repositories;
Expand All @@ -11,20 +9,16 @@ namespace Unity.GrantManager.Applications
public class ApplicationFormManager : DomainService, IApplicationFormManager
{
private readonly IApplicationFormRepository _applicationFormRepository;
private readonly IIntakeRepository _intakeRepository;

private readonly IFormAppService _formAppService;
private readonly IIntakeRepository _intakeRepository;

public ApplicationFormManager(IIntakeRepository intakeRepository,
IApplicationFormRepository applicationFormRepository,
IFormAppService formAppService)
IApplicationFormRepository applicationFormRepository)
{
_intakeRepository = intakeRepository;
_applicationFormRepository = applicationFormRepository;
_formAppService = formAppService;
_applicationFormRepository = applicationFormRepository;
}

public async Task<ApplicationForm> InitializeApplicationForm(EventSubscriptionDto eventSubscriptionDto)
public async Task<ApplicationForm> InitializeApplicationForm(EventSubscription eventSubscription)
{
Intake? intake = await _intakeRepository.FirstOrDefaultAsync();
var applicationForm = new ApplicationForm();
Expand All @@ -36,7 +30,7 @@ public async Task<ApplicationForm> InitializeApplicationForm(EventSubscriptionDt
{
IntakeId = intake.Id,
ApplicationFormName = "New Form - Setup API KEY",
ChefsApplicationFormGuid = eventSubscriptionDto.FormId.ToString(),
ChefsApplicationFormGuid = eventSubscription.FormId.ToString(),
ChefsCriteriaFormGuid = ""
},
autoSave: true
Expand All @@ -47,19 +41,19 @@ public async Task<ApplicationForm> InitializeApplicationForm(EventSubscriptionDt
return applicationForm;
}

public async Task<ApplicationForm> SynchronizePublishedForm(ApplicationForm applicationForm, dynamic formVersion)
public ApplicationForm SynchronizePublishedForm(ApplicationForm applicationForm,
dynamic formVersion,
dynamic form)
{
if (applicationForm.Version == null && formVersion != null)
{
var version = ((JObject)formVersion!).SelectToken("version");
var published = ((JObject)formVersion!).SelectToken("published");

if (published != null && ((JToken)published).ToString() == "True"
if (published != null && published.ToString() == "True"
&& version != null
&& applicationForm.ChefsApplicationFormGuid != null)
{

dynamic form = await _formAppService.GetForm(Guid.Parse(applicationForm.ChefsApplicationFormGuid));
{
JObject formObject = JObject.Parse(form.ToString());
var formName = formObject.SelectToken("name");
var formDescription = formObject.SelectToken("description");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Threading.Tasks;
using Unity.GrantManager.Events;
using Unity.GrantManager.Intakes;

namespace Unity.GrantManager.Applications
{
public interface IApplicationFormManager
{
public Task<ApplicationForm> InitializeApplicationForm(EventSubscriptionDto eventSubscriptionDto);
public Task<ApplicationForm> InitializeApplicationForm(EventSubscription eventSubscription);

public Task<ApplicationForm> SynchronizePublishedForm(ApplicationForm applicationForm, dynamic formVersion);
public ApplicationForm SynchronizePublishedForm(ApplicationForm applicationForm, dynamic formVersion, dynamic form);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Unity.GrantManager.Intakes
{
public class EventSubscription
{
public Guid FormId { get; set; }
public Guid FormVersion { get; set; }
public Guid SubmissionId { get; set; }
public string? SubscriptionEvent { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Unity.GrantManager.Application.Contracts\Unity.GrantManager.Application.Contracts.csproj" />
<ProjectReference Include="..\Unity.GrantManager.Domain.Shared\Unity.GrantManager.Domain.Shared.csproj" />
</ItemGroup>

Expand Down