use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class ContentDataSerializer method addValidationErrors.
private void addValidationErrors(final ValidationErrors validationErrors, final PropertySet contentAsData) {
if (validationErrors != null && validationErrors.hasErrors()) {
contentAsData.addSets(VALIDATION_ERRORS, validationErrors.stream().map(validationError -> {
final PropertySet propertySet = new PropertySet();
propertySet.addString("errorCode", validationError.getErrorCode().toString());
propertySet.addString("message", validationError.getMessage());
propertySet.addString("i18n", validationError.getI18n());
if (!validationError.getArgs().isEmpty()) {
try {
propertySet.addString("args", OBJECT_MAPPER.writeValueAsString(validationError.getArgs()));
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
}
if (validationError instanceof DataValidationError) {
propertySet.addString("propertyPath", ((DataValidationError) validationError).getPropertyPath().toString());
} else if (validationError instanceof AttachmentValidationError) {
propertySet.addString("attachment", ((AttachmentValidationError) validationError).getAttachment().toString());
}
return propertySet;
}).toArray(PropertySet[]::new));
}
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur1_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur1_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(1).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", null);
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_maxOccur1_with_two_nonnull_data_when_validate_then_MaximumOccurrencesValidationError.
@Test
public void given_input_with_maxOccur1_with_two_nonnull_data_when_validate_then_MaximumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).maximumOccurrences(1).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", "1");
content.getData().setString("myInput[1]", "2");
// exercise
final ValidationErrors validationResults = validate(content);
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur1_with_two_null_values_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur1_with_two_null_values_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(1).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", null);
content.getData().setString("myInput[1]", null);
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
use of com.enonic.xp.content.DataValidationError in project xp by enonic.
the class OccurrenceValidatorTest method given_input_with_minOccur1_and_maxOccur2_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError.
@Test
public void given_input_with_minOccur1_and_maxOccur2_with_one_null_value_when_validate_then_hasErrors_returns_MinimumOccurrencesValidationError() {
contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).minimumOccurrences(1).build());
Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
content.getData().setString("myInput[0]", null);
// exercise
final ValidationErrors validationResults = validate(content);
assertTrue(validationResults.hasErrors());
assertThat(validationResults.stream()).allMatch(ve -> ve instanceof DataValidationError);
}
Aggregations