All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.hermes.api.constraints.OneSourceRetransmissionValidator Maven / Gradle / Ivy

There is a newer version: 2.6.22
Show newest version
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();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy