View Javadoc
1   /**
2    * Copyright 2005-2014 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.kuali.rice.krad.datadictionary.DocumentEntry;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.document.Document;
22  import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
23  import org.kuali.rice.krad.document.DocumentViewPresentationControllerBase;
24  import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
25  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26  import org.kuali.rice.krad.uif.UifConstants;
27  
28  /**
29   * View type for KRAD documents
30   *
31   * <p>
32   * Provides commons configuration and default behavior applicable to documents
33   * in the KRAD module.
34   * </p>
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @BeanTag(name = "documentView-bean", parent = "Uif-DocumentView")
39  public class DocumentView extends FormView {
40  	private static final long serialVersionUID = 2251983409572774175L;
41  
42  	private Class<? extends Document> documentClass;
43  
44  	private boolean allowsNoteAttachments = true;
45  	private boolean allowsNoteFYI = false;
46  	private boolean displayTopicFieldInNotes = false;
47  
48  	private Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
49  
50  	public DocumentView() {
51  		super();
52  	}
53  
54      /**
55       * The following initialization is performed:
56       *
57       * <ul>
58       * <li>Retrieve the document entry</li>
59       * <li>Set up the document view authorizer and presentation controller</li>
60       * </ul>
61       *
62       * {@inheritDoc}
63       */
64      @Override
65      public void performInitialization(Object model) {
66          super.performInitialization(model);
67  
68          // get document entry
69          DocumentEntry documentEntry = getDocumentEntryForView();
70          pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
71  
72          // setup authorizer and presentation controller using the configured authorizer and pc for document
73          if (getAuthorizer() == null) {
74              setAuthorizer(new DocumentViewAuthorizerBase());
75          }
76  
77          if (getAuthorizer() instanceof DocumentViewAuthorizerBase) {
78              DocumentViewAuthorizerBase documentViewAuthorizerBase = (DocumentViewAuthorizerBase) getAuthorizer();
79              if (documentViewAuthorizerBase.getDocumentAuthorizer() == null) {
80                  documentViewAuthorizerBase.setDocumentAuthorizerClass(documentEntry.getDocumentAuthorizerClass());
81              }
82          }
83  
84          if (getPresentationController() == null) {
85              setPresentationController(new DocumentViewPresentationControllerBase());
86          }
87  
88          if (getPresentationController() instanceof DocumentViewPresentationControllerBase) {
89              DocumentViewPresentationControllerBase documentViewPresentationControllerBase =
90                      (DocumentViewPresentationControllerBase) getPresentationController();
91              if (documentViewPresentationControllerBase.getDocumentPresentationController() == null) {
92                  documentViewPresentationControllerBase.setDocumentPresentationControllerClass(
93                          documentEntry.getDocumentPresentationControllerClass());
94              }
95          }
96  
97          getObjectPathToConcreteClassMapping().put(getDefaultBindingObjectPath(), getDocumentClass());
98      }
99  
100     /**
101      * Retrieves the associated {@link DocumentEntry} for the document view
102      *
103      * @return DocumentEntry entry (exception thrown if one is not found)
104      */
105     protected DocumentEntry getDocumentEntryForView() {
106         DocumentEntry documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getDocumentEntryByClass(
107                 getDocumentClass());
108 
109         if (documentEntry == null) {
110             throw new RuntimeException(
111                     "Unable to find document entry for document class: " + getDocumentClass().getName());
112         }
113 
114         return documentEntry;
115     }
116 
117     /**
118      * Gets the document class
119      *
120      * @return Class<? extends Document> the document class.
121      */
122     @BeanTagAttribute(name="documentClass")
123 	public Class<? extends Document> getDocumentClass() {
124 		return this.documentClass;
125 	}
126 
127     /**
128      * Sets the document class
129      *
130      * @param documentClass
131      */
132 	public void setDocumentClass(Class<? extends Document> documentClass) {
133 		this.documentClass = documentClass;
134 	}
135 
136     /**
137      * Gets boolean that indicates if the document view allows note attachments
138      *
139      * @return true if the document view allows note attachments
140      */
141     @BeanTagAttribute(name="allowsNoteAttachments")
142 	public boolean isAllowsNoteAttachments() {
143 		return this.allowsNoteAttachments;
144 	}
145 
146     /**
147      * Sets boolean that indicates if the document view allows note attachments
148      *
149      * @param allowsNoteAttachments
150      */
151 	public void setAllowsNoteAttachments(boolean allowsNoteAttachments) {
152 		this.allowsNoteAttachments = allowsNoteAttachments;
153 	}
154 
155     /**
156      * Gets boolean that indicates if the document view allows note FYI
157      *
158      * @return true if the document view allows note FYI
159      */
160     @BeanTagAttribute(name="allowsNoteFYI")
161 	public boolean isAllowsNoteFYI() {
162 		return this.allowsNoteFYI;
163 	}
164 
165     /**
166      * Sets boolean that indicates if the document view allows note FYI
167      *
168      * @param allowsNoteFYI
169      */
170 	public void setAllowsNoteFYI(boolean allowsNoteFYI) {
171 		this.allowsNoteFYI = allowsNoteFYI;
172 	}
173 
174     /**
175      * Gets boolean that indicates if the document view displays the topic field in notes
176      *
177      * @return true if the document view displays the topic field in notes
178      */
179     @BeanTagAttribute(name="displayTopicFieldInNotes")
180 	public boolean isDisplayTopicFieldInNotes() {
181 		return this.displayTopicFieldInNotes;
182 	}
183 
184     /**
185      * Sets boolean that indicates if the document view displays the topic field in notes
186      *
187      * @param displayTopicFieldInNotes
188      */
189 	public void setDisplayTopicFieldInNotes(boolean displayTopicFieldInNotes) {
190 		this.displayTopicFieldInNotes = displayTopicFieldInNotes;
191 	}
192 
193     /**
194      * Gets attachment types values finder classs
195      *
196      * @return attachment types values finder class
197      */
198     @BeanTagAttribute(name="attachmentTypesValuesFinderClass",type = BeanTagAttribute.AttributeType.SINGLEBEAN)
199 	public Class<? extends KeyValuesFinder> getAttachmentTypesValuesFinderClass() {
200 		return this.attachmentTypesValuesFinderClass;
201 	}
202 
203     /**
204      * Sets attachment types values finder classs
205      *
206      * @param attachmentTypesValuesFinderClass
207      */
208 	public void setAttachmentTypesValuesFinderClass(Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass) {
209 		this.attachmentTypesValuesFinderClass = attachmentTypesValuesFinderClass;
210 	}
211 }