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.kew.actionlist.web;
017
018import org.kuali.rice.core.api.config.property.ConfigContext;
019import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
020import org.kuali.rice.kew.actionlist.ActionToTake;
021import org.kuali.rice.kew.api.KewApiConstants;
022import org.kuali.rice.kew.util.WebFriendlyRecipient;
023import org.kuali.rice.kim.api.identity.principal.Principal;
024import org.kuali.rice.kim.api.services.KimApiServiceLocator;
025import org.kuali.rice.kns.web.struts.form.KualiForm;
026import org.kuali.rice.kns.web.ui.ExtraButton;
027import org.kuali.rice.krad.util.GlobalVariables;
028import org.kuali.rice.krad.util.KRADConstants;
029import org.kuali.rice.krad.util.UrlFactory;
030
031import javax.servlet.http.HttpServletRequest;
032import java.util.ArrayList;
033import java.util.HashMap;
034import java.util.List;
035import java.util.Map;
036import java.util.Properties;
037
038/**
039 * Struts form for action ActionListAction
040 *
041 * @author Kuali Rice Team (rice.collab@kuali.org)
042 */
043public class ActionListForm extends KualiForm {
044
045    private static final long serialVersionUID = -6246391732337228007L;
046
047    private String delegator;
048    private String methodToCall = "";
049    private String helpDeskActionListUserName;
050    private String docType;
051    private String filterLegend;
052    private String actionListType;
053    private Boolean customActionList;
054    private String defaultActionToTake;
055    private List<ActionToTake> actionsToTake = new ArrayList<ActionToTake>();
056    private Map<?, ?> defaultActions = new HashMap<Object, Object>();
057    private String delegationId;
058    private List<?> delegators;
059    private Boolean hasCustomActions;
060    private Boolean routeLogPopup;
061    private Boolean documentPopup;
062    private List<WebFriendlyRecipient> primaryDelegates;
063    private String primaryDelegateId;
064
065    private Boolean hasDisplayParameters;
066
067    // "sticky" parameters for paginated action list
068    private Integer currentPage;
069    private String currentSort;
070    private String currentDir;
071
072    // parameters for paginated action list
073    private Integer page;
074    private String sort;
075    private String dir;
076
077    private int count;
078    private String cssFile = "kuali.css";
079    private String logoAlign = "left";
080    private String viewOutbox;
081    private String[] outboxItems;
082    private boolean outBoxEmpty;
083    private Boolean showOutbox;
084    private List<ExtraButton> headerButtons = new ArrayList<ExtraButton>();
085
086    public String getHelpDeskActionListUserName() {
087        return helpDeskActionListUserName;
088    }
089
090    public void setHelpDeskActionListUserName(String helpDeskActionListUserName) {
091        this.helpDeskActionListUserName = helpDeskActionListUserName;
092    }
093
094    @Override
095    public String getMethodToCall() {
096        return methodToCall;
097    }
098
099    @Override
100    public void setMethodToCall(String methodToCall) {
101        this.methodToCall = methodToCall;
102    }
103
104    public String getDelegator() {
105        return delegator;
106    }
107
108    public void setDelegator(String delegator) {
109        this.delegator = delegator;
110    }
111
112    public String getDocType() {
113        return docType;
114    }
115
116    public void setDocType(String docType) {
117        this.docType = docType;
118    }
119
120    public String getFilterLegend() {
121        return filterLegend;
122    }
123
124    public void setFilterLegend(String filterLegend) {
125        this.filterLegend = filterLegend;
126    }
127
128    public String getActionListType() {
129        if (actionListType == null) {
130            setActionListType("all");
131        }
132        return actionListType;
133    }
134
135    public void setActionListType(String actionListType) {
136        this.actionListType = actionListType;
137    }
138
139    public Boolean getCustomActionList() {
140        return customActionList;
141    }
142
143    public void setCustomActionList(Boolean customActionList) {
144        this.customActionList = customActionList;
145    }
146
147    public String getDefaultActionToTake() {
148        return defaultActionToTake;
149    }
150
151    public void setDefaultActionToTake(String defaultActionToTake) {
152        this.defaultActionToTake = defaultActionToTake;
153    }
154
155    public List<ActionToTake> getActionsToTake() {
156        return actionsToTake;
157    }
158
159    public void setActionsToTake(List<ActionToTake> actionsToTake) {
160        this.actionsToTake = actionsToTake;
161    }
162
163    public ActionToTake getActions(int index) {
164        while (getActionsToTake().size() <= index) {
165            getActionsToTake().add(new ActionToTake());
166        }
167        return getActionsToTake().get(index);
168    }
169
170    public Map<?, ?> getDefaultActions() {
171        return defaultActions;
172    }
173
174    public void setDefaultActions(Map<?, ?> defaultActions) {
175        this.defaultActions = defaultActions;
176    }
177
178    public String getDelegationId() {
179        return delegationId;
180    }
181
182    public void setDelegationId(String delegationId) {
183        this.delegationId = delegationId;
184    }
185
186    public List<?> getDelegators() {
187        return delegators;
188    }
189
190    public void setDelegators(List<?> delegators) {
191        this.delegators = delegators;
192    }
193
194    public Boolean getHasCustomActions() {
195        return hasCustomActions;
196    }
197
198    public void setHasCustomActions(Boolean hasCustomActions) {
199        this.hasCustomActions = hasCustomActions;
200    }
201
202    public String getDir() {
203        return dir;
204    }
205
206    public void setDir(String dir) {
207        this.dir = dir;
208    }
209
210    public Integer getPage() {
211        return page;
212    }
213
214    public void setPage(Integer page) {
215        this.page = page;
216    }
217
218    public String getSort() {
219        return sort;
220    }
221
222    public void setSort(String sort) {
223        this.sort = sort;
224    }
225
226    public Integer getCurrentPage() {
227        return currentPage;
228    }
229
230    public void setCurrentPage(Integer currentPage) {
231        this.currentPage = currentPage;
232    }
233
234    public String getCurrentDir() {
235        return currentDir;
236    }
237
238    public void setCurrentDir(String currentDir) {
239        this.currentDir = currentDir;
240    }
241
242    public String getCurrentSort() {
243        return currentSort;
244    }
245
246    public void setCurrentSort(String currentSort) {
247        this.currentSort = currentSort;
248    }
249
250    public int getCount() {
251        return count;
252    }
253
254    public void setCount(int count) {
255        this.count = count;
256    }
257
258    public String getCssFile() {
259        return cssFile;
260    }
261
262    public void setCssFile(String cssFile) {
263        this.cssFile = cssFile;
264    }
265
266    public String getLogoAlign() {
267        return logoAlign;
268    }
269
270    public void setLogoAlign(String logoAlign) {
271        this.logoAlign = logoAlign;
272    }
273
274    public String getViewOutbox() {
275        return this.viewOutbox;
276    }
277
278    public void setViewOutbox(String viewOutbox) {
279        this.viewOutbox = viewOutbox;
280    }
281
282    public String[] getOutboxItems() {
283        return outboxItems;
284    }
285
286    public void setOutboxItems(String[] outboxItems) {
287        this.outboxItems = outboxItems;
288    }
289
290    public boolean isOutBoxEmpty() {
291        return this.outBoxEmpty;
292    }
293
294    public void setOutBoxEmpty(boolean outBoxEmpty) {
295        this.outBoxEmpty = outBoxEmpty;
296    }
297
298    public Boolean getShowOutbox() {
299        return this.showOutbox;
300    }
301
302    public void setShowOutbox(Boolean showOutbox) {
303        this.showOutbox = showOutbox;
304    }
305
306    public List<ExtraButton> getHeaderButtons() {
307        return this.headerButtons;
308    }
309
310    public void setHeaderButtons(List<ExtraButton> headerButtons) {
311        this.headerButtons = headerButtons;
312    }
313
314    public String getMenuBar() {
315        String url = "";
316        Properties parameters = new Properties();
317        url = UrlFactory.parameterizeUrl(KRADConstants.MAINTENANCE_ACTION, parameters);
318        String krBaseUrl = ConfigContext.getCurrentContextConfig().getKRBaseURL();
319        url = "<a href=\""
320                + url
321                + "\"><img src=\""
322                + krBaseUrl
323                + "/images/tinybutton-preferences.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
324        return url;
325    }
326
327    @Override
328    public void populate(HttpServletRequest request) {
329        setHeaderButtons(getHeaderButtons());
330
331        // take the UserSession from the HttpSession and add it to the request
332        request.setAttribute(KRADConstants.USER_SESSION_KEY, GlobalVariables.getUserSession());
333
334        //refactor actionlist.jsp not to be dependent on this
335        request.setAttribute("preferences", GlobalVariables.getUserSession().retrieveObject(KewApiConstants.PREFERENCES));
336
337        String principalId = GlobalVariables.getUserSession().getPrincipalId();
338        final Principal hdalPrinc = (Principal) GlobalVariables.getUserSession().retrieveObject(
339                KewApiConstants.HELP_DESK_ACTION_LIST_PRINCIPAL_ATTR_NAME);
340        if (hdalPrinc != null) {
341            setHelpDeskActionListUserName(hdalPrinc.getPrincipalName());
342        }
343        boolean isHelpDeskAuthorized = KimApiServiceLocator.getPermissionService().isAuthorized(principalId,
344                KewApiConstants.KEW_NAMESPACE, KewApiConstants.PermissionNames.VIEW_OTHER_ACTION_LIST,
345                new HashMap<String, String>());
346        if (isHelpDeskAuthorized) {
347            request.setAttribute("helpDeskActionList", "true");
348        }
349        //String routeLogPopup = "false";
350        //boolean routeLogPopupInd = Utilities.getKNSParameterBooleanValue(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KewApiConstants.ACTION_LIST_ROUTE_LOG_POPUP_IND);
351        //if (routeLogPopupInd) {
352        //      routeLogPopup = "true";
353        //}
354        //String documentPopup = "false";
355        //boolean documentPopupInd = Utilities.getKNSParameterBooleanValue(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KewApiConstants.ACTION_LIST_DOCUMENT_POPUP_IND);
356        //if (documentPopupInd) {
357        //    documentPopup = "true";
358        //}
359        setRouteLogPopup(CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(
360                KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE,
361                KewApiConstants.ACTION_LIST_ROUTE_LOG_POPUP_IND));
362        setDocumentPopup(CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(
363                KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE,
364                KewApiConstants.ACTION_LIST_DOCUMENT_POPUP_IND));
365        request.setAttribute("noRefresh", Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(
366                KewApiConstants.ACTION_LIST_NO_REFRESH)));
367        super.populate(request);
368    }
369
370    public Boolean getRouteLogPopup() {
371        return this.routeLogPopup;
372    }
373
374    public Boolean getDocumentPopup() {
375        return this.documentPopup;
376    }
377
378    public void setRouteLogPopup(Boolean routeLogPopup) {
379        this.routeLogPopup = routeLogPopup;
380    }
381
382    public void setDocumentPopup(Boolean documentPopup) {
383        this.documentPopup = documentPopup;
384    }
385
386    public Boolean getHasDisplayParameters() {
387        return this.hasDisplayParameters;
388    }
389
390    public void setHasDisplayParameters(Boolean hasDisplayParameters) {
391        this.hasDisplayParameters = hasDisplayParameters;
392    }
393
394    public List<WebFriendlyRecipient> getPrimaryDelegates() {
395        return this.primaryDelegates;
396    }
397
398    public void setPrimaryDelegates(List<WebFriendlyRecipient> primaryDelegates) {
399        this.primaryDelegates = primaryDelegates;
400    }
401
402    public String getPrimaryDelegateId() {
403        return this.primaryDelegateId;
404    }
405
406    public void setPrimaryDelegateId(String primaryDelegateId) {
407        this.primaryDelegateId = primaryDelegateId;
408    }
409
410}