Skip to content

Commit

Permalink
feat(legal entity): extended legal entity length (#860)
Browse files Browse the repository at this point in the history
* feat(company names): Increase company name length to align with front-end

Length increase is required for many companies. There are also companies with special characters at the start. Back-end was already misaligned with frontend-registration.

Refs: eclipse-tractusx/portal#360

---------

Co-authored-by: Dhirender Singh <[email protected]>
Co-authored-by: Dhirender Singh (Cofinity-X) <[email protected]>
Co-authored-by: Phil Schneider <[email protected]>
  • Loading branch information
4 people authored Aug 14, 2024
1 parent 0823e2d commit 4c39a2f
Show file tree
Hide file tree
Showing 33 changed files with 232 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class CompanyDataBusinessLogic(
{
private static readonly Regex BpnsRegex = new(ValidationExpressions.Bpns, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private static readonly Regex EcmRegex = new(ValidationExpressions.ExternalCertificateNumber, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private readonly IIdentityData _identityData = identityService.IdentityData;
private readonly CompanyDataSettings _settings = options.Value;

Expand Down Expand Up @@ -267,9 +266,9 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data,
throw new ControllerArgumentException("ValidTill date should be greater than current date");
}

if (data.Issuer != null && !Company.IsMatch(data.Issuer!))
if (data.Issuer != null && !data.Issuer.IsValidCompanyName())
{
throw new ControllerArgumentException("Issuer length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name");
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 @@ -24,13 +24,11 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library;
using System.Text.RegularExpressions;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;

public class InvitationBusinessLogic : IInvitationBusinessLogic
{
private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private readonly IPortalRepositories _portalRepositories;

/// <summary>
Expand All @@ -50,14 +48,9 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData)
throw new ControllerArgumentException("email must not be empty", "email");
}

if (string.IsNullOrWhiteSpace(invitationData.OrganisationName))
if (invitationData.OrganisationName == null || !invitationData.OrganisationName.IsValidCompanyName())
{
throw new ControllerArgumentException("organisationName must not be empty", "organisationName");
}

if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !Company.IsMatch(invitationData.OrganisationName))
{
throw new ControllerArgumentException("OrganisationName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", "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 @@ -47,16 +47,14 @@ public class NetworkBusinessLogic(
{
private static readonly Regex Name = new(ValidationExpressions.Name, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private static readonly Regex ExternalId = new("^[A-Za-z0-9\\-+_/,.]{6,36}$", RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1));

private readonly IIdentityData _identityData = identityService.IdentityData;
private readonly PartnerRegistrationSettings _settings = options.Value;

public async Task HandlePartnerRegistration(PartnerRegistrationData data)
{
if (!string.IsNullOrEmpty(data.Name) && !Company.IsMatch(data.Name))
if (!data.Name.IsValidCompanyName())
{
throw new ControllerArgumentException("OrganisationName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", "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 @@ -63,7 +63,6 @@ public sealed class RegistrationBusinessLogic(
: IRegistrationBusinessLogic
{
private static readonly Regex BpnRegex = new(ValidationExpressions.Bpn, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1));

private readonly IIdentityData _identityData = identityService.IdentityData;
private readonly RegistrationSettings _settings = configuration.Value;
Expand All @@ -85,9 +84,9 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
{
throw NotFoundException.Create(AdministrationRegistrationErrors.APPLICATION_NOT_FOUND, [new("applicationId", applicationId.ToString())]);
}
if (!string.IsNullOrEmpty(companyWithAddress.Name) && !Company.IsMatch(companyWithAddress.Name))
if (!companyWithAddress.Name.IsValidCompanyName())
{
throw new ControllerArgumentException("OrganisationName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", "organisationName");
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]);
}

return new CompanyWithAddressData(
Expand Down Expand Up @@ -124,9 +123,9 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu

public Task<Pagination.Response<CompanyApplicationDetails>> GetCompanyApplicationDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName)
{
if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName))
if (companyName != null && !companyName.IsValidCompanyName())
{
throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name", nameof(companyName));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]);
}
var applications = portalRepositories.GetInstance<IApplicationRepository>()
.GetCompanyApplicationsFilteredQuery(
Expand Down Expand Up @@ -164,9 +163,9 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu

public Task<Pagination.Response<CompanyDetailsOspOnboarding>> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName)
{
if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName))
if (companyName != null && !companyName.IsValidCompanyName())
{
throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name", nameof(companyName));
throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]);
}
var applications = portalRepositories.GetInstance<IApplicationRepository>()
.GetExternalCompanyApplicationsFilteredQuery(_identityData.CompanyId,
Expand Down Expand Up @@ -199,9 +198,9 @@ private async Task<CompanyWithAddressData> GetCompanyWithAddressAsyncInternal(Gu
}
public Task<Pagination.Response<CompanyApplicationWithCompanyUserDetails>> GetAllCompanyApplicationsDetailsAsync(int page, int size, string? companyName)
{
if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName))
if (companyName != null && !companyName.IsValidCompanyName())
{
throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name", 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);
2 changes: 1 addition & 1 deletion src/framework/Framework.Async/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Cors/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.DBAccess/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.IO/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Linq/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Logging/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Models/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* 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 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
{
INCORRECT_COMPANY_NAME
}
2 changes: 1 addition & 1 deletion src/framework/Framework.Models/ValidationExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public static class ValidationExpressions
public const string Name = @"^.+$";
public const string Bpn = @"^(BPNL|bpnl)[\w|\d]{12}$";
public const string Bpns = @"^(BPNS|bpns)[\w|\d]{12}$";
public const string Company = @"^\d*?[A-Za-zÀ-ÿ]\d?([A-Za-z0-9À-ÿ-_+=.,:;!?'\x22&#@()]\s?){2,40}$";
public const string Company = @"^(?!.*\s$)([\wÀ-ÿ£$€¥¢@%*+\-/\\,.:;=<>!?&^#'\x22()[\]]\s?){1,160}$";
public const string ExternalCertificateNumber = @"^[a-zA-Z0-9]{0,36}$";
}
31 changes: 31 additions & 0 deletions src/framework/Framework.Models/ValidationExpressionsValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using System.Text.RegularExpressions;

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

public static class ValidationExpressionsValidator
{
private static readonly Regex CompanyRegex = new(ValidationExpressions.Company, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(1));
public static bool IsValidCompanyName(this string companyName)
{
return CompanyRegex.IsMatch(companyName);
}
}
2 changes: 1 addition & 1 deletion src/framework/Framework.Seeding/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Swagger/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Token/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/framework/Framework.Web/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Project>
<PropertyGroup>
<VersionPrefix>2.5.0</VersionPrefix>
<VersionPrefix>2.6.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
Loading

0 comments on commit 4c39a2f

Please sign in to comment.