From 79d033f462c07cf622902f2cc7362b948a4888d6 Mon Sep 17 00:00:00 2001 From: Nico Koprowski Date: Fri, 22 Sep 2023 16:51:24 +0200 Subject: [PATCH] feat(orchestrator): add api endpoint for requesting cleaning tasks - add endpoint to orchestrator api - add DTO model for business partner and cleaning task in orchestrator - connect endpoint with orchestrator controller - return static dummy data on endpoint invocation - add tests for validating endpoint invocation and dummy data return --- .../exception/BpdmUpsertLimitException.kt | 29 +++ bpdm-orchestrator-api/pom.xml | 88 ++++---- .../orchestrator/api/CleaningTaskApi.kt | 63 ++++++ .../api/client/OrchestrationApiClient.kt | 5 + .../api/client/OrchestrationApiClientImpl.kt | 11 + .../api/model/AlternativePostalAddressDto.kt | 37 ++++ .../api/model/BusinessPartnerDto.kt | 39 ++++ .../orchestrator/api/model/CleaningStep.kt | 26 +++ .../api/model/PhysicalPostalAddressDto.kt | 42 ++++ .../api/model/PostalAddressDto.kt | 30 +++ .../api/model/ReservationState.kt | 25 +++ .../orchestrator/api/model/ResultState.kt | 26 +++ .../orchestrator/api/model/StreetDto.kt | 34 +++ .../api/model/TaskCreateRequest.kt | 30 +++ .../api/model/TaskCreateResponse.kt | 31 +++ .../orchestrator/api/model/TaskError.kt | 30 +++ .../orchestrator/api/model/TaskErrorType.kt | 25 +++ .../orchestrator/api/model/TaskMode.kt | 25 +++ .../api/model/TaskProcessingStateDto.kt | 42 ++++ .../api/model/TaskRequesterState.kt | 32 +++ bpdm-orchestrator/pom.xml | 7 +- .../tractusx/bpdm/orchestrator/Application.kt | 5 +- .../config/ApiConfigProperties.kt | 27 +++ .../controller/CleaningTaskController.kt | 73 +++++++ .../src/main/resources/application.properties | 6 +- .../bpdm/orchestrator/ApplicationTests.kt | 8 +- .../config/OrchestratorClientConfig.kt | 36 +++ .../controller/CleaningTaskControllerIT.kt | 79 +++++++ .../bpdm/orchestrator/util/TestValues.kt | 206 ++++++++++++++++++ .../resources/application-test.properties | 18 ++ pom.xml | 5 + 31 files changed, 1088 insertions(+), 52 deletions(-) create mode 100644 bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/exception/BpdmUpsertLimitException.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/CleaningTaskApi.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/AlternativePostalAddressDto.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/BusinessPartnerDto.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/CleaningStep.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PhysicalPostalAddressDto.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PostalAddressDto.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ReservationState.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ResultState.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/StreetDto.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateRequest.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateResponse.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskError.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskMode.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskProcessingStateDto.kt create mode 100644 bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskRequesterState.kt create mode 100644 bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/ApiConfigProperties.kt create mode 100644 bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskController.kt create mode 100644 bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/OrchestratorClientConfig.kt create mode 100644 bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskControllerIT.kt create mode 100644 bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/util/TestValues.kt create mode 100644 bpdm-orchestrator/src/test/resources/application-test.properties diff --git a/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/exception/BpdmUpsertLimitException.kt b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/exception/BpdmUpsertLimitException.kt new file mode 100644 index 000000000..bb0204405 --- /dev/null +++ b/bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/exception/BpdmUpsertLimitException.kt @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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.bpdm.common.exception + +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ResponseStatus + +@ResponseStatus(HttpStatus.BAD_REQUEST) +class BpdmUpsertLimitException( + actualSize: Int, + limit: Int +) : RuntimeException("The number of upsertable items ($actualSize) surpasses the upsert limit of $limit") \ No newline at end of file diff --git a/bpdm-orchestrator-api/pom.xml b/bpdm-orchestrator-api/pom.xml index 1275f39cf..6a65d5ed0 100644 --- a/bpdm-orchestrator-api/pom.xml +++ b/bpdm-orchestrator-api/pom.xml @@ -19,58 +19,58 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - bpdm-orchestrator-api - orchestrator-api - Business Partner Data Management Orchestrator Api - jar + bpdm-orchestrator-api + Business Partner Data Management Orchestrator Api + API definition and client logic for the BPDM Orchestrator + jar - - org.eclipse.tractusx - bpdm-parent - 4.1.0-SNAPSHOT - + + org.eclipse.tractusx + bpdm-parent + 4.1.0-SNAPSHOT + - - UTF-8 - + + UTF-8 + - - - ${project.groupId} - bpdm-common - - - org.springframework.boot - spring-boot-starter-webflux - - - com.fasterxml.jackson.module - jackson-module-kotlin - + + + ${project.groupId} + bpdm-common + + + org.springframework.boot + spring-boot-starter-webflux + + + com.fasterxml.jackson.module + jackson-module-kotlin + - + - - src/main/kotlin + + src/main/kotlin - - - org.jetbrains.kotlin - kotlin-maven-plugin - - - - - - github - GitHub CatenaX-NG Apache Maven Packages - https://maven.pkg.github.com/catenax-ng/tx-bpdm - - + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + + + + github + GitHub CatenaX-NG Apache Maven Packages + https://maven.pkg.github.com/catenax-ng/tx-bpdm + + diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/CleaningTaskApi.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/CleaningTaskApi.kt new file mode 100644 index 000000000..92a81bd91 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/CleaningTaskApi.kt @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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 + +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.TaskCreateRequest +import org.eclipse.tractusx.orchestrator.api.model.TaskCreateResponse +import org.springframework.http.MediaType +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.service.annotation.HttpExchange +import org.springframework.web.service.annotation.PostExchange + +@RequestMapping("/api/cleaning-tasks", produces = [MediaType.APPLICATION_JSON_VALUE]) +@HttpExchange("/api/cleaning-tasks") +interface CleaningTaskApi { + + @Operation( + summary = "Create new cleaning tasks for given business partner data", + description = "Create cleaning tasks for given business partner data in given cleaning mode. " + + "The mode decides through which cleaning steps the given business partner data will go through. " + + "The response contains the states of the created cleaning tasks in the order of given business partner data." + + "If there is an error in the request no cleaning tasks are created (all or nothing). " + + "For a single request, the maximum number of business partners in the request is limited to \${bpdm.api.upsert-limit} entries." + ) + @ApiResponses( + value = [ + ApiResponse( + responseCode = "200", + description = "The states of successfully created cleaning tasks including the task identifier for tracking purposes." + ), + ApiResponse(responseCode = "400", description = "On malformed task create requests or reaching upsert limit", content = [Content()]), + ] + ) + @Tag(name = "Requester") + @PostMapping + @PostExchange + fun createCleaningTasks(@RequestBody createRequest: TaskCreateRequest): TaskCreateResponse + + +} \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClient.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClient.kt index 2a40491c9..e191ef7f0 100644 --- a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClient.kt +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClient.kt @@ -19,5 +19,10 @@ package org.eclipse.tractusx.orchestrator.api.client +import org.eclipse.tractusx.orchestrator.api.CleaningTaskApi + interface OrchestrationApiClient { + + val cleaningTasks: CleaningTaskApi + } \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClientImpl.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClientImpl.kt index ec2bc0ccb..a839d8c88 100644 --- a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClientImpl.kt +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/client/OrchestrationApiClientImpl.kt @@ -20,11 +20,18 @@ package org.eclipse.tractusx.orchestrator.api.client import org.eclipse.tractusx.bpdm.common.service.ParameterObjectArgumentResolver +import org.eclipse.tractusx.orchestrator.api.CleaningTaskApi import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.support.WebClientAdapter import org.springframework.web.service.invoker.HttpServiceProxyFactory import java.time.Duration +/** + * In a Spring configuration a bean of this class is instantiated passing a webClientProvider which configures the web client with e.g. OIDC configuration. + * A lazy HttpServiceProxyFactory private property is defined: On first access it creates a HttpServiceProxyFactory configured with the web client. + * Several lazy API clients are defined: On first access they are created from the HttpServiceProxyFactory for the specific API interface. + * All this has to be done lazily because during integration tests the web client URL may not be available yet on Spring initialization. + */ class OrchestrationApiClientImpl( private val webClientProvider: () -> WebClient ) : OrchestrationApiClient { @@ -36,4 +43,8 @@ class OrchestrationApiClientImpl( .blockTimeout(Duration.ofSeconds(30)) .build() } + + override val cleaningTasks by lazy { createClient() } + private inline fun createClient() = + httpServiceProxyFactory.createClient(T::class.java) } \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/AlternativePostalAddressDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/AlternativePostalAddressDto.kt new file mode 100644 index 000000000..134ade3a8 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/AlternativePostalAddressDto.kt @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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 com.neovisionaries.i18n.CountryCode +import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto +import org.eclipse.tractusx.bpdm.common.dto.IBaseAlternativePostalAddressDto +import org.eclipse.tractusx.bpdm.common.model.DeliveryServiceType + +data class AlternativePostalAddressDto( + override val geographicCoordinates: GeoCoordinateDto? = null, + override val country: CountryCode? = null, + override val administrativeAreaLevel1: String? = null, + override val postalCode: String? = null, + override val city: String? = null, + override val deliveryServiceType: DeliveryServiceType? = null, + override val deliveryServiceQualifier: String? = null, + override val deliveryServiceNumber: String? = null + +) : IBaseAlternativePostalAddressDto diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/BusinessPartnerDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/BusinessPartnerDto.kt new file mode 100644 index 000000000..59a8edbb1 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/BusinessPartnerDto.kt @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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 org.eclipse.tractusx.bpdm.common.dto.* + + +data class BusinessPartnerDto( + override val nameParts: List = emptyList(), + override val shortName: String? = null, + override val identifiers: Collection = emptyList(), + override val legalForm: String? = null, + override val states: Collection = emptyList(), + override val classifications: Collection = emptyList(), + override val roles: Collection = emptyList(), + override val postalAddress: PostalAddressDto = PostalAddressDto(), + override val isOwner: Boolean = false, + override val bpnL: String? = null, + override val bpnS: String? = null, + override val bpnA: String? = null + +) : IBaseBusinessPartnerDto diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/CleaningStep.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/CleaningStep.kt new file mode 100644 index 000000000..8ef7a9c86 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/CleaningStep.kt @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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 + +enum class CleaningStep { + GenericCleaning, + BpnProcessing, + GoldenRecordUpdate +} \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PhysicalPostalAddressDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PhysicalPostalAddressDto.kt new file mode 100644 index 000000000..ae4efdfdb --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PhysicalPostalAddressDto.kt @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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 com.neovisionaries.i18n.CountryCode +import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto +import org.eclipse.tractusx.bpdm.common.dto.IBasePhysicalPostalAddressDto + +data class PhysicalPostalAddressDto( + override val geographicCoordinates: GeoCoordinateDto? = null, + override val country: CountryCode? = null, + override val administrativeAreaLevel1: String? = null, + override val administrativeAreaLevel2: String? = null, + override val administrativeAreaLevel3: String? = null, + override val postalCode: String? = null, + override val city: String? = null, + override val district: String? = null, + override val street: StreetDto? = null, + override val companyPostalCode: String? = null, + override val industrialZone: String? = null, + override val building: String? = null, + override val floor: String? = null, + override val door: String? = null + +) : IBasePhysicalPostalAddressDto diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PostalAddressDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PostalAddressDto.kt new file mode 100644 index 000000000..0909c11cf --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/PostalAddressDto.kt @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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 org.eclipse.tractusx.bpdm.common.dto.AddressType +import org.eclipse.tractusx.bpdm.common.dto.IBaseBusinessPartnerPostalAddressDto + +data class PostalAddressDto( + override val addressType: AddressType? = null, + override val physicalPostalAddress: PhysicalPostalAddressDto? = null, + override val alternativePostalAddress: AlternativePostalAddressDto? = null + +) : IBaseBusinessPartnerPostalAddressDto diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ReservationState.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ReservationState.kt new file mode 100644 index 000000000..5ea86f07a --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ReservationState.kt @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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 + +enum class ReservationState { + Queued, + Reserved +} \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ResultState.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ResultState.kt new file mode 100644 index 000000000..ebc542d7b --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/ResultState.kt @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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 + +enum class ResultState { + Pending, + Success, + Error +} \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/StreetDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/StreetDto.kt new file mode 100644 index 000000000..88eb89ffa --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/StreetDto.kt @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 org.eclipse.tractusx.bpdm.common.dto.IStreetDetailedDto + +data class StreetDto( + override val name: String? = null, + override val houseNumber: String? = null, + override val milestone: String? = null, + override val direction: String? = null, + override val namePrefix: String? = null, + override val additionalNamePrefix: String? = null, + override val nameSuffix: String? = null, + override val additionalNameSuffix: String? = null + +) : IStreetDetailedDto diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateRequest.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateRequest.kt new file mode 100644 index 000000000..1de7f1ca5 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateRequest.kt @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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 to specify for which business partner data cleaning tasks should be created and in which mode") +data class TaskCreateRequest( + @get:Schema(required = true, description = "The cleaning mode affecting which cleaning steps the business partner goes through") + val mode: TaskMode, + @get:Schema(required = true, description = "The list of business partner data to be cleaned") + val businessPartners: List +) diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateResponse.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateResponse.kt new file mode 100644 index 000000000..e4a300d47 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskCreateResponse.kt @@ -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 TaskCreateResponse( + val createdTasks: List +) { + +} + + diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskError.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskError.kt new file mode 100644 index 000000000..506b88710 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskError.kt @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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 = "Describes an error that happened during processing of a cleaning task") +data class TaskError( + @get:Schema(description = "The type of error that occurred", required = true) + val type: TaskErrorType, + @get:Schema(description = "The free text, detailed description of the error", required = true) + val description: String +) diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt new file mode 100644 index 000000000..95815be8c --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskErrorType.kt @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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 + +enum class TaskErrorType { + Timeout, + Unspecified +} \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskMode.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskMode.kt new file mode 100644 index 000000000..36345e939 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskMode.kt @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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 + +enum class TaskMode { + UpdateFromSharingMember, + UpdateFromPool +} \ No newline at end of file diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskProcessingStateDto.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskProcessingStateDto.kt new file mode 100644 index 000000000..d7dbd54e7 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskProcessingStateDto.kt @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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 +import java.time.Instant + +@Schema(description = "Contains detail information about the current processing state of a cleaning task") +data class TaskProcessingStateDto( + @get:Schema(description = "The last cleaning step this cleaning task has entered", required = true) + val cleaningStep: CleaningStep, + @get:Schema(description = "Whether the cleaning task is queued or already reserved in the latest cleaning step", required = true) + val reservationState: ReservationState, + @get:Schema(description = "The processing result of the cleaning task, can also still be pending", required = true) + val resultState: ResultState, + @get:Schema( + description = "The actual errors that happened during processing if the cleaning task has an error result state. " + + "The errors refer to the latest cleaning step.", required = true + ) + val errors: List = emptyList(), + @get:Schema(description = "When the cleaning task has been created", required = true) + val createdAt: Instant, + @get:Schema(description = "When the cleaning task has last been modified", required = true) + val modifiedAt: Instant +) diff --git a/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskRequesterState.kt b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskRequesterState.kt new file mode 100644 index 000000000..6903e9ae3 --- /dev/null +++ b/bpdm-orchestrator-api/src/main/kotlin/org/eclipse/tractusx/orchestrator/api/model/TaskRequesterState.kt @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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 = "The cleaning task's processing state together with optional business partner data in case processing is done") +data class TaskRequesterState( + @get:Schema(required = true) + val taskId: String, + val businessPartnerResult: BusinessPartnerDto?, + @get:Schema(required = true) + val processingState: TaskProcessingStateDto +) diff --git a/bpdm-orchestrator/pom.xml b/bpdm-orchestrator/pom.xml index 33457c3a4..25c34f6e6 100644 --- a/bpdm-orchestrator/pom.xml +++ b/bpdm-orchestrator/pom.xml @@ -25,7 +25,7 @@ bpdm-orchestrator Business Partner Data Management Orchestrator - Orchestrator component acts as a passive component and offers for each processing steps individual endpoints + Orchestrator component acts as a passive component and offers for each processing steps individual endpoints jar @@ -40,6 +40,11 @@ bpdm-common + + ${project.groupId} + bpdm-orchestrator-api + + org.jetbrains.kotlin kotlin-stdlib diff --git a/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/Application.kt b/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/Application.kt index 2e767dbaf..6bba9be25 100644 --- a/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/Application.kt +++ b/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/Application.kt @@ -17,14 +17,15 @@ * SPDX-License-Identifier: Apache-2.0 ******************************************************************************/ -package com.catenax.bpdm.orchestrator +package org.eclipse.tractusx.bpdm.orchestrator import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration import org.springframework.boot.context.properties.ConfigurationPropertiesScan import org.springframework.boot.runApplication -@SpringBootApplication(exclude=[DataSourceAutoConfiguration::class]) + +@SpringBootApplication(exclude = [DataSourceAutoConfiguration::class]) @ConfigurationPropertiesScan class Application diff --git a/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/ApiConfigProperties.kt b/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/ApiConfigProperties.kt new file mode 100644 index 000000000..0a0eb6469 --- /dev/null +++ b/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/ApiConfigProperties.kt @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.bpdm.orchestrator.config + +import org.springframework.boot.context.properties.ConfigurationProperties + +@ConfigurationProperties(prefix = "bpdm.api") +data class ApiConfigProperties( + val upsertLimit: Int = 100, +) diff --git a/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskController.kt b/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskController.kt new file mode 100644 index 000000000..fda28c8ea --- /dev/null +++ b/bpdm-orchestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskController.kt @@ -0,0 +1,73 @@ +/******************************************************************************* + * 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.bpdm.orchestrator.controller + +import org.eclipse.tractusx.bpdm.common.exception.BpdmUpsertLimitException +import org.eclipse.tractusx.bpdm.orchestrator.config.ApiConfigProperties +import org.eclipse.tractusx.orchestrator.api.CleaningTaskApi +import org.eclipse.tractusx.orchestrator.api.model.* +import org.springframework.web.bind.annotation.RestController +import java.time.Instant + +@RestController +class CleaningTaskController( + val apiConfigProperties: ApiConfigProperties +) : CleaningTaskApi { + + //While we don't have an implementation use a dummy response for the endpoints + val dummyResponseCreateTask = + TaskCreateResponse( + listOf( + TaskRequesterState( + taskId = "0", + businessPartnerResult = null, + processingState = TaskProcessingStateDto( + cleaningStep = CleaningStep.GenericCleaning, + reservationState = ReservationState.Queued, + resultState = ResultState.Pending, + errors = emptyList(), + createdAt = Instant.now(), + modifiedAt = Instant.now() + ) + ), + TaskRequesterState( + taskId = "1", + businessPartnerResult = null, + processingState = TaskProcessingStateDto( + cleaningStep = CleaningStep.GenericCleaning, + 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) + throw BpdmUpsertLimitException(createRequest.businessPartners.size, apiConfigProperties.upsertLimit) + + //ToDo: Replace with service logic + return dummyResponseCreateTask + } +} \ No newline at end of file diff --git a/bpdm-orchestrator/src/main/resources/application.properties b/bpdm-orchestrator/src/main/resources/application.properties index 02ceaf64b..786d5279d 100644 --- a/bpdm-orchestrator/src/main/resources/application.properties +++ b/bpdm-orchestrator/src/main/resources/application.properties @@ -25,7 +25,9 @@ server.port=8085 ## # Logging Configuration bpdm.logging.unknown-user=Anonymous - +## +# Api Request Restrictions +bpdm.api.upsert-limit=100 ## #Springdoc swagger configuration springdoc.api-docs.enabled=true @@ -40,3 +42,5 @@ management.endpoint.health.probes.enabled=true management.health.livenessState.enabled=true management.health.readinessState.enabled=true + + diff --git a/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/ApplicationTests.kt b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/ApplicationTests.kt index 5ce7ee2dc..5fffc9dbe 100644 --- a/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/ApplicationTests.kt +++ b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/ApplicationTests.kt @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ******************************************************************************/ -package com.catenax.bpdm.orchestrator +package org.eclipse.tractusx.bpdm.orchestrator import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest @@ -27,9 +27,9 @@ import org.springframework.test.context.ActiveProfiles @ActiveProfiles("test") class ApplicationTests { - @Test - fun contextLoads() { + @Test + fun contextLoads() { - } + } } \ No newline at end of file diff --git a/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/OrchestratorClientConfig.kt b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/OrchestratorClientConfig.kt new file mode 100644 index 000000000..2fc79ef9e --- /dev/null +++ b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/config/OrchestratorClientConfig.kt @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.bpdm.orchestrator.config + +import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient +import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClientImpl +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.reactive.function.client.WebClient + +@Configuration +class OrchestratorClientConfig { + @Bean + fun orchestratorClient(webServerAppCtxt: ServletWebServerApplicationContext): OrchestrationApiClient { + return OrchestrationApiClientImpl { WebClient.create("http://localhost:${webServerAppCtxt.webServer.port}") } + } + +} \ No newline at end of file diff --git a/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskControllerIT.kt b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskControllerIT.kt new file mode 100644 index 000000000..26e7d7c0d --- /dev/null +++ b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/controller/CleaningTaskControllerIT.kt @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.bpdm.orchestrator.controller + +import org.assertj.core.api.Assertions +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.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.web.reactive.function.client.WebClientResponseException + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = ["bpdm.api.upsert-limit=3"]) +class CleaningTaskControllerIT @Autowired constructor( + val orchestratorClient: OrchestrationApiClient, + val cleaningTaskController: CleaningTaskController +) { + + /** + * Validate create cleaning task endpoint is invokable with request body and returns dummy response + */ + @Test + fun `request cleaning task and expect dummy response`() { + val request = TaskCreateRequest( + mode = TaskMode.UpdateFromSharingMember, + businessPartners = listOf(TestValues.businessPartner1, TestValues.businessPartner2) + ) + + val expected = cleaningTaskController.dummyResponseCreateTask + + val response = orchestratorClient.cleaningTasks.createCleaningTasks(request) + + Assertions.assertThat(response).isEqualTo(expected) + } + + /** + * When requesting cleaning of too many business partners (over the upsert limit) + * Then throw exception + */ + @Test + fun `expect exception on surpassing upsert limit`() { + + //Create entries above the upsert limit of 3 + val request = TaskCreateRequest( + mode = TaskMode.UpdateFromPool, + businessPartners = listOf( + TestValues.businessPartner1, + TestValues.businessPartner1, + TestValues.businessPartner1, + TestValues.businessPartner1 + ) + ) + + Assertions.assertThatThrownBy { + orchestratorClient.cleaningTasks.createCleaningTasks(request) + }.isInstanceOf(WebClientResponseException::class.java) + } + +} \ No newline at end of file diff --git a/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/util/TestValues.kt b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/util/TestValues.kt new file mode 100644 index 000000000..e7cfd60ff --- /dev/null +++ b/bpdm-orchestrator/src/test/kotlin/org/eclipse/tractusx/bpdm/orchestrator/util/TestValues.kt @@ -0,0 +1,206 @@ +/******************************************************************************* + * 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.bpdm.orchestrator.util + +import com.neovisionaries.i18n.CountryCode +import org.eclipse.tractusx.bpdm.common.dto.* +import org.eclipse.tractusx.bpdm.common.model.BusinessStateType +import org.eclipse.tractusx.bpdm.common.model.ClassificationType +import org.eclipse.tractusx.bpdm.common.model.DeliveryServiceType +import org.eclipse.tractusx.orchestrator.api.model.* +import org.eclipse.tractusx.orchestrator.api.model.AlternativePostalAddressDto +import org.eclipse.tractusx.orchestrator.api.model.PhysicalPostalAddressDto +import org.eclipse.tractusx.orchestrator.api.model.StreetDto +import java.time.LocalDateTime + +/** + * Contains complex test values that can be used as templates by the test classes + * Test values here should have as many unique values as possible to reduce the probability of finding matching errors + */ +object TestValues { + + //Business Partner with two entries in every collection + val businessPartner1 = BusinessPartnerDto( + nameParts = listOf("NamePart1", "NamePart2"), + shortName = "shortname", + identifiers = listOf( + BusinessPartnerIdentifierDto( + type = "identifier-type-1", + value = "identifier-value-1", + issuingBody = "issuingBody-1" + ), + BusinessPartnerIdentifierDto( + type = "identifier-type-2", + value = "identifier-value-2", + issuingBody = "issuingBody-2" + ), + ), + legalForm = "legal-form", + states = listOf( + BusinessPartnerStateDto( + validFrom = LocalDateTime.of(2020, 9, 22, 15, 50), + validTo = LocalDateTime.of(2023, 10, 23, 16, 40), + type = BusinessStateType.INACTIVE, + description = "business-state-description-1" + ), + BusinessPartnerStateDto( + validFrom = LocalDateTime.of(2000, 8, 21, 14, 30), + validTo = LocalDateTime.of(2020, 9, 22, 15, 50), + type = BusinessStateType.ACTIVE, + description = "business-state-description-2" + ) + ), + classifications = listOf( + ClassificationDto( + type = ClassificationType.NACE, + code = "code-1", + value = "value-1" + ), + ClassificationDto( + type = ClassificationType.NAF, + code = "code-2", + value = "value-2" + ), + ), + roles = listOf( + BusinessPartnerRole.CUSTOMER, + BusinessPartnerRole.SUPPLIER + ), + postalAddress = PostalAddressDto( + addressType = AddressType.AdditionalAddress, + physicalPostalAddress = PhysicalPostalAddressDto( + geographicCoordinates = GeoCoordinateDto(0.5f, 0.5f, 0.5f), + country = CountryCode.DE, + administrativeAreaLevel1 = "DE-BW", + administrativeAreaLevel2 = "bw-admin-level-2", + administrativeAreaLevel3 = "bw-admin-level-3", + postalCode = "phys-postal-code", + city = "city", + district = "district", + street = StreetDto( + name = "name", + houseNumber = "house-number", + milestone = "milestone", + direction = "direction", + namePrefix = "name-prefix", + additionalNamePrefix = "add-name-prefix", + nameSuffix = "name-suffix", + additionalNameSuffix = "add-name-suffix" + + ), + companyPostalCode = "comp-postal-code", + industrialZone = "industrial-zone", + building = "building", + floor = "floor", + door = "door" + ), + alternativePostalAddress = AlternativePostalAddressDto( + geographicCoordinates = GeoCoordinateDto(0.6f, 0.6f, 0.6f), + country = CountryCode.DE, + administrativeAreaLevel1 = "DE-BY", + postalCode = "alt-post-code", + city = "alt-city", + deliveryServiceNumber = "delivery-service-number", + deliveryServiceQualifier = "delivery-service-qualifier", + deliveryServiceType = DeliveryServiceType.PO_BOX + ) + ), + isOwner = false, + bpnL = "BPNLTEST", + bpnS = "BPNSTEST", + bpnA = "BPNATEST" + ) + + //Business Partner with single entry in every collection + val businessPartner2 = BusinessPartnerDto( + nameParts = listOf("name-part-2"), + shortName = "shortname-2", + identifiers = listOf( + BusinessPartnerIdentifierDto( + type = "identifier-type-2", + value = "identifier-value-2", + issuingBody = "issuingBody-2" + ) + ), + legalForm = "legal-form-2", + states = listOf( + BusinessPartnerStateDto( + validFrom = LocalDateTime.of(1988, 10, 4, 22, 30), + validTo = LocalDateTime.of(2023, 1, 1, 10, 10), + type = BusinessStateType.ACTIVE, + description = "business-state-description-2" + ) + ), + classifications = listOf( + ClassificationDto( + type = ClassificationType.SIC, + code = "code-2", + value = "value-2" + ) + ), + roles = listOf( + BusinessPartnerRole.CUSTOMER + ), + postalAddress = PostalAddressDto( + addressType = AddressType.LegalAddress, + physicalPostalAddress = PhysicalPostalAddressDto( + geographicCoordinates = GeoCoordinateDto(0.4f, 0.4f, 0.4f), + country = CountryCode.FR, + administrativeAreaLevel1 = "FR-ARA", + administrativeAreaLevel2 = "fr-admin-level-2", + administrativeAreaLevel3 = "fr-admin-level-3", + postalCode = "phys-postal-code-2", + city = "city-2", + district = "district-2", + street = StreetDto( + name = "name-2", + houseNumber = "house-number-2", + milestone = "milestone-2", + direction = "direction-2", + namePrefix = "name-prefix-2", + additionalNamePrefix = "add-name-prefix-2", + nameSuffix = "name-suffix-2", + additionalNameSuffix = "add-name-suffix-2" + + ), + companyPostalCode = "comp-postal-code-2", + industrialZone = "industrial-zone-2", + building = "building-2", + floor = "floor-2", + door = "door-2" + ), + alternativePostalAddress = AlternativePostalAddressDto( + geographicCoordinates = GeoCoordinateDto(0.2f, 0.2f, 0.2f), + country = CountryCode.FR, + administrativeAreaLevel1 = "FR-BFC", + postalCode = "alt-post-code-2", + city = "alt-city-2", + deliveryServiceNumber = "delivery-service-number-2", + deliveryServiceQualifier = "delivery-service-qualifier-2", + deliveryServiceType = DeliveryServiceType.BOITE_POSTALE + ) + ), + isOwner = true, + bpnL = "BPNLTEST-2", + bpnS = "BPNSTEST-2", + bpnA = "BPNATEST-2" + ) + +} \ No newline at end of file diff --git a/bpdm-orchestrator/src/test/resources/application-test.properties b/bpdm-orchestrator/src/test/resources/application-test.properties new file mode 100644 index 000000000..57e0edaaa --- /dev/null +++ b/bpdm-orchestrator/src/test/resources/application-test.properties @@ -0,0 +1,18 @@ +################################################################################ +# 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 +################################################################################ diff --git a/pom.xml b/pom.xml index 7fd095c39..f3117c068 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,11 @@ bpdm-gate-api ${project.version} + + ${project.groupId} + bpdm-orchestrator-api + ${project.version} + ${project.groupId} bpdm-cleaning-service-dummy