1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.rule.event;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.krad.document.Document;
21 import org.kuali.rice.krad.util.KRADPropertyConstants;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26
27
28
29 abstract public class KualiDocumentEventBase implements KualiDocumentEvent {
30 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
39
40
41
42
43
44 protected KualiDocumentEventBase(String description, String errorPathPrefix) {
45 this.description = description;
46 this.errorPathPrefix = errorPathPrefix;
47 }
48
49
50
51
52
53
54
55
56 public KualiDocumentEventBase(String description, String errorPathPrefix, Document document) {
57 this.description = description;
58 this.errorPathPrefix = errorPathPrefix;
59 this.document = document;
60
61 LOG.debug(description);
62 }
63
64
65
66
67
68 public final Document getDocument() {
69 return document;
70 }
71
72
73
74
75 public final String getName() {
76 return this.getClass().getName();
77 }
78
79
80
81
82 public final String getDescription() {
83 return description;
84 }
85
86
87
88
89 public String getErrorPathPrefix() {
90 return errorPathPrefix;
91 }
92
93
94
95
96
97 @Override
98 public String toString() {
99 return getName();
100 }
101
102
103
104
105 public void validate() {
106 if (getDocument() == null) {
107 throw new IllegalArgumentException("invalid (null) event document");
108 }
109 }
110
111
112
113
114 public List<KualiDocumentEvent> generateEvents() {
115 return new ArrayList<KualiDocumentEvent>();
116 }
117
118
119
120
121
122
123
124
125 protected static String getDocumentId(Document document) {
126 String docId = "(null document)";
127
128 if (document != null) {
129 String documentNumber = document.getDocumentNumber();
130 if (StringUtils.isBlank(documentNumber)) {
131 docId = "(blank " + KRADPropertyConstants.DOCUMENT_NUMBER + ")";
132 }
133 else {
134 docId = documentNumber;
135 }
136 }
137
138 return docId;
139 }
140 }