Skip to content

Commit

Permalink
feat(orchestrator): add api endpoint for requesting cleaning tasks
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
nicoprow committed Sep 25, 2023
1 parent e675d75 commit 79d033f
Show file tree
Hide file tree
Showing 31 changed files with 1,088 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -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")
88 changes: 44 additions & 44 deletions bpdm-orchestrator-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,58 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>bpdm-orchestrator-api</artifactId>
<name>orchestrator-api</name>
<description>Business Partner Data Management Orchestrator Api</description>
<packaging>jar</packaging>
<artifactId>bpdm-orchestrator-api</artifactId>
<name>Business Partner Data Management Orchestrator Api</name>
<description>API definition and client logic for the BPDM Orchestrator</description>
<packaging>jar</packaging>

<parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>bpdm-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
</parent>
<parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>bpdm-parent</artifactId>
<version>4.1.0-SNAPSHOT</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bpdm-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bpdm-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>

</dependencies>
</dependencies>


<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>

<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub CatenaX-NG Apache Maven Packages</name>
<url>https://maven.pkg.github.com/catenax-ng/tx-bpdm</url>
</repository>
</distributionManagement>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub CatenaX-NG Apache Maven Packages</name>
<url>https://maven.pkg.github.com/catenax-ng/tx-bpdm</url>
</repository>
</distributionManagement>

</project>
Original file line number Diff line number Diff line change
@@ -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


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@

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

import org.eclipse.tractusx.orchestrator.api.CleaningTaskApi

interface OrchestrationApiClient {

val cleaningTasks: CleaningTaskApi

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,4 +43,8 @@ class OrchestrationApiClientImpl(
.blockTimeout(Duration.ofSeconds(30))
.build()
}

override val cleaningTasks by lazy { createClient<CleaningTaskApi>() }
private inline fun <reified T> createClient() =
httpServiceProxyFactory.createClient(T::class.java)
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<String> = emptyList(),
override val shortName: String? = null,
override val identifiers: Collection<BusinessPartnerIdentifierDto> = emptyList(),
override val legalForm: String? = null,
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
override val classifications: Collection<ClassificationDto> = emptyList(),
override val roles: Collection<BusinessPartnerRole> = 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
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 79d033f

Please sign in to comment.