001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.view;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.rice.krad.datadictionary.DocumentEntry;
020 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
021 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
022 import org.kuali.rice.krad.document.Document;
023 import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
024 import org.kuali.rice.krad.document.DocumentViewPresentationControllerBase;
025 import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
026 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
027 import org.kuali.rice.krad.uif.UifConstants;
028
029 /**
030 * View type for KRAD documents
031 *
032 * <p>
033 * Provides commons configuration and default behavior applicable to documents
034 * in the KRAD module.
035 * </p>
036 *
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039 @BeanTag(name = "documentView-bean", parent = "Uif-DocumentView")
040 public class DocumentView extends FormView {
041 private static final long serialVersionUID = 2251983409572774175L;
042
043 private Class<? extends Document> documentClass;
044
045 private boolean allowsNoteAttachments = true;
046 private boolean allowsNoteFYI = false;
047 private boolean displayTopicFieldInNotes = false;
048
049 private Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
050
051 public DocumentView() {
052 super();
053 }
054
055 /**
056 * The following initialization is performed:
057 *
058 * <ul>
059 * <li>Retrieve the document entry</li>
060 * <li>Set up the document view authorizer and presentation controller</li>
061 * </ul>
062 *
063 * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View,
064 * java.lang.Object)
065 */
066 @Override
067 public void performInitialization(View view, Object model) {
068 super.performInitialization(view, model);
069
070 // get document entry
071 DocumentEntry documentEntry = getDocumentEntryForView();
072 pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
073
074 // setup authorizer and presentation controller using the configured authorizer and pc for document
075 if (getAuthorizer() == null) {
076 setAuthorizer(new DocumentViewAuthorizerBase());
077 }
078
079 if (getAuthorizer() instanceof DocumentViewAuthorizerBase) {
080 DocumentViewAuthorizerBase documentViewAuthorizerBase = (DocumentViewAuthorizerBase) getAuthorizer();
081 if (documentViewAuthorizerBase.getDocumentAuthorizer() == null) {
082 documentViewAuthorizerBase.setDocumentAuthorizerClass(documentEntry.getDocumentAuthorizerClass());
083 }
084 }
085
086 if (getPresentationController() == null) {
087 setPresentationController(new DocumentViewPresentationControllerBase());
088 }
089
090 if (getPresentationController() instanceof DocumentViewPresentationControllerBase) {
091 DocumentViewPresentationControllerBase documentViewPresentationControllerBase =
092 (DocumentViewPresentationControllerBase) getPresentationController();
093 if (documentViewPresentationControllerBase.getDocumentPresentationController() == null) {
094 documentViewPresentationControllerBase.setDocumentPresentationControllerClass(
095 documentEntry.getDocumentPresentationControllerClass());
096 }
097 }
098
099 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 }