Skip to content

Commit

Permalink
feat(Orchestrator): Add new search api by list of task
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed Sep 27, 2023
1 parent 87f9b84 commit 79505d9
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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.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 +61,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: List<String>): 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 = "Response object for giving a list of created cleaning tasks")
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: List<String>): TaskStateResponse {
// ToDo: Replace with service logic
return dummyResponseTaskState
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,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 = 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)
}

}

0 comments on commit 79505d9

Please sign in to comment.