| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.rule.web; |
| 18 | |
|
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.HashMap; |
| 21 | |
import java.util.Iterator; |
| 22 | |
import java.util.List; |
| 23 | |
import java.util.Map; |
| 24 | |
|
| 25 | |
import javax.servlet.http.HttpServletRequest; |
| 26 | |
import javax.servlet.http.HttpServletResponse; |
| 27 | |
|
| 28 | |
import org.apache.log4j.Logger; |
| 29 | |
import org.apache.struts.action.ActionForm; |
| 30 | |
import org.apache.struts.action.ActionForward; |
| 31 | |
import org.apache.struts.action.ActionMapping; |
| 32 | |
import org.apache.struts.action.ActionMessages; |
| 33 | |
import org.kuali.rice.core.config.ConfigContext; |
| 34 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 35 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
| 36 | |
import org.kuali.rice.kew.engine.node.BranchPrototype; |
| 37 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
| 38 | |
import org.kuali.rice.kew.engine.node.RouteNodeConfigParam; |
| 39 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
| 40 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
| 41 | |
import org.kuali.rice.kew.rule.service.RuleService; |
| 42 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 43 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 44 | |
import org.kuali.rice.kew.web.KewKualiAction; |
| 45 | |
import org.kuali.rice.kim.bo.Group; |
| 46 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
| 47 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
| 48 | |
import org.kuali.rice.kim.bo.role.dto.KimResponsibilityInfo; |
| 49 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 50 | |
import org.kuali.rice.kns.service.DocumentHelperService; |
| 51 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 52 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
| 53 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 54 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | 0 | public class RuleQuickLinksAction extends KewKualiAction { |
| 63 | |
|
| 64 | 0 | private static final Logger LOG = Logger.getLogger(RuleQuickLinksAction.class); |
| 65 | |
|
| 66 | |
private MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
| 67 | |
private DocumentHelperService documentHelperService; |
| 68 | |
|
| 69 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 70 | 0 | makeLookupPathParam(mapping, request); |
| 71 | 0 | establishRequiredState(request, form); |
| 72 | 0 | return mapping.findForward("basic"); |
| 73 | |
} |
| 74 | |
|
| 75 | |
@SuppressWarnings("unchecked") |
| 76 | |
public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception { |
| 77 | 0 | RuleQuickLinksForm qlForm = (RuleQuickLinksForm) form; |
| 78 | |
List<DocumentType> documentTypes; |
| 79 | 0 | if (qlForm.getRootDocTypeName() != null) { |
| 80 | 0 | documentTypes = new ArrayList<DocumentType>(); |
| 81 | 0 | DocumentType docType = getDocumentTypeService().findByName(qlForm.getRootDocTypeName()); |
| 82 | 0 | documentTypes.add(docType); |
| 83 | 0 | request.setAttribute("renderOpened", Boolean.TRUE); |
| 84 | 0 | } else { |
| 85 | 0 | documentTypes = getDocumentTypeService().findAllCurrentRootDocuments(); |
| 86 | |
} |
| 87 | 0 | qlForm.setDocumentTypeQuickLinksStructures(getDocumentTypeDataStructure(documentTypes)); |
| 88 | 0 | int shouldDisplayCount = 0; |
| 89 | 0 | for ( DocumentTypeQuickLinksStructure dt : qlForm.getDocumentTypeQuickLinksStructures() ) { |
| 90 | 0 | if ( dt.isShouldDisplay() ) { |
| 91 | 0 | shouldDisplayCount++; |
| 92 | |
} |
| 93 | |
} |
| 94 | 0 | if ( shouldDisplayCount == 1 ) { |
| 95 | 0 | request.setAttribute("renderOpened", Boolean.TRUE); |
| 96 | |
} |
| 97 | 0 | String documentTypeName = getMaintenanceDocumentDictionaryService().getDocumentTypeName(DocumentType.class); |
| 98 | |
try { |
| 99 | 0 | if ((documentTypeName != null) && getDocumentHelperService().getDocumentAuthorizer(documentTypeName).canInitiate(documentTypeName, GlobalVariables.getUserSession().getPerson())) { |
| 100 | 0 | qlForm.setCanInitiateDocumentTypeDocument( true ); |
| 101 | |
} |
| 102 | 0 | } catch (Exception ex) { |
| 103 | |
|
| 104 | 0 | LOG.error( "Unable to check initiation permission for "+ documentTypeName, ex ); |
| 105 | 0 | } |
| 106 | |
|
| 107 | 0 | return null; |
| 108 | |
} |
| 109 | |
|
| 110 | |
public ActionForward addDelegationRule(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 111 | 0 | ActionForward result = null; |
| 112 | |
|
| 113 | 0 | Long ruleTemplateId = new Long(request.getParameter("delegationRuleBaseValues.ruleTemplate.ruleTemplateId")); |
| 114 | 0 | String docTypeName = request.getParameter("delegationRuleBaseValues.documentType.name"); |
| 115 | 0 | List rules = getRuleService().search(docTypeName, null, ruleTemplateId, "", null, null, Boolean.FALSE, Boolean.TRUE, new HashMap(), null); |
| 116 | |
|
| 117 | 0 | if (rules.size() == 1) { |
| 118 | 0 | RuleBaseValues rule = (RuleBaseValues)rules.get(0); |
| 119 | 0 | String url = ConfigContext.getCurrentContextConfig().getKEWBaseURL() + |
| 120 | |
"/DelegateRule.do?methodToCall=start" + |
| 121 | |
"&parentRuleId=" + rule.getRuleBaseValuesId(); |
| 122 | 0 | result = new ActionForward(url, true); |
| 123 | 0 | } else { |
| 124 | 0 | makeLookupPathParam(mapping, request); |
| 125 | 0 | result = new ActionForward(ConfigContext.getCurrentContextConfig().getKRBaseURL() + |
| 126 | |
"/lookup.do?methodToCall=start&"+ stripMethodToCall(request.getQueryString()), true); |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | return result; |
| 130 | |
} |
| 131 | |
|
| 132 | |
private List getDocumentTypeDataStructure(List rootDocuments) { |
| 133 | 0 | List documentTypeQuickLinksStructures = new ArrayList(); |
| 134 | 0 | for (Iterator iter = rootDocuments.iterator(); iter.hasNext();) { |
| 135 | 0 | DocumentTypeQuickLinksStructure quickLinkStruct =new DocumentTypeQuickLinksStructure((DocumentType) iter.next()); |
| 136 | 0 | if (! quickLinkStruct.getFlattenedNodes().isEmpty() || ! quickLinkStruct.getChildrenDocumentTypes().isEmpty()) { |
| 137 | 0 | documentTypeQuickLinksStructures.add(quickLinkStruct); |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | } |
| 141 | |
|
| 142 | 0 | return documentTypeQuickLinksStructures; |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | 0 | public static class DocumentTypeQuickLinksStructure { |
| 153 | |
private DocumentType documentType; |
| 154 | 0 | private List<RouteNode> flattenedNodes = new ArrayList<RouteNode>(); |
| 155 | 0 | private List<DocumentTypeQuickLinksStructure> childrenDocumentTypes = new ArrayList<DocumentTypeQuickLinksStructure>(); |
| 156 | 0 | private List<KimPermissionInfo> permissions = null; |
| 157 | |
|
| 158 | 0 | private DocumentTypeQuickLinksStructure(DocumentType documentType) { |
| 159 | 0 | this.documentType = documentType; |
| 160 | 0 | if ( documentType != null ) { |
| 161 | 0 | List<RouteNode> tempFlattenedNodes = KEWServiceLocator.getRouteNodeService() |
| 162 | |
.getFlattenedNodes( documentType, true ); |
| 163 | 0 | for ( RouteNode routeNode : tempFlattenedNodes ) { |
| 164 | 0 | if ( routeNode.isFlexRM() || routeNode.isRoleNode() ) { |
| 165 | 0 | flattenedNodes.add( new RouteNodeForDisplay( routeNode ) ); |
| 166 | |
} |
| 167 | |
} |
| 168 | 0 | for ( Iterator<DocumentType> iter = documentType.getChildrenDocTypes().iterator(); iter.hasNext(); ) { |
| 169 | 0 | childrenDocumentTypes.add( new DocumentTypeQuickLinksStructure( iter.next() ) ); |
| 170 | |
} |
| 171 | |
} |
| 172 | 0 | } |
| 173 | |
|
| 174 | |
public List getChildrenDocumentTypes() { |
| 175 | 0 | return childrenDocumentTypes; |
| 176 | |
} |
| 177 | |
public void setChildrenDocumentTypes(List<DocumentTypeQuickLinksStructure> childrenDocumentTypes) { |
| 178 | 0 | this.childrenDocumentTypes = childrenDocumentTypes; |
| 179 | 0 | } |
| 180 | |
public DocumentType getDocumentType() { |
| 181 | 0 | return documentType; |
| 182 | |
} |
| 183 | |
public void setDocumentType(DocumentType documentType) { |
| 184 | 0 | this.documentType = documentType; |
| 185 | 0 | } |
| 186 | |
public List getFlattenedNodes() { |
| 187 | 0 | return flattenedNodes; |
| 188 | |
} |
| 189 | |
public void setFlattenedNodes(List<RouteNode> flattenedNodes) { |
| 190 | 0 | this.flattenedNodes = flattenedNodes; |
| 191 | 0 | } |
| 192 | |
public boolean isShouldDisplay() { |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | 0 | return true; |
| 202 | |
} |
| 203 | |
|
| 204 | |
public List<KimPermissionInfo> getPermissions() { |
| 205 | 0 | if ( permissions == null ) { |
| 206 | |
|
| 207 | |
|
| 208 | 0 | Map<String,String> searchCriteria = new HashMap<String,String>(); |
| 209 | 0 | searchCriteria.put("attributeName", "documentTypeName" ); |
| 210 | 0 | searchCriteria.put("active", "Y"); |
| 211 | 0 | searchCriteria.put("detailCriteria", |
| 212 | |
KimAttributes.DOCUMENT_TYPE_NAME+"="+getDocumentType().getName() |
| 213 | |
); |
| 214 | 0 | permissions = KIMServiceLocator.getPermissionService().lookupPermissions( searchCriteria, false ); |
| 215 | |
|
| 216 | |
} |
| 217 | 0 | return permissions; |
| 218 | |
} |
| 219 | |
|
| 220 | |
public boolean isHasRelatedPermissions() { |
| 221 | 0 | return !getPermissions().isEmpty(); |
| 222 | |
} |
| 223 | |
|
| 224 | |
public int getRelatedPermissionCount() { |
| 225 | 0 | return getPermissions().size(); |
| 226 | |
} |
| 227 | |
} |
| 228 | |
|
| 229 | 0 | public static class RouteNodeForDisplay extends RouteNode { |
| 230 | |
private static final long serialVersionUID = 1L; |
| 231 | |
private RouteNode baseNode; |
| 232 | |
|
| 233 | 0 | public RouteNodeForDisplay( RouteNode baseNode ) { |
| 234 | 0 | this.baseNode = baseNode; |
| 235 | 0 | } |
| 236 | |
|
| 237 | |
public boolean equals(Object obj) { |
| 238 | 0 | return this.baseNode.equals(obj); |
| 239 | |
} |
| 240 | |
|
| 241 | |
public String getActivationType() { |
| 242 | 0 | return this.baseNode.getActivationType(); |
| 243 | |
} |
| 244 | |
|
| 245 | |
public BranchPrototype getBranch() { |
| 246 | 0 | return this.baseNode.getBranch(); |
| 247 | |
} |
| 248 | |
|
| 249 | |
public List<RouteNodeConfigParam> getConfigParams() { |
| 250 | 0 | return this.baseNode.getConfigParams(); |
| 251 | |
} |
| 252 | |
|
| 253 | |
public String getContentFragment() { |
| 254 | 0 | return this.baseNode.getContentFragment(); |
| 255 | |
} |
| 256 | |
|
| 257 | |
public DocumentType getDocumentType() { |
| 258 | 0 | return this.baseNode.getDocumentType(); |
| 259 | |
} |
| 260 | |
|
| 261 | |
public Long getDocumentTypeId() { |
| 262 | 0 | return this.baseNode.getDocumentTypeId(); |
| 263 | |
} |
| 264 | |
public Group getExceptionWorkgroup() { |
| 265 | 0 | return this.baseNode.getExceptionWorkgroup(); |
| 266 | |
} |
| 267 | |
public String getExceptionWorkgroupId() { |
| 268 | 0 | return this.baseNode.getExceptionWorkgroupId(); |
| 269 | |
} |
| 270 | |
public String getExceptionWorkgroupName() { |
| 271 | 0 | return this.baseNode.getExceptionWorkgroupName(); |
| 272 | |
} |
| 273 | |
public Boolean getFinalApprovalInd() { |
| 274 | 0 | return this.baseNode.getFinalApprovalInd(); |
| 275 | |
} |
| 276 | |
public Integer getLockVerNbr() { |
| 277 | 0 | return this.baseNode.getLockVerNbr(); |
| 278 | |
} |
| 279 | |
public Boolean getMandatoryRouteInd() { |
| 280 | 0 | return this.baseNode.getMandatoryRouteInd(); |
| 281 | |
} |
| 282 | |
public List<RouteNode> getNextNodes() { |
| 283 | 0 | return this.baseNode.getNextNodes(); |
| 284 | |
} |
| 285 | |
public String getNodeType() { |
| 286 | 0 | return this.baseNode.getNodeType(); |
| 287 | |
} |
| 288 | |
public List<RouteNode> getPreviousNodes() { |
| 289 | 0 | return this.baseNode.getPreviousNodes(); |
| 290 | |
} |
| 291 | |
public String getRouteMethodCode() { |
| 292 | 0 | return this.baseNode.getRouteMethodCode(); |
| 293 | |
} |
| 294 | |
public String getRouteMethodName() { |
| 295 | 0 | return this.baseNode.getRouteMethodName(); |
| 296 | |
} |
| 297 | |
public Long getRouteNodeId() { |
| 298 | 0 | return this.baseNode.getRouteNodeId(); |
| 299 | |
} |
| 300 | |
public String getRouteNodeName() { |
| 301 | 0 | return this.baseNode.getRouteNodeName(); |
| 302 | |
} |
| 303 | |
public RuleTemplate getRuleTemplate() { |
| 304 | 0 | return this.baseNode.getRuleTemplate(); |
| 305 | |
} |
| 306 | |
public int hashCode() { |
| 307 | 0 | return this.baseNode.hashCode(); |
| 308 | |
} |
| 309 | |
public boolean isExceptionGroupDefined() { |
| 310 | 0 | return this.baseNode.isExceptionGroupDefined(); |
| 311 | |
} |
| 312 | |
public boolean isFlexRM() { |
| 313 | 0 | return this.baseNode.isFlexRM(); |
| 314 | |
} |
| 315 | |
public boolean isRoleNode() { |
| 316 | 0 | return this.baseNode.isRoleNode(); |
| 317 | |
} |
| 318 | |
public String toString() { |
| 319 | 0 | return this.baseNode.toString(); |
| 320 | |
} |
| 321 | |
|
| 322 | 0 | private List<? extends KimResponsibilityInfo> responsibilities = null; |
| 323 | |
|
| 324 | |
public List<? extends KimResponsibilityInfo> getResponsibilities() { |
| 325 | 0 | if ( responsibilities == null ) { |
| 326 | 0 | Map<String,String> searchCriteria = new HashMap<String,String>(); |
| 327 | 0 | searchCriteria.put("template.namespaceCode", KNSConstants.KUALI_RICE_WORKFLOW_NAMESPACE); |
| 328 | 0 | searchCriteria.put("template.name", KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME); |
| 329 | 0 | searchCriteria.put("active", "Y"); |
| 330 | 0 | searchCriteria.put("detailCriteria", |
| 331 | |
KimAttributes.DOCUMENT_TYPE_NAME+"="+getDocumentType().getName() |
| 332 | |
+ "," |
| 333 | |
+ KimAttributes.ROUTE_NODE_NAME+"="+getRouteNodeName() ); |
| 334 | 0 | responsibilities = KIMServiceLocator.getResponsibilityService().lookupResponsibilityInfo(searchCriteria, true); |
| 335 | |
} |
| 336 | 0 | return responsibilities; |
| 337 | |
} |
| 338 | |
|
| 339 | |
public int getResponsibilityCount() { |
| 340 | 0 | return getResponsibilities().size(); |
| 341 | |
} |
| 342 | |
|
| 343 | |
public boolean isHasResponsibility() { |
| 344 | 0 | return !getResponsibilities().isEmpty(); |
| 345 | |
} |
| 346 | |
} |
| 347 | |
|
| 348 | |
private void makeLookupPathParam(ActionMapping mapping, HttpServletRequest request) { |
| 349 | 0 | String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix(); |
| 350 | 0 | request.setAttribute("basePath", basePath); |
| 351 | 0 | } |
| 352 | |
|
| 353 | |
private String stripMethodToCall(String queryString) { |
| 354 | 0 | return queryString.replaceAll("methodToCall=addDelegationRule&", ""); |
| 355 | |
} |
| 356 | |
|
| 357 | |
private DocumentTypeService getDocumentTypeService() { |
| 358 | 0 | return KEWServiceLocator.getDocumentTypeService(); |
| 359 | |
} |
| 360 | |
|
| 361 | |
private RuleService getRuleService() { |
| 362 | 0 | return KEWServiceLocator.getRuleService(); |
| 363 | |
} |
| 364 | |
|
| 365 | |
public DocumentHelperService getDocumentHelperService() { |
| 366 | 0 | if(documentHelperService == null){ |
| 367 | 0 | documentHelperService = KNSServiceLocator.getDocumentHelperService(); |
| 368 | |
} |
| 369 | 0 | return documentHelperService; |
| 370 | |
} |
| 371 | |
|
| 372 | |
public MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
| 373 | 0 | if(maintenanceDocumentDictionaryService == null){ |
| 374 | 0 | maintenanceDocumentDictionaryService = KNSServiceLocator.getMaintenanceDocumentDictionaryService(); |
| 375 | |
} |
| 376 | 0 | return maintenanceDocumentDictionaryService; |
| 377 | |
} |
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
@Override |
| 383 | |
public ActionForward toggleTab(ActionMapping mapping, ActionForm form, |
| 384 | |
HttpServletRequest request, HttpServletResponse response) |
| 385 | |
throws Exception { |
| 386 | |
|
| 387 | 0 | establishRequiredState(request, form); |
| 388 | 0 | return super.toggleTab(mapping, form, request, response); |
| 389 | |
} |
| 390 | |
|
| 391 | |
} |