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.core.api.CoreApiServiceLocator;
20  import org.kuali.rice.core.api.util.RiceKeyConstants;
21  import org.kuali.rice.kew.api.KewApiServiceLocator;
22  import org.kuali.rice.kew.api.doctype.DocumentType;
23  import org.kuali.rice.krad.bo.Note;
24  import org.kuali.rice.krad.datadictionary.DocumentEntry;
25  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
26  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
27  import org.kuali.rice.krad.document.Document;
28  import org.kuali.rice.krad.document.DocumentRequestAuthorizationCache;
29  import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
30  import org.kuali.rice.krad.document.DocumentViewPresentationControllerBase;
31  import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
32  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
33  import org.kuali.rice.krad.uif.UifConstants;
34  import org.kuali.rice.krad.uif.util.LifecycleElement;
35  import org.kuali.rice.krad.util.KRADConstants;
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  @BeanTag(name = "documentView", parent = "Uif-DocumentView")
48  public class DocumentView extends FormView {
49  	private static final long serialVersionUID = 2251983409572774175L;
50  
51  	private Class<? extends Document> documentClass;
52  
53  	private boolean allowsNoteAttachments = true;
54  	private boolean allowsNoteFYI = false;
55  	private boolean displayTopicFieldInNotes = false;
56      private boolean superUserView = false;
57  
58      private Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
59  
60  	public DocumentView() {
61  		super();
62  
63          setRequestAuthorizationCacheClass(DocumentRequestAuthorizationCache.class);
64  	}
65  
66      
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77      @Override
78      public void performInitialization(Object model) {
79          super.performInitialization(model);
80  
81          
82          DocumentEntry documentEntry = getDocumentEntryForView();
83          pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
84  
85          
86          String documentTypeName = documentEntry.getDocumentTypeName();
87          DocumentType documentType = KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName);
88  
89          if (getHeader() != null && StringUtils.isBlank(getHeaderText())) {
90              setHeaderText(documentType.getLabel());
91          }
92  
93          
94          if (getAuthorizer() == null) {
95              setAuthorizer(new DocumentViewAuthorizerBase());
96          }
97  
98          if (getAuthorizer() instanceof DocumentViewAuthorizerBase) {
99              DocumentViewAuthorizerBase documentViewAuthorizerBase = (DocumentViewAuthorizerBase) getAuthorizer();
100             if (documentViewAuthorizerBase.getDocumentAuthorizer() == null) {
101                 documentViewAuthorizerBase.setDocumentAuthorizerClass(documentEntry.getDocumentAuthorizerClass());
102             }
103         }
104 
105         if (getPresentationController() == null) {
106             setPresentationController(new DocumentViewPresentationControllerBase());
107         }
108 
109         if (getPresentationController() instanceof DocumentViewPresentationControllerBase) {
110             DocumentViewPresentationControllerBase documentViewPresentationControllerBase =
111                     (DocumentViewPresentationControllerBase) getPresentationController();
112             if (documentViewPresentationControllerBase.getDocumentPresentationController() == null) {
113                 documentViewPresentationControllerBase.setDocumentPresentationControllerClass(
114                         documentEntry.getDocumentPresentationControllerClass());
115             }
116         }
117 
118         getObjectPathToConcreteClassMapping().put(getDefaultBindingObjectPath(), getDocumentClass());
119     }
120 
121     
122 
123 
124 
125 
126     protected DocumentEntry getDocumentEntryForView() {
127         DocumentEntry documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getDocumentEntryByClass(
128                 getDocumentClass());
129 
130         if (documentEntry == null) {
131             throw new RuntimeException(
132                     "Unable to find document entry for document class: " + getDocumentClass().getName());
133         }
134 
135         return documentEntry;
136     }
137 
138     
139 
140 
141 
142 
143 
144 
145 
146 
147 
148     @BeanTagAttribute(name = "explanationDataMaxLength")
149     public int getExplanationDataMaxLength() {
150         return KRADServiceLocatorWeb.getDataDictionaryService().getAttributeMaxLength(Note.class,
151                 KRADConstants.NOTE_TEXT_PROPERTY_NAME) -
152                 (CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
153                         RiceKeyConstants.MESSAGE_DISAPPROVAL_NOTE_TEXT_INTRO) + KRADConstants.BLANK_SPACE).length();
154     }
155 
156     
157 
158 
159 
160 
161     @BeanTagAttribute
162 	public Class<? extends Document> getDocumentClass() {
163 		return this.documentClass;
164 	}
165 
166     
167 
168 
169 
170 
171 	public void setDocumentClass(Class<? extends Document> documentClass) {
172 		this.documentClass = documentClass;
173 	}
174 
175     
176 
177 
178 
179 
180     @BeanTagAttribute
181 	public boolean isAllowsNoteAttachments() {
182 		return this.allowsNoteAttachments;
183 	}
184 
185     
186 
187 
188 
189 
190 	public void setAllowsNoteAttachments(boolean allowsNoteAttachments) {
191 		this.allowsNoteAttachments = allowsNoteAttachments;
192 	}
193 
194     
195 
196 
197 
198 
199     @BeanTagAttribute
200 	public boolean isAllowsNoteFYI() {
201 		return this.allowsNoteFYI;
202 	}
203 
204     
205 
206 
207 
208 
209 	public void setAllowsNoteFYI(boolean allowsNoteFYI) {
210 		this.allowsNoteFYI = allowsNoteFYI;
211 	}
212 
213     
214 
215 
216 
217 
218     @BeanTagAttribute
219 	public boolean isDisplayTopicFieldInNotes() {
220 		return this.displayTopicFieldInNotes;
221 	}
222 
223     
224 
225 
226 
227 
228 	public void setDisplayTopicFieldInNotes(boolean displayTopicFieldInNotes) {
229 		this.displayTopicFieldInNotes = displayTopicFieldInNotes;
230 	}
231 
232     
233 
234 
235 
236 
237     @BeanTagAttribute
238 	public Class<? extends KeyValuesFinder> getAttachmentTypesValuesFinderClass() {
239 		return this.attachmentTypesValuesFinderClass;
240 	}
241 
242     
243 
244 
245 
246 
247 	public void setAttachmentTypesValuesFinderClass(Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass) {
248 		this.attachmentTypesValuesFinderClass = attachmentTypesValuesFinderClass;
249 	}
250 
251     
252 
253 
254 
255 
256 
257     public boolean isSuperUserView() {
258         return superUserView;
259     }
260 
261     
262 
263 
264     public void setSuperUserView(boolean superUserView) {
265         checkMutable(true);
266         this.superUserView = superUserView;
267     }
268 
269 }