pl.allegro.tech.hermes.api.constraints.OneSourceRetransmissionValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-api Show documentation
Show all versions of hermes-api Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.api.constraints;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import pl.allegro.tech.hermes.api.OfflineRetransmissionRequest;
public class OneSourceRetransmissionValidator implements ConstraintValidator {
public static final String EMPTY_STRING = "";
@Override
public boolean isValid(OfflineRetransmissionRequest offlineRetransmissionRequest, ConstraintValidatorContext context) {
var sourceViewPath = offlineRetransmissionRequest.getSourceViewPath();
var sourceTopic = offlineRetransmissionRequest.getSourceTopic();
return (nonBlank(sourceViewPath.orElse(EMPTY_STRING)) && sourceTopic.isEmpty())
|| (nonBlank(sourceTopic.orElse(EMPTY_STRING)) && sourceViewPath.isEmpty());
}
private static boolean nonBlank(String value) {
return value != null && !value.isBlank();
}
}