Skip to content

Commit

Permalink
fix(Gate): ChangelogEntity to ChangelogEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed Mar 31, 2023
1 parent bae9c8c commit 5d7e066
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.response.LsaType

@Entity
@Table(name = "changelog_entries")
class ChangelogEntity(
class ChangelogEntry(

@Column(name = "external_id", nullable = false, updatable = false)
val externalId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@

package org.eclipse.tractusx.bpdm.gate.repository

import io.swagger.v3.oas.annotations.Parameter
import org.eclipse.tractusx.bpdm.gate.api.model.response.LsaType
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntity
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
import org.springframework.data.jpa.domain.Specification
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Query
import java.time.Instant


interface ChangelogRepository : JpaRepository<ChangelogEntity, Long>, JpaSpecificationExecutor<ChangelogEntity> {
interface ChangelogRepository : JpaRepository<ChangelogEntry, Long>, JpaSpecificationExecutor<ChangelogEntry> {

object Specs {

/**
* Restrict to entries with any one of the given ExternalIds; ignore if null
*/
fun byExternalIdsIn(externalIds: Collection<String>) =
Specification<ChangelogEntity> { root, _, _ ->
Specification<ChangelogEntry> { root, _, _ ->

externalIds.let {
root.get<String>(ChangelogEntity::externalId.name).`in`(externalIds.map { externalId -> externalId })
root.get<String>(ChangelogEntry::externalId.name).`in`(externalIds.map { externalId -> externalId })
}

}
Expand All @@ -49,24 +48,24 @@ interface ChangelogRepository : JpaRepository<ChangelogEntity, Long>, JpaSpecifi
* Restrict to entries created at or after the given instant; ignore if null
*/
fun byCreatedAtGreaterThan(createdAt: Instant?) =
Specification<ChangelogEntity> { root, _, builder ->
Specification<ChangelogEntry> { root, _, builder ->
createdAt?.let {
builder.greaterThanOrEqualTo(root.get(ChangelogEntity::createdAt.name), createdAt)
builder.greaterThanOrEqualTo(root.get(ChangelogEntry::createdAt.name), createdAt)
}
}

/**
* Restrict to entries for the LsaType; ignore if null
*/
fun byLsaType(lsaType: LsaType?) =
Specification<ChangelogEntity> { root, _, builder ->
Specification<ChangelogEntry> { root, _, builder ->
lsaType?.let {
builder.equal(root.get<LsaType>(ChangelogEntity::businessPartnerType.name), lsaType)
builder.equal(root.get<LsaType>(ChangelogEntry::businessPartnerType.name), lsaType)
}
}
}

@Query("select distinct u.externalId from ChangelogEntity u where u.externalId in :externalIdList")
@Query("select distinct u.externalId from ChangelogEntry u where u.externalId in :externalIdList")
fun findExternalIdsInListDistinct(externalIdList: Collection<String>): Set<String>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.response.OptionalLsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageOutputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse
import org.eclipse.tractusx.bpdm.gate.config.BpnConfigProperties
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntity
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
import org.eclipse.tractusx.bpdm.gate.exception.SaasInvalidRecordException
import org.eclipse.tractusx.bpdm.gate.exception.SaasNonexistentParentException
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository
Expand Down Expand Up @@ -158,7 +158,7 @@ class AddressService(

// create changelog entry if all goes well from saasClient
addresses.forEach { address ->
changelogRepository.save(ChangelogEntity(address.externalId, LsaType.Address))
changelogRepository.save(ChangelogEntry(address.externalId, LsaType.Address))
}

deleteParentRelationsOfAddresses(addresses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateOutput
import org.eclipse.tractusx.bpdm.gate.api.model.response.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageOutputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntity
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository
import org.springframework.stereotype.Service

Expand All @@ -56,7 +56,7 @@ class LegalEntityService(

// create changelog entry if all goes well from saasClient
legalEntities.forEach { legalEntity ->
changelogRepository.save(ChangelogEntity(legalEntity.externalId, LsaType.LegalEntity))
changelogRepository.save(ChangelogEntry(legalEntity.externalId, LsaType.LegalEntity))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
package org.eclipse.tractusx.bpdm.gate.service

import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntity
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogResponse
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
import org.springframework.data.domain.Page


fun <S, T> Page<S>.toDto(dtoContent: Collection<T>): PageResponse<T> {
return PageResponse(this.totalElements, this.totalPages, this.number, this.numberOfElements, dtoContent)
}

fun ChangelogEntity.toGateDto(): ChangelogResponse {
fun ChangelogEntry.toGateDto(): ChangelogResponse {
return ChangelogResponse(
externalId,
businessPartnerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.response.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageOutputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse
import org.eclipse.tractusx.bpdm.gate.config.BpnConfigProperties
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntity
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
import org.eclipse.tractusx.bpdm.gate.exception.SaasInvalidRecordException
import org.eclipse.tractusx.bpdm.gate.exception.SaasNonexistentParentException
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository
Expand Down Expand Up @@ -146,7 +146,7 @@ class SiteService(

// create changelog entry if all goes well from saasClient
sites.forEach { site ->
changelogRepository.save(ChangelogEntity(site.externalId, LsaType.Site))
changelogRepository.save(ChangelogEntry(site.externalId, LsaType.Site))
}

deleteParentRelationsOfSites(sites)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import org.eclipse.tractusx.bpdm.gate.api.exception.ChangeLogOutputError
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.ErrorInfo
import org.eclipse.tractusx.bpdm.gate.config.SaasConfigProperties
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntity
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry

import org.eclipse.tractusx.bpdm.gate.util.*

Expand Down Expand Up @@ -139,10 +139,10 @@ internal class ChangeLogControllerIT @Autowired constructor(
.usingRecursiveComparison()
.ignoringAllOverriddenEquals()
.ignoringCollectionOrder()
.isEqualTo(emptyList<ChangelogEntity>())
.isEqualTo(emptyList<ChangelogEntry>())

assertRecursively(searchResult.content)
.isEqualTo(emptyList<ChangelogEntity>())
.isEqualTo(emptyList<ChangelogEntry>())

assertRecursively(searchResult.errors)
.isEqualTo(listOf(
Expand Down Expand Up @@ -196,7 +196,7 @@ internal class ChangeLogControllerIT @Autowired constructor(
val searchResult = gateClient.changelog().getChangelogEntriesLsaType(PaginationRequest(), null, lsaTypeParamNotFound)

assertRecursively(searchResult.content)
.isEqualTo(emptyList<ChangelogEntity>())
.isEqualTo(emptyList<ChangelogEntry>())
}

/**
Expand Down

0 comments on commit 5d7e066

Please sign in to comment.