diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java b/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java index 365b965..58cc339 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java @@ -48,7 +48,7 @@ public ErrorInfo handleValidationException(HttpServletRequest request, Validatio String errorMessage = e.getErrors() .stream() - .map(DefaultMessageSourceResolvable::getDefaultMessage) + .map(err -> "%s %s".formatted(err.getObjectName(), err.getDefaultMessage())) .collect(Collectors.joining(",", "[", "]")); return new ErrorInfo(errorMessage, request.getRequestURI()); diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java index 4da95a7..ff8488e 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java @@ -302,4 +302,9 @@ public void removeAll(URI subjectURI, URI propertyURI, URI context){ .setParameter("context", context) .executeUpdate(); } + + @Override + public Class getType() { + return type; + } } \ No newline at end of file diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/GenericDao.java b/src/main/java/cz/cvut/kbss/analysis/dao/GenericDao.java index 05b62e4..402c6fc 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dao/GenericDao.java +++ b/src/main/java/cz/cvut/kbss/analysis/dao/GenericDao.java @@ -127,4 +127,9 @@ public interface GenericDao { * @param context */ void deleteContext(URI context); + + /** + * @return the type of the entity managed by this class. + */ + Class getType(); } diff --git a/src/main/java/cz/cvut/kbss/analysis/model/NamedEntity.java b/src/main/java/cz/cvut/kbss/analysis/model/NamedEntity.java index d0e25ac..0ae0c23 100644 --- a/src/main/java/cz/cvut/kbss/analysis/model/NamedEntity.java +++ b/src/main/java/cz/cvut/kbss/analysis/model/NamedEntity.java @@ -16,7 +16,7 @@ @Setter public class NamedEntity extends AbstractEntity{ - @NotEmpty(message = "Name must not be empty") + @NotEmpty(message = "name is empty.") @ParticipationConstraints(nonEmpty = true) @OWLDataProperty(iri = Vocabulary.s_p_name) private String name; diff --git a/src/main/java/cz/cvut/kbss/analysis/service/BaseRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/BaseRepositoryService.java index 31d6b52..3e83fcd 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/BaseRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/BaseRepositoryService.java @@ -262,7 +262,8 @@ public boolean existsInPersistenceContext(URI id) { * @throws ValidationException In case the instance is not valid */ public void validate(T instance, Object ... groups) { - DataBinder binder = new DataBinder(instance); + DataBinder binder = new DataBinder(instance, getPrimaryDao().getType().getSimpleName()); + binder.setValidator(validator); BindingResult bindingResult = binder.getBindingResult(); diff --git a/src/main/java/cz/cvut/kbss/analysis/service/validation/NamedEntityValidator.java b/src/main/java/cz/cvut/kbss/analysis/service/validation/NamedEntityValidator.java index 763dd82..58c7855 100644 --- a/src/main/java/cz/cvut/kbss/analysis/service/validation/NamedEntityValidator.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/validation/NamedEntityValidator.java @@ -48,13 +48,13 @@ protected void customValidation(Object target, Errors errors, Object... validati NamedEntity entity = (NamedEntity) target; if(existsWithName(entity)) - errors.rejectValue("name", "name.duplicate", "Duplicate entity name"); + errors.rejectValue("name", "name.duplicate", "uri is not null nor unique."); if(groups.isCreateGroup() && exists(entity)){ - errors.rejectValue("uri", "uri.exists", "The uri should be null or unique"); + errors.rejectValue("uri", "uri.exists", "name already exists."); } if(groups.isUpdateGroup() && !exists(entity)){ - errors.rejectValue("uri", "uri.not-exists", "Uri does not refer to an existing entity"); + errors.rejectValue("uri", "uri.not-exists", "uri does not refer to an existing entity."); } }