Skip to content

Commit

Permalink
feat(BPDM): Clean import and unused vars for code smelling
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed Nov 3, 2023
1 parent 75aaf79 commit 46fd81e
Show file tree
Hide file tree
Showing 30 changed files with 85 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.catenax.bpdm.bridge.dummy.service.SyncService
import io.swagger.v3.oas.annotations.Operation
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,6 @@ class GateUpdateService(
)
}

private fun buildSuccessSharingStateDto(
businessPartnerType: BusinessPartnerType,
externalId: String?,
bpn: String,
processStarted: Boolean
): SharingStateDto? {
if (externalId == null) {
logger.warn { "Encountered externalId=null in Pool response for $bpn, can't update the Gate sharing state" }
return null
}
return SharingStateDto(
businessPartnerType = businessPartnerType,
externalId = externalId,
sharingStateType = SharingStateType.Success,
bpn = bpn,
sharingProcessStarted = if (processStarted) LocalDateTime.now() else null
)
}

private fun buildErrorSharingStateDto(
businessPartnerType: BusinessPartnerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ class BridgeSyncIT @Autowired constructor(
businessPartnerType = null,
externalIds = null
)
val sharingStatesOkay = sharingStates.content
return sharingStates.content
.filter { it.sharingStateType == SharingStateType.Success && it.bpn != null }
return sharingStatesOkay
}

private fun assertEqualLegalEntity(gateVersion: LegalEntityGateInputRequest, poolVersion: LegalEntityMatchVerboseDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ import java.time.LocalDateTime
*/
object CommonValues {

val fixedTaskId = "taskid-123123"
const val fixedTaskId = "taskid-123123"

val nameParts = listOf("Part1", "Part2")
const val shortName = "ShortName"
val identifiers = listOf(
private val nameParts = listOf("Part1", "Part2")
private const val shortName = "ShortName"
private val identifiers = listOf(
BusinessPartnerIdentifierDto(
type = "Type1",
value = "Value1",
issuingBody = "IssuingBody1"
)
)
const val legalForm = "LegalForm"
val states = listOf(
private const val legalForm = "LegalForm"
private val states = listOf(
BusinessPartnerStateDto(
validFrom = LocalDateTime.now(),
validTo = LocalDateTime.now().plusDays(10),
type = BusinessStateType.ACTIVE,
description = "ActiveState"
)
)
val classifications = listOf(
private val classifications = listOf(
ClassificationDto(
type = ClassificationType.NACE,
code = "Code1",
value = "Value1"
)
)
val roles = listOf(BusinessPartnerRole.SUPPLIER, BusinessPartnerRole.CUSTOMER)
val physicalPostalAddress = PhysicalPostalAddressDto(
private val roles = listOf(BusinessPartnerRole.SUPPLIER, BusinessPartnerRole.CUSTOMER)
private val physicalPostalAddress = PhysicalPostalAddressDto(
geographicCoordinates = GeoCoordinateDto(longitude = 12.34f, latitude = 56.78f),
country = CountryCode.PT,
administrativeAreaLevel1 = "AdminArea1",
Expand All @@ -85,24 +85,24 @@ object CommonValues {
door = "Door"
)

val postalAddressForLegalAndSite = PostalAddressDto(
private val postalAddressForLegalAndSite = PostalAddressDto(
addressType = AddressType.LegalAndSiteMainAddress,
physicalPostalAddress = physicalPostalAddress
)
val postalAddressForLegal = PostalAddressDto(
private val postalAddressForLegal = PostalAddressDto(
addressType = AddressType.LegalAddress,
physicalPostalAddress = physicalPostalAddress
)
val postalAddressForSite = PostalAddressDto(
private val postalAddressForSite = PostalAddressDto(
addressType = AddressType.SiteMainAddress,
physicalPostalAddress = physicalPostalAddress
)
val postalAddressForAdditional = PostalAddressDto(
private val postalAddressForAdditional = PostalAddressDto(
addressType = AddressType.AdditionalAddress,
physicalPostalAddress = physicalPostalAddress
)

val businessPartnerWithEmptyBpns = BusinessPartnerGenericDto(
private val businessPartnerWithEmptyBpns = BusinessPartnerGenericDto(
nameParts = nameParts,
shortName = shortName,
identifiers = identifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.eclipse.tractusx.bpdm.common.dto

import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.LegalEntityIdentifierDescription


data class LegalEntityIdentifierDto(

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ private class DataClassUnwrappedJsonDeserializerForType(destinationJavaType: Jav

val constructorValues = constructorParameters.map { param ->
val jacksonType = ctxt.typeFactory.constructType(param.type.javaType)
val node = if (param.jsonUnwrapped) rootNode else rootNode.get(param.name)
val node = if (param.jsonUnwrapped) rootNode else rootNode[param.name]
val value = readTreeAsValue(ctxt, node, jacksonType)
if (value == null && !param.type.isMarkedNullable)
throw IllegalArgumentException("Field '${param.name}' of '$destinationClass' is required")
require(value != null || param.type.isMarkedNullable) {
"Field '${param.name}' of '$destinationClass' is required"
}
value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import kotlin.reflect.full.memberProperties
* This doesn't work out of the box, so we added this HttpServiceArgumentResolver that can be added to HttpServiceProxyFactory.
*/
class ParameterObjectArgumentResolver : HttpServiceArgumentResolver {
val conversionService = DefaultFormattingConversionService()
private val conversionService = DefaultFormattingConversionService()
override fun resolve(argument: Any?, parameter: MethodParameter, requestValues: HttpRequestValues.Builder): Boolean {
val annot = parameter.getParameterAnnotation(ParameterObject::class.java)
if (annot != null && argument != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package org.eclipse.tractusx.bpdm.common.util

class JpaMermaidCreator {

val MAX_ENUM_VALUES = 15
private val MAX_ENUM_VALUES = 15

fun getMermaid(allClassInfos: MutableCollection<JpaClassInfo>, title: String): String {

Expand All @@ -30,7 +30,7 @@ class JpaMermaidCreator {

appendHeader(mermaid, title)
appendEnums(mermaid, allClassInfos)

val whiteSpace = " "
allClassInfos
.sortedBy { it.entityName }
.forEach { classInfo ->
Expand All @@ -43,11 +43,11 @@ class JpaMermaidCreator {
if (attrInfo.primitiveType is JpaStringType && attrInfo.primitiveType.typeHint == TypeHint.ENUM) {
mermaid.append(" ").append(attrInfo.primitiveType.domValueType?.simpleName)
} else {
mermaid.append(" ").append(attrInfo.primitiveType.getTypeName())
mermaid.append(whiteSpace).append(attrInfo.primitiveType.getTypeName())
}
}
if (attrInfo is JdyObjectReferenceInfo) {
mermaid.append(" ").append(attrInfo.referencedClass.entityName)
mermaid.append(whiteSpace).append(attrInfo.referencedClass.entityName)
if (attrInfo.embedded) {
mermaidRelationship.append(" ").append(classInfo.entityName).append(" ..> ").append(attrInfo.referencedClass.entityName)
.appendLine()
Expand Down Expand Up @@ -77,14 +77,16 @@ class JpaMermaidCreator {

allClassInfos.forEach { classInfo ->
classInfo.attributeList.forEach { attrInfo ->

if (attrInfo is JpaPrimitiveAttributeInfo && attrInfo.primitiveType is JpaStringType && attrInfo.primitiveType.typeHint == TypeHint.ENUM) {

if (attrInfo.primitiveType.domValueType != null && !allEnums.contains(attrInfo.primitiveType.domValueType)) {
appendEnum(mermaid, attrInfo.primitiveType.domValueType, attrInfo.primitiveType.domValues)
allEnums.add(attrInfo.primitiveType.domValueType)
}
if (attrInfo is JpaPrimitiveAttributeInfo
&& attrInfo.primitiveType is JpaStringType
&& attrInfo.primitiveType.typeHint == TypeHint.ENUM
&& attrInfo.primitiveType.domValueType != null
&& !allEnums.contains(attrInfo.primitiveType.domValueType)
) {
appendEnum(mermaid, attrInfo.primitiveType.domValueType, attrInfo.primitiveType.domValues)
allEnums.add(attrInfo.primitiveType.domValueType)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package org.eclipse.tractusx.bpdm.common.util

import jakarta.persistence.*
import jakarta.persistence.Column
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Temporal
import jakarta.persistence.TemporalType
import jakarta.persistence.metamodel.*
import jakarta.persistence.metamodel.Attribute.PersistentAttributeType.*
import jakarta.validation.constraints.DecimalMax
Expand Down Expand Up @@ -95,21 +98,18 @@ class JpaMetaModelReader {
jpaEntity.attributes.forEach { attr ->
if (!attr.isCollection) {
if (attr.persistentAttributeType === Attribute.PersistentAttributeType.BASIC) {

createPrimitiveField(attr)?.let {
classInfo.attributeList.add(it)
}
} else if (attr.persistentAttributeType === ONE_TO_ONE || attr.persistentAttributeType === MANY_TO_ONE) {

createObjectReference(attr, className2InfoMap)?.let {
classInfo.attributeList.add(it)
}
} else if (attr.persistentAttributeType === EMBEDDED) {

} else if (attr.persistentAttributeType === ONE_TO_ONE
|| attr.persistentAttributeType === MANY_TO_ONE
|| attr.persistentAttributeType === EMBEDDED
) {
createObjectReference(attr, className2InfoMap)?.let {
classInfo.attributeList.add(it)
}
}

}
}
}
Expand All @@ -118,16 +118,13 @@ class JpaMetaModelReader {
private fun buildAssociationsForClassInfo(classInfo: JpaClassInfo, jpaEntity: EntityType<*>, className2InfoMap: MutableMap<String, JpaClassInfo>) {

jpaEntity.attributes.forEach {
if (it.isCollection) {
if (it.persistentAttributeType === Attribute.PersistentAttributeType.ONE_TO_MANY) {
val wrapper = JpaCollectionWrapper(it)
val metaDetailClass = className2InfoMap[wrapper.referencedType?.name]
val mapping = wrapper.getAnnotationInfo(OneToMany::class.java)
val joinColumn = wrapper.getAnnotationInfo(JoinColumn::class.java)
val metaAssocName = it.name
val metaAssoc = metaDetailClass?.let { it1 -> JpaAssociationInfo(assocName = metaAssocName, detailClass = it1) }
metaAssoc?.let { it1 -> classInfo.associationList.add(it1) }
}
if (it.isCollection && it.persistentAttributeType === Attribute.PersistentAttributeType.ONE_TO_MANY) {
val wrapper = JpaCollectionWrapper(it)
val metaDetailClass = className2InfoMap[wrapper.referencedType?.name]

val metaAssocName = it.name
val metaAssoc = metaDetailClass?.let { it1 -> JpaAssociationInfo(assocName = metaAssocName, detailClass = it1) }
metaAssoc?.let { it1 -> classInfo.associationList.add(it1) }
}
}
}
Expand All @@ -140,7 +137,7 @@ class JpaMetaModelReader {
val wrapper = JpaFieldWrapper(curAttr)
val isKey = (curAttr as SingularAttribute).isId
val isNotNull = !curAttr.isOptional || !wrapper.isNullable()
val isGenerated = wrapper.getGeneratedInfo() != null

val refTypeName = wrapper.getRefTypeName()
val referenceType = className2InfoMap[refTypeName]
val metaAttr = referenceType?.let {
Expand Down Expand Up @@ -209,10 +206,10 @@ class JpaMetaModelReader {
} else if (aTypeClass.isAssignableFrom(BigDecimal::class.java)) {
val column = wrapper.getAnnotationInfo(Column::class.java)
var scale = 0
var precision = 0

if (column != null) {
scale = column.scale
precision = column.precision

}
val decMin: DecimalMin? = wrapper.getAnnotationInfo(DecimalMin::class.java)
val decMax: DecimalMax? = wrapper.getAnnotationInfo(DecimalMax::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test

class DataClassUnwrappedJsonDeserializerTest {

val objectMapper = buildObjectMapper()
private val objectMapper: ObjectMapper = buildObjectMapper()

@Test
fun `test standard cases`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ import org.springframework.web.bind.annotation.ResponseStatus
class BpdmInvalidPartnerException(
partnerId: String,
reason: String
) : RuntimeException("Partner with ID '$partnerId' is invalid: $reason") {
}
) : RuntimeException("Partner with ID '$partnerId' is invalid: $reason")
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AddressService(
*/
fun getAddressesOutput(externalIds: Collection<String>? = null, page: Int, size: Int): PageDto<AddressGateOutputDto> {

val logisticAddressPage = if (externalIds != null && externalIds.isNotEmpty()) {
val logisticAddressPage = if (!externalIds.isNullOrEmpty()) {
addressRepository.findByExternalIdInAndStage(externalIds, StageType.Output, PageRequest.of(page, size))
} else {
addressRepository.findByStage(StageType.Output, PageRequest.of(page, size))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,29 +275,25 @@ fun getLegalAddressExternalIdForLegalEntityExternalId(legalEntityExternalId: Str
//Logistic Address mapping to AddressGateInputResponse
fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddress): AddressGateInputDto {

val addressGateInputResponse = AddressGateInputDto(
return AddressGateInputDto(
address = logisticAddressPage.toLogisticAddressDto(),
externalId = externalId,
legalEntityExternalId = legalEntity?.externalId,
siteExternalId = site?.externalId,
)

return addressGateInputResponse
}

//Logistic Address mapping to LogisticAddressDto
fun LogisticAddress.toLogisticAddressDto(): LogisticAddressGateDto {

val logisticAddress = LogisticAddressGateDto(
return LogisticAddressGateDto(
nameParts = getNamePartValues(nameParts),
states = mapToDtoStates(states),
roles = roles.map { it.roleName },
physicalPostalAddress = physicalPostalAddress.toPhysicalPostalAddress(),
alternativePostalAddress = alternativePostalAddress?.toAlternativePostalAddressDto(),
identifiers = mapToAddressIdentifiersDto(identifiers)
)

return logisticAddress
}

fun getNamePartValues(nameparts: MutableSet<NameParts>): Collection<String> {
Expand Down Expand Up @@ -429,15 +425,13 @@ fun Site.toSiteGateInputResponse(sitePage: Site): SiteGateInputDto {
//Logistic Address mapping to AddressGateOutputResponse
fun LogisticAddress.toAddressGateOutputResponse(logisticAddressPage: LogisticAddress): AddressGateOutputDto {

val addressGateOutputResponse = AddressGateOutputDto(
return AddressGateOutputDto(
address = logisticAddressPage.toLogisticAddressDto(),
externalId = externalId,
legalEntityExternalId = legalEntity?.externalId,
siteExternalId = site?.externalId,
bpna = bpn!!,
)

return addressGateOutputResponse
}

//Site mapping to SiteGateOutputResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
}

private fun mockOrchestratorApiCleaned() {
val TaskStateResponse =
val taskStateResponse =
TaskStateResponse(
listOf(
TaskClientStateDto(
Expand Down Expand Up @@ -479,7 +479,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
gateWireMockServer.stubFor(
WireMock.post(WireMock.urlPathEqualTo(ORCHESTRATOR_SEARCH_TASK_STATES_URL))
.willReturn(
WireMock.okJson(objectMapper.writeValueAsString(TaskStateResponse))
WireMock.okJson(objectMapper.writeValueAsString(taskStateResponse))
)
)
}
Expand Down
Loading

0 comments on commit 46fd81e

Please sign in to comment.