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

com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException Maven / Gradle / Ivy

There is a newer version: 10.2.0
Show newest version
package com.atlassian.bamboo.specs.api.exceptions;

import com.atlassian.bamboo.specs.api.validators.common.ValidationContext;
import com.atlassian.bamboo.specs.api.validators.common.ValidationProblem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Errors in export properties objects (mostly required properties, and context free validation).
 */
public class PropertiesValidationException extends RuntimeException {
    private final List errors;

    public PropertiesValidationException(@NotNull final String message) {
        this(message, null);
    }

    public PropertiesValidationException(@NotNull final String message, @Nullable Throwable cause) {
        this(Collections.singletonList(new ValidationProblem(message)), cause);
    }

    public PropertiesValidationException(@NotNull ValidationContext validationContext, @NotNull final String message) {
        this(new ValidationProblem(validationContext, message));
    }

    public PropertiesValidationException(@NotNull final List errors) {
        this(errors, null);
    }

    public PropertiesValidationException(@NotNull final ValidationProblem error) {
        this(Collections.singletonList(error), null);
    }

    public PropertiesValidationException(@NotNull final List errors, @Nullable Throwable cause) {
        super(errorsToMessage(errors), cause);
        this.errors = errors;
    }

    public List getErrors() {
        return errors;
    }

    private static String errorsToMessage(@NotNull final List errors) {
        return errors.stream()
                .map(ValidationProblem::getMessage)
                .collect(Collectors.joining("\n------------------------------\n"));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy