Skip to content

Commit

Permalink
Use _ separator for new entity names since 7.0 #179
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-shustanov committed Apr 19, 2019
1 parent ff86c85 commit 5b39747
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.haulmont.cuba.cli.cubaplugin.screen.entityscreen

import com.beust.jcommander.Parameters
import com.haulmont.cuba.cli.commands.NonInteractiveInfo
import com.haulmont.cuba.cli.cubaplugin.model.Entity
import com.haulmont.cuba.cli.cubaplugin.model.ModuleStructure
import com.haulmont.cuba.cli.cubaplugin.model.PlatformVersion
import com.haulmont.cuba.cli.generation.Properties
Expand All @@ -31,13 +32,13 @@ class CreateBrowseScreenCommand(private val forceVersion: PlatformVersion? = nul

override fun getModelName(): String = EntityScreenModel.MODEL_NAME

override fun createModel(answers: Answers): EntityScreenModel = EntityScreenModel(answers, entitySearch)
override fun createModel(answers: Answers): EntityScreenModel = EntityScreenModel(answers)

override fun getDefaultScreenId(entityName: String) = projectModel.namespace + "$" + entityName.split('.').last() + ".browse"
override fun getDefaultScreenId(entityName: String) = "$entityName.browse"

override fun getDefaultControllerName(entityName: String) = entityName.split('.').last() + "Browse"
override fun getDefaultControllerName(entity: Entity) = entity.className + "Browse"

override fun getDefaultDescriptorName(entityName: String) = entityName.split('.').last().toLowerCase() + "-browse"
override fun getDefaultDescriptorName(entity: Entity) = entity.className.toLowerCase() + "-browse"

override fun generate(bindings: Map<String, Any>) {
TemplateProcessor(resources.getTemplate("browseScreen"), bindings, version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.haulmont.cuba.cli.cubaplugin.screen.entityscreen

import com.beust.jcommander.Parameters
import com.haulmont.cuba.cli.commands.NonInteractiveInfo
import com.haulmont.cuba.cli.cubaplugin.model.Entity
import com.haulmont.cuba.cli.cubaplugin.model.ModuleStructure
import com.haulmont.cuba.cli.cubaplugin.model.PlatformVersion
import com.haulmont.cuba.cli.generation.Properties
Expand All @@ -31,13 +32,13 @@ class CreateEditScreenCommand(private val forceVersion: PlatformVersion? = null)

override fun getModelName(): String = EntityScreenModel.MODEL_NAME

override fun createModel(answers: Answers): EntityScreenModel = EntityScreenModel(answers, entitySearch)
override fun createModel(answers: Answers): EntityScreenModel = EntityScreenModel(answers)

override fun getDefaultScreenId(entityName: String) = projectModel.namespace + "$" + entityName.split('.').last() + ".edit"
override fun getDefaultScreenId(entityName: String) = "$entityName.edit"

override fun getDefaultControllerName(entityName: String) = entityName.split('.').last() + "Edit"
override fun getDefaultControllerName(entity: Entity) = entity.className + "Edit"

override fun getDefaultDescriptorName(entityName: String) = entityName.split('.').last().toLowerCase() + "-edit"
override fun getDefaultDescriptorName(entity: Entity) = entity.className.toLowerCase() + "-edit"

override fun generate(bindings: Map<String, Any>) {
TemplateProcessor(resources.getTemplate("editScreen"), bindings, version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package com.haulmont.cuba.cli.cubaplugin.screen.entityscreen
import com.haulmont.cuba.cli.Resources
import com.haulmont.cuba.cli.commands.NonInteractiveInfo
import com.haulmont.cuba.cli.cubaplugin.di.cubaKodein
import com.haulmont.cuba.cli.cubaplugin.model.Entity
import com.haulmont.cuba.cli.cubaplugin.screen.ScreenCommandBase
import com.haulmont.cuba.cli.prompting.Option
import com.haulmont.cuba.cli.prompting.QuestionsList
import org.kodein.di.generic.instance
import java.io.PrintWriter
Expand All @@ -45,32 +47,31 @@ abstract class EntityScreenCommandBase<out T : EntityScreenModel> : ScreenComman
override fun QuestionsList.prompting() {
val entitiesList = entitySearch.getAllEntities()
.filter { !it.embeddable }
.map { it.fqn }
if (entitiesList.isEmpty()) {
printWriter.println("Project does not have any suitable entities.")
abort()
}

textOptions("entityName", "Choose entity", entitiesList)
options("entity", "Choose entity", entitiesList.map { Option("", it.fqn, it) })

question("packageName", "Package name") {
validate {
checkIsPackage()
}

default { answers ->
val entityName: String by answers
val entity: Entity by answers

val packageParts = entityName.split('.').filter { it != "entity" }
packageParts.take(packageParts.lastIndex).joinToString(".") + ".web." + packageParts.last().toLowerCase()
val packageParts = entity.packageName.split('.').filter { it != "entity" }
packageParts.joinToString(".") + ".web." + entity.className.toLowerCase()
}
}

question("screenId", "Screen id") {
default { answers ->
val entityName: String by answers
val entity: Entity by answers

getDefaultScreenId(entityName)
getDefaultScreenId(entity.name)
}

validate {
Expand All @@ -80,9 +81,9 @@ abstract class EntityScreenCommandBase<out T : EntityScreenModel> : ScreenComman

question("descriptorName", "Descriptor name") {
default { answers ->
val entityName: String by answers
val entity: Entity by answers

getDefaultDescriptorName(entityName)
getDefaultDescriptorName(entity)
}

validate {
Expand All @@ -94,8 +95,8 @@ abstract class EntityScreenCommandBase<out T : EntityScreenModel> : ScreenComman

question("controllerName", "Controller name") {
default { answers ->
val entityName: String by answers
getDefaultControllerName(entityName)
val entity: Entity by answers
getDefaultControllerName(entity)
}

validate {
Expand All @@ -106,9 +107,9 @@ abstract class EntityScreenCommandBase<out T : EntityScreenModel> : ScreenComman
}
}

protected abstract fun getDefaultControllerName(entityName: String): String
protected abstract fun getDefaultControllerName(entity: Entity): String

protected abstract fun getDefaultDescriptorName(entityName: String): String
protected abstract fun getDefaultDescriptorName(entity: Entity): String

protected abstract fun getDefaultScreenId(entityName: String) : String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import com.haulmont.cuba.cli.cubaplugin.model.Entity
import com.haulmont.cuba.cli.cubaplugin.model.EntitySearch
import com.haulmont.cuba.cli.prompting.Answers

class EntityScreenModel(answers: Answers, entitySearch: EntitySearch) {
class EntityScreenModel(answers: Answers) {
val screenId: String by answers
val descriptorName: String by answers
val packageName: String by answers
val entity: Entity = entitySearch.findEntity(answers["entityName"] as String)!!
val entity: Entity by answers
val controllerName: String by answers

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.haulmont.cuba.cli.cubaplugin.screen.entityscreen

import com.beust.jcommander.Parameters
import com.haulmont.cuba.cli.cubaplugin.model.Entity
import com.haulmont.cuba.cli.cubaplugin.model.ModuleStructure
import com.haulmont.cuba.cli.generation.Properties
import com.haulmont.cuba.cli.generation.TemplateProcessor
Expand All @@ -26,13 +27,13 @@ import com.haulmont.cuba.cli.prompting.Answers
class MasterDetailScreenCommand : EntityScreenCommandBase<EntityScreenModel>() {
override fun getModelName(): String = EntityScreenModel.MODEL_NAME

override fun createModel(answers: Answers): EntityScreenModel = EntityScreenModel(answers, entitySearch)
override fun createModel(answers: Answers): EntityScreenModel = EntityScreenModel(answers)

override fun getDefaultScreenId(entityName: String) = projectModel.namespace + "$" + entityName.split('.').last() + ".browse"
override fun getDefaultScreenId(entityName: String) = "$entityName.browse"

override fun getDefaultControllerName(entityName: String) = entityName.split('.').last() + "Browse"
override fun getDefaultControllerName(entity: Entity) = entity.className + "Browse"

override fun getDefaultDescriptorName(entityName: String) = entityName.split('.').last().toLowerCase() + "-browse"
override fun getDefaultDescriptorName(entity: Entity) = entity.className.toLowerCase() + "-browse"

override fun generate(bindings: Map<String, Any>) {
TemplateProcessor(resources.getTemplate("masterDetailScreen"), bindings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.haulmont.cuba.cli.cubaplugin.project

import com.haulmont.cuba.cli.CliPlugin
import com.haulmont.cuba.cli.command.CommandTestBase
import com.haulmont.cuba.cli.commands.CommandExecutionException
import com.haulmont.cuba.cli.cubaplugin.CubaPlugin
import com.haulmont.cuba.cli.cubaplugin.di.cubaKodein
import com.haulmont.cuba.cli.cubaplugin.model.PlatformVersion
Expand Down Expand Up @@ -64,4 +65,11 @@ class ProjectInitCommandTest : CommandTestBase() {
assertTrue(projectModel.namespace == "tp")
assertTrue(projectModel.platformVersion == PlatformVersion("7.1-SNAPSHOT"))
}

@Test
fun testFailOnCreatingInsideAnotherProject() {
createProject()
executeCommand(ProjectInitCommand(kodein))
assertErrorEvent<CommandExecutionException>()
}
}

0 comments on commit 5b39747

Please sign in to comment.