Created
September 21, 2018 15:05
-
-
Save thetekst/8b7c93cb985307e310656fb7451a2bc5 to your computer and use it in GitHub Desktop.
Validate emails and each email length apart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Data | |
@ToString(exclude = {"password"}) | |
public class MyRequest { | |
@NotEmpty | |
@Size(min = 1, max = 64) | |
private String password; | |
private Set<String> emails; | |
private String phone; | |
@AssertTrue(message="passVerify field should be equal than pass field") | |
private boolean isValid() { | |
return !CollectionUtils.isEmpty(emails) && emails.stream() | |
.filter(f -> f.length() > 10) | |
.findFirst() | |
.orElse("") | |
.equals(""); | |
} | |
} | |
@Slf4j | |
@RequiredArgsConstructor | |
@Service | |
public class MyService { | |
public void process(final MyRequest request) { | |
log.info("request: {}", request); | |
if(CollectionUtils.isEmpty(request.getEmails()) || StringUtils.isNotBlank(request.getEmails().stream() | |
.filter(f -> f.length() > EMAIL_MAX_LENGTH) | |
.findFirst() | |
.orElse(""))) { | |
throw new ServiceException(Errors.INTERNAL_ERROR); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment