| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.api.validation; |
| 17 | |
|
| 18 | |
import org.apache.commons.collections.CollectionUtils; |
| 19 | |
import org.kuali.rice.core.api.CoreConstants; |
| 20 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
| 21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 22 | |
import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; |
| 23 | |
import org.kuali.rice.kew.api.rule.RuleContract; |
| 24 | |
import org.kuali.rice.kew.api.rule.RuleDelegationContract; |
| 25 | |
import org.kuali.rice.kew.api.rule.RuleResponsibility; |
| 26 | |
import org.kuali.rice.kew.api.rule.RuleResponsibilityContract; |
| 27 | |
import org.w3c.dom.Element; |
| 28 | |
|
| 29 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 30 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 31 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 32 | |
import javax.xml.bind.annotation.XmlElement; |
| 33 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 34 | |
import javax.xml.bind.annotation.XmlType; |
| 35 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
| 36 | |
import java.io.Serializable; |
| 37 | |
import java.util.ArrayList; |
| 38 | |
import java.util.Collection; |
| 39 | |
import java.util.Collections; |
| 40 | |
import java.util.HashMap; |
| 41 | |
import java.util.List; |
| 42 | |
import java.util.Map; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
@XmlRootElement(name = ValidationResults.Constants.ROOT_ELEMENT_NAME) |
| 50 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 51 | |
@XmlType(name = ValidationResults.Constants.TYPE_NAME, propOrder = { |
| 52 | |
ValidationResults.Elements.ERRORS, |
| 53 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 54 | |
}) |
| 55 | 7 | public class ValidationResults |
| 56 | |
extends AbstractDataTransferObject |
| 57 | |
implements ValidationResultsContract { |
| 58 | |
|
| 59 | |
public static final String GLOBAL = "org.kuali.rice.kew.api.validation.ValidationResults.GLOBAL"; |
| 60 | |
|
| 61 | |
@XmlElement(name = Elements.ERRORS, required = false) |
| 62 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
| 63 | |
private final Map<String, String> errors; |
| 64 | |
|
| 65 | 13 | @SuppressWarnings("unused") |
| 66 | |
@XmlAnyElement |
| 67 | |
private final Collection<Element> _futureElements = null; |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | 6 | private ValidationResults() { |
| 73 | 6 | this.errors = Collections.emptyMap(); |
| 74 | 6 | } |
| 75 | |
|
| 76 | 7 | private ValidationResults(Builder builder) { |
| 77 | 7 | this.errors = Collections.unmodifiableMap(builder.getErrors()); |
| 78 | 7 | } |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public Map<String, String> getErrors() { |
| 82 | 8 | return errors; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | 7 | public final static class Builder |
| 90 | |
implements Serializable, ModelBuilder, ValidationResultsContract |
| 91 | |
{ |
| 92 | |
|
| 93 | 8 | private Map<String, String> errors = new HashMap<String, String>(); |
| 94 | |
|
| 95 | 8 | private Builder() { |
| 96 | 8 | } |
| 97 | |
|
| 98 | |
public static Builder create() { |
| 99 | 8 | return new Builder(); |
| 100 | |
} |
| 101 | |
|
| 102 | |
public static Builder create(ValidationResultsContract contract) { |
| 103 | 2 | if (contract == null) { |
| 104 | 1 | throw new IllegalArgumentException("contract was null"); |
| 105 | |
} |
| 106 | 1 | Builder builder = create(); |
| 107 | 1 | if (contract.getErrors() != null) { |
| 108 | 1 | builder.setErrors(contract.getErrors()); |
| 109 | |
} |
| 110 | 1 | return builder; |
| 111 | |
} |
| 112 | |
|
| 113 | |
public ValidationResults build() { |
| 114 | 7 | return new ValidationResults(this); |
| 115 | |
} |
| 116 | |
|
| 117 | |
@Override |
| 118 | |
public Map<String, String> getErrors() { |
| 119 | 11 | return Collections.unmodifiableMap(this.errors); |
| 120 | |
} |
| 121 | |
|
| 122 | |
public void setErrors(Map<String, String> errors) { |
| 123 | 1 | this.errors = new HashMap<String, String>(errors); |
| 124 | 1 | } |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
public void addError(String errorMessage) { |
| 131 | 0 | addError(GLOBAL, errorMessage); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public void addError(String fieldName, String errorMessage) { |
| 139 | 11 | errors.put(fieldName, errorMessage); |
| 140 | 11 | } |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | 0 | static class Constants { |
| 147 | |
final static String ROOT_ELEMENT_NAME = "validationResults"; |
| 148 | |
final static String TYPE_NAME = "ValidationResultsType"; |
| 149 | |
} |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | 0 | static class Elements { |
| 154 | |
final static String ERRORS = "errors"; |
| 155 | |
} |
| 156 | |
} |