diff --git a/src/main/java/org/seed/core/entity/EntityValidator.java b/src/main/java/org/seed/core/entity/EntityValidator.java index a2c9b9820..cb7698477 100644 --- a/src/main/java/org/seed/core/entity/EntityValidator.java +++ b/src/main/java/org/seed/core/entity/EntityValidator.java @@ -387,10 +387,11 @@ private void validateName(Entity entity, final ValidationErrors errors) { else if (!isNameLengthAllowed(entity.getName())) { errors.addOverlongName(getMaxNameLength()); } - else if (!NameUtils.containsAlphabet(entity.getName())) { - errors.addIllegalName(entity.getName()); + else if (!NameUtils.containsAlphabet(entity.getInternalName()) || + NameUtils.isIllegalEntityName(entity.getInternalName())) { + errors.addIllegalName(entity.getInternalName()); } - else if (NameUtils.startsWithNumber(entity.getName())) { + else if (NameUtils.startsWithNumber(entity.getInternalName())) { errors.addError("val.illegal.namestartswithnumber"); } } diff --git a/src/main/java/org/seed/core/util/NameUtils.java b/src/main/java/org/seed/core/util/NameUtils.java index 6d8957bba..b6a4d0b0c 100644 --- a/src/main/java/org/seed/core/util/NameUtils.java +++ b/src/main/java/org/seed/core/util/NameUtils.java @@ -56,6 +56,8 @@ public abstract class NameUtils { "1", "j", "ja", "on", "true", "y", "yes" }; + private static final String ILLEGAL_ENTITYNAME = "entity"; + private NameUtils() {} public static boolean isKeyword(String name) { @@ -66,6 +68,11 @@ public static boolean isSqlKeyword(String name) { return name != null && find(SQL_KEYWORDS, name); } + public static boolean isIllegalEntityName(String name) { + return ILLEGAL_ENTITYNAME.equalsIgnoreCase(name) || + (name != null && find(ILLEGAL_FIELDNAMES, name)); + } + public static boolean isIllegalFieldName(String name) { return isKeyword(name) || (name != null && find(ILLEGAL_FIELDNAMES, name)); diff --git a/src/main/java/org/seed/ui/zk/vm/admin/AdminEntityViewModel.java b/src/main/java/org/seed/ui/zk/vm/admin/AdminEntityViewModel.java index 94014570b..05b133d58 100644 --- a/src/main/java/org/seed/ui/zk/vm/admin/AdminEntityViewModel.java +++ b/src/main/java/org/seed/ui/zk/vm/admin/AdminEntityViewModel.java @@ -789,7 +789,7 @@ public void selectOption(@BindingParam("option") String option) { } break; - case C.AUTOLAYOUT: + case "autolayout": if (getOptions().isAutoLayout()) { entityMeta.setGeneric(false); entityMeta.setParentEntity(null); diff --git a/src/test/java/org/seed/test/integration/entity/CreateEntityTest.java b/src/test/java/org/seed/test/integration/entity/CreateEntityTest.java index 1afcb9cb8..cc17513ea 100644 --- a/src/test/java/org/seed/test/integration/entity/CreateEntityTest.java +++ b/src/test/java/org/seed/test/integration/entity/CreateEntityTest.java @@ -42,6 +42,11 @@ void testCreateEntity() { clickButton(tabpanel, "save"); findValidationMessage(); // name is empty + findTextbox(tabpanel, "name").sendKeys("Entity"); + clickButton(tabpanel, "save"); + findValidationMessage(); // name is illegal + + clearTextbox(tabpanel, "name"); findTextbox(tabpanel, "name").sendKeys("IntegrationTest"); saveEntity(tabpanel); } diff --git a/src/test/java/org/seed/test/unit/util/NameUtilsTest.java b/src/test/java/org/seed/test/unit/util/NameUtilsTest.java index e6e2e523c..1108d3315 100644 --- a/src/test/java/org/seed/test/unit/util/NameUtilsTest.java +++ b/src/test/java/org/seed/test/unit/util/NameUtilsTest.java @@ -48,6 +48,19 @@ void testIsSqlKeyword() { assertTrue(NameUtils.isSqlKeyword("FROM")); } + @Test + void testIsIllegalEntityName() { + assertFalse(NameUtils.isIllegalEntityName(null)); + assertFalse(NameUtils.isIllegalEntityName("")); + assertFalse(NameUtils.isIllegalEntityName("test")); + assertFalse(NameUtils.isIllegalEntityName("entität")); + + assertTrue(NameUtils.isIllegalEntityName("entity")); + assertTrue(NameUtils.isIllegalEntityName("Entity")); + assertTrue(NameUtils.isIllegalEntityName("id")); + assertTrue(NameUtils.isIllegalEntityName("UID")); + } + @Test void testIsIllegalFieldName() { assertFalse(NameUtils.isIllegalFieldName(null));