diff --git a/src/administration/Administration.Service/BusinessLogic/INetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/INetworkBusinessLogic.cs index 684562fda6..d67ef4abed 100644 --- a/src/administration/Administration.Service/BusinessLogic/INetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/INetworkBusinessLogic.cs @@ -18,6 +18,7 @@ ********************************************************************************/ using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; @@ -26,4 +27,5 @@ public interface INetworkBusinessLogic { Task HandlePartnerRegistration(PartnerRegistrationData data); Task RetriggerProcessStep(string externalId, ProcessStepTypeId processStepTypeId); + Task> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName, string? externalId, DateCreatedOrderFilter? dateCreatedOrderFilter); } diff --git a/src/administration/Administration.Service/BusinessLogic/IRegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/IRegistrationBusinessLogic.cs index 41b1581324..8f9e27414b 100644 --- a/src/administration/Administration.Service/BusinessLogic/IRegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/IRegistrationBusinessLogic.cs @@ -32,7 +32,6 @@ public interface IRegistrationBusinessLogic { Task GetCompanyWithAddressAsync(Guid applicationId); Task> GetCompanyApplicationDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName); - Task> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName, string? externalId, DateCreatedOrderFilter? dateCreatedOrderFilter); Task> GetAllCompanyApplicationsDetailsAsync(int page, int size, string? companyName); Task UpdateCompanyBpn(Guid applicationId, string bpn); diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 2ba3be6374..67b6957102 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -17,8 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.DependencyInjection; +using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Extensions; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq; @@ -296,4 +298,45 @@ private static void ValidateUsers(UserDetailData user) throw new ControllerArgumentException("Lastname does not match expected format"); } } + + public Task> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName, string? externalId, DateCreatedOrderFilter? dateCreatedOrderFilter) + { + if (companyName != null && !companyName.IsValidCompanyName()) + { + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new ErrorParameter("name", "CompanyName")]); + } + + var applicationsQuery = portalRepositories.GetInstance() + .GetExternalCompanyApplicationsFilteredQuery(_identityData.CompanyId, + companyName?.Length >= 3 ? companyName : null, externalId, + companyApplicationStatusFilter.GetCompanyApplicationStatusIds()); + + var orderedQuery = dateCreatedOrderFilter == null || dateCreatedOrderFilter.Value == DateCreatedOrderFilter.DESC + ? applicationsQuery.AsSplitQuery().OrderByDescending(application => application.DateCreated) + : applicationsQuery.AsSplitQuery().OrderBy(application => application.DateCreated); + + return Pagination.CreateResponseAsync( + page, + size, + _settings.ApplicationsMaxPageSize, + (skip, take) => new Pagination.AsyncSource( + applicationsQuery.CountAsync(), + orderedQuery + .Skip(skip) + .Take(take) + .Select(application => new CompanyDetailsOspOnboarding( + application.CompanyId, + application.NetworkRegistration!.ExternalId, + application.Id, + application.ApplicationStatusId, + application.DateCreated, + application.Company!.DateCreated, + application.DateLastChanged, + application.Company!.Name, + application.Company.CompanyAssignedRoles.Select(companyAssignedRoles => companyAssignedRoles.CompanyRoleId), + application.Company.IdentityProviders.Select(x => new IdentityProvidersDetails(x.Id, x.IamIdentityProvider!.IamIdpAlias)), + application.Company.BusinessPartnerNumber, + application.Company.Identities.Count(x => x.CompanyUser!.Identity!.UserStatusId != UserStatusId.DELETED))) + .AsAsyncEnumerable())); + } } diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index 3db4a91b2d..ac441f7701 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -59,13 +59,11 @@ public sealed class RegistrationBusinessLogic( IIssuerComponentBusinessLogic issuerComponentBusinessLogic, IProvisioningManager provisioningManager, IMailingProcessCreation mailingProcessCreation, - IIdentityService identityService, ILogger logger) : IRegistrationBusinessLogic { private static readonly Regex BpnRegex = new(ValidationExpressions.Bpn, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); - private readonly IIdentityData _identityData = identityService.IdentityData; private readonly RegistrationSettings _settings = configuration.Value; public Task GetCompanyWithAddressAsync(Guid applicationId) @@ -162,45 +160,6 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu .AsAsyncEnumerable())); } - public Task> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName, string? externalId, DateCreatedOrderFilter? dateCreatedOrderFilter) - { - if (companyName != null && !companyName.IsValidCompanyName()) - { - throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new ErrorParameter("name", "CompanyName")]); - } - var applicationsQuery = portalRepositories.GetInstance() - .GetExternalCompanyApplicationsFilteredQuery(_identityData.CompanyId, - companyName?.Length >= 3 ? companyName : null, externalId, - companyApplicationStatusFilter.GetCompanyApplicationStatusIds()); - - var orderedQuery = dateCreatedOrderFilter == null || dateCreatedOrderFilter.Value == DateCreatedOrderFilter.DESC - ? applicationsQuery.AsSplitQuery().OrderByDescending(application => application.DateCreated) - : applicationsQuery.AsSplitQuery().OrderBy(application => application.DateCreated); - - return Pagination.CreateResponseAsync( - page, - size, - _settings.ApplicationsMaxPageSize, - (skip, take) => new Pagination.AsyncSource( - applicationsQuery.CountAsync(), - orderedQuery - .Skip(skip) - .Take(take) - .Select(application => new CompanyDetailsOspOnboarding( - application.CompanyId, - application.NetworkRegistration!.ExternalId, - application.Id, - application.ApplicationStatusId, - application.DateCreated, - application.Company!.DateCreated, - application.DateLastChanged, - application.Company!.Name, - application.Company.CompanyAssignedRoles.Select(companyAssignedRoles => companyAssignedRoles.CompanyRoleId), - application.Company.IdentityProviders.Select(x => new IdentityProvidersDetails(x.Id, x.IamIdentityProvider!.IamIdpAlias)), - application.Company.BusinessPartnerNumber, - application.Company.Identities.Count(x => x.CompanyUser!.Identity!.UserStatusId != UserStatusId.DELETED))) - .AsAsyncEnumerable())); - } public Task> GetAllCompanyApplicationsDetailsAsync(int page, int size, string? companyName) { if (companyName != null && !companyName.IsValidCompanyName()) diff --git a/src/administration/Administration.Service/Controllers/NetworkController.cs b/src/administration/Administration.Service/Controllers/NetworkController.cs index 8e0c88d4a2..d0c0e79b15 100644 --- a/src/administration/Administration.Service/Controllers/NetworkController.cs +++ b/src/administration/Administration.Service/Controllers/NetworkController.cs @@ -22,6 +22,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Web; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.Web; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; using Org.Eclipse.TractusX.Portal.Backend.Web.Identity; @@ -32,33 +33,23 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers [EnvironmentRoute("MVC_ROUTING_BASEPATH", "registration/[controller]")] [Produces("application/json")] [Consumes("application/json")] -public class NetworkController : ControllerBase +public class NetworkController(INetworkBusinessLogic logic) + : ControllerBase { - private readonly INetworkBusinessLogic _logic; - - /// - /// Creates a new instance of - /// - /// The business logic for the registration - public NetworkController(INetworkBusinessLogic logic) - { - _logic = logic; - } - /// /// Registers a partner company /// /// Data for the registration - /// Example: POST: api/administration/registration/network/{externalId}/retrigger-synchronize-users + /// Example: POST: api/administration/registration/network/{externalId}/partnerRegistration /// Empty response on success. [HttpPost] [Authorize(Policy = PolicyTypes.ValidCompany)] - [Authorize(Roles = "create_partner_registration")] + [Authorize(Roles = "configure_partner_registration")] [Route("partnerRegistration")] [ProducesResponseType(StatusCodes.Status200OK)] public async Task PartnerRegister([FromBody] PartnerRegistrationData data) { - await _logic.HandlePartnerRegistration(data).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.HandlePartnerRegistration(data).ConfigureAwait(ConfigureAwaitOptions.None); return Ok(); } @@ -79,7 +70,7 @@ public async Task PartnerRegister([FromBody] PartnerRegistrationData d [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerSynchronizeUser([FromRoute] string externalId) { - await _logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_SYNCHRONIZE_USER).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_SYNCHRONIZE_USER).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -100,7 +91,7 @@ public async Task RetriggerSynchronizeUser([FromRoute] string e [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerCallbackOspApprove([FromRoute] string externalId) { - await _logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_APPROVED).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_APPROVED).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -121,7 +112,7 @@ public async Task RetriggerCallbackOspApprove([FromRoute] strin [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerCallbackOspDecline([FromRoute] string externalId) { - await _logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_DECLINED).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_DECLINED).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -142,7 +133,7 @@ public async Task RetriggerCallbackOspDecline([FromRoute] strin [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerCallbackOspSubmitted([FromRoute] string externalId) { - await _logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_SUBMITTED).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_SUBMITTED).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -163,7 +154,30 @@ public async Task RetriggerCallbackOspSubmitted([FromRoute] str [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerRemoveKeycloakUser([FromRoute] string externalId) { - await _logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_REMOVE_KEYCLOAK_USERS).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_REMOVE_KEYCLOAK_USERS).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } + + /// + /// Get OSP Company Application Detail by Company Name or Status + /// + /// page index start from 0 + /// size to get number of records + /// Search by company applicationstatus + /// search by company name + /// search by external Id + /// sort result by dateCreated ascending or descending + /// OSp Company Application Details + /// + /// Example: GET: api/administration/registration/network/companies?companyName=Car&page=0&size=4&companyApplicationStatus=Closed
+ /// Example: GET: api/administration/registration/network/companies?page=0&size=4 + ///
+ /// Result as a OSP Company Application Details + [HttpGet] + [Authorize(Roles = "configure_partner_registration")] + [Authorize(Policy = PolicyTypes.ValidCompany)] + [Route("companies")] + [ProducesResponseType(typeof(Pagination.Response), StatusCodes.Status200OK)] + public Task> GetOspCompanyDetailsAsync([FromQuery] int page, [FromQuery] int size, [FromQuery] CompanyApplicationStatusFilter? companyApplicationStatusFilter = null, [FromQuery] string? companyName = null, [FromQuery] string? externalId = null, [FromQuery] DateCreatedOrderFilter? dateCreatedOrderFilter = null) => + logic.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName, externalId, dateCreatedOrderFilter); } diff --git a/src/administration/Administration.Service/Controllers/RegistrationController.cs b/src/administration/Administration.Service/Controllers/RegistrationController.cs index 4b1142c6f7..ceda61aca3 100644 --- a/src/administration/Administration.Service/Controllers/RegistrationController.cs +++ b/src/administration/Administration.Service/Controllers/RegistrationController.cs @@ -38,19 +38,9 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers [EnvironmentRoute("MVC_ROUTING_BASEPATH", "registration")] [Produces("application/json")] [Consumes("application/json")] -public class RegistrationController : ControllerBase +public class RegistrationController(IRegistrationBusinessLogic logic) + : ControllerBase { - private readonly IRegistrationBusinessLogic _logic; - - /// - /// Creates a new instance of - /// - /// The business logic for the registration - public RegistrationController(IRegistrationBusinessLogic logic) - { - _logic = logic; - } - /// /// Gets the company with its address /// @@ -67,7 +57,7 @@ public RegistrationController(IRegistrationBusinessLogic logic) [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public Task GetCompanyWithAddressAsync([FromRoute] Guid applicationId) => - _logic.GetCompanyWithAddressAsync(applicationId); + logic.GetCompanyWithAddressAsync(applicationId); /// /// Get Application Detail by Company Name or Status @@ -87,7 +77,7 @@ public Task GetCompanyWithAddressAsync([FromRoute] Guid [Route("applications")] [ProducesResponseType(typeof(Pagination.Response), StatusCodes.Status200OK)] public Task> GetApplicationDetailsAsync([FromQuery] int page, [FromQuery] int size, [FromQuery] CompanyApplicationStatusFilter? companyApplicationStatusFilter = null, [FromQuery] string? companyName = null) => - _logic.GetCompanyApplicationDetailsAsync(page, size, companyApplicationStatusFilter, companyName); + logic.GetCompanyApplicationDetailsAsync(page, size, companyApplicationStatusFilter, companyName); /// /// fetch all applications details with company user details. @@ -103,7 +93,7 @@ public Task GetCompanyWithAddressAsync([FromRoute] Guid [Route("applicationsWithStatus")] [ProducesResponseType(typeof(Pagination.Response), StatusCodes.Status200OK)] public Task> GetAllCompanyApplicationsDetailsAsync([FromQuery] int page = 0, [FromQuery] int size = 15, [FromQuery] string? companyName = null) => - _logic.GetAllCompanyApplicationsDetailsAsync(page, size, companyName); + logic.GetAllCompanyApplicationsDetailsAsync(page, size, companyName); /// /// Update the BPN for a Company @@ -125,7 +115,7 @@ public Task GetCompanyWithAddressAsync([FromRoute] Guid [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status409Conflict)] public Task UpdateCompanyBpn([FromRoute] Guid applicationId, [FromRoute] string bpn) => - _logic.UpdateCompanyBpn(applicationId, bpn); + logic.UpdateCompanyBpn(applicationId, bpn); /// /// Approves the registration verification for the application with the given id @@ -146,7 +136,7 @@ public Task UpdateCompanyBpn([FromRoute] Guid applicationId, [FromRoute] string [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task ApproveApplication([FromRoute] Guid applicationId) { - await _logic.ApproveRegistrationVerification(applicationId).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.ApproveRegistrationVerification(applicationId).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -171,7 +161,7 @@ public async Task ApproveApplication([FromRoute] Guid applicati [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task DeclineApplication([FromRoute] Guid applicationId, [FromBody] RegistrationDeclineData data, CancellationToken cancellationToken) { - await _logic.DeclineRegistrationVerification(applicationId, data.Comment, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.DeclineRegistrationVerification(applicationId, data.Comment, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -193,7 +183,7 @@ public async Task DeclineApplication([FromRoute] Guid applicati [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task ProcessClearinghouseResponse([FromBody] ClearinghouseResponseData responseData, CancellationToken cancellationToken) { - await _logic.ProcessClearinghouseResponseAsync(responseData, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.ProcessClearinghouseResponseAsync(responseData, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -216,7 +206,7 @@ public async Task ProcessClearinghouseResponse([FromBody] Clear [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task ProcessDimResponse([FromRoute] string bpn, [FromBody] DimWalletData responseData, CancellationToken cancellationToken) { - await _logic.ProcessDimResponseAsync(bpn, responseData, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.ProcessDimResponseAsync(bpn, responseData, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -235,7 +225,7 @@ public async Task ProcessDimResponse([FromRoute] string bpn, [F [ProducesResponseType(typeof(ChecklistDetails), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public Task> GetChecklistForApplication([FromRoute] Guid applicationId) => - _logic.GetChecklistForApplicationAsync(applicationId); + logic.GetChecklistForApplicationAsync(applicationId); /// /// Retriggers the last failed to override the clearinghouse-result @@ -255,7 +245,7 @@ public Task> GetChecklistForApplication([FromRoute [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task OverrideClearinghouseChecklist([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.CLEARING_HOUSE, ProcessStepTypeId.MANUAL_TRIGGER_OVERRIDE_CLEARING_HOUSE).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.CLEARING_HOUSE, ProcessStepTypeId.MANUAL_TRIGGER_OVERRIDE_CLEARING_HOUSE).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -277,7 +267,7 @@ public async Task OverrideClearinghouseChecklist([FromRoute] Gu [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerClearinghouseChecklist([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.CLEARING_HOUSE, ProcessStepTypeId.RETRIGGER_CLEARING_HOUSE).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.CLEARING_HOUSE, ProcessStepTypeId.RETRIGGER_CLEARING_HOUSE).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -299,7 +289,7 @@ public async Task RetriggerClearinghouseChecklist([FromRoute] G [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task TriggerIdentityWallet([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_IDENTITY_WALLET).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_IDENTITY_WALLET).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -321,7 +311,7 @@ public async Task TriggerIdentityWallet([FromRoute] Guid applic [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task TriggerSelfDescription([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP, ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_LP).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP, ProcessStepTypeId.RETRIGGER_SELF_DESCRIPTION_LP).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -344,7 +334,7 @@ public async Task TriggerSelfDescription([FromRoute] Guid appli [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task TriggerBpn([FromRoute] Guid applicationId, [FromQuery] ProcessStepTypeId processTypeId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, processTypeId).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, processTypeId).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -366,7 +356,7 @@ public async Task TriggerBpn([FromRoute] Guid applicationId, [F [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task ProcessClearinghouseSelfDescription([FromBody] SelfDescriptionResponseData data, CancellationToken cancellationToken) { - await _logic.ProcessClearinghouseSelfDescription(data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.ProcessClearinghouseSelfDescription(data, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -385,7 +375,7 @@ public async Task ProcessClearinghouseSelfDescription([FromBody [ProducesResponseType(typeof(FileContentResult), StatusCodes.Status404NotFound)] public async Task GetDocumentContentFileAsync([FromRoute] Guid documentId) { - var (fileName, content, contentType) = await _logic.GetDocumentAsync(documentId).ConfigureAwait(ConfigureAwaitOptions.None); + var (fileName, content, contentType) = await logic.GetDocumentAsync(documentId).ConfigureAwait(ConfigureAwaitOptions.None); return File(content, contentType, fileName); } @@ -407,7 +397,7 @@ public async Task GetDocumentContentFileAsync([FromRoute] Guid doc [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerCreateDimWallet([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_CREATE_DIM_WALLET).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_CREATE_DIM_WALLET).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -429,7 +419,7 @@ public async Task RetriggerCreateDimWallet([FromRoute] Guid app [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerValidateDid([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_VALIDATE_DID_DOCUMENT).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_VALIDATE_DID_DOCUMENT).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -451,7 +441,7 @@ public async Task RetriggerValidateDid([FromRoute] Guid applica [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerTransmitBpnDid([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_TRANSMIT_DID_BPN).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.IDENTITY_WALLET, ProcessStepTypeId.RETRIGGER_TRANSMIT_DID_BPN).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -473,7 +463,7 @@ public async Task RetriggerTransmitBpnDid([FromRoute] Guid appl [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerBpnCredential([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.BPNL_CREDENTIAL, ProcessStepTypeId.RETRIGGER_REQUEST_BPN_CREDENTIAL).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.BPNL_CREDENTIAL, ProcessStepTypeId.RETRIGGER_REQUEST_BPN_CREDENTIAL).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -495,7 +485,7 @@ public async Task RetriggerBpnCredential([FromRoute] Guid appli [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerMembershipCredential([FromRoute] Guid applicationId) { - await _logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.MEMBERSHIP_CREDENTIAL, ProcessStepTypeId.RETRIGGER_REQUEST_MEMBERSHIP_CREDENTIAL).ConfigureAwait(ConfigureAwaitOptions.None); + await logic.TriggerChecklistAsync(applicationId, ApplicationChecklistEntryTypeId.MEMBERSHIP_CREDENTIAL, ProcessStepTypeId.RETRIGGER_REQUEST_MEMBERSHIP_CREDENTIAL).ConfigureAwait(ConfigureAwaitOptions.None); return NoContent(); } @@ -517,7 +507,7 @@ public async Task RetriggerMembershipCredential([FromRoute] Gui [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task ProcessIssuerBpnResponse([FromBody] IssuerResponseData responseData, CancellationToken cancellationToken) { - await _logic.ProcessIssuerBpnResponseAsync(responseData, cancellationToken).ConfigureAwait(false); + await logic.ProcessIssuerBpnResponseAsync(responseData, cancellationToken).ConfigureAwait(false); return NoContent(); } @@ -539,7 +529,7 @@ public async Task ProcessIssuerBpnResponse([FromBody] IssuerRes [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task ProcessIssuerMembershipResponse([FromBody] IssuerResponseData responseData, CancellationToken cancellationToken) { - await _logic.ProcessIssuerMembershipResponseAsync(responseData, cancellationToken).ConfigureAwait(false); + await logic.ProcessIssuerMembershipResponseAsync(responseData, cancellationToken).ConfigureAwait(false); return NoContent(); } @@ -560,7 +550,7 @@ public async Task ProcessIssuerMembershipResponse([FromBody] Is [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerDeleteIdpSharedRealm([FromRoute] Guid processId) { - await _logic.RetriggerDeleteIdpSharedRealm(processId).ConfigureAwait(false); + await logic.RetriggerDeleteIdpSharedRealm(processId).ConfigureAwait(false); return NoContent(); } @@ -581,7 +571,7 @@ public async Task RetriggerDeleteIdpSharedRealm([FromRoute] Gui [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerDeleteIdpSharedServiceAccount([FromRoute] Guid processId) { - await _logic.RetriggerDeleteIdpSharedServiceAccount(processId).ConfigureAwait(false); + await logic.RetriggerDeleteIdpSharedServiceAccount(processId).ConfigureAwait(false); return NoContent(); } @@ -602,7 +592,7 @@ public async Task RetriggerDeleteIdpSharedServiceAccount([FromR [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerDeleteCentralIdentityProvider([FromRoute] Guid processId) { - await _logic.RetriggerDeleteCentralIdentityProvider(processId).ConfigureAwait(false); + await logic.RetriggerDeleteCentralIdentityProvider(processId).ConfigureAwait(false); return NoContent(); } @@ -623,31 +613,8 @@ public async Task RetriggerDeleteCentralIdentityProvider([FromR [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)] public async Task RetriggerDeleteCentralUser([FromRoute] Guid processId) { - await _logic.RetriggerDeleteCentralUser(processId).ConfigureAwait(false); + await logic.RetriggerDeleteCentralUser(processId).ConfigureAwait(false); return NoContent(); } - - /// - /// Get OSP Company Application Detail by Company Name or Status - /// - /// page index start from 0 - /// size to get number of records - /// Search by company applicationstatus - /// search by company name - /// search by external Id - /// sort result by dateCreated ascending or descending - /// OSp Company Application Details - /// - /// Example: GET: api/administration/registration/network/companies?companyName=Car&page=0&size=4&companyApplicationStatus=Closed
- /// Example: GET: api/administration/registration/network/companies?page=0&size=4 - ///
- /// Result as a OSP Company Application Details - [HttpGet] - [Authorize(Roles = "view_submitted_applications")] - [Authorize(Policy = PolicyTypes.ValidCompany)] - [Route("network/companies")] - [ProducesResponseType(typeof(Pagination.Response), StatusCodes.Status200OK)] - public Task> GetOspCompanyDetailsAsync([FromQuery] int page, [FromQuery] int size, [FromQuery] CompanyApplicationStatusFilter? companyApplicationStatusFilter = null, [FromQuery] string? companyName = null, [FromQuery] string? externalId = null, [FromQuery] DateCreatedOrderFilter? dateCreatedOrderFilter = null) => - _logic.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName, externalId, dateCreatedOrderFilter); } diff --git a/src/administration/Administration.Service/DependencyInjection/PartnerRegistrationSettings.cs b/src/administration/Administration.Service/DependencyInjection/PartnerRegistrationSettings.cs index 28fc83cca4..b847710016 100644 --- a/src/administration/Administration.Service/DependencyInjection/PartnerRegistrationSettings.cs +++ b/src/administration/Administration.Service/DependencyInjection/PartnerRegistrationSettings.cs @@ -25,6 +25,8 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.DependencyI public class PartnerRegistrationSettings { + public int ApplicationsMaxPageSize { get; set; } + [Required] [DistinctValues("x => x.ClientId")] public IEnumerable InitialRoles { get; set; } = null!; diff --git a/src/administration/Administration.Service/appsettings.json b/src/administration/Administration.Service/appsettings.json index b8e9af6ed0..55fa24eb0d 100644 --- a/src/administration/Administration.Service/appsettings.json +++ b/src/administration/Administration.Service/appsettings.json @@ -387,7 +387,8 @@ }, "Network2Network": { "InitialRoles": [], - "BasePortalAddress": "" + "BasePortalAddress": "", + "ApplicationsMaxPageSize": 20 }, "OnboardingServiceProvider": { "Username": "", diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs index bb0958da2c..7736ccf8fd 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs @@ -22,6 +22,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; @@ -33,6 +34,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Provisioning.Library.Models; using Org.Eclipse.TractusX.Portal.Backend.Provisioning.Library.Service; using Org.Eclipse.TractusX.Portal.Backend.Registration.Common; +using Org.Eclipse.TractusX.Portal.Backend.Tests.Shared; using Org.Eclipse.TractusX.Portal.Backend.Tests.Shared.Extensions; using System.Collections.Immutable; @@ -42,6 +44,7 @@ public class NetworkBusinessLogicTests { private const string Bpn = "BPNL00000001TEST"; private static readonly string ExistingExternalId = Guid.NewGuid().ToString(); + private static readonly Guid CompanyId = new("95c4339e-e087-4cd2-a5b8-44d385e64630"); private static readonly Guid UserRoleId = Guid.NewGuid(); private static readonly Guid MultiIdpCompanyId = Guid.NewGuid(); private static readonly Guid NoIdpCompanyId = Guid.NewGuid(); @@ -88,14 +91,15 @@ public NetworkBusinessLogicTests() var settings = new PartnerRegistrationSettings { - InitialRoles = new[] { new UserRoleConfig("cl1", new[] { "Company Admin" }) } + InitialRoles = new[] { new UserRoleConfig("cl1", new[] { "Company Admin" }) }, + ApplicationsMaxPageSize = 20 }; var options = A.Fake>(); A.CallTo(() => options.Value).Returns(settings); A.CallTo(() => _identity.IdentityId).Returns(Guid.NewGuid()); A.CallTo(() => _identity.IdentityTypeId).Returns(IdentityTypeId.COMPANY_USER); - A.CallTo(() => _identity.CompanyId).Returns(Guid.NewGuid()); + A.CallTo(() => _identity.CompanyId).Returns(CompanyId); A.CallTo(() => _identityService.IdentityData).Returns(_identity); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_companyRepository); @@ -707,6 +711,92 @@ public async Task RetriggerSynchronizeUser_CallsExpected() #endregion + #region GetOSPCompanyApplicationDetailsAsync + + [Theory] + [InlineData(null, null)] + [InlineData(null, DateCreatedOrderFilter.ASC)] + [InlineData(null, DateCreatedOrderFilter.DESC)] + [InlineData(CompanyApplicationStatusFilter.Closed, null)] + [InlineData(CompanyApplicationStatusFilter.InReview, null)] + [InlineData(CompanyApplicationStatusFilter.Closed, DateCreatedOrderFilter.ASC)] + [InlineData(CompanyApplicationStatusFilter.InReview, DateCreatedOrderFilter.ASC)] + [InlineData(CompanyApplicationStatusFilter.Closed, DateCreatedOrderFilter.DESC)] + [InlineData(CompanyApplicationStatusFilter.InReview, DateCreatedOrderFilter.DESC)] + public async Task GetOspCompanyApplicationDetailsAsync_WithDefaultRequest_GetsExpectedEntries(CompanyApplicationStatusFilter? statusFilter, DateCreatedOrderFilter? dateCreatedOrderFilter) + { + // Arrange + var companyName = "TestCompany"; + var externalId = _fixture.Create(); + var data = _fixture.CreateMany<(Guid Id, Guid CompanyId, CompanyApplicationStatusId CompanyApplicationStatusId, DateTimeOffset Created)>(10) + .Select(x => new CompanyApplication(x.Id, x.CompanyId, x.CompanyApplicationStatusId, CompanyApplicationTypeId.EXTERNAL, x.Created) + { + Company = new Company(x.CompanyId, _fixture.Create(), _fixture.Create(), x.Created) + { + Name = _fixture.Create(), + BusinessPartnerNumber = _fixture.Create(), + }, + NetworkRegistration = new NetworkRegistration(Guid.NewGuid(), _fixture.Create(), x.CompanyId, Guid.NewGuid(), Guid.NewGuid(), x.Id, x.Created) + { + ExternalId = _fixture.Create(), + DateCreated = _fixture.Create(), + }, + DateLastChanged = _fixture.Create() + }).ToImmutableList(); + + var queryData = new AsyncEnumerableStub(data).AsQueryable(); + + A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(A._, A._, A._, A>._)) + .Returns(queryData); + + // Act + var result = await _sut.GetOspCompanyDetailsAsync(0, 3, statusFilter, companyName, externalId, dateCreatedOrderFilter); + + // Assert + Assert.IsType>(result); + + switch (statusFilter) + { + case CompanyApplicationStatusFilter.Closed: + A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(CompanyId, companyName, externalId, A>.That.IsSameSequenceAs(new[] { CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED }))).MustHaveHappenedOnceExactly(); + break; + case CompanyApplicationStatusFilter.InReview: + A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(CompanyId, companyName, externalId, A>.That.IsSameSequenceAs(new[] { CompanyApplicationStatusId.SUBMITTED }))).MustHaveHappenedOnceExactly(); + break; + default: + A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(CompanyId, companyName, externalId, A>.That.IsSameSequenceAs(new[] { CompanyApplicationStatusId.SUBMITTED, CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED }))).MustHaveHappenedOnceExactly(); + break; + } + + result.Meta.NumberOfElements.Should().Be(10); + + var sorted = dateCreatedOrderFilter switch + { + DateCreatedOrderFilter.ASC => data.OrderBy(application => application.Company!.DateCreated).Take(3).ToImmutableArray(), + DateCreatedOrderFilter.DESC => data.OrderByDescending(application => application.Company!.DateCreated).Take(3).ToImmutableArray(), + _ => data.OrderByDescending(application => application.Company!.DateCreated).Take(3).ToImmutableArray() + }; + + result.Content.Should().HaveCount(3).And.Satisfy( + x => x.ApplicationId == sorted[0].Id && x.CompanyApplicationStatusId == sorted[0].ApplicationStatusId && x.DateCreated == sorted[0].DateCreated && x.DateLastChanged == sorted[0].DateLastChanged && x.CompanyId == sorted[0].CompanyId && x.CompanyName == sorted[0].Company!.Name && x.BusinessPartnerNumber == sorted[0].Company!.BusinessPartnerNumber, + x => x.ApplicationId == sorted[1].Id && x.CompanyApplicationStatusId == sorted[1].ApplicationStatusId && x.DateCreated == sorted[1].DateCreated && x.DateLastChanged == sorted[1].DateLastChanged && x.CompanyId == sorted[1].CompanyId && x.CompanyName == sorted[1].Company!.Name && x.BusinessPartnerNumber == sorted[1].Company!.BusinessPartnerNumber, + x => x.ApplicationId == sorted[2].Id && x.CompanyApplicationStatusId == sorted[2].ApplicationStatusId && x.DateCreated == sorted[2].DateCreated && x.DateLastChanged == sorted[2].DateLastChanged && x.CompanyId == sorted[2].CompanyId && x.CompanyName == sorted[2].Company!.Name && x.BusinessPartnerNumber == sorted[2].Company!.BusinessPartnerNumber + ); + + switch (dateCreatedOrderFilter) + { + case DateCreatedOrderFilter.ASC: + result.Content.Should().BeInAscendingOrder(x => x.DateCreated); + break; + case null: + case DateCreatedOrderFilter.DESC: + result.Content.Should().BeInDescendingOrder(x => x.DateCreated); + break; + } + } + + #endregion + #region Setup private void SetupRepos() diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs index e6a41683d6..e78de09114 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/RegistrationBusinessLogicTest.cs @@ -74,7 +74,6 @@ public class RegistrationBusinessLogicTest private readonly IFixture _fixture; private readonly IRegistrationBusinessLogic _logic; private readonly ICompanyRepository _companyRepository; - private readonly IConnectorsRepository _connectorRepository; private readonly IApplicationChecklistService _checklistService; private readonly IClearinghouseBusinessLogic _clearinghouseBusinessLogic; private readonly ISdFactoryBusinessLogic _sdFactoryBusinessLogic; @@ -83,8 +82,6 @@ public class RegistrationBusinessLogicTest private readonly IProvisioningManager _provisioningManager; private readonly IDimBusinessLogic _dimBusinessLogic; private readonly IOptions _options; - private readonly IIdentityData _identityData; - private readonly IIdentityService _identityService; private readonly ILogger _logger; public RegistrationBusinessLogicTest() @@ -99,15 +96,12 @@ public RegistrationBusinessLogicTest() _processStepRepository = A.Fake(); _userRepository = A.Fake(); _companyRepository = A.Fake(); - _connectorRepository = A.Fake(); _mailingProcessCreation = A.Fake(); _options = A.Fake>(); var settings = A.Fake(); settings.ApplicationsMaxPageSize = 15; A.CallTo(() => _options.Value).Returns(settings); - _identityService = A.Fake(); - _identityData = A.Fake(); _clearinghouseBusinessLogic = A.Fake(); _sdFactoryBusinessLogic = A.Fake(); @@ -121,17 +115,11 @@ public RegistrationBusinessLogicTest() A.CallTo(() => _portalRepositories.GetInstance()).Returns(_documentRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_userRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_companyRepository); - A.CallTo(() => _portalRepositories.GetInstance()).Returns(_connectorRepository); A.CallTo(() => _portalRepositories.GetInstance()).Returns(_processStepRepository); - A.CallTo(() => _identityData.IdentityId).Returns(Guid.NewGuid()); - A.CallTo(() => _identityData.IdentityTypeId).Returns(IdentityTypeId.COMPANY_USER); - A.CallTo(() => _identityData.CompanyId).Returns(CompanyId); - A.CallTo(() => _identityService.IdentityData).Returns(_identityData); - _logger = A.Fake>(); - _logic = new RegistrationBusinessLogic(_portalRepositories, _options, _checklistService, _clearinghouseBusinessLogic, _sdFactoryBusinessLogic, _dimBusinessLogic, _issuerComponentBusinessLogic, _provisioningManager, _mailingProcessCreation, _identityService, _logger); + _logic = new RegistrationBusinessLogic(_portalRepositories, _options, _checklistService, _clearinghouseBusinessLogic, _sdFactoryBusinessLogic, _dimBusinessLogic, _issuerComponentBusinessLogic, _provisioningManager, _mailingProcessCreation, _logger); } #region GetCompanyApplicationDetailsAsync @@ -190,92 +178,6 @@ public async Task GetCompanyApplicationDetailsAsync_WithClosedRequest_GetsExpect #endregion - #region GetOSPCompanyApplicationDetailsAsync - - [Theory] - [InlineData(null, null)] - [InlineData(null, DateCreatedOrderFilter.ASC)] - [InlineData(null, DateCreatedOrderFilter.DESC)] - [InlineData(CompanyApplicationStatusFilter.Closed, null)] - [InlineData(CompanyApplicationStatusFilter.InReview, null)] - [InlineData(CompanyApplicationStatusFilter.Closed, DateCreatedOrderFilter.ASC)] - [InlineData(CompanyApplicationStatusFilter.InReview, DateCreatedOrderFilter.ASC)] - [InlineData(CompanyApplicationStatusFilter.Closed, DateCreatedOrderFilter.DESC)] - [InlineData(CompanyApplicationStatusFilter.InReview, DateCreatedOrderFilter.DESC)] - public async Task GetOspCompanyApplicationDetailsAsync_WithDefaultRequest_GetsExpectedEntries(CompanyApplicationStatusFilter? statusFilter, DateCreatedOrderFilter? dateCreatedOrderFilter) - { - // Arrange - var companyName = "TestCompany"; - var externalId = _fixture.Create(); - var data = _fixture.CreateMany<(Guid Id, Guid CompanyId, CompanyApplicationStatusId CompanyApplicationStatusId, DateTimeOffset Created)>(10) - .Select(x => new CompanyApplication(x.Id, x.CompanyId, x.CompanyApplicationStatusId, CompanyApplicationTypeId.EXTERNAL, x.Created) - { - Company = new Company(x.CompanyId, _fixture.Create(), _fixture.Create(), x.Created) - { - Name = _fixture.Create(), - BusinessPartnerNumber = _fixture.Create(), - }, - NetworkRegistration = new NetworkRegistration(Guid.NewGuid(), _fixture.Create(), x.CompanyId, Guid.NewGuid(), Guid.NewGuid(), x.Id, x.Created) - { - ExternalId = _fixture.Create(), - DateCreated = _fixture.Create(), - }, - DateLastChanged = _fixture.Create() - }).ToImmutableList(); - - var queryData = new AsyncEnumerableStub(data).AsQueryable(); - - A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(A._, A._, A._, A>._)) - .Returns(queryData); - - // Act - var result = await _logic.GetOspCompanyDetailsAsync(0, 3, statusFilter, companyName, externalId, dateCreatedOrderFilter); - - // Assert - Assert.IsType>(result); - - switch (statusFilter) - { - case CompanyApplicationStatusFilter.Closed: - A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(CompanyId, companyName, externalId, A>.That.IsSameSequenceAs(new[] { CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED }))).MustHaveHappenedOnceExactly(); - break; - case CompanyApplicationStatusFilter.InReview: - A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(CompanyId, companyName, externalId, A>.That.IsSameSequenceAs(new[] { CompanyApplicationStatusId.SUBMITTED }))).MustHaveHappenedOnceExactly(); - break; - default: - A.CallTo(() => _applicationRepository.GetExternalCompanyApplicationsFilteredQuery(CompanyId, companyName, externalId, A>.That.IsSameSequenceAs(new[] { CompanyApplicationStatusId.SUBMITTED, CompanyApplicationStatusId.CONFIRMED, CompanyApplicationStatusId.DECLINED }))).MustHaveHappenedOnceExactly(); - break; - } - - result.Meta.NumberOfElements.Should().Be(10); - - var sorted = dateCreatedOrderFilter switch - { - DateCreatedOrderFilter.ASC => data.OrderBy(application => application.Company!.DateCreated).Take(3).ToImmutableArray(), - DateCreatedOrderFilter.DESC => data.OrderByDescending(application => application.Company!.DateCreated).Take(3).ToImmutableArray(), - _ => data.OrderByDescending(application => application.Company!.DateCreated).Take(3).ToImmutableArray() - }; - - result.Content.Should().HaveCount(3).And.Satisfy( - x => x.ApplicationId == sorted[0].Id && x.CompanyApplicationStatusId == sorted[0].ApplicationStatusId && x.DateCreated == sorted[0].DateCreated && x.DateLastChanged == sorted[0].DateLastChanged && x.CompanyId == sorted[0].CompanyId && x.CompanyName == sorted[0].Company!.Name && x.BusinessPartnerNumber == sorted[0].Company!.BusinessPartnerNumber, - x => x.ApplicationId == sorted[1].Id && x.CompanyApplicationStatusId == sorted[1].ApplicationStatusId && x.DateCreated == sorted[1].DateCreated && x.DateLastChanged == sorted[1].DateLastChanged && x.CompanyId == sorted[1].CompanyId && x.CompanyName == sorted[1].Company!.Name && x.BusinessPartnerNumber == sorted[1].Company!.BusinessPartnerNumber, - x => x.ApplicationId == sorted[2].Id && x.CompanyApplicationStatusId == sorted[2].ApplicationStatusId && x.DateCreated == sorted[2].DateCreated && x.DateLastChanged == sorted[2].DateLastChanged && x.CompanyId == sorted[2].CompanyId && x.CompanyName == sorted[2].Company!.Name && x.BusinessPartnerNumber == sorted[2].Company!.BusinessPartnerNumber - ); - - switch (dateCreatedOrderFilter) - { - case DateCreatedOrderFilter.ASC: - result.Content.Should().BeInAscendingOrder(x => x.DateCreated); - break; - case null: - case DateCreatedOrderFilter.DESC: - result.Content.Should().BeInDescendingOrder(x => x.DateCreated); - break; - } - } - - #endregion - #region GetCompanyWithAddressAsync [Theory] @@ -449,8 +351,7 @@ public async Task UpdateCompanyBpnAsync_WithUseDimWalletFalse_CallsExpected(bool A.CallTo(() => _options.Value).Returns(new RegistrationSettings { UseDimWallet = useDimWallet }); var entry = new ApplicationChecklistEntry(IdWithoutBpn, ApplicationChecklistEntryTypeId.BUSINESS_PARTNER_NUMBER, ApplicationChecklistEntryStatusId.TO_DO, DateTimeOffset.UtcNow); SetupForUpdateCompanyBpn(entry); - var identityService = A.Fake(); - var logic = new RegistrationBusinessLogic(_portalRepositories, options, _checklistService, null!, null!, _dimBusinessLogic, null!, _provisioningManager, null!, identityService, null!); + var logic = new RegistrationBusinessLogic(_portalRepositories, options, _checklistService, null!, null!, _dimBusinessLogic, null!, _provisioningManager, null!, null!); // Act await logic.UpdateCompanyBpn(IdWithoutBpn, ValidBpn); @@ -527,8 +428,7 @@ public async Task SetRegistrationVerification_WithApproval_CallsExpected(bool us { // Arrange var options = Options.Create(new RegistrationSettings { UseDimWallet = useDimWallet }); - var identityService = A.Fake(); - var logic = new RegistrationBusinessLogic(_portalRepositories, options, _checklistService, null!, null!, _dimBusinessLogic, null!, null!, null!, identityService, null!); + var logic = new RegistrationBusinessLogic(_portalRepositories, options, _checklistService, null!, null!, _dimBusinessLogic, null!, null!, null!, null!); var entry = new ApplicationChecklistEntry(IdWithBpn, ApplicationChecklistEntryTypeId.REGISTRATION_VERIFICATION, ApplicationChecklistEntryStatusId.TO_DO, DateTimeOffset.UtcNow); SetupForApproveRegistrationVerification(entry); @@ -824,7 +724,7 @@ public async Task TriggerChecklistAsync_WithValidData_ReturnsExpected(Applicatio var settings = A.Fake(); A.CallTo(() => _options.Value).Returns(settings); - var logic = new RegistrationBusinessLogic(_portalRepositories, _options, _checklistService, _clearinghouseBusinessLogic, _sdFactoryBusinessLogic, _dimBusinessLogic, _issuerComponentBusinessLogic, _provisioningManager, _mailingProcessCreation, _identityService, _logger); + var logic = new RegistrationBusinessLogic(_portalRepositories, _options, _checklistService, _clearinghouseBusinessLogic, _sdFactoryBusinessLogic, _dimBusinessLogic, _issuerComponentBusinessLogic, _provisioningManager, _mailingProcessCreation, _logger); await logic.TriggerChecklistAsync(applicationId, typeId, stepId); // Assert diff --git a/tests/administration/Administration.Service.Tests/Controllers/NetworkControllerTests.cs b/tests/administration/Administration.Service.Tests/Controllers/NetworkControllerTests.cs index ee67f8f1e7..c59e512580 100644 --- a/tests/administration/Administration.Service.Tests/Controllers/NetworkControllerTests.cs +++ b/tests/administration/Administration.Service.Tests/Controllers/NetworkControllerTests.cs @@ -20,6 +20,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Tests.Controllers; @@ -110,4 +111,28 @@ public async Task RetriggerCallbackOspSubmitted_ReturnsExpected() A.CallTo(() => _logic.RetriggerProcessStep(externalId, ProcessStepTypeId.RETRIGGER_CALLBACK_OSP_SUBMITTED)) .MustHaveHappenedOnceExactly(); } + + [Fact] + public async Task GetOspCompanyApplicationDetailsAsync_ReturnsCompanyApplicationDetails() + { + //Arrange + var page = _fixture.Create(); + var size = _fixture.Create(); + var companyApplicationStatusFilter = _fixture.Create(); + var companyName = _fixture.Create(); + var externalId = _fixture.Create(); + var dateCreatedOrderFilter = _fixture.Create(); + + var paginationResponse = new Pagination.Response(new Pagination.Metadata(15, 1, 1, 15), _fixture.CreateMany(5)); + A.CallTo(() => _logic.GetOspCompanyDetailsAsync(A._, A._, A._, A._, A._, A._)) + .Returns(paginationResponse); + + //Act + var result = await _controller.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName, externalId, dateCreatedOrderFilter); + + //Assert + A.CallTo(() => _logic.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName, externalId, dateCreatedOrderFilter)).MustHaveHappenedOnceExactly(); + Assert.IsType>(result); + result.Content.Should().HaveCount(5); + } } diff --git a/tests/administration/Administration.Service.Tests/Controllers/RegistrationControllerTest.cs b/tests/administration/Administration.Service.Tests/Controllers/RegistrationControllerTest.cs index 23b73ca995..856d684475 100644 --- a/tests/administration/Administration.Service.Tests/Controllers/RegistrationControllerTest.cs +++ b/tests/administration/Administration.Service.Tests/Controllers/RegistrationControllerTest.cs @@ -70,30 +70,6 @@ public async Task GetCompanyApplicationDetailsAsync_ReturnsCompanyApplicationDet result.Content.Should().HaveCount(5); } - [Fact] - public async Task GetOspCompanyApplicationDetailsAsync_ReturnsCompanyApplicationDetails() - { - //Arrange - var page = _fixture.Create(); - var size = _fixture.Create(); - var companyApplicationStatusFilter = _fixture.Create(); - var companyName = _fixture.Create(); - var externalId = _fixture.Create(); - var dateCreatedOrderFilter = _fixture.Create(); - - var paginationResponse = new Pagination.Response(new Pagination.Metadata(15, 1, 1, 15), _fixture.CreateMany(5)); - A.CallTo(() => _logic.GetOspCompanyDetailsAsync(A._, A._, A._, A._, A._, A._)) - .Returns(paginationResponse); - - //Act - var result = await _controller.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName, externalId, dateCreatedOrderFilter); - - //Assert - A.CallTo(() => _logic.GetOspCompanyDetailsAsync(page, size, companyApplicationStatusFilter, companyName, externalId, dateCreatedOrderFilter)).MustHaveHappenedOnceExactly(); - Assert.IsType>(result); - result.Content.Should().HaveCount(5); - } - [Fact] public async Task GetCompanyWithAddressAsync_ReturnsExpectedResult() {