Skip to content

Commit

Permalink
fix sonar findings
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Dec 17, 2024
1 parent f2518f9 commit cefc21f
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
********************************************************************************/

using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Async;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
********************************************************************************/

using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
********************************************************************************/

using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using Org.Eclipse.TractusX.Portal.Backend.Framework.IO;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,35 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using System.Collections.Immutable;

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

public class AdministrationCompanyDataErrorMessageContainer : IErrorMessageContainer
{
private static readonly IReadOnlyDictionary<int, string> _messageContainer = new Dictionary<AdministrationCompanyDataErrors, string> {
{ AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_INVALID_COMPANY, "company {companyId} is not a valid company" },
{ AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_INCORR_COMPANY_STATUS, "Company Status is Incorrect" },
{ AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_USECASEID_NOT_AVAL, "UseCaseId {useCaseId} is not available"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_LANG_CODE_NOT_VALID, "language {languageShortName} is not a valid languagecode"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_NOT_COMPANY_NOT_EXIST, "company {companyId} does not exist"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_UNEXP_COMP_ROLES_NOR_DETAILS_NULL, "neither CompanyRoleIds nor ConsentStatusDetails should ever be null here"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_AGREEMENT_ACTIVE_INACTIVE_MISSING, "All agreements need to get signed as Active or InActive. Missing consents: { consentType }"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_NOT_UNASSIGN_ALL_ROLES_ATLEAST_ONE_ACTIVE_NEEDED,"Company can't unassign from all roles, Atleast one Company role need to signed as active"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_AGREEMENT_NOT_ASSOCIATE_COMPANY_ROLES, "Agreements not associated with requested companyRoles: {companyRoles}"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_EXTER_CERT_APLHA_LENGTH, "ExternalCertificateNumber must be alphanumeric and length should not be greater than 36"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_PREFIXED_BPNS_SIXTEEN_CHAR, "BPN must contain exactly 16 characters and must be prefixed with BPNS"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_NOT_GREATER_CURR_DATE, "ValidFrom date should not be greater than current date"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_SHOULD_GREATER_THAN_CURR_DATE, "ValidTill date should be greater than current date"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_CERT_TYPE_NOT_ASSIGN_CERTIFICATE, "{certificateType} is not assigned to a certificate"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_BPN_NOT_EMPTY, "businessPartnerNumber must not be empty"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_COMP_NOT_EXISTS_FOR_BPN, "company does not exist for {businessPartnerNumber}"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_MULTIPLE_ACTIVE_CERT_NOT_ALLOWED_ONE_DOC, "There must not be multiple active certificates for document {documentId}"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_NOT_DOC_NOT_EXIST, "Document is not existing"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_FORBIDDEN_USER_NOT_ALLOW_DEL_DOC, "User is not allowed to delete this document"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_NOT_COMP_CERT_DOC_NOT_EXIST, "Company certificate document {documentId} does not exist"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_FORBIDDEN_DOC_STATUS_NOT_LOCKED, "Document {documentId} status is not locked"},
{ AdministrationCompanyDataErrors.COMPANY_DATA_NOT_PROCESSID_NOT_EXIST, "process {processId} does not exist"}
}.ToImmutableDictionary(x => (int)x.Key, x => x.Value);
private static readonly IReadOnlyDictionary<int, string> _messageContainer = ImmutableDictionary.CreateRange<int, string>([
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_INVALID_COMPANY, "company {companyId} is not a valid company"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_INCORR_COMPANY_STATUS, "Company Status is Incorrect"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_USECASEID_NOT_AVAL, "UseCaseId {useCaseId} is not available"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_LANG_CODE_NOT_VALID, "language {languageShortName} is not a valid languagecode"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_NOT_COMPANY_NOT_EXIST, "company {companyId} does not exist"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_UNEXP_COMP_ROLES_NOR_DETAILS_NULL, "neither CompanyRoleIds nor ConsentStatusDetails should ever be null here"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_AGREEMENT_ACTIVE_INACTIVE_MISSING, "All agreements need to get signed as Active or InActive. Missing consents: { consentType }"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_NOT_UNASSIGN_ALL_ROLES_ATLEAST_ONE_ACTIVE_NEEDED,"Company can't unassign from all roles, Atleast one Company role need to signed as active"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_AGREEMENT_NOT_ASSOCIATE_COMPANY_ROLES, "Agreements not associated with requested companyRoles: {companyRoles}"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_EXTER_CERT_APLHA_LENGTH, "ExternalCertificateNumber must be alphanumeric and length should not be greater than 36"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_PREFIXED_BPNS_SIXTEEN_CHAR, "BPN must contain exactly 16 characters and must be prefixed with BPNS"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_NOT_GREATER_CURR_DATE, "ValidFrom date should not be greater than current date"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_SHOULD_GREATER_THAN_CURR_DATE, "ValidTill date should be greater than current date"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_CERT_TYPE_NOT_ASSIGN_CERTIFICATE, "{certificateType} is not assigned to a certificate"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_BPN_NOT_EMPTY, "businessPartnerNumber must not be empty"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_ARGUMENT_COMP_NOT_EXISTS_FOR_BPN, "company does not exist for {businessPartnerNumber}"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_CONFLICT_MULTIPLE_ACTIVE_CERT_NOT_ALLOWED_ONE_DOC, "There must not be multiple active certificates for document {documentId}"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_NOT_DOC_NOT_EXIST, "Document is not existing"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_FORBIDDEN_USER_NOT_ALLOW_DEL_DOC, "User is not allowed to delete this document"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_NOT_COMP_CERT_DOC_NOT_EXIST, "Company certificate document {documentId} does not exist"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_FORBIDDEN_DOC_STATUS_NOT_LOCKED, "Document {documentId} status is not locked"),
new((int)AdministrationCompanyDataErrors.COMPANY_DATA_NOT_PROCESSID_NOT_EXIST, "process {processId} does not exist")
]);

public Type Type { get => typeof(AdministrationCompanyDataErrors); }

public IReadOnlyDictionary<int, string> MessageContainer { get => _messageContainer; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using System.Collections.Immutable;

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

public class AdministrationDocumentErrorMessageContainer : IErrorMessageContainer
{
private static readonly IReadOnlyDictionary<int, string> _messageContainer = new Dictionary<AdministrationDocumentErrors, string> {
{ AdministrationDocumentErrors.DOCUMENT_NOT_DOC_NOT_EXIST, "Document {documentId} does not exist" },
{ AdministrationDocumentErrors.DOCUMENT_FORBIDDEN_USER_NOT_ALLOW_ACCESS_DOC, "User is not allowed to access the document"},
{ AdministrationDocumentErrors.DOCUMENT_UNEXPECT_DOC_CONTENT_NOT_NULL, "documentContent should never be null here"},
{ AdministrationDocumentErrors.DOCUMENT_NOT_SELFDESP_DOC_NOT_EXIST, "Self description document {documentId} does not exist"},
{ AdministrationDocumentErrors.DOCUMENT_FORBIDDEN_USER_NOT_ALLOW_DEL_DOC, "User is not allowed to delete this document"},
{ AdministrationDocumentErrors.DOCUMENT_ARGUMENT_INCORR_DOC_STATUS, "Incorrect document status"},
{ AdministrationDocumentErrors.DOCUMENT_FORBIDDEN_ENDPOINT_ALLOW_USE_IN_DEV_ENV, "Endpoint can only be used on dev environment"}
}.ToImmutableDictionary(x => (int)x.Key, x => x.Value);
private static readonly IReadOnlyDictionary<int, string> _messageContainer = ImmutableDictionary.CreateRange<int, string>([
new((int)AdministrationDocumentErrors.DOCUMENT_NOT_DOC_NOT_EXIST, "Document {documentId} does not exist"),
new((int)AdministrationDocumentErrors.DOCUMENT_FORBIDDEN_USER_NOT_ALLOW_ACCESS_DOC, "User is not allowed to access the document"),
new((int)AdministrationDocumentErrors.DOCUMENT_UNEXPECT_DOC_CONTENT_NOT_NULL, "documentContent should never be null here"),
new((int)AdministrationDocumentErrors.DOCUMENT_NOT_SELFDESP_DOC_NOT_EXIST, "Self description document {documentId} does not exist"),
new((int)AdministrationDocumentErrors.DOCUMENT_FORBIDDEN_USER_NOT_ALLOW_DEL_DOC, "User is not allowed to delete this document"),
new((int)AdministrationDocumentErrors.DOCUMENT_ARGUMENT_INCORR_DOC_STATUS, "Incorrect document status"),
new((int)AdministrationDocumentErrors.DOCUMENT_FORBIDDEN_ENDPOINT_ALLOW_USE_IN_DEV_ENV, "Endpoint can only be used on dev environment")
]);

public Type Type { get => typeof(AdministrationDocumentErrors); }

public IReadOnlyDictionary<int, string> MessageContainer { get => _messageContainer; }
Expand Down
Loading

0 comments on commit cefc21f

Please sign in to comment.