View Javadoc

1   /**
2    * Copyright 2005-2012 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.document.Document;
21  import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
22  import org.kuali.rice.krad.document.DocumentViewPresentationControllerBase;
23  import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
24  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25  import org.kuali.rice.krad.uif.UifConstants;
26  
27  /**
28   * View type for KRAD documents
29   * 
30   * <p>
31   * Provides commons configuration and default behavior applicable to documents
32   * in the KRAD module.
33   * </p>
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class DocumentView extends FormView {
38  	private static final long serialVersionUID = 2251983409572774175L;
39  
40  	private Class<? extends Document> documentClass;
41  
42  	private boolean allowsNoteAttachments = true;
43  	private boolean allowsNoteFYI = false;
44  	private boolean displayTopicFieldInNotes = false;
45  
46  	private Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
47  
48  	public DocumentView() {
49  		super();
50  	}
51  
52      /**
53       * The following initialization is performed:
54       *
55       * <ul>
56       * <li>Retrieve the document entry</li>
57       * <li>Set up the document view authorizer and presentation controller</li>
58       * </ul>
59       *
60       * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View,
61       *      java.lang.Object)
62       */
63      @Override
64      public void performInitialization(View view, Object model) {
65          super.performInitialization(view, model);
66  
67          // get document entry
68          DocumentEntry documentEntry = getDocumentEntryForView();
69          pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
70  
71          // setup authorizer and presentation controller using the configured authorizer and pc for document
72          if (getAuthorizer() == null) {
73              setAuthorizer(new DocumentViewAuthorizerBase());
74          }
75  
76          if (getAuthorizer() instanceof DocumentViewAuthorizerBase) {
77              DocumentViewAuthorizerBase documentViewAuthorizerBase = (DocumentViewAuthorizerBase) getAuthorizer();
78              if (documentViewAuthorizerBase.getDocumentAuthorizer() == null) {
79                  documentViewAuthorizerBase.setDocumentAuthorizerClass(documentEntry.getDocumentAuthorizerClass());
80              }
81          }
82  
83          if (getPresentationController() == null) {
84              setPresentationController(new DocumentViewPresentationControllerBase());
85          }
86  
87          if (getPresentationController() instanceof DocumentViewPresentationControllerBase) {
88              DocumentViewPresentationControllerBase documentViewPresentationControllerBase =
89                      (DocumentViewPresentationControllerBase) getPresentationController();
90              if (documentViewPresentationControllerBase.getDocumentPresentationController() == null) {
91                  documentViewPresentationControllerBase.setDocumentPresentationControllerClass(
92                          documentEntry.getDocumentPresentationControllerClass());
93              }
94          }
95      }
96  
97      /**
98       * Retrieves the associated {@link DocumentEntry} for the document view
99       *
100      * @return DocumentEntry entry (exception thrown if one is not found)
101      */
102     protected DocumentEntry getDocumentEntryForView() {
103         DocumentEntry documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getDocumentEntryByClass(
104                 getDocumentClass());
105 
106         if (documentEntry == null) {
107             throw new RuntimeException(
108                     "Unable to find document entry for document class: " + getDocumentClass().getName());
109         }
110 
111         return documentEntry;
112     }
113 
114 	public Class<? extends Document> getDocumentClass() {
115 		return this.documentClass;
116 	}
117 
118 	public void setDocumentClass(Class<? extends Document> documentClass) {
119 		this.documentClass = documentClass;
120 	}
121 
122 	public boolean isAllowsNoteAttachments() {
123 		return this.allowsNoteAttachments;
124 	}
125 
126 	public void setAllowsNoteAttachments(boolean allowsNoteAttachments) {
127 		this.allowsNoteAttachments = allowsNoteAttachments;
128 	}
129 
130 	public boolean isAllowsNoteFYI() {
131 		return this.allowsNoteFYI;
132 	}
133 
134 	public void setAllowsNoteFYI(boolean allowsNoteFYI) {
135 		this.allowsNoteFYI = allowsNoteFYI;
136 	}
137 
138 	public boolean isDisplayTopicFieldInNotes() {
139 		return this.displayTopicFieldInNotes;
140 	}
141 
142 	public void setDisplayTopicFieldInNotes(boolean displayTopicFieldInNotes) {
143 		this.displayTopicFieldInNotes = displayTopicFieldInNotes;
144 	}
145 
146 	public Class<? extends KeyValuesFinder> getAttachmentTypesValuesFinderClass() {
147 		return this.attachmentTypesValuesFinderClass;
148 	}
149 
150 	public void setAttachmentTypesValuesFinderClass(Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass) {
151 		this.attachmentTypesValuesFinderClass = attachmentTypesValuesFinderClass;
152 	}
153 
154 }