001/**
002 * Copyright 2005-2015 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.document;
017
018import org.kuali.rice.kew.api.WorkflowDocument;
019import org.kuali.rice.kew.api.action.ActionType;
020import org.kuali.rice.kew.api.action.ValidActions;
021import org.kuali.rice.krad.uif.view.RequestAuthorizationCache;
022
023/**
024 * Request authorization cache object which adds caching on workflow document calls
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028public class DocumentRequestAuthorizationCache extends RequestAuthorizationCache {
029
030    private static final long serialVersionUID = -3965168125219051628L;
031
032    private WorkflowDocumentInfo workflowDocumentInfo;
033
034    public void createWorkflowDocumentInfo(WorkflowDocument workflowDocument) {
035        if (this.workflowDocumentInfo == null) {
036            this.workflowDocumentInfo = new WorkflowDocumentInfo(workflowDocument);
037        }
038    }
039
040    public WorkflowDocumentInfo getWorkflowDocumentInfo() {
041        return workflowDocumentInfo;
042    }
043
044    public static class WorkflowDocumentInfo {
045
046        private Boolean isCompletionRequested;
047        private Boolean isApprovalRequested;
048        private Boolean isAcknowledgeRequested;
049        private Boolean isFYIRequested;
050        private Boolean isInitiated;
051        private Boolean isSaved;
052        private Boolean isEnroute;
053        private Boolean isException;
054        private Boolean isCanceled;
055        private Boolean isRecalled;
056        private Boolean isDisapproved;
057        private Boolean isApproved;
058        private Boolean isProcessed;
059        private Boolean isFinal;
060
061        private ValidActions validActions;
062
063        private WorkflowDocument workflowDocument;
064
065        public WorkflowDocumentInfo(WorkflowDocument workflowDocument) {
066            this.workflowDocument = workflowDocument;
067        }
068
069        public boolean isCompletionRequested() {
070            if (isCompletionRequested == null) {
071                isCompletionRequested = Boolean.valueOf(workflowDocument.isCompletionRequested());
072            }
073
074            return isCompletionRequested.booleanValue();
075        }
076
077        public boolean isApprovalRequested() {
078            if (isApprovalRequested == null) {
079                isApprovalRequested = Boolean.valueOf(workflowDocument.isApprovalRequested());
080            }
081
082            return isApprovalRequested.booleanValue();
083        }
084
085        public boolean isAcknowledgeRequested() {
086            if (isAcknowledgeRequested == null) {
087                isAcknowledgeRequested = Boolean.valueOf(workflowDocument.isAcknowledgeRequested());
088            }
089
090            return isAcknowledgeRequested.booleanValue();
091        }
092
093        public boolean isFYIRequested() {
094            if (isFYIRequested == null) {
095                isFYIRequested = Boolean.valueOf(workflowDocument.isFYIRequested());
096            }
097
098            return isFYIRequested.booleanValue();
099        }
100
101        public boolean isInitiated() {
102            if (isInitiated == null) {
103                isInitiated = Boolean.valueOf(workflowDocument.isInitiated());
104            }
105
106            return isInitiated.booleanValue();
107        }
108
109        public boolean isSaved() {
110            if (isSaved == null) {
111                isSaved = Boolean.valueOf(workflowDocument.isSaved());
112            }
113
114            return isSaved.booleanValue();
115        }
116
117        public boolean isEnroute() {
118            if (isEnroute == null) {
119                isEnroute = Boolean.valueOf(workflowDocument.isEnroute());
120            }
121
122            return isEnroute.booleanValue();
123        }
124
125        public boolean isException() {
126            if (isException == null) {
127                isException = Boolean.valueOf(workflowDocument.isException());
128            }
129
130            return isException.booleanValue();
131        }
132
133        public boolean isCanceled() {
134            if (isCanceled == null) {
135                isCanceled = Boolean.valueOf(workflowDocument.isCanceled());
136            }
137
138            return isCanceled.booleanValue();
139        }
140
141        public boolean isRecalled() {
142            if (isRecalled == null) {
143                isRecalled = Boolean.valueOf(workflowDocument.isRecalled());
144            }
145
146            return isRecalled.booleanValue();
147        }
148
149        public boolean isDisapproved() {
150            if (isDisapproved == null) {
151                isDisapproved = Boolean.valueOf(workflowDocument.isDisapproved());
152            }
153
154            return isDisapproved.booleanValue();
155        }
156
157        public boolean isApproved() {
158            if (isApproved == null) {
159                isApproved = Boolean.valueOf(workflowDocument.isApproved());
160            }
161
162            return isApproved.booleanValue();
163        }
164
165        public boolean isProcessed() {
166            if (isProcessed == null) {
167                isProcessed = Boolean.valueOf(workflowDocument.isProcessed());
168            }
169
170            return isProcessed.booleanValue();
171        }
172
173        public boolean isFinal() {
174            if (isFinal == null) {
175                isFinal = Boolean.valueOf(workflowDocument.isFinal());
176            }
177
178            return isFinal.booleanValue();
179        }
180
181        public ValidActions getValidActions() {
182            if (validActions == null) {
183                validActions = workflowDocument.getValidActions();
184            }
185
186            return validActions;
187        }
188
189        public boolean isValidAction(ActionType actionType) {
190            if (actionType == null) {
191                throw new IllegalArgumentException("actionType was null");
192            }
193
194            return getValidActions().getValidActions().contains(actionType);
195        }
196
197        public WorkflowDocument getWorkflowDocument() {
198            return workflowDocument;
199        }
200    }
201}