/** * Copyright (c) 2009 - 2012 Red Hat, Inc. * * This software is licensed to you under the GNU General Public License, * version 2 (GPLv2). There is NO WARRANTY for this software, express or * implied, including the implied warranties of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 * along with this software; if not, see * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. * * Red Hat trademarks are not licensed under GPLv2. No permission is * granted to use or replicate Red Hat trademarks that are incorporated * in this software or its documentation. */ package org.candlepin.policy; import java.util.LinkedList; import java.util.List; /** * Results of an enforcer validation. Basically used to support multiple * errors being generated by an attempt to consume (perhaps multiple attribute * checks failed), but also the possibility of warnings, which do not actually * prevent the entitlement from being given out. */ public class ValidationResult { private List<ValidationError> errors; private List<ValidationWarning> warnings; /** * default ctor */ public ValidationResult() { errors = new LinkedList<ValidationError>(); warnings = new LinkedList<ValidationWarning>(); } /** * Return the list of errors if any. * @return the list of errors if any. */ public List<ValidationError> getErrors() { return errors; } /** * Add an error * @param error error to add */ public void addError(ValidationError error) { errors.add(error); } /** * Add an error * @param resourceKey string to use for the error */ public void addError(String resourceKey) { errors.add(new ValidationError(resourceKey)); } /** * Return the list of warnings if any. * @return the list of warnings if any. */ public List<ValidationWarning> getWarnings() { return warnings; } /** * Add a warning * @param warning warning to add */ public void addWarning(ValidationWarning warning) { warnings.add(warning); } /** * Add a warning * @param resourceKey resource key */ public void addWarning(String resourceKey) { warnings.add(new ValidationWarning(resourceKey)); } public void add(ValidationResult result) { errors.addAll(result.getErrors()); warnings.addAll(result.getWarnings()); } /** * Returns true if there were any errors during validation. * @return true if there were any errors during validation. */ public boolean hasErrors() { return !errors.isEmpty(); } /** * Returns true if there were any warnings during validation. * @return true if there were any warnings during validation. */ public boolean hasWarnings() { return !warnings.isEmpty(); } /** * Returns true if validation is successful, false otherwise. * @return true if validation is successful, false otherwise. */ public boolean isSuccessful() { return !hasErrors(); } }