Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): #222 Wrong Schema for Entities with Error Response #243

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,72 @@ package org.eclipse.tractusx.bpdm.pool.api.model.response
import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressResponse

@Schema(name = "EntitiesWithErrorsResponse", description = "Holds information about successfully and failed entities after the creating/updating of several objects")

data class EntitiesWithErrors<ENTITY, out ERROR : ErrorCode>(
open class EntitiesWithErrors<ENTITY, out ERROR : ErrorCode>(

@Schema(description = "Successfully created entities")
val entities: Collection<ENTITY>,
open val entities: Collection<ENTITY>,
@Schema(description = "Errors for not created entities")
val errors: Collection<ErrorInfo<ERROR>>
open val errors: Collection<ErrorInfo<ERROR>>
) {
val entityCount: Int
get() = entities.size
val errorCount: Int
get() = errors.size
}

typealias LegalEntityPartnerCreateResponseWrapper = EntitiesWithErrors<LegalEntityPartnerCreateResponse, LegalEntityCreateError>
typealias LegalEntityPartnerUpdateResponseWrapper = EntitiesWithErrors<LegalEntityPartnerCreateResponse, LegalEntityUpdateError>
typealias SitePartnerCreateResponseWrapper = EntitiesWithErrors<SitePartnerCreateResponse, SiteCreateError>
typealias SitePartnerUpdateResponseWrapper = EntitiesWithErrors<SitePartnerCreateResponse, SiteUpdateError>
typealias AddressPartnerCreateResponseWrapper = EntitiesWithErrors<AddressPartnerCreateResponse, AddressCreateError>
typealias AddressPartnerUpdateResponseWrapper = EntitiesWithErrors<LogisticAddressResponse, AddressUpdateError>
@Schema(
name = "LegalEntityCreateWrapper",
description = "Holds information about successfully and failed entities after the creating/updating of several objects"
)
data class LegalEntityPartnerCreateResponseWrapper(
override val entities: Collection<LegalEntityPartnerCreateResponse>,
override val errors: Collection<ErrorInfo<LegalEntityCreateError>>
) : EntitiesWithErrors<LegalEntityPartnerCreateResponse, LegalEntityCreateError>(entities, errors)

@Schema(
name = "LegalEntityUpdateWrapper",
description = "Holds information about successfully and failed entities after the creating/updating of several objects"
)
data class LegalEntityPartnerUpdateResponseWrapper(
override val entities: Collection<LegalEntityPartnerCreateResponse>,
override val errors: Collection<ErrorInfo<LegalEntityUpdateError>>
) : EntitiesWithErrors<LegalEntityPartnerCreateResponse, LegalEntityUpdateError>(entities, errors)

@Schema(
name = "SiteCreateWrapper",
description = "Holds information about successfully and failed entities after the creating/updating of several objects"
)
data class SitePartnerCreateResponseWrapper(
override val entities: Collection<SitePartnerCreateResponse>,
override val errors: Collection<ErrorInfo<SiteCreateError>>
) : EntitiesWithErrors<SitePartnerCreateResponse, SiteCreateError>(entities, errors)

@Schema(
name = "SiteUpdateWrapper",
description = "Holds information about successfully and failed entities after the creating/updating of several objects"
)
data class SitePartnerUpdateResponseWrapper(
override val entities: Collection<SitePartnerCreateResponse>,
override val errors: Collection<ErrorInfo<SiteUpdateError>>
) : EntitiesWithErrors<SitePartnerCreateResponse, SiteUpdateError>(entities, errors)

@Schema(
name = "AddressCreateWrapper",
description = "Holds information about successfully and failed entities after the creating/updating of several objects"
)
data class AddressPartnerCreateResponseWrapper(
override val entities: Collection<AddressPartnerCreateResponse>,
override val errors: Collection<ErrorInfo<AddressCreateError>>
) : EntitiesWithErrors<AddressPartnerCreateResponse, AddressCreateError>(entities, errors)

@Schema(
name = "AddressUpdateWrapper",
description = "Holds information about successfully and failed entities after the creating/updating of several objects"
)
data class AddressPartnerUpdateResponseWrapper(
override val entities: Collection<LogisticAddressResponse>,
override val errors: Collection<ErrorInfo<AddressUpdateError>>
) : EntitiesWithErrors<LogisticAddressResponse, AddressUpdateError>(entities, errors)



Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BusinessPartnerBuildService(

val validEntities = legalEntities.map { it.toUpsertDto(legalEntityWithIndexByBpnMap[it.bpn]!!.second) }

return EntitiesWithErrors(validEntities, errors)
return LegalEntityPartnerCreateResponseWrapper(validEntities, errors)
}

@Transactional
Expand Down Expand Up @@ -125,7 +125,7 @@ class BusinessPartnerBuildService(

val validEntities = sites.map { it.toUpsertDto(siteWithIndexByBpnMap[it.bpn]!!.second) }

return EntitiesWithErrors(validEntities, errors)
return SitePartnerCreateResponseWrapper(validEntities, errors)
}

@Transactional
Expand All @@ -150,7 +150,7 @@ class BusinessPartnerBuildService(

changelogService.createChangelogEntries(addressResponses.map { ChangelogEntryDto(it.address.bpna, ChangelogType.CREATE, ChangelogSubject.ADDRESS) })

return EntitiesWithErrors(addressResponses, errors)
return AddressPartnerCreateResponseWrapper(addressResponses, errors)
}

/**
Expand Down Expand Up @@ -184,7 +184,7 @@ class BusinessPartnerBuildService(

val validEntities = legalEntityRepository.saveAll(legalEntities).map { it.toUpsertDto(null) }

return EntitiesWithErrors(validEntities, errors)
return LegalEntityPartnerUpdateResponseWrapper(validEntities, errors)
}

@Transactional
Expand Down Expand Up @@ -212,7 +212,7 @@ class BusinessPartnerBuildService(
}
val validEntities = siteRepository.saveAll(sites).map { it.toUpsertDto(null) }

return EntitiesWithErrors(validEntities, errors)
return SitePartnerUpdateResponseWrapper(validEntities, errors)
}

fun updateAddresses(requests: Collection<AddressPartnerUpdateRequest>): AddressPartnerUpdateResponseWrapper {
Expand All @@ -233,7 +233,7 @@ class BusinessPartnerBuildService(
changelogService.createChangelogEntries(validAddresses.map { ChangelogEntryDto(it.bpn, ChangelogType.UPDATE, ChangelogSubject.ADDRESS) })

val addressResponses = logisticAddressRepository.saveAll(validAddresses).map { it.toDto() }
return EntitiesWithErrors(addressResponses, errors)
return AddressPartnerUpdateResponseWrapper(addressResponses, errors)
}

@Transactional
Expand Down