Skip to content

Commit

Permalink
entity fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seed-master committed Oct 16, 2023
1 parent 9f3a858 commit 0353272
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/seed/core/entity/EntityMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,15 @@ public String getDefaultIdentifierPattern() {
public EntityField findDefaultIdentifierField() {
// search in all unique fields first
final EntityField identifierField = firstMatch(getAllFields(),
field -> field.isUnique() && (field.getType().isText() || field.getType().isAutonum()));
field -> field.isUnique() && field.getType() != null &&
(field.getType().isText() || field.getType().isAutonum()));
if (identifierField != null) {
return identifierField;
}
// fallback: search current fields
return firstMatch(getAllFields(), field -> field.getType().isText() || field.getType().isAutonum());
return firstMatch(getAllFields(),
field -> field.getType() != null &&
(field.getType().isText() || field.getType().isAutonum()));
}

// includes generic fieldgroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ public List<EntityField> getConstraintFields(NestedEntity nested) {
final List<EntityField> fields = nested != null
? nested.getFields(true)
: getObject().getAllFields();
return subList(fields, entityField -> !entityField.getType().isAutonum());
return subList(fields, entityField -> entityField.getType() != null &&
!entityField.getType().isAutonum());
}

public boolean isAlreadyMandatory(EntityField field) {
Expand Down Expand Up @@ -1153,6 +1154,7 @@ private void validateMandatoryDefaultValues() throws ValidationException {
final ValidationErrors errors = new ValidationErrors(getObject());
for (EntityField entityField : getObject().getFields()) {
if (entityField.isMandatory() && !isAlreadyMandatory(entityField) &&
entityField.getType() != null &&
!entityField.getType().isAutonum() && !entityField.getType().isBinary() &&
!entityField.getType().isBoolean() && !entityField.getType().isFile() &&
!entityField.hasDefaultValue()) {
Expand Down

0 comments on commit 0353272

Please sign in to comment.