Skip to content

Commit

Permalink
entity validation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
seed-master committed Oct 9, 2023
1 parent e59fcc4 commit 48c3f60
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/seed/core/entity/EntityValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/seed/core/util/NameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/seed/test/unit/util/NameUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 48c3f60

Please sign in to comment.