| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| KualiDocumentEventBase |
|
| 1.6;1.6 |
| 1 | /* | |
| 2 | * Copyright 2005-2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.kns.rule.event; | |
| 17 | ||
| 18 | import java.util.ArrayList; | |
| 19 | import java.util.List; | |
| 20 | ||
| 21 | import org.apache.commons.lang.StringUtils; | |
| 22 | import org.apache.log4j.Logger; | |
| 23 | import org.kuali.rice.kns.document.Document; | |
| 24 | import org.kuali.rice.kns.util.KNSPropertyConstants; | |
| 25 | ||
| 26 | /** | |
| 27 | * Abstract superclass for document-related events. | |
| 28 | */ | |
| 29 | abstract public class KualiDocumentEventBase implements KualiDocumentEvent { | |
| 30 | 0 | private static final Logger LOG = Logger.getLogger(KualiDocumentEventBase.class); |
| 31 | ||
| 32 | private final String description; | |
| 33 | private final String errorPathPrefix; | |
| 34 | protected Document document; | |
| 35 | ||
| 36 | /** | |
| 37 | * | |
| 38 | * As a general rule, business rule classes should not change the original object. This constructor was created so that | |
| 39 | * PreRulesCheckEvent, a UI level rule checker, can make changes. | |
| 40 | * | |
| 41 | * @param description | |
| 42 | * @param errorPathPrefix | |
| 43 | */ | |
| 44 | 0 | protected KualiDocumentEventBase(String description, String errorPathPrefix) { |
| 45 | ||
| 46 | 0 | if (!(this instanceof PromptBeforeValidationEvent)) { |
| 47 | 0 | throw new Error("THIS CONSTRUCTOR SHOULD ONLY BE USED AT THE UI LAYER"); |
| 48 | } | |
| 49 | ||
| 50 | 0 | this.description = description; |
| 51 | 0 | this.errorPathPrefix = errorPathPrefix; |
| 52 | 0 | } |
| 53 | ||
| 54 | /** | |
| 55 | * Constructs a KualiEvent with the given description and errorPathPrefix for the given document. | |
| 56 | * | |
| 57 | * @param errorPathPrefix | |
| 58 | * @param document | |
| 59 | * @param description | |
| 60 | */ | |
| 61 | 0 | public KualiDocumentEventBase(String description, String errorPathPrefix, Document document) { |
| 62 | 0 | this.description = description; |
| 63 | 0 | this.errorPathPrefix = errorPathPrefix; |
| 64 | 0 | this.document = document; |
| 65 | ||
| 66 | 0 | LOG.debug(description); |
| 67 | 0 | } |
| 68 | ||
| 69 | ||
| 70 | /** | |
| 71 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#getDocument() | |
| 72 | */ | |
| 73 | public final Document getDocument() { | |
| 74 | 0 | return document; |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#getName() | |
| 79 | */ | |
| 80 | public final String getName() { | |
| 81 | 0 | return this.getClass().getName(); |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * @return a description of this event | |
| 86 | */ | |
| 87 | public final String getDescription() { | |
| 88 | 0 | return description; |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#getErrorPathPrefix() | |
| 93 | */ | |
| 94 | public String getErrorPathPrefix() { | |
| 95 | 0 | return errorPathPrefix; |
| 96 | } | |
| 97 | ||
| 98 | ||
| 99 | /** | |
| 100 | * @see java.lang.Object#toString() | |
| 101 | */ | |
| 102 | @Override | |
| 103 | public String toString() { | |
| 104 | 0 | return getName(); |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#validate() | |
| 109 | */ | |
| 110 | public void validate() { | |
| 111 | 0 | if (getDocument() == null) { |
| 112 | 0 | throw new IllegalArgumentException("invalid (null) event document"); |
| 113 | } | |
| 114 | 0 | } |
| 115 | ||
| 116 | /** | |
| 117 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#generateEvents() | |
| 118 | */ | |
| 119 | public List<KualiDocumentEvent> generateEvents() { | |
| 120 | 0 | return new ArrayList<KualiDocumentEvent>(); |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Provides null-safe access to the documentNumber of the given document. | |
| 125 | * | |
| 126 | * @param document | |
| 127 | * @return String containing the documentNumber of the given document, or some indication of why the documentNumber isn't | |
| 128 | * accessible | |
| 129 | */ | |
| 130 | protected static String getDocumentId(Document document) { | |
| 131 | 0 | String docId = "(null document)"; |
| 132 | ||
| 133 | 0 | if (document != null) { |
| 134 | 0 | String documentNumber = document.getDocumentNumber(); |
| 135 | 0 | if (StringUtils.isBlank(documentNumber)) { |
| 136 | 0 | docId = "(blank " + KNSPropertyConstants.DOCUMENT_NUMBER + ")"; |
| 137 | } | |
| 138 | else { | |
| 139 | 0 | docId = documentNumber; |
| 140 | } | |
| 141 | } | |
| 142 | ||
| 143 | 0 | return docId; |
| 144 | } | |
| 145 | } |