Skip to content

Commit

Permalink
avniproject/avni-webapp#1257 | User friendly error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed Sep 27, 2024
1 parent e3a21e2 commit ac536da
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,24 @@ public void validateForm(FormContract formContract) throws InvalidObjectExceptio
!conceptUuid.equals(PLACEHOLDER_CONCEPT_UUID) &&
!uniqueConcepts.add(conceptUuid)) {
throw new InvalidObjectException(String.format(
"Cannot use same concept twice. Form{uuid='%s',..} uses Concept{uuid='%s',..} twice",
"Cannot use same concept twice. Form{uuid='%s',..} uses Concept{name='%s',..} twice",
formContract.getUuid(),
conceptUuid));
conceptName));
}
String conceptDataType = formElement.getConcept().getDataType();
if (conceptDataType != null && multiSelectTypes.contains(ConceptDataType.valueOf(conceptDataType))) {
FormElement existingFormElement = formElementRepository.findByUuid(formElement.getUuid());
if (existingFormElement != null) {
if (!existingFormElement.getType().equals(formElement.getType())) {
throw new InvalidObjectException("Cannot change from Single to Multi Select or vice versa");
throw new InvalidObjectException(String.format("Cannot change from Single to Multi Select or vice versa for form element: %s", existingFormElement.getName()));
}
}
}
if (formElement.getConcept().isQuestionGroup()) {
FormElement existingFormElement = formElementRepository.findByUuid(formElement.getUuid());
if (existingFormElement != null) {
if (!existingFormElement.getKeyValues().get(KeyType.repeatable).equals(formElement.getKeyValues().get(KeyType.repeatable))) {
throw new InvalidObjectException("Cannot change from Repeatable to Non Repeatable or vice versa");
throw new InvalidObjectException(String.format("Cannot change from Repeatable to Non Repeatable or vice versa for form element: %s", existingFormElement.getName()));
}
}
}
Expand Down

0 comments on commit ac536da

Please sign in to comment.