Skip to content

Commit

Permalink
fix: attributeValue validator should ingore empty string (#15262)
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyen authored Oct 3, 2023
1 parent e55836d commit 7c7a4c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.function.Consumer;
import java.util.function.Function;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.ValueType;
Expand Down Expand Up @@ -91,6 +92,9 @@ public class DefaultAttributeValidator implements AttributeValidator {
*/
@Override
public void validate(ValueType valueType, String value, Consumer<ErrorReport> addError) {
if (StringUtils.isEmpty(value)) {
return;
}
mapValidators.getOrDefault(valueType, str -> List.of()).apply(value).forEach(addError::accept);

mapEntityCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,22 @@ void testNotPhoneNumber() {
assertFalse(CollectionUtils.isEmpty(objectReportList));
assertEquals(ErrorCode.E6021, objectReportList.get(0).getErrorReports().get(0).getErrorCode());
}

@Test
void testEmptyValue() {
attribute.setValueType(ValueType.EMAIL);
organisationUnit.getAttributeValues().add(new AttributeValue(attribute, ""));
List<ObjectReport> objectReportList = new ArrayList<>();

metadataAttributeCheck.check(
objectBundle,
OrganisationUnit.class,
Lists.newArrayList(organisationUnit),
Collections.emptyList(),
ImportStrategy.CREATE_AND_UPDATE,
validationContext,
objectReport -> objectReportList.add(objectReport));

assertTrue(CollectionUtils.isEmpty(objectReportList));
}
}

0 comments on commit 7c7a4c8

Please sign in to comment.