Skip to content

Commit

Permalink
Adding mapping logic between task error type and sharing error code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyao-cofinity-x committed Nov 12, 2024
1 parent 23a0c4f commit 2bf66e3
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import org.eclipse.tractusx.bpdm.gate.repository.SharingStateRepository
import org.eclipse.tractusx.bpdm.gate.repository.SyncRecordRepository
import org.eclipse.tractusx.bpdm.gate.repository.generic.BusinessPartnerRepository
import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient
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,10 +168,27 @@ class TaskResolutionChunkService(
return when (task.processingState.resultState) {
ResultState.Pending -> RequestCreationResult(sharingState, null, null, null)
ResultState.Success -> createUpsertRequestForSuccessfulTask(sharingState, task, input)
ResultState.Error -> RequestCreationResult.error(
ResultState.Error -> handleTaskErrorResult(sharingState, task)
}
}

private fun handleTaskErrorResult( sharingState: SharingStateDb, task: TaskClientStateDto): RequestCreationResult {

val errorDescription = task.processingState.errors.firstOrNull()?.description?.take(255)

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,
if (task.processingState.errors.isNotEmpty()) task.processingState.errors.joinToString(" // ") { it.description }.take(255) else null
task.processingState.errors.joinToString(" // ") { it.description }.take(255).ifEmpty { null }
)
}
}
Expand Down

0 comments on commit 2bf66e3

Please sign in to comment.