001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.krad.uif.view;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.datadictionary.DocumentEntry;
020import org.kuali.rice.krad.document.Document;
021import org.kuali.rice.krad.document.DocumentViewAuthorizerBase;
022import org.kuali.rice.krad.document.DocumentViewPresentationControllerBase;
023import org.kuali.rice.krad.keyvalues.KeyValuesFinder;
024import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
025import org.kuali.rice.krad.uif.UifConstants;
026
027/**
028 * View type for KRAD documents
029 * 
030 * <p>
031 * Provides commons configuration and default behavior applicable to documents
032 * in the KRAD module.
033 * </p>
034 * 
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037public class DocumentView extends FormView {
038        private static final long serialVersionUID = 2251983409572774175L;
039
040        private Class<? extends Document> documentClass;
041
042        private boolean allowsNoteAttachments = true;
043        private boolean allowsNoteFYI = false;
044        private boolean displayTopicFieldInNotes = false;
045
046        private Class<? extends KeyValuesFinder> attachmentTypesValuesFinderClass;
047
048        public DocumentView() {
049                super();
050        }
051
052    /**
053     * The following initialization is performed:
054     *
055     * <ul>
056     * <li>Retrieve the document entry</li>
057     * <li>Set up the document view authorizer and presentation controller</li>
058     * </ul>
059     *
060     * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View,
061     *      java.lang.Object)
062     */
063    @Override
064    public void performInitialization(View view, Object model) {
065        super.performInitialization(view, model);
066
067        // get document entry
068        DocumentEntry documentEntry = getDocumentEntryForView();
069        pushObjectToContext(UifConstants.ContextVariableNames.DOCUMENT_ENTRY, documentEntry);
070
071        // setup authorizer and presentation controller using the configured authorizer and pc for document
072        if (getAuthorizer() == null) {
073            setAuthorizer(new DocumentViewAuthorizerBase());
074        }
075
076        if (getAuthorizer() instanceof DocumentViewAuthorizerBase) {
077            DocumentViewAuthorizerBase documentViewAuthorizerBase = (DocumentViewAuthorizerBase) getAuthorizer();
078            if (documentViewAuthorizerBase.getDocumentAuthorizer() == null) {
079                documentViewAuthorizerBase.setDocumentAuthorizerClass(documentEntry.getDocumentAuthorizerClass());
080            }
081        }
082
083        if (getPresentationController() == null) {
084            setPresentationController(new DocumentViewPresentationControllerBase());
085        }
086
087        if (getPresentationController() instanceof DocumentViewPresentationControllerBase) {
088            DocumentViewPresentationControllerBase documentViewPresentationControllerBase =
089                    (DocumentViewPresentationControllerBase) getPresentationController();
090            if (documentViewPresentationControllerBase.getDocumentPresentationController() == null) {
091                documentViewPresentationControllerBase.setDocumentPresentationControllerClass(
092                        documentEntry.getDocumentPresentationControllerClass());
093            }
094        }
095    }
096
097    /**
098     * Retrieves the associated {@link DocumentEntry} for the document view
099     *
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}