1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.view;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.DocumentEntry;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.document.Document;
23 import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
24 import org.kuali.rice.krad.document.DocumentViewPresentationControllerBase;
25 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
26 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27 import org.kuali.rice.krad.uif.UifConstants;
28
29
30
31
32
33
34
35
36
37
38
39 @BeanTag(name = "documentView-bean", parent = "Uif-DocumentView")
40 public class DocumentView extends FormView {
41 private static final long serialVersionUID = 2251983409572774175L;
42
43 private Class<? extends Document> documentClass;
44
45 private boolean allowsNoteAttachments = true;
46 private boolean allowsNoteFYI = false;
47 private boolean displayTopicFieldInNotes = false;
48
49 private Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
50
51 public DocumentView() {
52 super();
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66 @Override
67 public void performInitialization(View view, Object model) {
68 super.performInitialization(view, model);
69
70
71 DocumentEntry documentEntry = getDocumentEntryForView();
72 pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
73
74
75 if (getAuthorizer() == null) {
76 setAuthorizer(new DocumentViewAuthorizerBase());
77 }
78
79 if (getAuthorizer() instanceof DocumentViewAuthorizerBase) {
80 DocumentViewAuthorizerBase documentViewAuthorizerBase = (DocumentViewAuthorizerBase) getAuthorizer();
81 if (documentViewAuthorizerBase.getDocumentAuthorizer() == null) {
82 documentViewAuthorizerBase.setDocumentAuthorizerClass(documentEntry.getDocumentAuthorizerClass());
83 }
84 }
85
86 if (getPresentationController() == null) {
87 setPresentationController(new DocumentViewPresentationControllerBase());
88 }
89
90 if (getPresentationController() instanceof DocumentViewPresentationControllerBase) {
91 DocumentViewPresentationControllerBase documentViewPresentationControllerBase =
92 (DocumentViewPresentationControllerBase) getPresentationController();
93 if (documentViewPresentationControllerBase.getDocumentPresentationController() == null) {
94 documentViewPresentationControllerBase.setDocumentPresentationControllerClass(
95 documentEntry.getDocumentPresentationControllerClass());
96 }
97 }
98
99 getObjectPathToConcreteClassMapping().put(getDefaultBindingObjectPath(), getDocumentClass());
100 }
101
102
103
104
105
106
107 protected DocumentEntry getDocumentEntryForView() {
108 DocumentEntry documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getDocumentEntryByClass(
109 getDocumentClass());
110
111 if (documentEntry == null) {
112 throw new RuntimeException(
113 "Unable to find document entry for document class: " + getDocumentClass().getName());
114 }
115
116 return documentEntry;
117 }
118
119
120
121
122
123
124 @BeanTagAttribute(name="documentClass")
125 public Class<? extends Document> getDocumentClass() {
126 return this.documentClass;
127 }
128
129
130
131
132
133
134 public void setDocumentClass(Class<? extends Document> documentClass) {
135 this.documentClass = documentClass;
136 }
137
138
139
140
141
142
143 @BeanTagAttribute(name="allowsNoteAttachments")
144 public boolean isAllowsNoteAttachments() {
145 return this.allowsNoteAttachments;
146 }
147
148
149
150
151
152
153 public void setAllowsNoteAttachments(boolean allowsNoteAttachments) {
154 this.allowsNoteAttachments = allowsNoteAttachments;
155 }
156
157
158
159
160
161
162 @BeanTagAttribute(name="allowsNoteFYI")
163 public boolean isAllowsNoteFYI() {
164 return this.allowsNoteFYI;
165 }
166
167
168
169
170
171
172 public void setAllowsNoteFYI(boolean allowsNoteFYI) {
173 this.allowsNoteFYI = allowsNoteFYI;
174 }
175
176
177
178
179
180
181 @BeanTagAttribute(name="displayTopicFieldInNotes")
182 public boolean isDisplayTopicFieldInNotes() {
183 return this.displayTopicFieldInNotes;
184 }
185
186
187
188
189
190
191 public void setDisplayTopicFieldInNotes(boolean displayTopicFieldInNotes) {
192 this.displayTopicFieldInNotes = displayTopicFieldInNotes;
193 }
194
195
196
197
198
199
200 @BeanTagAttribute(name="attachmentTypesValuesFinderClass",type = BeanTagAttribute.AttributeType.SINGLEBEAN)
201 public Class<? extends KeyValuesFinder> getAttachmentTypesValuesFinderClass() {
202 return this.attachmentTypesValuesFinderClass;
203 }
204
205
206
207
208
209
210 public void setAttachmentTypesValuesFinderClass(Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass) {
211 this.attachmentTypesValuesFinderClass = attachmentTypesValuesFinderClass;
212 }
213
214
215
216
217 @Override
218 protected <T> void copyProperties(T component) {
219 super.copyProperties(component);
220 DocumentView documentViewCopy = (DocumentView) component;
221
222 if(this.documentClass != null) {
223 documentViewCopy.setDocumentClass(this.getDocumentClass());
224 }
225
226 if(this.attachmentTypesValuesFinderClass != null) {
227 documentViewCopy.setAttachmentTypesValuesFinderClass(this.getAttachmentTypesValuesFinderClass());
228 }
229
230 documentViewCopy.setAllowsNoteAttachments(this.isAllowsNoteAttachments());
231 documentViewCopy.setAllowsNoteFYI(this.isAllowsNoteFYI());
232 documentViewCopy.setDisplayTopicFieldInNotes(this.isDisplayTopicFieldInNotes());
233 }
234 }