diff --git a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs index 10dd67c8c5..3e3364fee6 100644 --- a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs @@ -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; diff --git a/src/administration/Administration.Service/BusinessLogic/DocumentsBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/DocumentsBusinessLogic.cs index 8b5a6d2bd5..9504a78755 100644 --- a/src/administration/Administration.Service/BusinessLogic/DocumentsBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/DocumentsBusinessLogic.cs @@ -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; diff --git a/src/administration/Administration.Service/BusinessLogic/IdentityProviderBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/IdentityProviderBusinessLogic.cs index a76a486a6c..af37608494 100644 --- a/src/administration/Administration.Service/BusinessLogic/IdentityProviderBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/IdentityProviderBusinessLogic.cs @@ -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; diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 39a7967c82..7b79fc8435 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -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; diff --git a/src/administration/Administration.Service/ErrorHandling/AdministrationCompanyDataErrorMessageContainer.cs b/src/administration/Administration.Service/ErrorHandling/AdministrationCompanyDataErrorMessageContainer.cs index 3db5f96146..4e3a5cfdab 100644 --- a/src/administration/Administration.Service/ErrorHandling/AdministrationCompanyDataErrorMessageContainer.cs +++ b/src/administration/Administration.Service/ErrorHandling/AdministrationCompanyDataErrorMessageContainer.cs @@ -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 _messageContainer = new Dictionary { - { 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 _messageContainer = ImmutableDictionary.CreateRange([ + 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 MessageContainer { get => _messageContainer; } diff --git a/src/administration/Administration.Service/ErrorHandling/AdministrationDocumentErrorMessageContainer.cs b/src/administration/Administration.Service/ErrorHandling/AdministrationDocumentErrorMessageContainer.cs index c2a5c1d3fe..88d94571be 100644 --- a/src/administration/Administration.Service/ErrorHandling/AdministrationDocumentErrorMessageContainer.cs +++ b/src/administration/Administration.Service/ErrorHandling/AdministrationDocumentErrorMessageContainer.cs @@ -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 _messageContainer = new Dictionary { - { 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 _messageContainer = ImmutableDictionary.CreateRange([ + 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 MessageContainer { get => _messageContainer; } diff --git a/src/administration/Administration.Service/ErrorHandling/AdministrationIdentityProviderErrorMessageContainer.cs b/src/administration/Administration.Service/ErrorHandling/AdministrationIdentityProviderErrorMessageContainer.cs index b4b674466d..d78cfb1b5d 100644 --- a/src/administration/Administration.Service/ErrorHandling/AdministrationIdentityProviderErrorMessageContainer.cs +++ b/src/administration/Administration.Service/ErrorHandling/AdministrationIdentityProviderErrorMessageContainer.cs @@ -20,51 +20,54 @@ using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; using System.Collections.Immutable; +namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling; + public class AdministrationIdentityProviderErrorMessageContainer : IErrorMessageContainer { - private static readonly IReadOnlyDictionary _messageContainer = new Dictionary { - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_VAL_FOR_CATEGORY_ID, "unexpected value for category {categoryId}" }, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_VAL_OF_PROTOCOL, "unexcepted value of protocol: {protocol}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_PROVIDER_TYPE_CREATION_NOT_SUPPORTED, "creation of identityProviderType {typeId} is not supported"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_DISPLAY_NAME_CHAR_BET_TWO_TO_THIRTY, "displayName length must be 2-30 characters"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_ALLO_CHAR_AS_PER_REG_EX, "allowed characters in displayName: 'a-zA-Z0-9!?@&#'\"()_-=/*.,;: '"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_COMPANY_NOT_EXIST, "company {companyId} does not exist"}, - { AdministrationIdentityProviderErrors.IDENTITY_FORBIDDEN_NOT_ALLOW_CREATE_PROVIDER_TYPE, "Not allowed to create an identityProvider of type {typeId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_VAL_FOR_CATEGORY_OF_PROVIDER, "unexpected value for category {category} of identityProvider {identityProviderId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_CONFLICT_PROVIDER_NOT_ASSOCIATE_WITH_COMPANY, "identityProvider {identityProviderId} is not associated with company {companyId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_NOT_PROVIDER_NOT_EXIST, "identityProvider {identityProviderId} does not exist"}, - { AdministrationIdentityProviderErrors.IDENTITY_CONFLICT_SHARED_IDP_NOT_USE_SAML, "Shared Idps must not use SAML"}, - { AdministrationIdentityProviderErrors.IDENTITY_FORBIDDEN_COMP_NOT_OWNER_PROVIDER, "company {companyId} is not the owner of identityProvider {identityProviderId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_CONFLICT_PROVIDER_NOT_HAVE_IAMIDENTITY_PROVIDER_ALIAS, "identityprovider {identityProviderId} does not have an iamIdentityProvider.alias"}, - { AdministrationIdentityProviderErrors.IDENTITY_UNEXPECT_COMPANYID_ALIAS_NOT_NULL, "CompanyIdAliase should never be null here"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_NOT_DISABLE_PROVIDER, "cannot disable indentityProvider {identityProviderId} as no other active identityProvider exists for this company"}, - { AdministrationIdentityProviderErrors.IDENTITY_FORBIDDEN_USER_NOT_ALLOW_CHANGE_PROVIDER, "User not allowed to run the change for identity provider {identityProviderId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_OIDC_NOT_NULL, "property oidc must not be null"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_SAML_NOT_NULL, "property 'saml' must be null"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_CANNOT_DEL_ENABLE_PROVIDERID, "cannot delete identityProvider {identityProviderId} as it is enabled"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_NOT_DELETE_PROVIDER, "cannot delete indentityProvider {identityProviderId} as no other active identityProvider exists for this company"}, - { AdministrationIdentityProviderErrors.IDENTITY_NOT_COMP_USERID_NO_KEYLOCK_LINK_FOUND, "identityProviderLink for identityProvider {identityProviderId} not found in keycloak for user {companyUserId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_UNSUPPORTEDMEDIA_CONTENT_TYPE_ALLOWED, "Only contentType {contentType} files are allowed."}, - { AdministrationIdentityProviderErrors.IDENTITY_UNEXPECT_USER_PROFILE_LINK_DATA_NEVER_DEFAULT, "userProfileLinkData should never be default here"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_CSV_COMPAY_USERID, "unexpected value of {headerUserId}: {companyUserId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_SHARED_IDENTITY_PROVIDER_LINK, "unexpected update of shared identityProviderLink, alias {alias}, companyUser {companyUserId}, providerUserId: {userId}, providerUserName: {userName}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_INVALID_FORMAT_CSVHEADER, "invalid format: expected {csvHeader}, got ''"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_INVALID_FORMAT_CSVHEADER_WITH_CURR, "invalid format: expected {csvHeader}, got {current}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_USERID, "value for {headerUserId} type Guid expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_USERID_WITH_CURRENT_ITEMS, "invalid format for {headerUserId} type Guid: {current}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_FOR_HEADER_FIRSTNAME, "value for {headerFirstName} expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_FOR_HEADER_LASTNAME, "value for {headerLastName} expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_FOR_HEADER_EMAIL, "value for {headerEmail} expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDERALIAS, "value for {headerProviderAlias} expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDERALIAS_WITH_IDENTITY_ALIAS, "unexpected value for {headerProviderAlias}: {identityProviderAlias}"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDER_USERID, "value for {headerProviderUserId} expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDER_USERNAME, "value for {headerProviderUserName} expected"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_ATLEAST_ONE_PROVIDERID_SPECIFIED, "at least one identityProviderId must be specified"}, - { AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_INVALID_IDENTITY_PROVIDER_IDS, "invalid identityProviders: {invalidIds)} for company {companyId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_NOT_COMPANY_USERID_NOT_EXIST, "companyUserId {companyUserId} does not exist"}, - { AdministrationIdentityProviderErrors.IDENTITY_NOT_FOUND_COMPANY_OF_COMPANY_USER_ID, "identityProvider {identityProviderId} not found in company of user {companyUserId}"}, - { AdministrationIdentityProviderErrors.IDENTITY_UNEXPECT_COMPANY_USERID_NOT_LINKED_KEYCLOAK, "companyUserId {companyUserId} is not linked to keycloak"} - }.ToImmutableDictionary(x => (int)x.Key, x => x.Value); + private static readonly IReadOnlyDictionary _messageContainer = ImmutableDictionary.CreateRange([ + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_VAL_FOR_CATEGORY_ID, "unexpected value for category {categoryId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_VAL_OF_PROTOCOL, "unexcepted value of protocol: {protocol}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_PROVIDER_TYPE_CREATION_NOT_SUPPORTED, "creation of identityProviderType {typeId} is not supported"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_DISPLAY_NAME_CHAR_BET_TWO_TO_THIRTY, "displayName length must be 2-30 characters"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_ALLO_CHAR_AS_PER_REG_EX, "allowed characters in displayName: 'a-zA-Z0-9!?@&#'\"()_-=/*.,;: '"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_COMPANY_NOT_EXIST, "company {companyId} does not exist"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_FORBIDDEN_NOT_ALLOW_CREATE_PROVIDER_TYPE, "Not allowed to create an identityProvider of type {typeId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_VAL_FOR_CATEGORY_OF_PROVIDER, "unexpected value for category {category} of identityProvider {identityProviderId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_CONFLICT_PROVIDER_NOT_ASSOCIATE_WITH_COMPANY, "identityProvider {identityProviderId} is not associated with company {companyId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_NOT_PROVIDER_NOT_EXIST, "identityProvider {identityProviderId} does not exist"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_CONFLICT_SHARED_IDP_NOT_USE_SAML, "Shared Idps must not use SAML"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_FORBIDDEN_COMP_NOT_OWNER_PROVIDER, "company {companyId} is not the owner of identityProvider {identityProviderId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_CONFLICT_PROVIDER_NOT_HAVE_IAMIDENTITY_PROVIDER_ALIAS, "identityprovider {identityProviderId} does not have an iamIdentityProvider.alias"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_UNEXPECT_COMPANYID_ALIAS_NOT_NULL, "CompanyIdAliase should never be null here"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_NOT_DISABLE_PROVIDER, "cannot disable indentityProvider {identityProviderId} as no other active identityProvider exists for this company"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_FORBIDDEN_USER_NOT_ALLOW_CHANGE_PROVIDER, "User not allowed to run the change for identity provider {identityProviderId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_OIDC_NOT_NULL, "property oidc must not be null"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_SAML_NOT_NULL, "property 'saml' must be null"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_CANNOT_DEL_ENABLE_PROVIDERID, "cannot delete identityProvider {identityProviderId} as it is enabled"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_NOT_DELETE_PROVIDER, "cannot delete indentityProvider {identityProviderId} as no other active identityProvider exists for this company"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_NOT_COMP_USERID_NO_KEYLOCK_LINK_FOUND, "identityProviderLink for identityProvider {identityProviderId} not found in keycloak for user {companyUserId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_UNSUPPORTEDMEDIA_CONTENT_TYPE_ALLOWED, "Only contentType {contentType} files are allowed."), + new((int)AdministrationIdentityProviderErrors.IDENTITY_UNEXPECT_USER_PROFILE_LINK_DATA_NEVER_DEFAULT, "userProfileLinkData should never be default here"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_CSV_COMPAY_USERID, "unexpected value of {headerUserId}: {companyUserId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_UNEXPECT_SHARED_IDENTITY_PROVIDER_LINK, "unexpected update of shared identityProviderLink, alias {alias}, companyUser {companyUserId}, providerUserId: {userId}, providerUserName: {userName}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_INVALID_FORMAT_CSVHEADER, "invalid format: expected {csvHeader}, got ''"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_INVALID_FORMAT_CSVHEADER_WITH_CURR, "invalid format: expected {csvHeader}, got {current}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_USERID, "value for {headerUserId} type Guid expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_USERID_WITH_CURRENT_ITEMS, "invalid format for {headerUserId} type Guid: {current}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_FOR_HEADER_FIRSTNAME, "value for {headerFirstName} expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_FOR_HEADER_LASTNAME, "value for {headerLastName} expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_FOR_HEADER_EMAIL, "value for {headerEmail} expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDERALIAS, "value for {headerProviderAlias} expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDERALIAS_WITH_IDENTITY_ALIAS, "unexpected value for {headerProviderAlias}: {identityProviderAlias}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDER_USERID, "value for {headerProviderUserId} expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_VAL_HEADER_PROVIDER_USERNAME, "value for {headerProviderUserName} expected"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_ATLEAST_ONE_PROVIDERID_SPECIFIED, "at least one identityProviderId must be specified"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_ARGUMENT_INVALID_IDENTITY_PROVIDER_IDS, "invalid identityProviders: {invalidIds)} for company {companyId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_NOT_COMPANY_USERID_NOT_EXIST, "companyUserId {companyUserId} does not exist"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_NOT_FOUND_COMPANY_OF_COMPANY_USER_ID, "identityProvider {identityProviderId} not found in company of user {companyUserId}"), + new((int)AdministrationIdentityProviderErrors.IDENTITY_UNEXPECT_COMPANY_USERID_NOT_LINKED_KEYCLOAK, "companyUserId {companyUserId} is not linked to keycloak") + ]); + public Type Type { get => typeof(AdministrationIdentityProviderErrors); } public IReadOnlyDictionary MessageContainer { get => _messageContainer; } diff --git a/src/administration/Administration.Service/ErrorHandling/AdministrationNetworkErrorMessageContainer.cs b/src/administration/Administration.Service/ErrorHandling/AdministrationNetworkErrorMessageContainer.cs index 6f5f7cf568..9d09dcc11d 100644 --- a/src/administration/Administration.Service/ErrorHandling/AdministrationNetworkErrorMessageContainer.cs +++ b/src/administration/Administration.Service/ErrorHandling/AdministrationNetworkErrorMessageContainer.cs @@ -20,21 +20,24 @@ using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; using System.Collections.Immutable; +namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling; + public class AdministrationNetworkErrorMessageContainer : IErrorMessageContainer { - private static readonly IReadOnlyDictionary _messageContainer = new Dictionary { - { AdministrationNetworkErrors.NETWORK_SERVICE_ERROR_SAVED_USERS, "Errors occured while saving the users: {errors}"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_LEAST_ONE_COMP_ROLE_SELECT, "At least one company role must be selected {companyRoles}"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_EXTERNALID_BET_SIX_TO_THIRTYSIX, "ExternalId must be between 6 and 36 characters"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_EXTERNALID_EXISTS, "ExternalId {ExternalId} already exists"}, - { AdministrationNetworkErrors.NETWORK_CONFLICT_NO_MANAGED_PROVIDER, "company {ownerCompanyId} has no managed identityProvider"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_IDENTIFIER_SET_FOR_ALL_USERS, "Company {ownerCompanyId} has more than one identity provider linked, therefore identityProviderId must be set for all users"}, - { AdministrationNetworkErrors.NETWORK_CONFLICT_IDENTITY_PROVIDER_AS_NO_ALIAS, "identityProvider {identityProviderId} has no alias"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_IDPS_NOT_EXIST, "Idps {invalidIds} do not exist"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_MAIL_NOT_EMPTY_WITH_VALID_FORMAT, "Mail {email} must not be empty and have valid format"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_FIRST_NAME_NOT_MATCH_FORMAT, "Firstname does not match expected format"}, - { AdministrationNetworkErrors.NETWORK_ARGUMENT_LAST_NAME_NOT_MATCH_FORMAT, "Lastname does not match expected format"}, - }.ToImmutableDictionary(x => (int)x.Key, x => x.Value); + private static readonly IReadOnlyDictionary _messageContainer = ImmutableDictionary.CreateRange([ + new((int)AdministrationNetworkErrors.NETWORK_SERVICE_ERROR_SAVED_USERS, "Errors occured while saving the users: {errors}"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_LEAST_ONE_COMP_ROLE_SELECT, "At least one company role must be selected {companyRoles}"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_EXTERNALID_BET_SIX_TO_THIRTYSIX, "ExternalId must be between 6 and 36 characters"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_EXTERNALID_EXISTS, "ExternalId {ExternalId} already exists"), + new((int)AdministrationNetworkErrors.NETWORK_CONFLICT_NO_MANAGED_PROVIDER, "company {ownerCompanyId} has no managed identityProvider"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_IDENTIFIER_SET_FOR_ALL_USERS, "Company {ownerCompanyId} has more than one identity provider linked, therefore identityProviderId must be set for all users"), + new((int)AdministrationNetworkErrors.NETWORK_CONFLICT_IDENTITY_PROVIDER_AS_NO_ALIAS, "identityProvider {identityProviderId} has no alias"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_IDPS_NOT_EXIST, "Idps {invalidIds} do not exist"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_MAIL_NOT_EMPTY_WITH_VALID_FORMAT, "Mail {email} must not be empty and have valid format"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_FIRST_NAME_NOT_MATCH_FORMAT, "Firstname does not match expected format"), + new((int)AdministrationNetworkErrors.NETWORK_ARGUMENT_LAST_NAME_NOT_MATCH_FORMAT, "Lastname does not match expected format") + ]); + public Type Type { get => typeof(AdministrationNetworkErrors); } public IReadOnlyDictionary MessageContainer { get => _messageContainer; } diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs index b0f78f08fd..d91f25102b 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs @@ -19,6 +19,7 @@ using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; +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.DateTimeProvider; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/DocumentsBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/DocumentsBusinessLogicTests.cs index b4f3b75882..4c6a51e12c 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/DocumentsBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/DocumentsBusinessLogicTests.cs @@ -19,8 +19,8 @@ using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; +using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; -using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/IdentityProviderBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/IdentityProviderBusinessLogicTests.cs index f8584b7faa..ffdb7386cf 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/IdentityProviderBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/IdentityProviderBusinessLogicTests.cs @@ -21,6 +21,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; +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; diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs index 1791b16ef8..f877d2cbb4 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/NetworkBusinessLogicTests.cs @@ -20,6 +20,7 @@ using Microsoft.Extensions.Options; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; 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.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;