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(Orchestrator): Add taskId search Api #497

Merged
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 @@ -26,6 +26,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag
import org.eclipse.tractusx.orchestrator.api.model.TaskCreateRequest
import org.eclipse.tractusx.orchestrator.api.model.TaskCreateResponse
import org.eclipse.tractusx.orchestrator.api.model.TaskStateRequest
import org.eclipse.tractusx.orchestrator.api.model.TaskStateResponse
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
Expand Down Expand Up @@ -60,4 +62,20 @@ interface CleaningTaskApi {
fun createCleaningTasks(@RequestBody createRequest: TaskCreateRequest): TaskCreateResponse


@Operation(
summary = "Search for the state of cleaning tasks by task identifiers",
description = "Returns the state of finished cleaning tasks based on the provided task identifiers."
)
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "The state of the finished cleaning tasks for the provided task identifiers."
),
ApiResponse(responseCode = "400", description = "On malformed task search requests", content = [Content()]),
]
)
@PostMapping("/cleaning-tasks/state/search")
fun searchCleaningTaskState(@RequestBody searchTaskIdRequest: TaskStateRequest): TaskStateResponse

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021,2023 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 for giving a list of tasks to search")
data class TaskStateRequest(
val taskList: List<String>
) {

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021,2023 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 a given a list of tasks to search")
data class TaskStateResponse(
val createdTasks: List<TaskRequesterState>
) {

}


Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ class CleaningTaskController(
)
)

//While we don't have an implementation use a dummy response for the endpoints
val dummyResponseTaskState =
TaskStateResponse(
listOf(
TaskRequesterState(
taskId = "0",
businessPartnerResult = null,
processingState = TaskProcessingStateDto(
cleaningStep = CleaningStep.CleanAndSync,
reservationState = ReservationState.Queued,
resultState = ResultState.Pending,
errors = emptyList(),
createdAt = Instant.now(),
modifiedAt = Instant.now()
)
),
TaskRequesterState(
taskId = "1",
businessPartnerResult = null,
processingState = TaskProcessingStateDto(
cleaningStep = CleaningStep.Clean,
reservationState = ReservationState.Queued,
resultState = ResultState.Pending,
errors = emptyList(),
createdAt = Instant.now(),
modifiedAt = Instant.now()
)
)
)
)


override fun createCleaningTasks(createRequest: TaskCreateRequest): TaskCreateResponse {
if (createRequest.businessPartners.size > apiConfigProperties.upsertLimit)
Expand All @@ -70,4 +101,11 @@ class CleaningTaskController(
//ToDo: Replace with service logic
return dummyResponseCreateTask
}


override fun searchCleaningTaskState(searchTaskIdRequest: TaskStateRequest): TaskStateResponse {
// ToDo: Replace with service logic
return dummyResponseTaskState
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.eclipse.tractusx.bpdm.orchestrator.util.TestValues
import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient
import org.eclipse.tractusx.orchestrator.api.model.TaskCreateRequest
import org.eclipse.tractusx.orchestrator.api.model.TaskMode
import org.eclipse.tractusx.orchestrator.api.model.TaskStateRequest
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
Expand Down Expand Up @@ -76,4 +77,23 @@ class CleaningTaskControllerIT @Autowired constructor(
}.isInstanceOf(WebClientResponseException::class.java)
}

/**
* Search for taskId and get dummy response on the test
*/

@Test
fun `search cleaning task state and expect dummy response`() {

val request = TaskStateRequest(listOf("0", "1"))


val expected = cleaningTaskController.dummyResponseTaskState


val response = cleaningTaskController.searchCleaningTaskState(request)

// Assert that the response matches the expected value
Assertions.assertThat(response).isEqualTo(expected)
}

}