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