Skip to content
Open
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 @@ -67,9 +67,9 @@ class CleaningServiceDummy(
logger.info { "${cleaningTasks.size} tasks found for cleaning. Proceeding with cleaning..." }

if (cleaningTasks.isNotEmpty()) {
val cleaningResults = cleaningTasks.map { reservedTask ->
processCleaningTask(reservedTask)
}
val cleaningResults = cleaningTasks
.sortedBy { reservedTask-> reservedTask.priority }
.map { reservedTask -> processCleaningTask(reservedTask) }

orchestrationApiClient.goldenRecordTasks.resolveStepResults(TaskStepResultRequest(step, cleaningResults))
logger.info { "Cleaning tasks processing completed for this iteration." }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class CleaningServiceApiCallsTest @Autowired constructor(

// Helper method to create a sample TaskStepReservationResponse
private fun createSampleTaskStepReservationResponse(businessPartner: BusinessPartner): TaskStepReservationResponse {
return TaskStepReservationResponse(listOf(TaskStepReservationEntryDto(fixedTaskId, UUID.randomUUID().toString(), businessPartner)), Instant.MIN)
return TaskStepReservationResponse(listOf(TaskStepReservationEntryDto(fixedTaskId, UUID.randomUUID().toString(), businessPartner, PriorityEnum.High)), Instant.MIN)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.eclipse.tractusx.orchestrator.api.model.TaskClientStateDto
import org.eclipse.tractusx.orchestrator.api.model.TaskCreateRequest
import org.eclipse.tractusx.orchestrator.api.model.TaskCreateRequestEntry
import org.eclipse.tractusx.orchestrator.api.model.TaskMode
import org.springframework.beans.factory.annotation.Value
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand Down Expand Up @@ -67,7 +68,9 @@ class TaskCreationChunkService(
private val businessPartnerRepository: BusinessPartnerRepository,
private val orchestratorMappings: OrchestratorMappings,
private val orchestrationApiClient: OrchestrationApiClient,
private val properties: GoldenRecordTaskConfigProperties
private val properties: GoldenRecordTaskConfigProperties,
@Value("\${bpdm.origin-id}")
private val originId: String
) {
private val logger = KotlinLogging.logger { }

Expand Down Expand Up @@ -96,6 +99,6 @@ class TaskCreationChunkService(
if (orchestratorBusinessPartnersDto.isEmpty())
return emptyList()

return orchestrationApiClient.goldenRecordTasks.createTasks(TaskCreateRequest(mode, orchestratorBusinessPartnersDto)).createdTasks
return orchestrationApiClient.goldenRecordTasks.createTasks(TaskCreateRequest(mode, orchestratorBusinessPartnersDto, originId)).createdTasks
}
}
1 change: 1 addition & 0 deletions bpdm-gate/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ bpdm:
host: localhost
# The database schema to use for this application
schema: bpdmgate
origin-id: default-origin
#
# From here on are framework and dependency configuration
# More information about those properties can be taken from the respective documentation of Spring or the dependency
Expand Down
1 change: 1 addition & 0 deletions bpdm-gate/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
################################################################################

bpdm:
origin-id: test-origin
bpn:
owner-bpn-l: BPNL00000003CRHK
tasks:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.orchestrator.api

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag
import org.eclipse.tractusx.orchestrator.api.model.UpsertOriginRequest
import org.eclipse.tractusx.orchestrator.api.model.UpsertOriginResponse
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping

const val TagOrigin = "Origin Registrar"

@RequestMapping(OriginatorRegistrarApi.PRIORITY_INDICATOR_PATH, produces = [MediaType.APPLICATION_JSON_VALUE])
interface OriginatorRegistrarApi {
companion object{
const val PRIORITY_INDICATOR_PATH = "${ApiCommons.BASE_PATH}/register/origin"
}

@Operation(
summary = "Register Gate components along with their priority levels",
description = "This endpoint allows you to register Gate components, specifying their priority and threshold values."
)
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "Return the registered gate information."
),
ApiResponse(responseCode = "400", description = "On malformed requests", content = [Content()]),
]
)
@Tag(name = TagOrigin)
@PostMapping
fun registerOrigin(@RequestBody request: UpsertOriginRequest): UpsertOriginResponse

@Operation(
summary = "Retrieve registered Gate components using the originId",
description = "This endpoint enables fetching details of registered Gate components."
)
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "Returns the details of the registered Gate components."
),
ApiResponse(responseCode = "404", description = "Not found")
]
)
@Tag(name = TagOrigin)
@GetMapping("/{originId}")
fun fetchOrigin(@PathVariable("originId") originId: String): UpsertOriginResponse

@Operation(
summary = "Retrieve registered Gate components using the originId",
description = "This endpoint enables fetching details of registered Gate components."
)
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "Returns the details of the registered Gate components."
),
]
)
@Tag(name = TagOrigin)
@PutMapping("/{originId}")
fun updateOrigin(@PathVariable("originId") originId: String,
@RequestBody request: UpsertOriginRequest): UpsertOriginResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ interface OrchestrationApiClient {
val goldenRecordTasks: GoldenRecordTaskApiClient

val finishedTaskEvents: FinishedTaskEventApiClient

val originRegistrar: OriginatorRegistrarApiClient
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class OrchestrationApiClientImpl(

override val finishedTaskEvents by lazy { createClient<FinishedTaskEventApiClient>() }

override val originRegistrar by lazy { createClient<OriginatorRegistrarApiClient>() }

private inline fun <reified T> createClient() =
httpServiceProxyFactory.createClient(T::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.orchestrator.api.client

import org.eclipse.tractusx.orchestrator.api.OriginatorRegistrarApi
import org.eclipse.tractusx.orchestrator.api.model.UpsertOriginRequest
import org.eclipse.tractusx.orchestrator.api.model.UpsertOriginResponse
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.service.annotation.GetExchange
import org.springframework.web.service.annotation.HttpExchange
import org.springframework.web.service.annotation.PostExchange
import org.springframework.web.service.annotation.PutExchange

@HttpExchange(OriginatorRegistrarApi.PRIORITY_INDICATOR_PATH)
interface OriginatorRegistrarApiClient: OriginatorRegistrarApi{

@PostExchange
override fun registerOrigin(@RequestBody request: UpsertOriginRequest): UpsertOriginResponse

@GetExchange("/{originId}")
override fun fetchOrigin(@PathVariable("originId") originId: String): UpsertOriginResponse

@PutExchange("/{originId}")
override fun updateOrigin(@PathVariable("originId") originId: String,
@RequestBody request: UpsertOriginRequest): UpsertOriginResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

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

enum class PriorityEnum{
High,
Medium,
Low
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ data class TaskCreateRequest(
val mode: TaskMode,

@get:ArraySchema(arraySchema = Schema(description = "The list of tasks to create"))
val requests: List<TaskCreateRequestEntry>
val requests: List<TaskCreateRequestEntry>,

@get:Schema(required = true, description = "Indicates the originator of the record")
val originId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ data class TaskStepReservationEntryDto(
val recordId: String,

@get:Schema(description = "The business partner data to process")
val businessPartner: BusinessPartner
val businessPartner: BusinessPartner,

@get:Schema(description = "The priority for the record")
val priority: PriorityEnum
) : RequestWithKey {
override fun getRequestKey(): String {
return taskId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

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

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

@Schema(description = "Request object to register priority for the gates.")
data class UpsertOriginRequest(
@get:Schema(required = true, description = "Indicates the threshold for the gate records")
val threshold: Long,

@get: Schema(required = true, description = "Indicates the name of the originator")
val name: String,

@get: Schema(required = true, description = "Indicates the priority level for the registered origin.")
val priority: PriorityEnum
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

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

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

@Schema(description = "Response object for register priority of the gates.")
data class UpsertOriginResponse(
val originId: String,
val name: String,
val priority: PriorityEnum,
val threshold: Long,
){
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.controller

import org.eclipse.tractusx.bpdm.orchestrator.config.PermissionConfigProperties
import org.eclipse.tractusx.bpdm.orchestrator.service.OriginRegistrarService
import org.eclipse.tractusx.orchestrator.api.OriginatorRegistrarApi
import org.eclipse.tractusx.orchestrator.api.model.UpsertOriginRequest
import org.eclipse.tractusx.orchestrator.api.model.UpsertOriginResponse
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.RestController

@RestController
class OriginRegistrarController(
private val originRegistrarService: OriginRegistrarService
): OriginatorRegistrarApi {

@PreAuthorize("hasAuthority(${PermissionConfigProperties.CREATE_TASK})")
override fun registerOrigin(request: UpsertOriginRequest): UpsertOriginResponse {
return originRegistrarService.registerOrigin(request)
}

@PreAuthorize("hasAuthority(${PermissionConfigProperties.VIEW_TASK})")
override fun fetchOrigin(originId: String): UpsertOriginResponse {
return originRegistrarService.fetchOrigin(originId)
}

@PreAuthorize("hasAuthority(${PermissionConfigProperties.CREATE_TASK})")
override fun updateOrigin(originId: String, request: UpsertOriginRequest): UpsertOriginResponse {
return originRegistrarService.updateOrigin(originId,request)
}
}
Loading