View Javadoc
1   /**
2    * Copyright 2005-2016 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.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   * View type for KRAD documents
31   *
32   * <p>
33   * Provides commons configuration and default behavior applicable to documents
34   * in the KRAD module.
35   * </p>
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
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       * The following initialization is performed:
57       *
58       * <ul>
59       * <li>Retrieve the document entry</li>
60       * <li>Set up the document view authorizer and presentation controller</li>
61       * </ul>
62       *
63       * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View,
64       *      java.lang.Object)
65       */
66      @Override
67      public void performInitialization(View view, Object model) {
68          super.performInitialization(view, model);
69  
70          // get document entry
71          DocumentEntry documentEntry = getDocumentEntryForView();
72          pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
73  
74          // setup authorizer and presentation controller using the configured authorizer and pc for document
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      * Retrieves the associated {@link DocumentEntry} for the document view
104      *
105      * @return DocumentEntry entry (exception thrown if one is not found)
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      * Gets the document class
121      *
122      * @return Class<? extends Document> the document class.
123      */
124     @BeanTagAttribute(name="documentClass")
125 	public Class<? extends Document> getDocumentClass() {
126 		return this.documentClass;
127 	}
128 
129     /**
130      * Sets the document class
131      *
132      * @param documentClass
133      */
134 	public void setDocumentClass(Class<? extends Document> documentClass) {
135 		this.documentClass = documentClass;
136 	}
137 
138     /**
139      * Gets boolean that indicates if the document view allows note attachments
140      *
141      * @return true if the document view allows note attachments
142      */
143     @BeanTagAttribute(name="allowsNoteAttachments")
144 	public boolean isAllowsNoteAttachments() {
145 		return this.allowsNoteAttachments;
146 	}
147 
148     /**
149      * Sets boolean that indicates if the document view allows note attachments
150      *
151      * @param allowsNoteAttachments
152      */
153 	public void setAllowsNoteAttachments(boolean allowsNoteAttachments) {
154 		this.allowsNoteAttachments = allowsNoteAttachments;
155 	}
156 
157     /**
158      * Gets boolean that indicates if the document view allows note FYI
159      *
160      * @return true if the document view allows note FYI
161      */
162     @BeanTagAttribute(name="allowsNoteFYI")
163 	public boolean isAllowsNoteFYI() {
164 		return this.allowsNoteFYI;
165 	}
166 
167     /**
168      * Sets boolean that indicates if the document view allows note FYI
169      *
170      * @param allowsNoteFYI
171      */
172 	public void setAllowsNoteFYI(boolean allowsNoteFYI) {
173 		this.allowsNoteFYI = allowsNoteFYI;
174 	}
175 
176     /**
177      * Gets boolean that indicates if the document view displays the topic field in notes
178      *
179      * @return true if the document view displays the topic field in notes
180      */
181     @BeanTagAttribute(name="displayTopicFieldInNotes")
182 	public boolean isDisplayTopicFieldInNotes() {
183 		return this.displayTopicFieldInNotes;
184 	}
185 
186     /**
187      * Sets boolean that indicates if the document view displays the topic field in notes
188      *
189      * @param displayTopicFieldInNotes
190      */
191 	public void setDisplayTopicFieldInNotes(boolean displayTopicFieldInNotes) {
192 		this.displayTopicFieldInNotes = displayTopicFieldInNotes;
193 	}
194 
195     /**
196      * Gets attachment types values finder classs
197      *
198      * @return attachment types values finder class
199      */
200     @BeanTagAttribute(name="attachmentTypesValuesFinderClass",type = BeanTagAttribute.AttributeType.SINGLEBEAN)
201 	public Class<? extends KeyValuesFinder> getAttachmentTypesValuesFinderClass() {
202 		return this.attachmentTypesValuesFinderClass;
203 	}
204 
205     /**
206      * Sets attachment types values finder classs
207      *
208      * @param attachmentTypesValuesFinderClass
209      */
210 	public void setAttachmentTypesValuesFinderClass(Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass) {
211 		this.attachmentTypesValuesFinderClass = attachmentTypesValuesFinderClass;
212 	}
213 
214     /**
215      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
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 }