Skip to content

Commit

Permalink
Fix #78 by redesigning add value menu
Browse files Browse the repository at this point in the history
- add unit tests for AddValueButton, CreateOppositionValueForm, and CreateValueWebForm
  • Loading branch information
b-camphart committed Jul 1, 2021
1 parent 0291008 commit bb47da4
Show file tree
Hide file tree
Showing 48 changed files with 2,136 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface AddOppositionToValueWeb {
val characterIncludedInTheme: CharacterIncludedInTheme?
)

interface OutputPort {
fun interface OutputPort {
suspend fun addedOppositionToValueWeb(response: ResponseModel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface AddValueWebToTheme {
val symbolicItemAdded: SymbolicRepresentationAddedToOpposition?
)

interface OutputPort {
fun interface OutputPort {
suspend fun addedValueWebToTheme(response: ResponseModel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ListAvailableOppositionValuesForCharacterInTheme {

suspend operator fun invoke(themeId: UUID, characterId: UUID, output: OutputPort)

interface OutputPort {
fun interface OutputPort {
suspend fun availableOppositionValuesListedForCharacterInTheme(response: OppositionValuesAvailableForCharacterInTheme)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.soyle.stories.theme.addOppositionToValueWeb

import com.soyle.stories.domain.validation.NonBlankString
import com.soyle.stories.usecase.theme.addOppositionToValueWeb.OppositionAddedToValueWeb
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Job

interface AddOppositionToValueWebController {

fun addOpposition(valueWebId: String)
fun addOppositionWithCharacter(valueWebId: String, name: NonBlankString, characterId: String)
fun addOpposition(valueWebId: String): Deferred<OppositionAddedToValueWeb>
fun addOpposition(valueWebId: String, name: NonBlankString): Deferred<OppositionAddedToValueWeb>
fun addOppositionWithCharacter(valueWebId: String, name: NonBlankString, characterId: String): Deferred<OppositionAddedToValueWeb>

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import com.soyle.stories.common.ThreadTransformer
import com.soyle.stories.domain.validation.NonBlankString
import com.soyle.stories.usecase.theme.addOppositionToValueWeb.AddOppositionToValueWeb
import com.soyle.stories.usecase.theme.addOppositionToValueWeb.AddOppositionToValueWeb.RequestModel
import com.soyle.stories.usecase.theme.addOppositionToValueWeb.OppositionAddedToValueWeb
import com.soyle.stories.usecase.theme.addSymbolicItemToOpposition.CharacterId
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Job
import java.util.*

class AddOppositionToValueWebControllerImpl(
Expand All @@ -13,29 +17,41 @@ class AddOppositionToValueWebControllerImpl(
private val addOppositionToValueWebOutputPort: AddOppositionToValueWeb.OutputPort
) : AddOppositionToValueWebController {

override fun addOpposition(valueWebId: String) {
override fun addOpposition(valueWebId: String): Deferred<OppositionAddedToValueWeb> {
val request = RequestModel(
UUID.fromString(valueWebId)
)
addOppositionToValueWeb(request)
return addOppositionToValueWeb(request)
}

override fun addOppositionWithCharacter(valueWebId: String, name: NonBlankString, characterId: String) {
override fun addOpposition(valueWebId: String, name: NonBlankString): Deferred<OppositionAddedToValueWeb> {
val request = RequestModel(
UUID.fromString(valueWebId),
name,
null
)
return addOppositionToValueWeb(request)
}

override fun addOppositionWithCharacter(valueWebId: String, name: NonBlankString, characterId: String): Deferred<OppositionAddedToValueWeb> {
val request = RequestModel(
UUID.fromString(valueWebId),
name,
CharacterId(UUID.fromString(characterId))
)
addOppositionToValueWeb(request)
return addOppositionToValueWeb(request)
}

private fun addOppositionToValueWeb(requestModel: RequestModel)
private fun addOppositionToValueWeb(requestModel: RequestModel): Deferred<OppositionAddedToValueWeb>
{
val deferred = CompletableDeferred<OppositionAddedToValueWeb>()
threadTransformer.async {
addOppositionToValueWeb.invoke(
requestModel, addOppositionToValueWebOutputPort
)
addOppositionToValueWeb.invoke(requestModel) {
deferred.complete(it.oppositionAddedToValueWeb)
addOppositionToValueWebOutputPort.addedOppositionToValueWeb(it)
}
}
return deferred
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.soyle.stories.theme.addValueWebToTheme

import com.soyle.stories.domain.validation.NonBlankString
import com.soyle.stories.usecase.theme.addValueWebToTheme.ValueWebAddedToTheme
import kotlinx.coroutines.Deferred

interface AddValueWebToThemeController {

fun addValueWebToTheme(themeId: String, name: NonBlankString, onError: (Throwable) -> Unit)
fun addValueWebToThemeWithCharacter(themeId: String, name: NonBlankString, characterId: String, onError: (Throwable) -> Unit)
fun addValueWebToTheme(themeId: String, name: NonBlankString, onError: (Throwable) -> Unit): Deferred<ValueWebAddedToTheme>
fun addValueWebToThemeWithCharacter(themeId: String, name: NonBlankString, characterId: String, onError: (Throwable) -> Unit): Deferred<ValueWebAddedToTheme>

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.soyle.stories.domain.validation.NonBlankString
import com.soyle.stories.usecase.theme.addSymbolicItemToOpposition.CharacterId
import com.soyle.stories.usecase.theme.addValueWebToTheme.AddValueWebToTheme
import com.soyle.stories.usecase.theme.addValueWebToTheme.AddValueWebToTheme.RequestModel
import com.soyle.stories.usecase.theme.addValueWebToTheme.ValueWebAddedToTheme
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import java.util.*

class AddValueWebToThemeControllerImpl(
Expand All @@ -13,39 +16,46 @@ class AddValueWebToThemeControllerImpl(
private val addValueWebToThemeOutputPort: AddValueWebToTheme.OutputPort
) : AddValueWebToThemeController {

override fun addValueWebToTheme(themeId: String, name: NonBlankString, onError: (Throwable) -> Unit) {
override fun addValueWebToTheme(
themeId: String,
name: NonBlankString,
onError: (Throwable) -> Unit
): Deferred<ValueWebAddedToTheme> {
val preparedThemeId = UUID.fromString(themeId)
threadTransformer.async {
try {
addValueWebToTheme.invoke(
RequestModel(
preparedThemeId,
name
), addValueWebToThemeOutputPort
)
} catch (t: Throwable) { onError(t) }
}
return addValueWebToTheme(
RequestModel(
preparedThemeId,
name
)
)
}

override fun addValueWebToThemeWithCharacter(
themeId: String,
name: NonBlankString,
characterId: String,
onError: (Throwable) -> Unit
) {
): Deferred<ValueWebAddedToTheme> {
val preparedThemeId = UUID.fromString(themeId)
val preparedCharacterId = UUID.fromString(characterId)
return addValueWebToTheme(
RequestModel(
preparedThemeId,
name,
CharacterId(preparedCharacterId)
)
)
}

private fun addValueWebToTheme(request: RequestModel): Deferred<ValueWebAddedToTheme> {
val deferred = CompletableDeferred<ValueWebAddedToTheme>()
threadTransformer.async {
try {
addValueWebToTheme.invoke(
RequestModel(
preparedThemeId,
name,
CharacterId(preparedCharacterId)
), addValueWebToThemeOutputPort
)
} catch (t: Throwable) { onError(t) }
addValueWebToTheme(request) {
deferred.complete(it.addedValueWeb)
addValueWebToThemeOutputPort.addedValueWebToTheme(it)
}
}
return deferred
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.soyle.stories.theme.valueWeb.opposition.list

import com.soyle.stories.common.ThreadTransformer
import com.soyle.stories.domain.character.Character
import com.soyle.stories.domain.theme.Theme
import com.soyle.stories.usecase.theme.listAvailableOppositionValuesForCharacterInTheme.ListAvailableOppositionValuesForCharacterInTheme
import kotlinx.coroutines.Job

interface ListAvailableOppositionValuesForCharacterInThemeController {
companion object {

operator fun invoke(
threadTransformer: ThreadTransformer,
getAvailableOppositionValuesForCharacterInTheme: ListAvailableOppositionValuesForCharacterInTheme
): ListAvailableOppositionValuesForCharacterInThemeController =
object : ListAvailableOppositionValuesForCharacterInThemeController {
override fun listAvailableOppositionValuesForCharacter(
themeId: Theme.Id,
characterId: Character.Id,
output: ListAvailableOppositionValuesForCharacterInTheme.OutputPort
): Job {
return threadTransformer.async {
getAvailableOppositionValuesForCharacterInTheme(
themeId.uuid,
characterId.uuid,
output
)
}
}
}
}

fun listAvailableOppositionValuesForCharacter(
themeId: Theme.Id,
characterId: Character.Id,
output: ListAvailableOppositionValuesForCharacterInTheme.OutputPort
): Job
}
5 changes: 5 additions & 0 deletions desktop/locale/src/main/kotlin/SoyleMessageBundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface SoyleMessageBundle {
val pleaseProvideALocationName: String
val replaceWith: String
val removeFromScene: String
val addValue: String
val createNewValueWeb: String
val createOppositionValue: String
val themeHasNoValueWebs: String
val nameCannotBeBlank: String

sealed class MessageSegment {
abstract val message: String
Expand Down
5 changes: 5 additions & 0 deletions desktop/locale/src/main/kotlin/en/EnglishMessages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ object EnglishMessages : SoyleMessageBundle {
override val pleaseProvideALocationName: String = "Please provide a location name."
override val removeFromScene: String = "Remove From Scene"
override val replaceWith: String = "Replace With..."
override val addValue: String = "Add Value"
override val createNewValueWeb: String = "Create New Value Web"
override val createOppositionValue: String = "Create Opposition Value"
override val themeHasNoValueWebs: String = "Theme Has No Value Webs"
override val nameCannotBeBlank: String = "Name Cannot Be Blank"
}
11 changes: 10 additions & 1 deletion desktop/src/main/kotlin/locale/LocaleHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import com.soyle.stories.scene.setting.SceneSettingToolLocale
import com.soyle.stories.scene.setting.list.SceneSettingItemListLocale
import com.soyle.stories.scene.setting.list.item.SceneSettingItemLocale
import com.soyle.stories.scene.setting.list.useLocationButton.UseLocationButtonLocale
import com.soyle.stories.theme.characterValueComparison.components.addValueButton.AddValueButtonLocale
import com.soyle.stories.theme.valueWeb.create.CreateValueWebFormLocale
import com.soyle.stories.theme.valueWeb.opposition.create.CreateOppositionValueFormLocale
import javafx.beans.value.ObservableValue
import javafx.scene.Parent
import tornadofx.*

class LocaleHolder(bundle: SoyleMessageBundle) : LocationDetailsLocale, SceneSettingToolLocale,
SceneSettingItemListLocale, SceneSettingItemLocale, UseLocationButtonLocale, CreateLocationDialogLocale {
SceneSettingItemListLocale, SceneSettingItemLocale, UseLocationButtonLocale, CreateLocationDialogLocale, AddValueButtonLocale,
CreateOppositionValueFormLocale, CreateValueWebFormLocale {

private val currentLocale = objectProperty<SoyleMessageBundle>(bundle)

Expand Down Expand Up @@ -81,6 +85,11 @@ class LocaleHolder(bundle: SoyleMessageBundle) : LocationDetailsLocale, SceneSet
override val pleaseProvideALocationName: ObservableValue<String> = currentLocale.stringBinding { it!!.pleaseProvideALocationName }
override val removeFromScene: ObservableValue<String> = currentLocale.stringBinding { it!!.removeFromScene }
override val replaceWith: ObservableValue<String> = currentLocale.stringBinding { it!!.replaceWith }
override val addValue: ObservableValue<String> = currentLocale.stringBinding { it!!.addValue }
override val createNewValueWeb: ObservableValue<String> = currentLocale.stringBinding { it!!.createNewValueWeb }
override val createOppositionValue: ObservableValue<String> = currentLocale.stringBinding { it!!.createOppositionValue }
override val themeHasNoValueWebs: ObservableValue<String> = currentLocale.stringBinding { it!!.themeHasNoValueWebs }
override val nameCannotBeBlank: ObservableValue<String> = currentLocale.stringBinding { it!!.nameCannotBeBlank }

private fun createDynamicMessage(parent: Parent, segment: SoyleMessageBundle.MessageSegment) {
when (segment) {
Expand Down
60 changes: 60 additions & 0 deletions desktop/src/main/kotlin/theme/Presentation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ package com.soyle.stories.desktop.config.theme
import com.soyle.stories.characterarc.moveCharacterArcSectionInMoralArgument.CharacterArcSectionMovedInMoralArgumentNotifier
import com.soyle.stories.characterarc.removeCharacterArcSectionFromMoralArgument.CharacterArcSectionRemovedNotifier
import com.soyle.stories.common.listensTo
import com.soyle.stories.desktop.config.locale.LocaleHolder
import com.soyle.stories.di.get
import com.soyle.stories.di.scoped
import com.soyle.stories.domain.character.Character
import com.soyle.stories.domain.theme.Theme
import com.soyle.stories.domain.theme.valueWeb.ValueWeb
import com.soyle.stories.layout.config.dynamic.MoralArgument
import com.soyle.stories.project.ProjectScope
import com.soyle.stories.theme.addCharacterArcSectionToMoralArgument.ArcSectionAddedToCharacterArcNotifier
import com.soyle.stories.theme.characterValueComparison.CharacterValueComparisonScope
import com.soyle.stories.theme.characterValueComparison.components.addValueButton.AddValueButton
import com.soyle.stories.theme.moralArgument.*
import com.soyle.stories.theme.valueWeb.create.CreateValueWebForm
import com.soyle.stories.theme.valueWeb.opposition.create.CreateOppositionValueForm
import com.soyle.stories.usecase.theme.addOppositionToValueWeb.OppositionAddedToValueWeb
import com.soyle.stories.usecase.theme.addValueWebToTheme.ValueWebAddedToTheme

object Presentation {

Expand Down Expand Up @@ -44,6 +55,55 @@ object Presentation {
)
}
}
scoped<ProjectScope> {
provide<CreateValueWebForm.Factory> {
object : CreateValueWebForm.Factory {
override fun invoke(
themeId: Theme.Id,
onCreateValueWeb: suspend (ValueWebAddedToTheme) -> Unit
): CreateValueWebForm {
return CreateValueWebForm(
themeId,
onCreateValueWeb,
applicationScope.get<LocaleHolder>(),
get()
)
}
}
}
provide<CreateOppositionValueForm.Factory> {
object : CreateOppositionValueForm.Factory {
override fun invoke(
valueWebId: ValueWeb.Id,
onCreateOppositionValue: suspend (OppositionAddedToValueWeb) -> Unit
): CreateOppositionValueForm {
return CreateOppositionValueForm(
valueWebId,
onCreateOppositionValue,
applicationScope.get<LocaleHolder>(),
get()
)
}
}
}
}
scoped<CharacterValueComparisonScope> {
provide<AddValueButton.Factory> {
object : AddValueButton.Factory {
override fun invoke(themeId: Theme.Id, characterId: Character.Id): AddValueButton {
return AddValueButton(
themeId,
characterId,
projectScope.applicationScope.get<LocaleHolder>(),
projectScope.get(),
projectScope.get(),
projectScope.get(),
projectScope.get()
)
}
}
}
}
}

}
Loading

0 comments on commit bb47da4

Please sign in to comment.