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

io.rocketbase.commons.exception.RegistrationException Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package io.rocketbase.commons.exception;

import io.rocketbase.commons.dto.validation.EmailErrorCodes;
import io.rocketbase.commons.dto.validation.PasswordErrorCodes;
import io.rocketbase.commons.dto.validation.UsernameErrorCodes;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

import java.util.LinkedHashSet;
import java.util.Set;

@Getter
@ToString
@RequiredArgsConstructor
public class RegistrationException extends RuntimeException implements BaseValidationException {

    private final Set> usernameErrors;
    private final Set> passwordErrors;
    private final Set> emailErrors;

    @Override
    public Set getErrors() {
        Set result = new LinkedHashSet<>();
        if (hasUsernameErrors()) {
            result.addAll(usernameErrors);
        }
        if (hasPasswordErrors()) {
            result.addAll(passwordErrors);
        }
        if (hasEmailErrors()) {
            result.addAll(emailErrors);
        }
        return null;
    }

    public boolean hasUsernameErrors() {
        return usernameErrors != null && !usernameErrors.isEmpty();
    }

    public boolean hasPasswordErrors() {
        return passwordErrors != null && !passwordErrors.isEmpty();
    }

    public boolean hasEmailErrors() {
        return emailErrors != null && !emailErrors.isEmpty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy