diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/exception/GateErrorCodes.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/exception/GateErrorCodes.kt index b49ca962f..36ccfb0d6 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/exception/GateErrorCodes.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/exception/GateErrorCodes.kt @@ -19,6 +19,8 @@ package org.eclipse.tractusx.bpdm.gate.api.exception +import io.swagger.v3.oas.annotations.media.Schema + /** * For every combination of possible errors a separate enum class is defined extending this marker interface. * We need separate enum classes in order to get the correct error codes for each endpoint in the Swagger schema. @@ -30,6 +32,12 @@ enum class BusinessPartnerSharingError : ErrorCode { SharingTimeout, BpnNotInPool, MissingTaskID, + NaturalPersonError, + BpnErrorNotFound, + BpnErrorTooManyOptions, + MandatoryFieldValidationFailed, + BlacklistCountryPresent, + UnknownSpecialCharacters } enum class ChangeLogOutputError : ErrorCode { diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/SharingStateDto.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/SharingStateDto.kt index a0358be42..11b93806b 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/SharingStateDto.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/model/response/SharingStateDto.kt @@ -27,8 +27,7 @@ import java.time.LocalDateTime @Schema( description = "A sharing state entry shows the progress in the sharing process and is updated each time the " + "progress for a business partner changes. The business partner is identified by a combination " + - "of external ID and business partner type." -) + "of external ID and business partner type.\n") data class SharingStateDto( @get:Schema(description = "The external identifier of the business partner for which the sharing state entry was created.") @@ -37,7 +36,13 @@ data class SharingStateDto( @get:Schema(description = "One of the sharing state types of the current sharing state.") val sharingStateType: SharingStateType = SharingStateType.Initial, - @get:Schema(description = "One of the sharing error codes in case the current sharing state type is \"error\".") + @get:Schema(description = "One of the sharing error codes in case the current sharing state type is \"error\". \n" + + "* `NaturalPersonError`: The provided record contains natural person information.\n" + + "* `BpnErrorNotFound`: The provided record can not be matched to a legal entity or an address.\n" + + "* `BpnErrorTooManyOptions`: The provided record can not link to a clear legal entity.\n" + + "* `MandatoryFieldValidationFailed`: The provided record does not fulfill mandatory validation rules.\n" + + "* `BlacklistCountryPresent`: The provided record is part of a country that is not allowed to be processed by the GR process (example: Brazil).\n" + + "* `UnknownSpecialCharacters`: The provided record contains unallowed special characters.") val sharingErrorCode: BusinessPartnerSharingError? = null, @get:Schema(description = "The error message in case the current sharing state type is \"error\".") diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/TaskResolutionServices.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/TaskResolutionServices.kt index 82a95c8fd..f8bb3d18d 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/TaskResolutionServices.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/TaskResolutionServices.kt @@ -38,6 +38,7 @@ import org.eclipse.tractusx.orchestrator.api.model.ResultState import org.eclipse.tractusx.orchestrator.api.model.TaskClientStateDto import org.eclipse.tractusx.orchestrator.api.model.TaskResultStateSearchRequest import org.eclipse.tractusx.orchestrator.api.model.TaskStateRequest +import org.eclipse.tractusx.orchestrator.api.model.* import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -171,11 +172,22 @@ class TaskResolutionChunkService( return when (task.processingState.resultState) { ResultState.Pending -> RequestCreationResult(sharingState, null, null, null) ResultState.Success -> createUpsertRequestForSuccessfulTask(sharingState, task, input) - ResultState.Error -> RequestCreationResult.error( - sharingState, - BusinessPartnerSharingError.SharingProcessError, - if (task.processingState.errors.isNotEmpty()) task.processingState.errors.joinToString(" // ") { it.description }.take(255) else null - ) + ResultState.Error -> handleTaskErrorResult(sharingState, task) + } + } + + private fun handleTaskErrorResult( sharingState: SharingStateDb, task: TaskClientStateDto): RequestCreationResult { + val errorDescription = task.processingState.errors.joinToString(" // ") { it.description }.take(255).ifEmpty { null } + + return when (task.processingState.errors.firstOrNull()?.type) { + TaskErrorType.Timeout -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.SharingTimeout, errorDescription) + TaskErrorType.NaturalPersonError -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.NaturalPersonError, errorDescription) + TaskErrorType.BpnErrorNotFound -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.BpnErrorNotFound, errorDescription) + TaskErrorType.BpnErrorTooManyOptions -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.BpnErrorTooManyOptions, errorDescription) + TaskErrorType.MandatoryFieldValidationFailed -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.MandatoryFieldValidationFailed, errorDescription) + TaskErrorType.BlacklistCountryPresent -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.BlacklistCountryPresent, errorDescription) + TaskErrorType.UnknownSpecialCharacters -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.UnknownSpecialCharacters, errorDescription) + else -> RequestCreationResult.error(sharingState, BusinessPartnerSharingError.SharingProcessError, errorDescription ) } } diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerAndSharingControllerIT.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerAndSharingControllerIT.kt index 9b5d33551..dd97ee0ac 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerAndSharingControllerIT.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerAndSharingControllerIT.kt @@ -199,7 +199,7 @@ class BusinessPartnerControllerAndSharingControllerIT @Autowired constructor( SharingStateDto( externalId = externalId5, sharingStateType = SharingStateType.Error, - sharingErrorCode = BusinessPartnerSharingError.SharingProcessError, + sharingErrorCode = BusinessPartnerSharingError.SharingTimeout, sharingErrorMessage = "Major Error // Minor Error", sharingProcessStarted = null, taskId = "1" diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerIT.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerIT.kt index d4caf81a8..5a201fffb 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerIT.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/BusinessPartnerControllerIT.kt @@ -336,7 +336,7 @@ class BusinessPartnerControllerIT @Autowired constructor( SharingStateDto( externalId = externalId5, sharingStateType = SharingStateType.Error, - sharingErrorCode = BusinessPartnerSharingError.SharingProcessError, + sharingErrorCode = BusinessPartnerSharingError.SharingTimeout, sharingErrorMessage = "Major Error // Minor Error", sharingProcessStarted = null, taskId = "1" diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorDto.kt index 6f8f42204..187258bc7 100644 --- a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorDto.kt +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorDto.kt @@ -21,10 +21,16 @@ package org.eclipse.tractusx.orchestrator.api.model import io.swagger.v3.oas.annotations.media.Schema -@Schema(description = "Describes an error that happened during processing of a task") +@Schema(description = "Describes an error that happened during processing of a task \n") data class TaskErrorDto( - @get:Schema(description = "The type of error that occurred", required = true) + @get:Schema(description = "The type of error that occurred. \n" + + "* `NaturalPersonError`: The provided record contains natural person information.\n" + + "* `BpnErrorNotFound`: The provided record can not be matched to a legal entity or an address.\n" + + "* `BpnErrorTooManyOptions`: The provided record can not link to a clear legal entity.\n" + + "* `MandatoryFieldValidationFailed`: The provided record does not fulfill mandatory validation rules.\n" + + "* `BlacklistCountryPresent`: The provided record is part of a country that is not allowed to be processed by the GR process (example: Brazil).\n" + + "* `UnknownSpecialCharacters`: The provided record contains unallowed special characters.\n" , required = true) val type: TaskErrorType, @get:Schema(description = "The free text, detailed description of the error", required = true) diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt index 7f18c36a9..bcea3c6cb 100644 --- a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt @@ -19,7 +19,15 @@ package org.eclipse.tractusx.orchestrator.api.model +import io.swagger.v3.oas.annotations.media.Schema + enum class TaskErrorType { Timeout, - Unspecified + Unspecified, + NaturalPersonError, + BpnErrorNotFound, + BpnErrorTooManyOptions, + MandatoryFieldValidationFailed, + BlacklistCountryPresent, + UnknownSpecialCharacters } \ No newline at end of file diff --git a/bpdm-orchestrator/src/main/resources/db/migration/V6_3_0_0__add_extend_error_code.sql b/bpdm-orchestrator/src/main/resources/db/migration/V6_3_0_0__add_extend_error_code.sql new file mode 100644 index 000000000..690388bca --- /dev/null +++ b/bpdm-orchestrator/src/main/resources/db/migration/V6_3_0_0__add_extend_error_code.sql @@ -0,0 +1,11 @@ +ALTER TABLE task_errors DROP CONSTRAINT task_errors_type_check; +ALTER TABLE task_errors ADD CONSTRAINT task_errors_type_check CHECK (type IN ( + 'Timeout', + 'Unspecified', + 'NaturalPersonError', + 'BpnErrorNotFound', + 'BpnErrorTooManyOptions', + 'MandatoryFieldValidationFailed', + 'BlacklistCountryPresent', + 'UnknownSpecialCharacters' +)); \ No newline at end of file