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 (Gate) - Added new error for missing task in orchestrator #618

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class BusinessPartnerSharingError : ErrorCode {
SharingProcessError,
SharingTimeout,
BpnNotInPool,
MissingTaskID,
}

enum class ChangeLogOutputError : ErrorCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,29 @@ class BusinessPartnerService(
.map { Pair(it, sharingStateMap[it.taskId]!!) }
.groupBy { (task, _) -> task.processingState.resultState }

val sharingStatesWithoutTasks = sharingStates.filter { it.taskId !in tasks.map { task -> task.taskId } }

val businessPartnersToUpsert = taskStatesByResult[ResultState.Success]?.map { (task, sharingState) ->
orchestratorMappings.toBusinessPartner(task.businessPartnerResult!!, sharingState.externalId)
} ?: emptyList()
upsertBusinessPartnersOutputFromCandidates(businessPartnersToUpsert)


val errorRequests = taskStatesByResult[ResultState.Error]?.map { (task, sharingState) ->
val errorRequests = (taskStatesByResult[ResultState.Error]?.map { (task, sharingState) ->
SharingStateService.ErrorRequest(
SharingStateService.SharingStateIdentifierDto(sharingState.externalId, sharingState.businessPartnerType),
BusinessPartnerSharingError.SharingProcessError,
if (task.processingState.errors.isNotEmpty()) task.processingState.errors.joinToString(" // ") { it.description } else null
)
} ?: emptyList()
} ?: emptyList()).toMutableList()

errorRequests.addAll(sharingStatesWithoutTasks.map { sharingState ->
SharingStateService.ErrorRequest(
SharingStateService.SharingStateIdentifierDto(sharingState.externalId, sharingState.businessPartnerType),
BusinessPartnerSharingError.MissingTaskID,
errorMessage = "Missing Task in Orchestrator"
)
})

sharingStateService.setError(errorRequests)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,5 +574,61 @@ class BusinessPartnerControllerIT @Autowired constructor(

}

@Test
fun `insert one business partners but task is missing in orchestrator`() {

val upsertRequests = listOf(
BusinessPartnerNonVerboseValues.bpInputRequestCleaned,
BusinessPartnerNonVerboseValues.bpInputRequestError,
BusinessPartnerNonVerboseValues.bpInputRequestChina,
)
gateClient.businessParters.upsertBusinessPartnersInput(upsertRequests).body!!

val externalId3 = BusinessPartnerNonVerboseValues.bpInputRequestChina.externalId

val createdSharingState = listOf(
SharingStateDto(
businessPartnerType = BusinessPartnerType.GENERIC,
externalId = externalId3,
sharingStateType = SharingStateType.Pending,
sharingErrorCode = null,
sharingErrorMessage = null,
bpn = null,
sharingProcessStarted = null,
taskId = "2"
)
)

//Firstly verifies if the Sharing States was created for new Business Partner
val externalIds = listOf(externalId3)
val upsertSharingStateResponses = readSharingStates(BusinessPartnerType.GENERIC, externalIds)
testHelpers
.assertRecursively(upsertSharingStateResponses)
.ignoringFieldsMatchingRegexes(".*${SharingStateDto::sharingProcessStarted.name}")
.isEqualTo(createdSharingState)

// Call Finish Cleaning Method
businessPartnerService.finishCleaningTask()

val cleanedSharingState = listOf(
SharingStateDto(
businessPartnerType = BusinessPartnerType.GENERIC,
externalId = externalId3,
sharingStateType = SharingStateType.Error,
sharingErrorCode = BusinessPartnerSharingError.MissingTaskID,
sharingErrorMessage = "Missing Task in Orchestrator",
bpn = null,
sharingProcessStarted = null,
taskId = "2"
)
)

//Check for Sharing State
val readCleanedSharingState = readSharingStates(BusinessPartnerType.GENERIC, externalIds)
testHelpers.assertRecursively(readCleanedSharingState)
.ignoringFieldsMatchingRegexes(".*${SharingStateDto::sharingProcessStarted.name}")
.isEqualTo(cleanedSharingState)

}

}