Skip to content

Commit

Permalink
feat(sd): handle companies and connectors with missing sd documents (#…
Browse files Browse the repository at this point in the history
…854)

* feat(sd): add endpoints to get companies and connectors with missing sd doc
* feat(sd): add process for sd document creation
* tests: add unit tests for sd creation process
Refs: #813
---------
Co-authored-by: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 authored Aug 6, 2024
1 parent 76138ca commit 7fa72b1
Show file tree
Hide file tree
Showing 45 changed files with 11,253 additions and 171 deletions.
30 changes: 30 additions & 0 deletions src/Portal.Backend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ 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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfDescriptionCreation.Executor.Tests", "..\tests\processes\SelfDescriptionCreation.Executor.Tests\SelfDescriptionCreation.Executor.Tests.csproj", "{E87898BA-59A4-4F02-9594-50756BBF4E22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1794,6 +1798,30 @@ 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
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x64.ActiveCfg = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x64.Build.0 = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x86.ActiveCfg = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Debug|x86.Build.0 = Debug|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|Any CPU.Build.0 = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x64.ActiveCfg = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x64.Build.0 = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x86.ActiveCfg = Release|Any CPU
{E87898BA-59A4-4F02-9594-50756BBF4E22}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1928,5 +1956,7 @@ 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}
{E87898BA-59A4-4F02-9594-50756BBF4E22} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ public async Task<DimUrlsResponse> GetDimServiceUrls()
);
}

public Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
_settings.MaxPageSize,
portalRepositories.GetInstance<ICompanyRepository>().GetCompaniesWithMissingSdDocument());

/// <inheritdoc />
public async Task<int> DeleteCompanyCertificateAsync(Guid documentId)
{
Expand Down Expand Up @@ -432,4 +439,18 @@ public async Task<int> DeleteCompanyCertificateAsync(Guid documentId)

return (documentDetails.FileName, documentDetails.Content, documentDetails.MediaTypeId.MapToMediaType());
}

public async Task TriggerSelfDescriptionCreation()
{
var hasMissingSdDocumentCompanies = await portalRepositories.GetInstance<ICompanyRepository>().HasAnyCompaniesWithMissingSelfDescription().ConfigureAwait(ConfigureAwaitOptions.None);
if (hasMissingSdDocumentCompanies)
{
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
var processId = processStepRepository.CreateProcess(ProcessTypeId.SELF_DESCRIPTION_CREATION).Id;

processStepRepository.CreateProcessStep(ProcessStepTypeId.SELF_DESCRIPTION_COMPANY_CREATION, ProcessStepStatusId.TODO, processId);

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public async Task<ConnectorData> GetCompanyConnectorData(Guid connectorId)
{
throw NotFoundException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_FOUND, new ErrorParameter[] { new("connectorId", connectorId.ToString()) });
}

if (!result.IsProviderCompany)
{
throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY, new ErrorParameter[] { new("companyId", companyId.ToString()), new("connectorId", connectorId.ToString()) });
}

return result.ConnectorData;
}

Expand Down Expand Up @@ -248,6 +250,7 @@ public async Task DeleteConnectorAsync(Guid connectorId)
{
throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY_NOR_HOST, new ErrorParameter[] { new("companyId", companyId.ToString()), new("connectorId", connectorId.ToString()) });
}

if (result.ServiceAccountId.HasValue && result.UserStatusId != UserStatusId.INACTIVE)
{
portalRepositories.GetInstance<IUserRepository>().AttachAndModifyIdentity(result.ServiceAccountId.Value, null, i =>
Expand Down Expand Up @@ -315,6 +318,7 @@ private static void RemoveConnectorAssignedOfferSubscriptions(Guid connectorId,
{
throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_DELETION_FAILED_OFFER_SUBSCRIPTION, new ErrorParameter[] { new("connectorId", connectorId.ToString()), new("activeConnectorOfferSubscription", string.Join(",", activeConnectorOfferSubscription)) });
}

var assignedOfferSubscriptions = connectorOfferSubscriptions.Select(cos => cos.AssignedOfferSubscriptionIds);
if (assignedOfferSubscriptions.Any())
{
Expand Down Expand Up @@ -358,7 +362,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 @@ -419,4 +423,24 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR
public IAsyncEnumerable<OfferSubscriptionConnectorData> GetConnectorOfferSubscriptionData(bool? connectorIdSet) =>
portalRepositories.GetInstance<IOfferSubscriptionsRepository>()
.GetConnectorOfferSubscriptionData(connectorIdSet, _identityData.CompanyId);

public Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
_settings.MaxPageSize,
portalRepositories.GetInstance<IConnectorsRepository>().GetConnectorsWithMissingSdDocument());

public async Task TriggerSelfDescriptionCreation()
{
var hasMissingSdDocumentConnectors = await portalRepositories.GetInstance<IConnectorsRepository>().HasAnyConnectorsWithMissingSelfDescription().ConfigureAwait(ConfigureAwaitOptions.None);
if (hasMissingSdDocumentConnectors)
{
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
var processId = processStepRepository.CreateProcess(ProcessTypeId.SELF_DESCRIPTION_CREATION).Id;
processStepRepository.CreateProcessStep(ProcessStepTypeId.SELF_DESCRIPTION_CONNECTOR_CREATION, ProcessStepStatusId.TODO, processId);

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ public interface ICompanyDataBusinessLogic

Task<Pagination.Response<CompanyCertificateData>> GetAllCompanyCertificatesAsync(int page, int size, CertificateSorting? sorting, CompanyCertificateStatusId? certificateStatus, CompanyCertificateTypeId? certificateType);
Task<DimUrlsResponse> GetDimServiceUrls();
Task<Pagination.Response<CompanyMissingSdDocumentData>> GetCompaniesWithMissingSdDocument(int page, int size);
Task TriggerSelfDescriptionCreation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ public interface IConnectorsBusinessLogic
/// </param>
/// <returns>Returns an IAsyncEnumerable of <see cref="OfferSubscriptionConnectorData"/></returns>
IAsyncEnumerable<OfferSubscriptionConnectorData> GetConnectorOfferSubscriptionData(bool? connectorIdSet);

Task<Pagination.Response<ConnectorMissingSdDocumentData>> GetConnectorsWithMissingSdDocument(int page, int size);

Task TriggerSelfDescriptionCreation();
}
Loading

0 comments on commit 7fa72b1

Please sign in to comment.