Skip to content

Commit

Permalink
adapted the translatable error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dhiren-singh-007 committed Aug 5, 2024
1 parent ccbbd87 commit ffea4a3
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data,

if (!string.IsNullOrEmpty(data.Issuer) && !ValidationExpressionsValidator.IsValidCompanyName(data.Issuer))
{
throw new ControllerArgumentException($"Issuer: {ValidationExpressionErrorMessages.CompanyError}", nameof(data.Issuer));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(data.Issuer))]);
}

var documentContentType = data.Document.ContentType.ParseMediaTypeId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData)

if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !ValidationExpressionsValidator.IsValidCompanyName(invitationData.OrganisationName))
{
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName");
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(invitationData.OrganisationName))]);
}

return ExecuteInvitationInternalAsync(invitationData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task HandlePartnerRegistration(PartnerRegistrationData data)
{
if (!ValidationExpressionsValidator.IsValidCompanyName(data.Name))
{
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName");
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]);
}

var ownerCompanyId = _identityData.CompanyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
}
if (!ValidationExpressionsValidator.IsValidCompanyName(companyWithAddress.Name))
{
throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName");
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]);
}

return new CompanyWithAddressData(
Expand Down Expand Up @@ -147,7 +147,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
{
if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]);
}
var applications = _portalRepositories.GetInstance<IApplicationRepository>()
.GetCompanyApplicationsFilteredQuery(
Expand Down Expand Up @@ -221,7 +221,7 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
{
if (!ValidationExpressionsValidator.IsValidCompanyName(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]);
}
var applications = _portalRepositories.GetInstance<IApplicationRepository>().GetAllCompanyApplicationsDetailsQuery(companyName);

Expand Down
4 changes: 3 additions & 1 deletion src/administration/Administration.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
Expand Down Expand Up @@ -94,7 +95,8 @@ await WebAppHelper
.AddSingleton<IErrorMessageContainer, AdministrationMailErrorMessageContainer>()
.AddSingleton<IErrorMessageContainer, AdministrationRegistrationErrorMessageContainer>()
.AddSingleton<IErrorMessageContainer, AdministrationServiceAccountErrorMessageContainer>()
.AddSingleton<IErrorMessageContainer, ProvisioningServiceErrorMessageContainer>();
.AddSingleton<IErrorMessageContainer, ProvisioningServiceErrorMessageContainer>()
.AddSingleton<IErrorMessageContainer, ValidationExpressionErrorMessageContainer>();

builder.Services.AddProvisioningDBAccess(builder.Configuration);
}).ConfigureAwait(ConfigureAwaitOptions.None);
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using System.Collections.Immutable;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models;

// This class contains error messages for validation expressions
public static class ValidationExpressionErrorMessages
public class ValidationExpressionErrorMessageContainer : IErrorMessageContainer
{
private static readonly IReadOnlyDictionary<int, string> _messageContainer = new Dictionary<ValidationExpressionErrors, string> {
{ ValidationExpressionErrors.INCORRECT_COMPANY_NAME, "{name}: length must be between 1 and 160 characters and not start or end with a white space" },

}.ToImmutableDictionary(x => (int)x.Key, x => x.Value);

public Type Type { get => typeof(ValidationExpressionErrors); }
public IReadOnlyDictionary<int, string> MessageContainer { get => _messageContainer; }
}

public enum ValidationExpressionErrors
{
public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space";
INCORRECT_COMPANY_NAME
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Task<Guid> AddAppAsync(AppRequestModel appRequestModel)

if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider))
{
throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(appRequestModel.Provider))]);
}

return CreateAppAsync(appRequestModel);
Expand Down Expand Up @@ -269,7 +269,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo

if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider))
{
throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(appRequestModel.Provider))]);
}

if (appRequestModel.SalesManagerId.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId)
{
if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}");
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]);
}

async Task<Pagination.Source<OfferCompanySubscriptionStatusResponse>?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take)
Expand Down
3 changes: 3 additions & 0 deletions src/marketplace/Apps.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library;
using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Service;
Expand Down Expand Up @@ -48,6 +50,7 @@ await WebAppHelper
.AddTransient<IAppChangeBusinessLogic, AppChangeBusinessLogic>()
.AddTransient<IOfferService, OfferService>()
.AddTransient<IOfferSubscriptionService, OfferSubscriptionService>()
.AddSingleton<IErrorMessageContainer, ValidationExpressionErrorMessageContainer>()
.AddTechnicalUserProfile()
.ConfigureAppsSettings(builder.Configuration.GetSection("AppMarketPlace"))
.AddOfferDocumentServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Task<OfferAutoSetupResponseData> AutoSetupServiceAsync(OfferAutoSetupData
{
if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName))
{
throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}");
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]);
}
async Task<Pagination.Source<OfferCompanySubscriptionStatusResponse>?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take)
{
Expand Down
3 changes: 3 additions & 0 deletions src/marketplace/Services.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library;
using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Web.DependencyInjection;
Expand Down Expand Up @@ -48,6 +50,7 @@ await WebAppHelper
.AddServiceBusinessLogic(builder.Configuration)
.AddTransient<IServiceReleaseBusinessLogic, ServiceReleaseBusinessLogic>()
.AddTransient<IServiceChangeBusinessLogic, ServiceChangeBusinessLogic>()
.AddSingleton<IErrorMessageContainer, ValidationExpressionErrorMessageContainer>()
.AddTechnicalUserProfile()
.AddOfferDocumentServices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,7 @@ public async Task CheckCompanyCertificateType_WithInvalidCall_ThrowsControllerFo

// Assert
var ex = await Assert.ThrowsAsync<ControllerArgumentException>(Act);
ex.Message.Should().Be($"Issuer: {ValidationExpressionErrorMessages.CompanyError} (Parameter 'Issuer')");
ex.ParamName.Should().Be("Issuer");
ex.Message.Should().Be(ValidationExpressionErrors.INCORRECT_COMPANY_NAME.ToString());
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public async Task ExecuteInvitation_WithInvalidOrganisationName_ThrowsController
async Task Act() => await _sut.ExecuteInvitation(invitationData);

var ex = await Assert.ThrowsAsync<ControllerArgumentException>(Act);
ex.Message.Should().Be($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError} (Parameter 'organisationName')");
ex.ParamName.Should().Be("organisationName");
ex.Message.Should().Be(ValidationExpressionErrors.INCORRECT_COMPANY_NAME.ToString());
}

#endregion
Expand Down

0 comments on commit ffea4a3

Please sign in to comment.