Skip to content

Commit

Permalink
feat(sd): add process for sd document creation
Browse files Browse the repository at this point in the history
Refs: #813
  • Loading branch information
Phil91 authored and ntruchsess committed Aug 6, 2024
1 parent 14c6d2c commit 59d5d59
Show file tree
Hide file tree
Showing 25 changed files with 10,052 additions and 112 deletions.
15 changes: 15 additions & 0 deletions src/Portal.Backend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityProviderProvisionin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserProvisioning.Executor.Tests", "..\tests\processes\UserProvisioning.Executor.Tests\UserProvisioning.Executor.Tests.csproj", "{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfDescriptionCreation.Executor", "processes\SelfDescriptionCreation.Executor\SelfDescriptionCreation.Executor.csproj", "{08535520-F6E6-4DAF-AB36-12C48437368A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1794,6 +1796,18 @@ Global
{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}.Release|x64.Build.0 = Release|Any CPU
{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}.Release|x86.ActiveCfg = Release|Any CPU
{0CBCC851-99A1-4005-9BBA-E6A20A0AEDAA}.Release|x86.Build.0 = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x64.ActiveCfg = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x64.Build.0 = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x86.ActiveCfg = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Debug|x86.Build.0 = Debug|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|Any CPU.Build.0 = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x64.ActiveCfg = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x64.Build.0 = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x86.ActiveCfg = Release|Any CPU
{08535520-F6E6-4DAF-AB36-12C48437368A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1928,5 +1942,6 @@ Global
{143433B2-2792-4C5F-A3C2-E5C91D68E30D} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
{9636BEC8-6929-4852-8DC8-8B41609630A3} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
{E5494227-BDFE-41F2-A12F-54292D76C29F} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
{08535520-F6E6-4DAF-AB36-12C48437368A} = {282CEF03-292F-4A49-83C6-997567D0FF5F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public async Task<DimUrlsResponse> GetDimServiceUrls()
);
}

public Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size) =>
public Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public async Task ProcessClearinghouseSelfDescription(SelfDescriptionResponseDat
throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_ALREADY_ASSIGNED, new ErrorParameter[] { new("externalId", data.ExternalId.ToString()) });
}

await sdFactoryBusinessLogic.ProcessFinishSelfDescriptionLpForConnector(data, _identityData.IdentityId, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
await sdFactoryBusinessLogic.ProcessFinishSelfDescriptionLpForConnector(data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ public IAsyncEnumerable<OfferSubscriptionConnectorData> GetConnectorOfferSubscri
portalRepositories.GetInstance<IOfferSubscriptionsRepository>()
.GetConnectorOfferSubscriptionData(connectorIdSet, _identityData.CompanyId);

public Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size) =>
public Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ public interface IRegistrationBusinessLogic
/// </summary>
/// <param name="processId">Id of the Process</param>
Task RetriggerDeleteCentralUser(Guid processId);

Task TriggerSelfDescriptionCreation();
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,24 @@ public async Task<NoContentResult> RetriggerDeleteCentralUser([FromRoute] Guid p
[ProducesResponseType(typeof(Pagination.Response<CompanyDetailsOspOnboarding>), StatusCodes.Status200OK)]
public Task<Pagination.Response<CompanyDetailsOspOnboarding>> GetOspCompanyDetailsAsync([FromQuery] int page, [FromQuery] int size, [FromQuery] CompanyApplicationStatusFilter? companyApplicationStatusFilter = null, [FromQuery] string? companyName = null) =>
_logic.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName);

/// <summary>
/// Triggers the process to create the missing self description documents
/// </summary>
/// <returns>NoContent</returns>
/// Example: POST: api/administration/registration/trigger-self-description
/// <response code="204">Empty response on success.</response>
/// <response code="404">No Process found for the processId</response>
[HttpPost]
[Authorize(Roles = "approve_new_partner")]
[Authorize(Policy = PolicyTypes.CompanyUser)]
[Route("trigger-self-description")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> TriggerSelfDescriptionProcess()
{
await _logic.TriggerSelfDescriptionCreation().ConfigureAwait(false);
return NoContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public interface ISdFactoryBusinessLogic
Task RegisterConnectorAsync(Guid connectorId, string selfDescriptionDocumentUrl, string businessPartnerNumber, CancellationToken cancellationToken);
Task<IApplicationChecklistService.WorkerChecklistProcessStepExecutionResult> StartSelfDescriptionRegistration(IApplicationChecklistService.WorkerChecklistProcessStepData context, CancellationToken cancellationToken);
Task ProcessFinishSelfDescriptionLpForApplication(SelfDescriptionResponseData data, Guid companyId, CancellationToken cancellationToken);
Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResponseData data, Guid companyUserId, CancellationToken cancellationToken);
Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResponseData data, CancellationToken cancellationToken);
Task ProcessFinishSelfDescriptionLpForCompany(SelfDescriptionResponseData data, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ public async Task ProcessFinishSelfDescriptionLpForApplication(SelfDescriptionRe
}

/// <inheritdoc />
public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResponseData data, Guid companyUserId, CancellationToken cancellationToken)
public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResponseData data, CancellationToken cancellationToken)
{
var confirm = ValidateData(data);
Guid? documentId = null;
if (confirm)
{
documentId = await ProcessDocument(SdFactoryResponseModelTitle.Connector, data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
}

portalRepositories.GetInstance<IConnectorsRepository>().AttachAndModifyConnector(data.ExternalId, null, con =>
{
if (documentId != null)
Expand All @@ -158,6 +159,16 @@ public async Task ProcessFinishSelfDescriptionLpForConnector(SelfDescriptionResp
});
}

public async Task ProcessFinishSelfDescriptionLpForCompany(SelfDescriptionResponseData data, CancellationToken cancellationToken)
{
if (data.Status == SelfDescriptionStatus.Confirm)
{
var documentId = await ProcessDocument(SdFactoryResponseModelTitle.LegalPerson, data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
portalRepositories.GetInstance<ICompanyRepository>().AttachAndModifyCompany(data.ExternalId, null,
c => { c.SelfDescriptionDocumentId = documentId; });
}
}

private static bool ValidateData(SelfDescriptionResponseData data)
{
var confirm = data.Status == SelfDescriptionStatus.Confirm;
Expand Down
2 changes: 1 addition & 1 deletion src/externalsystems/SdFactory.Library/ISdFactoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ public interface ISdFactoryService
/// <exception cref="ServiceException">throws an exception if the service call wasn't successfully</exception>
Task RegisterConnectorAsync(Guid connectorId, string selfDescriptionDocumentUrl, string businessPartnerNumber, CancellationToken cancellationToken);

Task RegisterSelfDescriptionAsync(Guid applicationId, IEnumerable<(UniqueIdentifierId Id, string Value)> uniqueIdentifiers, string countryCode, string businessPartnerNumber, CancellationToken cancellationToken);
Task RegisterSelfDescriptionAsync(Guid externalId, IEnumerable<(UniqueIdentifierId Id, string Value)> uniqueIdentifiers, string countryCode, string businessPartnerNumber, CancellationToken cancellationToken);
}
4 changes: 2 additions & 2 deletions src/externalsystems/SdFactory.Library/SdFactoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ await httpClient.PostAsJsonAsync(default(string?), requestModel, cancellationTok
}

/// <inheritdoc />
public async Task RegisterSelfDescriptionAsync(Guid applicationId, IEnumerable<(UniqueIdentifierId Id, string Value)> uniqueIdentifiers, string countryCode, string businessPartnerNumber, CancellationToken cancellationToken)
public async Task RegisterSelfDescriptionAsync(Guid externalId, IEnumerable<(UniqueIdentifierId Id, string Value)> uniqueIdentifiers, string countryCode, string businessPartnerNumber, CancellationToken cancellationToken)
{
var httpClient = await tokenService.GetAuthorizedClient<SdFactoryService>(_settings, cancellationToken)
.ConfigureAwait(ConfigureAwaitOptions.None);
var requestModel = new SdFactoryRequestModel(
applicationId.ToString(),
externalId.ToString(),
uniqueIdentifiers.Select(x => new RegistrationNumber(x.Id.GetSdUniqueIdentifierValue(), x.Value)),
countryCode,
countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,32 @@ public void RemoveProviderCompanyDetails(Guid providerCompanyDetailId) =>
c.Id,
c.Name)
).SingleOrDefaultAsync();

public Task<bool> HasAnyCompaniesWithMissingSelfDescription() =>
context.Companies.AnyAsync(c =>
c.SelfDescriptionDocumentId == null &&
c.CompanyApplications.Any(ca =>
ca.ApplicationChecklistEntries.Any(a =>
a.ApplicationChecklistEntryTypeId == ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.TO_DO &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.IN_PROGRESS)));

public IAsyncEnumerable<(Guid Id, IEnumerable<(UniqueIdentifierId Id, string Value)> UniqueIdentifiers, string? BusinessPartnerNumber, string CountryCode)> GetCompaniesWithMissingSelfDescription() =>
context.Companies.Where(c =>
c.SelfDescriptionDocumentId == null &&
c.CompanyApplications.Any(ca =>
ca.ApplicationChecklistEntries.Any(a =>
a.ApplicationChecklistEntryTypeId == ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.TO_DO &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.IN_PROGRESS)))
.Select(c => new ValueTuple<Guid, IEnumerable<(UniqueIdentifierId Id, string Value)>, string?, string>(
c.Id,
c.CompanyIdentifiers.Select(ci => new ValueTuple<UniqueIdentifierId, string>(ci.UniqueIdentifierId, ci.Value)),
c.BusinessPartnerNumber,
c.Address!.Country!.Alpha2Code
))
.ToAsyncEnumerable();

public Task<bool> IsExistingCompany(Guid companyId) =>
context.Companies.AnyAsync(c => c.Id == companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,13 @@ public void DeleteConnectorAssignedSubscriptions(Guid connectorId, IEnumerable<G
con.HostId ?? con.ProviderId,
con.HostId != null ? con.Host!.Name : con.Provider!.Name)
).SingleOrDefaultAsync();

public Task<bool> HasAnyConnectorsWithMissingSelfDescription() =>
_context.Connectors.AnyAsync(c => c.SelfDescriptionDocumentId == null);

public IAsyncEnumerable<(Guid Id, string? BusinessPartnerNumber, Guid? SelfDescriptionDocumentId)> GetConnectorsWithMissingSelfDescription() =>
_context.Connectors
.Where(c => c.SelfDescriptionDocumentId == null)
.Select(c => new ValueTuple<Guid, string?, Guid?>(c.Id, c.Provider!.BusinessPartnerNumber, c.Provider.SelfDescriptionDocumentId))
.ToAsyncEnumerable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,7 @@ public interface ICompanyRepository
Task<(string? Holder, string? BusinessPartnerNumber, WalletInformation? WalletInformation)> GetWalletData(Guid identityId);
void RemoveProviderCompanyDetails(Guid providerCompanyDetailId);
Func<int, int, Task<Pagination.Source<CompanyMissingSdDocumentData>?>> GetCompaniesWithMissingSdDocument();
Task<bool> HasAnyCompaniesWithMissingSelfDescription();
IAsyncEnumerable<(Guid Id, IEnumerable<(UniqueIdentifierId Id, string Value)> UniqueIdentifiers, string? BusinessPartnerNumber, string CountryCode)> GetCompaniesWithMissingSelfDescription();
Task<bool> IsExistingCompany(Guid companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ public interface IConnectorsRepository

void DeleteConnectorAssignedSubscriptions(Guid connectorId, IEnumerable<Guid> assignedOfferSubscriptions);
Func<int, int, Task<Pagination.Source<ConnectorMissingSdDocumentData>?>> GetConnectorsWithMissingSdDocument();
Task<bool> HasAnyConnectorsWithMissingSelfDescription();
IAsyncEnumerable<(Guid Id, string? BusinessPartnerNumber, Guid? SelfDescriptionDocumentId)> GetConnectorsWithMissingSelfDescription();
}
Loading

0 comments on commit 59d5d59

Please sign in to comment.