Skip to content

Commit

Permalink
feat(bpdm-gate): Extend error code
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyao-cofinity-x committed Nov 20, 2024
1 parent 28e8a3f commit 463cdc0
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,6 +32,12 @@ enum class BusinessPartnerSharingError : ErrorCode {
SharingTimeout,
BpnNotInPool,
MissingTaskID,
NaturalPersonError,
BpnErrorNotFound,
BpnErrorTooManyOptions,
MandatoryFieldValidationFailed,
BlacklistCountryPresent,
UnknownSpecialCharacters
}

enum class ChangeLogOutputError : ErrorCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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\".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 )
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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'
));

0 comments on commit 463cdc0

Please sign in to comment.