Skip to content

Commit

Permalink
feat(pool): eclipse-tractusx#432 Upsert Business Partners from Cleani…
Browse files Browse the repository at this point in the history
…ng Result

- create initial poll logic
- refactor legal entity creation validation so that it could be used by orchestrator DTOs
- create upsert L/S/A business partner logic
- create orchestration client configuration
  • Loading branch information
rainer-exxcellent authored and nicoprow committed Oct 20, 2023
1 parent 485e6c7 commit 4057840
Show file tree
Hide file tree
Showing 22 changed files with 1,056 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import org.eclipse.tractusx.bpdm.common.dto.openapidescription.AddressIdentifier
data class AddressIdentifierDto(

@get:Schema(description = AddressIdentifierDescription.value)
val value: String,
override val value: String,

@get:Schema(description = AddressIdentifierDescription.type)
val type: String,
)
override val type: String,
) : IBaseAddressIdentifierDto
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import java.time.LocalDateTime
data class AddressStateDto(

@get:Schema(description = AddressStateDescription.description)
val description: String?,
override val description: String?,

@get:Schema(description = AddressStateDescription.validFrom)
val validFrom: LocalDateTime?,
override val validFrom: LocalDateTime?,

@get:Schema(description = AddressStateDescription.validTo)
val validTo: LocalDateTime?,
override val validTo: LocalDateTime?,

@get:Schema(description = AddressStateDescription.type)
val type: BusinessStateType
)
override val type: BusinessStateType
): IBaseAddressStateDto
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import org.eclipse.tractusx.bpdm.common.model.ClassificationType
data class ClassificationDto(

@get:Schema(description = ClassificationDescription.type)
val type: ClassificationType,
override val type: ClassificationType,

@get:Schema(description = ClassificationDescription.code)
val code: String?,
override val code: String?,

@get:Schema(description = ClassificationDescription.value)
val value: String?
)
override val value: String?
) : IBaseClassificationDto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,4 @@ interface IBaseLegalEntityDto {
@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.classifications, required = false))
val classifications: Collection<IBaseClassificationDto>

// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = LegalEntityDescription.legalAddress)
val legalAddress: IBaseLogisticAddressDto?
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityDescri
@Schema(description = LegalEntityDescription.header)
data class LegalEntityDto(
@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.identifiers, required = false))
val identifiers: Collection<LegalEntityIdentifierDto> = emptyList(),
override val identifiers: Collection<LegalEntityIdentifierDto> = emptyList(),

@get:Schema(description = LegalEntityDescription.legalShortName)
val legalShortName: String?,
override val legalShortName: String?,

@get:Schema(description = LegalEntityDescription.legalForm)
val legalForm: String? = null,
override val legalForm: String? = null,

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.states))
val states: Collection<LegalEntityStateDto> = emptyList(),
override val states: Collection<LegalEntityStateDto> = emptyList(),

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.classifications, required = false))
val classifications: Collection<ClassificationDto> = emptyList(),
)
override val classifications: Collection<ClassificationDto> = emptyList(),
) : IBaseLegalEntityDto
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ package org.eclipse.tractusx.bpdm.common.dto
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityIdentifierDescription

@Schema(description = LegalEntityIdentifierDescription.header)
data class LegalEntityIdentifierDto(

@get:Schema(description = LegalEntityIdentifierDescription.value)
val value: String,

@get:Schema(description = LegalEntityIdentifierDescription.type)
val type: String,
data class LegalEntityIdentifierDto(

@get:Schema(description = LegalEntityIdentifierDescription.issuingBody)
val issuingBody: String?
)
override val value: String,
override val type: String,
override val issuingBody: String?
) : IBaseLegalEntityIdentifierDto
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import java.time.LocalDateTime
data class LegalEntityStateDto(

@get:Schema(description = LegalEntityStateDescription.description)
val description: String?,
override val description: String?,

@get:Schema(description = LegalEntityStateDescription.validFrom)
val validFrom: LocalDateTime?,
override val validFrom: LocalDateTime?,

@get:Schema(description = LegalEntityStateDescription.validTo)
val validTo: LocalDateTime?,
override val validTo: LocalDateTime?,

@get:Schema(description = LegalEntityStateDescription.type)
val type: BusinessStateType
)
override val type: BusinessStateType
) : IBaseLegalEntityStateDto
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ data class LogisticAddressDto(
val name: String? = null,

@get:ArraySchema(arraySchema = Schema(description = LogisticAddressDescription.states))
val states: Collection<AddressStateDto> = emptyList(),
override val states: Collection<AddressStateDto> = emptyList(),

@get:ArraySchema(arraySchema = Schema(description = LogisticAddressDescription.identifiers))
val identifiers: Collection<AddressIdentifierDto> = emptyList(),
override val identifiers: Collection<AddressIdentifierDto> = emptyList(),

// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = LogisticAddressDescription.physicalPostalAddress)
val physicalPostalAddress: PhysicalPostalAddressDto,
override val physicalPostalAddress: PhysicalPostalAddressDto,

// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = LogisticAddressDescription.alternativePostalAddress)
val alternativePostalAddress: AlternativePostalAddressDto? = null
)
override val alternativePostalAddress: AlternativePostalAddressDto? = null
) : IBaseLogisticAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ import java.time.LocalDateTime
@Schema(description = SiteStateDescription.header)
data class SiteStateDto(

@get:Schema(description = SiteStateDescription.description)
val description: String?,
override val description: String?,

@get:Schema(description = SiteStateDescription.validFrom)
val validFrom: LocalDateTime?,
override val validFrom: LocalDateTime?,

@get:Schema(description = SiteStateDescription.validTo)
val validTo: LocalDateTime?,
override val validTo: LocalDateTime?,

@get:Schema(description = SiteStateDescription.type)
val type: BusinessStateType
)
override val type: BusinessStateType
) : IBaseSiteStateDto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ data class LegalEntityDto(

override val classifications: Collection<BusinessPartnerClassificationDto> = emptyList(),

override val legalAddress: LogisticAddressDto? = null
val legalAddress: LogisticAddressDto? = null

) : IBaseLegalEntityDto
4 changes: 4 additions & 0 deletions bpdm-pool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>bpdm-pool-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bpdm-orchestrator-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class OpenSearchSyncStarterService(
* @return true if index mapping changed, false otherwise
*/
private fun updateOnInit(indexDefinition: IndexDefinition): Boolean {
val indexAlreadyExists = openSearchClient.indices().exists { it.index(indexDefinition.indexName) }.value()
/* val indexAlreadyExists = openSearchClient.indices().exists { it.index(indexDefinition.indexName) }.value()
return if (!indexAlreadyExists) {
true
Expand All @@ -137,7 +137,8 @@ class OpenSearchSyncStarterService(
deleteIndexIfExists(tempIndexName)
requiredMappingMetadata != existingMappingMetadata
}
}*/
return true
}

private fun getIndexMappings(indexName: String): MappingMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* 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.pool.config

import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClient
import org.eclipse.tractusx.orchestrator.api.client.OrchestrationApiClientImpl
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.client.WebClient


@Configuration
class OrchestratorClientConfig {

@Bean
fun orchestratorClientNoAuth(configProperties: OrchestratorClientConfigProperties): OrchestrationApiClient {
val url = configProperties.baseUrl
return OrchestrationApiClientImpl { webClientBuilder(url).build() }
}


private fun webClientBuilder(url: String) =
WebClient.builder()
.baseUrl(url)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* 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.pool.config

import org.springframework.boot.context.properties.ConfigurationProperties


@ConfigurationProperties(prefix = "bpdm.pool-orchestrator")
data class OrchestratorClientConfigProperties(
val baseUrl: String = "http://localhost:8085/"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* 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.pool.exception


class BpdmValidationException(message: String) : RuntimeException(message)
Loading

0 comments on commit 4057840

Please sign in to comment.