Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bpdm-gate): Extend error code #1003

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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,23 @@ enum class BusinessPartnerSharingError : ErrorCode {
SharingTimeout,
BpnNotInPool,
MissingTaskID,
@Schema(description = "The provided record contains natural person information. ")
NaturalPersonError,

@Schema(description = "The provided record can not be matched to a legal entity or an address.")
BpnErrorNotFound,

@Schema(description = "The provided record can not link to a clear legal entity.")
BpnErrorTooManyOptions,

@Schema(description = "The provided record does not fulfill mandatory validation rules. ")
MandatoryFieldValidationFailed,

@Schema(description = "The provided record is part of a country that is not allowed to be processed by the GR process (example: Brazil).")
BlacklistCountryPresent,

@Schema(description = "The provided record contains unallowed special characters. ")
UnknownSpecialCharacters
}

enum class ChangeLogOutputError : ErrorCode {
Expand Down
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,11 +168,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 @@ -19,7 +19,26 @@

package org.eclipse.tractusx.orchestrator.api.model

import io.swagger.v3.oas.annotations.media.Schema

enum class TaskErrorType {
Timeout,
Unspecified
Unspecified,
@Schema(description = "The provided record contains natural person information. ")
NaturalPersonError,

@Schema(description = "The provided record can not be matched to a legal entity or an address.")
BpnErrorNotFound,

@Schema(description = "The provided record can not link to a clear legal entity.")
BpnErrorTooManyOptions,

@Schema(description = "The provided record does not fulfill mandatory validation rules. ")
MandatoryFieldValidationFailed,

@Schema(description = "The provided record is part of a country that is not allowed to be processed by the GR process (example: Brazil).")
BlacklistCountryPresent,

@Schema(description = "The provided record contains unallowed special characters. ")
UnknownSpecialCharacters
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ create table golden_record_tasks (
create table task_errors (
task_id bigint not null,
description varchar(255) not null,
type varchar(255) not null check (type in ('Timeout', 'Unspecified'))
type varchar(255) not null check (type in ('Timeout', 'Unspecified', 'NaturalPersonError', 'BpnErrorNotFound', 'BpnErrorTooManyOptions','MandatoryFieldValidationFailed', 'BlacklistCountryPresent', 'UnknownSpecialCharacters'))
);

create table gate_records (
Expand Down
Loading