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