Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.rule.web;
 
 
 import java.util.List;
 
 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;


A Struts Action for building and interacting with the Rule Quick Links.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class RuleQuickLinksAction extends KewKualiAction {
 
 	private static final Logger LOG = Logger.getLogger(RuleQuickLinksAction.class);
 	
 
     public ActionForward start(ActionMapping mappingActionForm formHttpServletRequest requestHttpServletResponse responsethrows Exception {
     	makeLookupPathParam(mappingrequest);
     	establishRequiredState(requestform);
         return mapping.findForward("basic");
     }
 
     @SuppressWarnings("unchecked")
         RuleQuickLinksForm qlForm = (RuleQuickLinksFormform;
         List<DocumentTypedocumentTypes;
         if (qlForm.getRootDocTypeName() != null) {
         	documentTypes = new ArrayList<DocumentType>();
             DocumentType docType = getDocumentTypeService().findByName(qlForm.getRootDocTypeName());
             documentTypes.add(docType);
             request.setAttribute("renderOpened".);
         } else {
         	documentTypes = getDocumentTypeService().findAllCurrentRootDocuments();
         }
     	int shouldDisplayCount = 0;
         for ( DocumentTypeQuickLinksStructure dt : qlForm.getDocumentTypeQuickLinksStructures() ) {
         	if ( dt.isShouldDisplay() ) {
         		shouldDisplayCount++;
         	}
         }
    	if ( shouldDisplayCount == 1 ) {
            request.setAttribute("renderOpened".);
    	}
        try {
            if ((documentTypeName != null) && getDocumentHelperService().getDocumentAuthorizer(documentTypeName).canInitiate(documentTypeName, GlobalVariables.getUserSession().getPerson())) {
                qlForm.setCanInitiateDocumentTypeDocumenttrue );
            }
        } catch (Exception ex) {
			// just skip - and don't display links
        	.error"Unable to check initiation permission for "documentTypeNameex );
		}
        return null;
    }
    public ActionForward addDelegationRule(ActionMapping mappingActionForm formHttpServletRequest requestHttpServletResponse responsethrows Exception {
    	ActionForward result = null;
        String ruleTemplateId = request.getParameter("delegationRule.ruleTemplate.id");
        String docTypeName = request.getParameter("delegationRule.documentType.name");
        List rules = getRuleService().search(docTypeNamenullruleTemplateId""nullnull..new HashMap(), null);
        
        if (rules.size() == 1) {
            RuleBaseValues rule = (RuleBaseValues)rules.get(0);
            String url = ConfigContext.getCurrentContextConfig().getKEWBaseURL() +
                "/DelegateRule.do?methodToCall=start" +
            	"&parentRuleId=" + rule.getId();
            result = new ActionForward(urltrue);
        } else {
        	makeLookupPathParam(mappingrequest);
        	result = new ActionForward(ConfigContext.getCurrentContextConfig().getKRBaseURL() + 
        			"/lookup.do?methodToCall=start&"stripMethodToCall(request.getQueryString()), true);
        }
        
        return result;
    }
	private List getDocumentTypeDataStructure(List rootDocuments) {
		List documentTypeQuickLinksStructures = new ArrayList();
		for (Iterator iter = rootDocuments.iterator(); iter.hasNext();) {
			if (! quickLinkStruct.getFlattenedNodes().isEmpty() || ! quickLinkStruct.getChildrenDocumentTypes().isEmpty()) {
				documentTypeQuickLinksStructures.add(quickLinkStruct);
			}
		}
		return documentTypeQuickLinksStructures;
	}


A bean to hold a DocumentType with its flattened nodes for rendering purposes on the quick links.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
    public static class DocumentTypeQuickLinksStructure {
        private DocumentType documentType;
        private List<RouteNodeflattenedNodes = new ArrayList<RouteNode>();
        private List<Permissionpermissions = null;
        
        private DocumentTypeQuickLinksStructure(DocumentType documentType) {
			this. = documentType;
			if ( documentType != null ) {
				List<RouteNodetempFlattenedNodes = KEWServiceLocator.getRouteNodeService()
						.getFlattenedNodesdocumentTypetrue );
				for ( RouteNode routeNode : tempFlattenedNodes ) {
					if ( routeNode.isFlexRM() || routeNode.isRoleNode() ) {
						.addnew RouteNodeForDisplayrouteNode ) );
					}
				}
                Collections.sort(,new Comparator() {
                    public int compare(Object o1Object o2) {
                        return ( ((RouteNode)o1).getRouteNodeName().compareTo(((RouteNode)o2).getRouteNodeName()));
                    }
                });
				for ( Iterator<DocumentTypeiter = documentType.getChildrenDocTypes().iterator(); iter.hasNext(); ) {
				}
                Collections.sort(,new Comparator() {
                    public int compare(Object o1Object o2) {
                         return ( ((DocumentTypeQuickLinksStructure)o1)..getLabel().compareTo(((DocumentTypeQuickLinksStructure)o2)..getLabel()));
                    }
                });
			}
		}
        public List getChildrenDocumentTypes() {
            return ;
        }
        public void setChildrenDocumentTypes(List<DocumentTypeQuickLinksStructurechildrenDocumentTypes) {
            this. = childrenDocumentTypes;
        }
        public DocumentType getDocumentType() {
            return ;
        }
        public void setDocumentType(DocumentType documentType) {
            this. = documentType;
        }
        public List getFlattenedNodes() {
            return ;
        }
        public void setFlattenedNodes(List<RouteNodeflattenedNodes) {
            this. = flattenedNodes;
        }
        public boolean isShouldDisplay() {
//			if (flattenedNodes.isEmpty()) {
//				for (DocumentTypeQuickLinksStructure docType : childrenDocumentTypes) {
//					if (docType.isShouldDisplay()) {
//						return true;
//					}
//				}
//				return false;
//			}
			return true;
		}
			if (  == null ) {
                Predicate p = and(
                        equal("attributeName""documentTypeName"),
                        equal("active""Y"),
                        equal("detailCriteria",
				 = KimApiServiceLocator.getPermissionService().findPermissions( QueryByCriteria.Builder.fromPredicates(p)).getResults();
//				sqlLogger.setLevel( Level.INFO );
			}
			return ;
		}
		public boolean isHasRelatedPermissions() {
			return !getPermissions().isEmpty();
		}
		public int getRelatedPermissionCount() {
			return getPermissions().size();
		}
    }
    public static class RouteNodeForDisplay extends RouteNode {
    	private static final long serialVersionUID = 1L;
    	
		public RouteNodeForDisplayRouteNode baseNode ) {
			this. = baseNode;
		}
		public boolean equals(Object obj) {
			return this..equals(obj);
		}
		}
			return this..getBranch();
		}
			return this..getConfigParams();
		}
		}
			return this..getDocumentType();
		}
		}
		}
		}
		}
		}
		public Integer getLockVerNbr() {
			return this..getLockVerNbr();
		}
		}
			return this..getNextNodes();
		}
		public String getNodeType() {
			return this..getNodeType();
		}
			return this..getPreviousNodes();
		}
		}
		}
		public String getRouteNodeId() {
			return this..getRouteNodeId();
		}
			return this..getRouteNodeName();
		}
			return this..getRuleTemplate();
		}
		public int hashCode() {
			return this..hashCode();
		}
		public boolean isExceptionGroupDefined() {
		}
		public boolean isFlexRM() {
			return this..isFlexRM();
		}
		public boolean isRoleNode() {
			return this..isRoleNode();
		}
		public String toString() {
			return this..toString();
		}
			if (  == null ) {
				QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
                Predicate p = and(
                    equal("template.namespaceCode".),
                    equal("template.name".),
                    equal("active""Y"),
                    equal("attributes[documentTypeName]"getDocumentType().getName())
                    // KULRICE-8538 -- Check the route node by looping through the results below.  If it is added
                    // into the predicate, no rows are ever returned.
                    // equal("attributes[routeNodeName]", getRouteNodeName())
                );
                builder.setPredicates(p);
                List<ResponsibilitypossibleResponsibilities =
                    KimApiServiceLocator.getResponsibilityService().findResponsibilities(builder.build()).getResults();
                if ( !possibleResponsibilities.isEmpty() ) {
                    for ( Responsibility resp : possibleResponsibilities ) {
                        String routeNodeName = resp.getAttributes().get..);
                        if (StringUtils.isNotEmpty(routeNodeName) && StringUtils.equals(routeNodeNamegetRouteNodeName())){
                             .add(resp);
                        }
                    }
                } else {
                     = possibleResponsibilities;
                }
			}
		}
		public int getResponsibilityCount() {
		}
		public boolean isHasResponsibility() {
		}
    }
    
    private void makeLookupPathParam(ActionMapping mappingHttpServletRequest request) {
    	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix();
    	request.setAttribute("basePath"basePath);
    }
    private String stripMethodToCall(String queryString) {
        return queryString.replaceAll("methodToCall=addDelegationRule&""");
    }
        return KEWServiceLocator.getDocumentTypeService();
    }
    private RuleServiceInternal getRuleService() {
    	return KEWServiceLocator.getRuleService();
    }
    
		if( == null){
		}
	}
		}
	}
			throws Exception {
		establishRequiredState(requestform);
		return super.toggleTab(mappingformrequestresponse);
	}
New to GrepCode? Check out our FAQ X