@@ -2,11 +2,7 @@ package org.tix.feature.plan.presentation
2
2
3
3
import kotlinx.coroutines.flow.*
4
4
import org.tix.config.data.TixConfiguration
5
- import org.tix.config.data.raw.RawTixConfiguration
6
- import org.tix.config.domain.AuthConfigAction
7
- import org.tix.config.domain.ConfigBakerAction
8
5
import org.tix.config.domain.ConfigurationSourceOptions
9
- import org.tix.config.domain.TicketSystemAuth
10
6
import org.tix.domain.FlowResult
11
7
import org.tix.domain.FlowTransformer
12
8
import org.tix.domain.transform
@@ -20,16 +16,14 @@ import org.tix.feature.plan.domain.parse.MarkdownSourceValidator
20
16
import org.tix.feature.plan.domain.parse.MarkdownTextSource
21
17
22
18
class PlanSourceCombiner (
23
- private val authConfigUseCase : FlowTransformer <AuthConfigAction , TicketSystemAuth >,
24
- private val configBakerUseCase : FlowTransformer <ConfigBakerAction , FlowResult <TixConfiguration >>,
25
- private val configReadUseCase : FlowTransformer <ConfigurationSourceOptions , List <RawTixConfiguration >>,
26
- private val configMergeUseCase : FlowTransformer <List <RawTixConfiguration >, FlowResult <RawTixConfiguration >>,
19
+ private val configurationUseCase : FlowTransformer <ConfigurationSourceOptions , FlowResult <TixConfiguration >>,
27
20
private val markdownFileUseCase : FlowTransformer <String , FlowResult <String >>,
28
21
private val markdownValidator : MarkdownSourceValidator
29
22
) : FlowTransformer<MarkdownPlanAction, PlanSourceResult> {
30
23
override fun transformFlow (upstream : Flow <MarkdownPlanAction >): Flow <PlanSourceResult > =
31
24
upstream.flatMapLatest { action ->
32
- config(action.configSourceOptions)
25
+ flowOf(action.configSourceOptions)
26
+ .transform(configurationUseCase)
33
27
.combine(markdown(action.markdownSource)) { configResult, markdownResult ->
34
28
toResult(configResult, markdownResult)
35
29
}.catch {
@@ -38,25 +32,6 @@ class PlanSourceCombiner(
38
32
}
39
33
}
40
34
41
- private fun config (configSourceOptions : ConfigurationSourceOptions ) =
42
- flowOf(configSourceOptions)
43
- .transform(configReadUseCase)
44
- .transform(configMergeUseCase)
45
- .flatMapLatest { mergeResult ->
46
- bakeConfig(mergeResult, configSourceOptions.workspaceDirectory)
47
- }
48
-
49
- private fun bakeConfig (mergeResult : FlowResult <RawTixConfiguration >, path : String? ) =
50
- if (mergeResult.isSuccess) {
51
- val rawConfig = mergeResult.getOrThrow()
52
- flowOf(AuthConfigAction (path, rawConfig))
53
- .transform(authConfigUseCase)
54
- .map { ConfigBakerAction (rawConfig, it) }
55
- .transform(configBakerUseCase)
56
- } else {
57
- flowOf(FlowResult .failure(mergeResult.throwable))
58
- }
59
-
60
35
private fun markdown (markdownInput : MarkdownSource ): Flow <FlowResult <String >> {
61
36
val result = runCatching {
62
37
markdownValidator.validate(markdownInput)
@@ -90,17 +65,7 @@ sealed class PlanSourceResult {
90
65
}
91
66
92
67
fun planSourceCombiner (
93
- authConfigUseCase : FlowTransformer <AuthConfigAction , TicketSystemAuth >,
94
- configBakerUseCase : FlowTransformer <ConfigBakerAction , FlowResult <TixConfiguration >>,
95
- configReadUseCase : FlowTransformer <ConfigurationSourceOptions , List <RawTixConfiguration >>,
96
- configMergeUseCase : FlowTransformer <List <RawTixConfiguration >, FlowResult <RawTixConfiguration >>,
68
+ configUseCase : FlowTransformer <ConfigurationSourceOptions , FlowResult <TixConfiguration >>,
97
69
markdownFileUseCase : FlowTransformer <String , FlowResult <String >>,
98
70
markdownValidator : MarkdownSourceValidator
99
- ) = PlanSourceCombiner (
100
- authConfigUseCase,
101
- configBakerUseCase,
102
- configReadUseCase,
103
- configMergeUseCase,
104
- markdownFileUseCase,
105
- markdownValidator
106
- )
71
+ ) = PlanSourceCombiner (configUseCase, markdownFileUseCase, markdownValidator)
0 commit comments