001    /*
002     * Copyright 2011 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.kfs.module.bc.document.web.struts;
017    
018    import java.util.Arrays;
019    import java.util.Collections;
020    import java.util.Iterator;
021    import java.util.List;
022    
023    import javax.servlet.http.HttpServletRequest;
024    
025    import org.apache.struts.action.ActionMapping;
026    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionOrganizationReports;
027    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionPullup;
028    import org.kuali.kfs.sys.context.SpringContext;
029    import org.kuali.rice.kns.service.PersistenceService;
030    import org.kuali.rice.kns.util.TypedArrayList;
031    import org.kuali.rice.core.util.KeyLabelPair;
032    
033    /**
034     * ActionForm that supports the Organization Selection Tree page
035     */
036    public class OrganizationSelectionTreeForm extends BudgetExpansionForm {
037        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationSelectionTreeForm.class);
038    
039        private BudgetConstructionOrganizationReports pointOfViewOrg;
040        private List<BudgetConstructionPullup> selectionSubTreeOrgs;
041        private List<BudgetConstructionPullup> previousBranchOrgs;
042        private boolean hideDetails = false;
043        private String operatingModeTitle;
044        private String operatingModePullFlagLabel;
045    
046        private String currentPointOfViewKeyCode;
047        private String previousPointOfViewKeyCode;
048        private List<KeyLabelPair> pullFlagKeyLabels;
049    
050        // passed parms
051        private String operatingMode;
052    
053        private boolean accountSummaryConsolidation;
054        private boolean accountObjectDetailConsolidation;
055        private boolean monthObjectSummaryConsolidation;
056    
057        private String reportMode;
058    
059        // used to flag reset() not to reset check box values when returning from child expansion screen
060        private boolean noResetOnReturn = false;
061    
062        /**
063         * Constructs a OrganizationSelectionTreeForm.java.
064         */
065        public OrganizationSelectionTreeForm() {
066            super();
067            this.setPointOfViewOrg(new BudgetConstructionOrganizationReports());
068            this.setSelectionSubTreeOrgs(new TypedArrayList(BudgetConstructionPullup.class));
069            this.setPreviousBranchOrgs(new TypedArrayList(BudgetConstructionPullup.class));
070            this.setPullFlagKeyLabels(new TypedArrayList(KeyLabelPair.class));
071    
072        }
073    
074        /**
075         * @see org.kuali.rice.kns.web.struts.form.KualiForm#populate(javax.servlet.http.HttpServletRequest)
076         */
077        @Override
078        public void populate(HttpServletRequest request) {
079    
080            super.populate(request);
081            populatePreviousBranchOrgs();
082            populateSelectionSubTreeOrgs();
083    
084        }
085    
086        public void populateSelectionSubTreeOrgs() {
087    
088            Iterator<BudgetConstructionPullup> selectionOrgs = getSelectionSubTreeOrgs().iterator();
089            while (selectionOrgs.hasNext()) {
090                BudgetConstructionPullup selectionOrg = (BudgetConstructionPullup) selectionOrgs.next();
091    
092                final List<String> REFRESH_FIELDS = Collections.unmodifiableList(Arrays.asList(new String[] { "organization" }));
093                SpringContext.getBean(PersistenceService.class).retrieveReferenceObjects(selectionOrg, REFRESH_FIELDS);
094            }
095    
096        }
097    
098        public void populatePreviousBranchOrgs() {
099    
100            Iterator<BudgetConstructionPullup> previousBranchOrgs = getPreviousBranchOrgs().iterator();
101            while (previousBranchOrgs.hasNext()) {
102                BudgetConstructionPullup previousBranchOrg = (BudgetConstructionPullup) previousBranchOrgs.next();
103                final List<String> REFRESH_FIELDS = Collections.unmodifiableList(Arrays.asList(new String[] { "organization" }));
104                SpringContext.getBean(PersistenceService.class).retrieveReferenceObjects(previousBranchOrg, REFRESH_FIELDS);
105            }
106    
107        }
108    
109        /**
110         * Gets the pointOfViewOrg attribute.
111         * 
112         * @return Returns the pointOfViewOrg.
113         */
114        public BudgetConstructionOrganizationReports getPointOfViewOrg() {
115            return pointOfViewOrg;
116        }
117    
118        /**
119         * Sets the pointOfViewOrg attribute value.
120         * 
121         * @param pointOfViewOrg The pointOfViewOrg to set.
122         */
123        public void setPointOfViewOrg(BudgetConstructionOrganizationReports pointOfViewOrg) {
124            this.pointOfViewOrg = pointOfViewOrg;
125        }
126    
127        /**
128         * Gets the hideDetails attribute.
129         * 
130         * @return Returns the hideDetails.
131         */
132        public boolean isHideDetails() {
133            return hideDetails;
134        }
135    
136        /**
137         * Sets the hideDetails attribute value.
138         * 
139         * @param hideDetails The hideDetails to set.
140         */
141        public void setHideDetails(boolean hideDetails) {
142            this.hideDetails = hideDetails;
143        }
144    
145        /**
146         * Gets the operatingMode attribute.
147         * 
148         * @return Returns the operatingMode.
149         */
150        public String getOperatingMode() {
151            return operatingMode;
152        }
153    
154        /**
155         * Sets the operatingMode attribute value.
156         * 
157         * @param operatingMode The operatingMode to set.
158         */
159        public void setOperatingMode(String operatingMode) {
160            this.operatingMode = operatingMode;
161        }
162    
163        /**
164         * Gets the operatingModeTitle attribute.
165         * 
166         * @return Returns the operatingModeTitle.
167         */
168        public String getOperatingModeTitle() {
169            return operatingModeTitle;
170        }
171    
172        /**
173         * Sets the operatingModeTitle attribute value.
174         * 
175         * @param operatingModeTitle The operatingModeTitle to set.
176         */
177        public void setOperatingModeTitle(String operatingModeTitle) {
178            this.operatingModeTitle = operatingModeTitle;
179        }
180    
181        /**
182         * Gets the currentPointOfViewKeyCode attribute.
183         * 
184         * @return Returns the currentPointOfViewKeyCode.
185         */
186        public String getCurrentPointOfViewKeyCode() {
187            return currentPointOfViewKeyCode;
188        }
189    
190        /**
191         * Sets the currentPointOfViewKeyCode attribute value.
192         * 
193         * @param currentPointOfViewKeyCode The currentPointOfViewKeyCode to set.
194         */
195        public void setCurrentPointOfViewKeyCode(String currentPointOfViewKeyCode) {
196            this.currentPointOfViewKeyCode = currentPointOfViewKeyCode;
197        }
198    
199        /**
200         * Gets the previousPointOfViewKeyCode attribute.
201         * 
202         * @return Returns the previousPointOfViewKeyCode.
203         */
204        public String getPreviousPointOfViewKeyCode() {
205            return previousPointOfViewKeyCode;
206        }
207    
208        /**
209         * Sets the previousPointOfViewKeyCode attribute value.
210         * 
211         * @param previousPointOfViewKeyCode The previousPointOfViewKeyCode to set.
212         */
213        public void setPreviousPointOfViewKeyCode(String previousPointOfViewKeyCode) {
214            this.previousPointOfViewKeyCode = previousPointOfViewKeyCode;
215        }
216    
217        /**
218         * Gets the selectionSubTree attribute.
219         * 
220         * @return Returns the selectionSubTree.
221         */
222        public List<BudgetConstructionPullup> getSelectionSubTreeOrgs() {
223            return selectionSubTreeOrgs;
224        }
225    
226        /**
227         * Sets the selectionSubTree attribute value.
228         * 
229         * @param selectionSubTree The selectionSubTree to set.
230         */
231        public void setSelectionSubTreeOrgs(List<BudgetConstructionPullup> selectionSubTree) {
232            this.selectionSubTreeOrgs = selectionSubTree;
233        }
234    
235        /**
236         * Gets the previousBranchOrgs attribute.
237         * 
238         * @return Returns the previousBranchOrgs.
239         */
240        public List<BudgetConstructionPullup> getPreviousBranchOrgs() {
241            return previousBranchOrgs;
242        }
243    
244        /**
245         * Sets the previousBranchOrgs attribute value.
246         * 
247         * @param previousBranchOrgs The previousBranchOrgs to set.
248         */
249        public void setPreviousBranchOrgs(List<BudgetConstructionPullup> previousBranchOrgs) {
250            this.previousBranchOrgs = previousBranchOrgs;
251        }
252    
253        /**
254         * Gets the pullFlagKeyLabels attribute.
255         * 
256         * @return Returns the pullFlagKeyLabels.
257         */
258        public List<KeyLabelPair> getPullFlagKeyLabels() {
259            return pullFlagKeyLabels;
260        }
261    
262        /**
263         * Sets the pullFlagKeyLabels attribute value.
264         * 
265         * @param pullFlagKeyLabels The pullFlagKeyLabels to set.
266         */
267        public void setPullFlagKeyLabels(List<KeyLabelPair> pullFlagKeyLabels) {
268            this.pullFlagKeyLabels = pullFlagKeyLabels;
269        }
270    
271        /**
272         * Gets the operatingModePullFlagLabel attribute.
273         * 
274         * @return Returns the operatingModePullFlagLabel.
275         */
276        public String getOperatingModePullFlagLabel() {
277            return operatingModePullFlagLabel;
278        }
279    
280        /**
281         * Sets the operatingModePullFlagLabel attribute value.
282         * 
283         * @param operatingModePullFlagLabel The operatingModePullFlagLabel to set.
284         */
285        public void setOperatingModePullFlagLabel(String operatingModePullFlagLabel) {
286            this.operatingModePullFlagLabel = operatingModePullFlagLabel;
287        }
288    
289        public boolean isAccountSummaryConsolidation() {
290            return accountSummaryConsolidation;
291        }
292    
293        public void setAccountSummaryConsolidation(boolean accountSummaryConsolidation) {
294            this.accountSummaryConsolidation = accountSummaryConsolidation;
295        }
296    
297        public String getReportMode() {
298            return reportMode;
299        }
300    
301        public void setReportMode(String reportMode) {
302            this.reportMode = reportMode;
303        }
304    
305        public boolean isAccountObjectDetailConsolidation() {
306            return accountObjectDetailConsolidation;
307        }
308    
309        public void setAccountObjectDetailConsolidation(boolean accountObjectDetailConsolidation) {
310            this.accountObjectDetailConsolidation = accountObjectDetailConsolidation;
311        }
312    
313        public boolean isMonthObjectSummaryConsolidation() {
314            return monthObjectSummaryConsolidation;
315        }
316    
317        public void setMonthObjectSummaryConsolidation(boolean monthObjectSummaryConsolidation) {
318            this.monthObjectSummaryConsolidation = monthObjectSummaryConsolidation;
319        }
320    
321        /**
322         * @see org.kuali.rice.kns.web.struts.form.KualiForm#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String,
323         *      javax.servlet.http.HttpServletRequest)
324         */
325        @Override
326        public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
327    
328            if (methodToCallParameterValue.equalsIgnoreCase("performBuildPointOfView")) {
329                return true;
330            }
331            return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
332        }
333    
334        /**
335         * @see org.kuali.rice.kns.web.struts.form.KualiForm#reset(org.apache.struts.action.ActionMapping,
336         *      javax.servlet.http.HttpServletRequest) resets check box fields if not returning from a child expansion screen
337         */
338        @Override
339        public void reset(ActionMapping mapping, HttpServletRequest request) {
340    
341            if (this.isNoResetOnReturn()) {
342                this.setNoResetOnReturn(false);
343            }
344            else {
345                super.reset(mapping, request);
346                for (BudgetConstructionPullup selectionSubTreeOrg : selectionSubTreeOrgs) {
347                    selectionSubTreeOrg.setPullFlag(0);
348                }
349                this.setAccountSummaryConsolidation(false);
350                this.setAccountObjectDetailConsolidation(false);
351                this.setMonthObjectSummaryConsolidation(false);
352            }
353    
354            this.getMessages().clear();
355        }
356    
357        /**
358         * Gets the noResetOnReturn attribute.
359         * 
360         * @return Returns the noResetOnReturn.
361         */
362        public boolean isNoResetOnReturn() {
363            return noResetOnReturn;
364        }
365    
366        /**
367         * Sets the noResetOnReturn attribute value.
368         * 
369         * @param noResetOnReturn The noResetOnReturn to set.
370         */
371        public void setNoResetOnReturn(boolean noResetOnReturn) {
372            this.noResetOnReturn = noResetOnReturn;
373        }
374    
375    }