-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: do not work with reactive stuff
- Loading branch information
1 parent
58a886e
commit 50bba70
Showing
15 changed files
with
147 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 40 additions & 39 deletions
79
...adapter/out/nasaapi/ReactiveRestClient.kt → ...command/adapter/out/nasaapi/RestClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 7 additions & 9 deletions
16
...n/cqrshexagonaldemo/demoparent/command/adapter/out/searchresult/SearchResultOutAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.command.adapter.out.searchresult | ||
|
||
import io.holixon.cqrshexagonaldemo.demoparent.command.adapter.out.searchresult.entity.SearchResultItemEntity | ||
import io.holixon.cqrshexagonaldemo.demoparent.command.adapter.out.searchresult.mapper.EntityMapper | ||
import io.holixon.cqrshexagonaldemo.demoparent.command.adapter.out.searchresult.repo.ItemRepository | ||
import io.holixon.cqrshexagonaldemo.demoparent.command.application.port.out.searchresult.SearchResultOutPort | ||
import io.holixon.cqrshexagonaldemo.demoparent.command.domain.SearchResultItem | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Service | ||
import reactor.core.publisher.Mono | ||
import reactor.core.scheduler.Schedulers | ||
|
||
@Service | ||
class SearchResultOutAdapter @Autowired constructor( | ||
val mapper: EntityMapper, | ||
val itemRepository: ItemRepository | ||
) : SearchResultOutPort { | ||
|
||
override fun saveSearchResult(searchResultItem: SearchResultItem): Mono<SearchResultItem> { | ||
override fun saveSearchResult(searchResultItem: SearchResultItem): SearchResultItem { | ||
val itemEntity = mapper.toEntity(searchResultItem) | ||
itemEntity.data.forEach { dataItemEntity -> | ||
itemEntity.data?.forEach { dataItemEntity -> | ||
dataItemEntity.searchResultItem = itemEntity | ||
dataItemEntity.links.forEach { linkEntity -> | ||
dataItemEntity.links?.forEach { linkEntity -> | ||
linkEntity.dataItem = dataItemEntity | ||
} | ||
} | ||
|
||
return Mono | ||
.fromCallable { itemRepository.save(itemEntity) } | ||
.subscribeOn(Schedulers.boundedElastic()) | ||
.map { savedEntity -> mapper.toDomainObject(savedEntity) } | ||
val savedEntity: SearchResultItemEntity = itemRepository.save(itemEntity) | ||
val toDomainObject = mapper.toDomainObject(savedEntity) | ||
return toDomainObject | ||
} | ||
} |
18 changes: 12 additions & 6 deletions
18
...olixon/cqrshexagonaldemo/demoparent/command/adapter/out/searchresult/entity/BaseEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.command.adapter.out.searchresult.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.EntityListeners | ||
import jakarta.persistence.MappedSuperclass | ||
import org.springframework.data.annotation.CreatedBy | ||
import org.springframework.data.annotation.CreatedDate | ||
import org.springframework.data.annotation.LastModifiedBy | ||
import org.springframework.data.annotation.LastModifiedDate | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener | ||
import java.io.Serializable | ||
import java.time.Instant | ||
|
||
@MappedSuperclass | ||
abstract class BaseEntity : Serializable { | ||
|
||
@EntityListeners(AuditingEntityListener::class) | ||
abstract class BaseEntity( | ||
@CreatedDate | ||
@Column(updatable = false) | ||
var created: Instant? = null | ||
open var created: Instant?, | ||
|
||
@LastModifiedDate | ||
val updated: Instant? = null | ||
open val updated: Instant?, | ||
|
||
@CreatedBy | ||
@Column(updatable = false) | ||
var createdBy: String? = null | ||
open var createdBy: String?, | ||
|
||
@LastModifiedBy | ||
val updatedBy: String? = null | ||
open val updatedBy: String? | ||
|
||
) : Serializable { | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 12 additions & 3 deletions
15
...exagonaldemo/demoparent/command/adapter/out/searchresult/entity/SearchResultItemEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.command.adapter.out.searchresult.entity | ||
|
||
import jakarta.persistence.* | ||
import java.time.Instant | ||
|
||
|
||
@Entity | ||
@Table( | ||
name = "search_result_item", | ||
schema = "command" | ||
) | ||
class SearchResultItemEntity( | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
var id: Long, | ||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "searchResultItem") | ||
var data: Set<DataItemEntity>, | ||
|
||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "searchResultItem", cascade = [CascadeType.PERSIST]) | ||
var data: Set<DataItemEntity>?, | ||
|
||
@Column(nullable = false) | ||
var href: String, | ||
created: Instant?, | ||
updated: Instant?, | ||
createdBy: String?, | ||
updatedBy: String? | ||
|
||
) : BaseEntity() { | ||
) : BaseEntity(created, updated, createdBy, updatedBy) { | ||
} |
22 changes: 14 additions & 8 deletions
22
...main/kotlin/io/holixon/cqrshexagonaldemo/demoparent/command/application/CommandService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.command.application | ||
|
||
import io.holixon.cqrshexagonaldemo.demoparent.command.application.port.out.nasaapi.NasaApiOutPort | ||
import io.holixon.cqrshexagonaldemo.demoparent.command.application.port.out.searchresult.SearchResultOutPort | ||
import mu.KLogging | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.context.event.ApplicationReadyEvent | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Service | ||
import java.util.stream.Stream | ||
|
||
@Service | ||
open class CommandService @Autowired constructor(val nasaApi: NasaApiOutPort) { | ||
open class CommandService @Autowired constructor( | ||
val nasaApi: NasaApiOutPort, | ||
val outPort: SearchResultOutPort | ||
) { | ||
|
||
companion object : KLogging() | ||
|
||
@Async | ||
@EventListener | ||
fun init(applicationReadyEvent: ApplicationReadyEvent) { | ||
findItems("Ceres") | ||
} | ||
|
||
fun findItems(searchTerm: String) { | ||
nasaApi.findItemsBySearchTerm(searchTerm) | ||
.doOnNext { item -> | ||
val dataItem = item.data[0] | ||
val toList = nasaApi.findItemsBySearchTerm(searchTerm) | ||
.stream() | ||
.map { searchResultItem -> outPort.saveSearchResult(searchResultItem) } | ||
.map { searchResultItem -> | ||
val dataItem = searchResultItem.data[0] | ||
logger.info("nasaId: {} - title: {}", dataItem.nasaId, dataItem.title) | ||
dataItem | ||
} | ||
.flatMapIterable { item -> item.links } | ||
.subscribe { link -> logger.info("uri {}", link.href) } | ||
.flatMap { item -> item.links?.stream() ?: Stream.empty() } | ||
.toList() | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.