From 735b10026991b7bed95c0c62298832addd8fdceb Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:18:00 +0200 Subject: [PATCH] Reformatted error class usage --- .../BusinessLogic/InvitationBusinessLogic.cs | 2 +- .../BusinessLogic/NetworkBusinessLogic.cs | 2 +- .../RegistrationBusinessLogic.cs | 6 ++--- .../ValidationExpressionErrorMessages.cs | 26 +++++++++++++++++++ .../Framework.Models/ValidationExpressions.cs | 1 - .../BusinessLogic/AppReleaseBusinessLogic.cs | 4 +-- .../BusinessLogic/AppsBusinessLogic.cs | 2 +- .../BusinessLogic/ServiceBusinessLogic.cs | 2 +- 8 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/framework/Framework.Models/ValidationExpressionErrorMessages.cs diff --git a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs index e09b37d54d..80f7c8ad70 100644 --- a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs @@ -57,7 +57,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData) if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !Company.IsMatch(invitationData.OrganisationName)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } return ExecuteInvitationInternalAsync(invitationData); diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 0000d82a9b..16061c9d8d 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -62,7 +62,7 @@ public async Task HandlePartnerRegistration(PartnerRegistrationData data) { if (!string.IsNullOrEmpty(data.Name) && !Company.IsMatch(data.Name)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } var ownerCompanyId = _identityData.CompanyId; var networkRepository = _portalRepositories.GetInstance(); diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index 5e24b2b038..a52b76e1cf 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -107,7 +107,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } if (!string.IsNullOrEmpty(companyWithAddress.Name) && !Company.IsMatch(companyWithAddress.Name)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } return new CompanyWithAddressData( @@ -146,7 +146,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName)); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); } var applications = _portalRepositories.GetInstance() .GetCompanyApplicationsFilteredQuery( @@ -185,7 +185,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName)); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); } var applications = _portalRepositories.GetInstance().GetAllCompanyApplicationsDetailsQuery(companyName); diff --git a/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs b/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs new file mode 100644 index 0000000000..7d5f185f7d --- /dev/null +++ b/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs @@ -0,0 +1,26 @@ +/******************************************************************************** + * 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 + ********************************************************************************/ + +namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; + +// This class contains error messages for validation expressions +public static class ValidationExpressionErrorMessages +{ + public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space"; +} diff --git a/src/framework/Framework.Models/ValidationExpressions.cs b/src/framework/Framework.Models/ValidationExpressions.cs index d6410ff823..be30311273 100644 --- a/src/framework/Framework.Models/ValidationExpressions.cs +++ b/src/framework/Framework.Models/ValidationExpressions.cs @@ -24,5 +24,4 @@ public static class ValidationExpressions public const string Name = @"^.+$"; public const string Bpn = @"^(BPNL|bpnl)[\w|\d]{12}$"; public const string Company = @"^(?!.*\s$)([\wÀ-ÿ£$€¥¢@%*+\-/\\,.:;=<>!?&^#'\x22()[\]]\s?){1,160}$"; - public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space"; } diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index 3e34145f83..cb00807b4e 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -191,7 +191,7 @@ public Task AddAppAsync(AppRequestModel appRequestModel) if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) { - throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider)); + throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); } return CreateAppAsync(appRequestModel); @@ -271,7 +271,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) { - throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider)); + throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); } if (appRequestModel.SalesManagerId.HasValue) diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs index de1fd23d92..4c36b0a64e 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs @@ -164,7 +164,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId) { if (!string.IsNullOrWhiteSpace(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}"); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs index 54888e4f32..07e9e52343 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs @@ -141,7 +141,7 @@ public Task AutoSetupServiceAsync(OfferAutoSetupData { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}"); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) {