001    /**
002     * Copyright 2005-2012 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.document;
017    
018    import org.kuali.rice.krad.uif.view.View;
019    import org.kuali.rice.krad.uif.view.ViewModel;
020    import org.kuali.rice.krad.uif.view.ViewPresentationControllerBase;
021    import org.kuali.rice.krad.util.KRADConstants;
022    import org.kuali.rice.krad.util.ObjectUtils;
023    import org.kuali.rice.krad.web.form.DocumentFormBase;
024    import org.kuali.rice.krad.web.form.UifFormBase;
025    
026    import java.util.HashSet;
027    import java.util.Set;
028    
029    /**
030     * Implementation of {@link org.kuali.rice.krad.uif.view.ViewPresentationController} for
031     * {@link org.kuali.rice.krad.uif.view.DocumentView} instances
032     *
033     * <p>
034     * Adds flags for various document actions like save, route, cancel
035     * </p>
036     *
037     * <p>
038     * By default delegates to the {@link DocumentPresentationController} configured for the document in the data dictionary
039     * </p>
040     *
041     * @author Kuali Rice Team (rice.collab@kuali.org)
042     */
043    public class DocumentViewPresentationControllerBase extends ViewPresentationControllerBase implements DocumentPresentationController {
044        private static final long serialVersionUID = 1461173145806477758L;
045    
046        private DocumentPresentationController documentPresentationController;
047    
048        @Override
049        public Set<String> getActionFlags(View view, UifFormBase model) {
050            Set<String> documentActions = new HashSet<String>();
051    
052            Document document = ((DocumentFormBase) model).getDocument();
053    
054            if (canEdit(document)) {
055                documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
056            }
057    
058            if (canAnnotate(document)) {
059                documentActions.add(KRADConstants.KUALI_ACTION_CAN_ANNOTATE);
060            }
061    
062            if (canClose(document)) {
063                documentActions.add(KRADConstants.KUALI_ACTION_CAN_CLOSE);
064            }
065    
066            if (canSave(document)) {
067                documentActions.add(KRADConstants.KUALI_ACTION_CAN_SAVE);
068            }
069    
070            if (canRoute(document)) {
071                documentActions.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
072            }
073    
074            if (canCancel(document)) {
075                documentActions.add(KRADConstants.KUALI_ACTION_CAN_CANCEL);
076            }
077    
078            if (canReload(document)) {
079                documentActions.add(KRADConstants.KUALI_ACTION_CAN_RELOAD);
080            }
081    
082            if (canCopy(document)) {
083                documentActions.add(KRADConstants.KUALI_ACTION_CAN_COPY);
084            }
085    
086            if (canPerformRouteReport(document)) {
087                documentActions.add(KRADConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT);
088            }
089    
090            if (canAddAdhocRequests(document)) {
091                documentActions.add(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
092            }
093    
094            if (canBlanketApprove(document)) {
095                documentActions.add(KRADConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
096            }
097    
098            if (canApprove(document)) {
099                documentActions.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
100            }
101    
102            if (canDisapprove(document)) {
103                documentActions.add(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
104            }
105    
106            if (canSendAdhocRequests(document)) {
107                documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
108            }
109    
110            if (canSendNoteFyi(document)) {
111                documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI);
112            }
113    
114            if (this.canEditDocumentOverview(document)) {
115                documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT_DOCUMENT_OVERVIEW);
116            }
117    
118            if (canFyi(document)) {
119                documentActions.add(KRADConstants.KUALI_ACTION_CAN_FYI);
120            }
121    
122            if (canAcknowledge(document)) {
123                documentActions.add(KRADConstants.KUALI_ACTION_CAN_ACKNOWLEDGE);
124            }
125    
126            return documentActions;
127        }
128    
129        public boolean canInitiate(String documentTypeName) {
130            return getDocumentPresentationController().canInitiate(documentTypeName);
131        }
132    
133        public boolean canEdit(Document document) {
134            return getDocumentPresentationController().canEdit(document);
135        }
136    
137        /**
138         * Verify the document can be edited in addition to the view
139         */
140        @Override
141        public boolean canEditView(View view, ViewModel model) {
142            DocumentFormBase documentForm = (DocumentFormBase) model;
143    
144            return super.canEditView(view, model) && canEdit(documentForm.getDocument());
145        }
146    
147        public boolean canAnnotate(Document document) {
148            return getDocumentPresentationController().canAnnotate(document);
149        }
150    
151        public boolean canReload(Document document) {
152            return getDocumentPresentationController().canReload(document);
153        }
154    
155        public boolean canClose(Document document) {
156            return getDocumentPresentationController().canClose(document);
157        }
158    
159        public boolean canSave(Document document) {
160            return getDocumentPresentationController().canSave(document);
161        }
162    
163        public boolean canRoute(Document document) {
164            return getDocumentPresentationController().canRoute(document);
165        }
166    
167        public boolean canCancel(Document document) {
168            return getDocumentPresentationController().canEdit(document);
169        }
170    
171        public boolean canCopy(Document document) {
172            return getDocumentPresentationController().canCopy(document);
173        }
174    
175        public boolean canPerformRouteReport(Document document) {
176            return getDocumentPresentationController().canPerformRouteReport(document);
177        }
178    
179        public boolean canAddAdhocRequests(Document document) {
180            return getDocumentPresentationController().canAddAdhocRequests(document);
181        }
182    
183        public boolean canBlanketApprove(Document document) {
184            return getDocumentPresentationController().canBlanketApprove(document);
185        }
186    
187        public boolean canApprove(Document document) {
188            return getDocumentPresentationController().canApprove(document);
189        }
190    
191        public boolean canDisapprove(Document document) {
192            return getDocumentPresentationController().canDisapprove(document);
193        }
194    
195        public boolean canSendAdhocRequests(Document document) {
196            return getDocumentPresentationController().canSendAdhocRequests(document);
197        }
198    
199        public boolean canSendNoteFyi(Document document) {
200            return getDocumentPresentationController().canSendNoteFyi(document);
201        }
202    
203        public boolean canEditDocumentOverview(Document document) {
204            return getDocumentPresentationController().canEditDocumentOverview(document);
205        }
206    
207        public boolean canFyi(Document document) {
208            return getDocumentPresentationController().canFyi(document);
209        }
210    
211        public boolean canAcknowledge(Document document) {
212            return getDocumentPresentationController().canAcknowledge(document);
213        }
214    
215        public DocumentPresentationController getDocumentPresentationController() {
216            return documentPresentationController;
217        }
218    
219        public void setDocumentPresentationController(DocumentPresentationController documentPresentationController) {
220            this.documentPresentationController = documentPresentationController;
221        }
222    
223        public void setDocumentPresentationControllerClass(
224                Class<? extends DocumentPresentationController> documentPresentationControllerClass) {
225            this.documentPresentationController = ObjectUtils.newInstance(documentPresentationControllerClass);
226        }
227    }