Skip to content

Revert "RDM-3325: White space validation rules applied on text fields" #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class FieldType implements Serializable {
public static final String LABEL = "Label";
public static final String CASE_PAYMENT_HISTORY_VIEWER = "CasePaymentHistoryViewer";
public static final String CASE_HISTORY_VIEWER = "CaseHistoryViewer";
public static final String TEXT = "Text";

private String id = null;
private String type = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ List<ValidationResult> validate(final String dataFieldId,
default Boolean isNullOrEmpty(final JsonNode dataValue) {
return dataValue == null
|| dataValue.isNull()
|| (dataValue.isTextual() && (null == dataValue.asText() || dataValue.asText().length() == 0))
|| (dataValue.isTextual() && (null == dataValue.asText() || dataValue.asText().trim().length() == 0))
|| (dataValue.isObject() && dataValue.toString().equals("{}"));
}

default Boolean isNull(final JsonNode dataValue) {
return dataValue == null
|| dataValue.isNull()
|| (dataValue.isTextual() && (null == dataValue.asText()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public List<ValidationResult> validate(final String dataFieldId,
final CaseField caseFieldDefinition) {

// Empty text should still check against MIN - MIN may or may not be 0
if (isNull(dataValue)) {
if (isNullOrEmpty(dataValue)) {
return Collections.emptyList();
}

Expand All @@ -34,7 +34,7 @@ public List<ValidationResult> validate(final String dataFieldId,
return Collections.singletonList(new ValidationResult(nodeType + " is not a string", dataFieldId));
}

final String value = dataValue.textValue().trim();
final String value = dataValue.textValue();

if (!checkMax(caseFieldDefinition.getFieldType().getMax(), value)) {
return Collections.singletonList(new ValidationResult(value + " exceed maximum length " + caseFieldDefinition.getFieldType().getMax(), dataFieldId));
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/java/uk/gov/hmcts/ccd/domain/types/TextValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ void nullTextValue() {
assertThat(validationResult, hasSize(0));
}

@Test
@DisplayName("should NOT be valid with only white spaces or leading trailing white spaces")
void checkWhitespaces() {
final JsonNode whitespaceValue = NODE_FACTORY.textNode(" ");
final List<ValidationResult> whitespaceValueResult = validator.validate(FIELD_ID, whitespaceValue, caseField);
assertThat(whitespaceValueResult, hasSize(1));

final JsonNode trailingwhitespaces = NODE_FACTORY.textNode(" Testing ");
final List<ValidationResult> trailingwhitespacesResult = validator.validate(FIELD_ID, trailingwhitespaces, caseField);
assertThat(trailingwhitespacesResult, hasSize(0));
}

private CaseFieldBuilder caseField() {
return new CaseFieldBuilder(FIELD_ID).withType(TextValidator.TYPE_ID);
}
Expand Down

This file was deleted.