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.dao.impl;
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 
     public List<RuleDelegationBofindByDelegateRuleId(String ruleId) {
         Criteria crit = new Criteria();
         crit.addEqualTo("delegateRuleId"ruleId);
         return (Listthis.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleDelegationBo.classcrit));
     }
 
     public void save(RuleDelegationBo ruleDelegation) {
     	this.getPersistenceBrokerTemplate().store(ruleDelegation);
     }
         Criteria crit = new Criteria();
         crit.addEqualTo("delegationRule.currentInd"true);
         return (Listthis.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleDelegationBo.classcrit));
     }
 
     public RuleDelegationBo findByRuleDelegationId(String ruleDelegationId){
         Criteria crit = new Criteria();
         crit.addEqualTo("ruleDelegationId"ruleDelegationId);
 
     }
     public void delete(String ruleDelegationId){
     	this.getPersistenceBrokerTemplate().delete(findByRuleDelegationId(ruleDelegationId));
     }
 
     public List<RuleDelegationBofindByResponsibilityIdWithCurrentRule(String responsibilityId) {
     	Criteria crit = new Criteria();
     	crit.addEqualTo("responsibilityId"responsibilityId);
     	crit.addEqualTo("delegationRule.currentInd"true);
     	return new ArrayList<RuleDelegationBo>(delegations);
     }

    
 
     public List<RuleDelegationBosearch(String parentRuleBaseVaueIdString parentResponsibilityIdString docTypeNameString ruleId,
             String ruleTemplateIdString ruleDescriptionString workgroupId,
             String principalIdString delegationTypeBoolean activeInd,
             Map extensionValuesString workflowIdDirective) {
         Criteria crit = new Criteria(); //getSearchCriteria(docTypeName, ruleTemplateId, ruleDescription, delegationType, activeInd, extensionValues);
 
         if (StringUtils.isNotBlank(delegationType) && !delegationType.equals(.)) {
         	crit.addEqualTo("delegationType"delegationType);
         }
         
         if (StringUtils.isNotBlank(parentRuleBaseVaueId) && StringUtils.isNumeric(parentRuleBaseVaueId)) {
             crit.addIn("responsibilityId"this.getRuleResponsibilitySubQuery(new Long(parentRuleBaseVaueId)));
         }
 
         if (StringUtils.isNotBlank(parentResponsibilityId) && StringUtils.isNumeric(parentResponsibilityId)) {
             crit.addEqualTo("responsibilityId"parentResponsibilityId);
         }
        crit.addIn("delegateRuleId"getRuleBaseValuesSubQuery(docTypeNameruleId,
                                                               ruleTemplateIdruleDescriptionworkgroupId,
                                                               principalIdactiveInd,
                                                               extensionValuesworkflowIdDirective));
        QueryByCriteria query = new QueryByCriteria(RuleDelegationBo.classcrittrue);
    }

    
    public List<RuleDelegationBosearch(String parentRuleBaseVaueIdString parentResponsibilityIdString docTypeNameString ruleTemplateId,
            String ruleDescriptionCollection<StringworkgroupIds,
            String workflowIdString delegationTypeBoolean activeInd,
            Map extensionValuesCollection actionRequestCodes) {
        Criteria crit = new Criteria();
        
        if (StringUtils.isNotBlank(delegationType) && !delegationType.equals(.)) {
        	crit.addEqualTo("delegationType"delegationType);
        }
        
        if (StringUtils.isNotBlank(parentRuleBaseVaueId) && StringUtils.isNumeric(parentRuleBaseVaueId)) {
            crit.addIn("responsibilityId"this.getRuleResponsibilitySubQuery(new Long(parentRuleBaseVaueId)));
        }
        if (StringUtils.isNotBlank(parentResponsibilityId) && StringUtils.isNumeric(parentResponsibilityId)) {
            crit.addEqualTo("responsibilityId"parentResponsibilityId);
        }
        crit.addIn("delegateRuleId"getRuleBaseValuesSubQuery(docTypeNameruleTemplateId,
                                                               ruleDescriptionworkgroupIds,
                                                               workflowIdactiveInd,
                                                               extensionValuesactionRequestCodes));
        QueryByCriteria query = new QueryByCriteria(RuleDelegationBo.classcrittrue);
        return (Listthis.getPersistenceBrokerTemplate().getCollectionByQuery(query);
    }
    private ReportQueryByCriteria getResponsibilitySubQuery(String ruleResponsibilityName) {
        Criteria responsibilityCrit = new Criteria();
        responsibilityCrit.addLike("ruleResponsibilityName"ruleResponsibilityName);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.classresponsibilityCrit);
        query.setAttributes(new String[] { "ruleBaseValuesId" });
        return query;
    }
            Set<StringworkgroupIdStrings = new HashSet<String>();
            for (Long workgroupId : workgroupIds) {
                workgroupIdStrings.add(workgroupId.toString());
            }
        Criteria responsibilityCrit = new Criteria();
        responsibilityCrit.addIn("ruleResponsibilityName"workgroupIds);
        responsibilityCrit.addEqualTo("ruleResponsibilityType".);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.classresponsibilityCrit);
        query.setAttributes(new String[] { "ruleBaseValuesId" });
        return query;
    }
    private ReportQueryByCriteria getRuleBaseValuesSubQuery(String docTypeNameString ruleTemplateId,
            String ruleDescriptionCollection<StringworkgroupIds,
            String workflowIdBoolean activeInd,
            Map<StringStringextensionValuesCollection actionRequestCodes) {
        Criteria crit = getSearchCriteria(docTypeNameruleTemplateIdruleDescriptionactiveIndextensionValues);
        crit.addIn("responsibilities.ruleBaseValuesId"getResponsibilitySubQuery(workgroupIdsworkflowIdactionRequestCodes, (workflowId != null), ((workgroupIds != null) && !workgroupIds.isEmpty())));
        crit.addEqualTo("delegateRule", 1);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleBaseValues.classcrit);
        query.setAttributes(new String[] { "id" });
        return query;
    }
    private ReportQueryByCriteria getRuleBaseValuesSubQuery(String docTypeNameString ruleId,
            String ruleTemplateIdString ruleDescriptionString workgroupId,
            String principalIdBoolean activeInd,
            Map<StringStringextensionValuesString workflowIdDirective) {
        Criteria crit = getSearchCriteria(docTypeNameruleTemplateIdruleDescriptionactiveIndextensionValues);
        if (ruleId != null) {
            crit.addEqualTo("id"ruleId);
        }
        if (workgroupId != null) {
            crit.addIn("ruleResponsibilities.ruleBaseValuesId"getResponsibilitySubQuery(workgroupId));
        }
        List<StringworkgroupIds = new ArrayList<String>();
        Boolean searchUser = .;
        Boolean searchUserInWorkgroups = .;
        if (workflowIdDirective != null) {
            if ("group".equals(workflowIdDirective)) {
                searchUserInWorkgroups = .;
            } else if ("".equals(workflowIdDirective)) {
                searchUser = .;
                searchUserInWorkgroups = .;
            } else {
                searchUser = .;
            }
        }
        if (!org.apache.commons.lang.StringUtils.isEmpty(principalId) && searchUserInWorkgroups)
        {
            Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
            if (principal == null)
            {
                throw new RiceRuntimeException("Failed to locate user for the given workflow id: " + principalId);
            }
            workgroupIds = KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(principalId);
        }
        if (CollectionUtils.isNotEmpty(workgroupIds) || StringUtils.isNotBlank(principalId)) {
            crit.addIn("ruleResponsibilities.ruleBaseValuesId"getResponsibilitySubQuery(workgroupIdsprincipalIdsearchUsersearchUserInWorkgroups));
        }
        crit.addEqualTo("delegateRule", 1);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleBaseValues.classcrit);
        query.setAttributes(new String[] { "id" });
        return query;
        //return (List<RuleDelegation>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleDelegation.class, crit, true));
    }
    private ReportQueryByCriteria getRuleResponsibilitySubQuery(Long ruleBaseValuesId) {
        Criteria crit = new Criteria();
        crit.addEqualTo("ruleBaseValuesId"ruleBaseValuesId);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.classcrit);
        query.setAttributes(new String[] { "responsibilityId" });
        return query;
        //return getResponsibilitySubQuery(workgroupIdStrings,workflowId,new ArrayList<String>(), searchUser, searchUserInWorkgroups);
    }
    private ReportQueryByCriteria getResponsibilitySubQuery(List<StringworkgroupIdsString workflowIdBoolean searchUserBoolean searchUserInWorkgroups) {
        Collection<StringworkgroupIdStrings = new ArrayList<String>();
        for (String workgroupId : workgroupIds) {
            workgroupIdStrings.add(workgroupId);
        }
        return getResponsibilitySubQuery(workgroupIdStrings,workflowId,new ArrayList<String>(), searchUsersearchUserInWorkgroups);
    }
    private ReportQueryByCriteria getResponsibilitySubQuery(Collection<StringworkgroupIdsString workflowIdCollection<StringactionRequestCodesBoolean searchUserBoolean searchUserInWorkgroups) {
        Criteria responsibilityCrit = new Criteria();
        if ( (actionRequestCodes != null) && (!actionRequestCodes.isEmpty()) ) {
            responsibilityCrit.addIn("actionRequestedCd"actionRequestCodes);
        }
        Criteria ruleResponsibilityNameCrit = null;
        if (!org.apache.commons.lang.StringUtils.isEmpty(workflowId)) {
            // workflow user id exists
            if (searchUser != null && searchUser) {
                // searching user wishes to search for rules specific to user
                ruleResponsibilityNameCrit = new Criteria();
                ruleResponsibilityNameCrit.addLike("ruleResponsibilityName"workflowId);
                ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType".);
            }
            if ( (searchUserInWorkgroups != null && searchUserInWorkgroups) && (workgroupIds != null) && (!workgroupIds.isEmpty()) ) {
                // at least one workgroup id exists and user wishes to search on workgroups
                if (ruleResponsibilityNameCrit == null) {
                    ruleResponsibilityNameCrit = new Criteria();
                }
                Criteria workgroupCrit = new Criteria();
                workgroupCrit.addIn("ruleResponsibilityName"workgroupIds);
                workgroupCrit.addEqualTo("ruleResponsibilityType".);
                ruleResponsibilityNameCrit.addOrCriteria(workgroupCrit);
            }
        } else if ( (workgroupIds != null) && (workgroupIds.size() == 1) ) {
            // no user and one workgroup id
            ruleResponsibilityNameCrit = new Criteria();
            ruleResponsibilityNameCrit.addLike("ruleResponsibilityName"workgroupIds.iterator().next());
            ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType".);
        } else if ( (workgroupIds != null) && (workgroupIds.size() > 1) ) {
            // no user and more than one workgroup id
            ruleResponsibilityNameCrit = new Criteria();
            ruleResponsibilityNameCrit.addIn("ruleResponsibilityName"workgroupIds);
            ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType".);
        }
        if (ruleResponsibilityNameCrit != null) {
            responsibilityCrit.addAndCriteria(ruleResponsibilityNameCrit);
        }
        ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.classresponsibilityCrit);
        query.setAttributes(new String[] { "ruleBaseValuesId" });
        return query;
    }
    private Criteria getSearchCriteria(String docTypeNameString ruleTemplateIdString ruleDescriptionBoolean activeIndMap<StringStringextensionValues) {
        Criteria crit = new Criteria();
        crit.addEqualTo("currentInd".);
        crit.addEqualTo("templateRuleInd".);
        if (activeInd != null) {
            crit.addEqualTo("active"activeInd);
        }
        if (docTypeName != null) {
            crit.addLike("UPPER(docTypeName)"docTypeName.toUpperCase());
        }
        if (ruleDescription != null && !ruleDescription.trim().equals("")) {
            crit.addLike("UPPER(description)"ruleDescription.toUpperCase());
        }
        if (ruleTemplateId != null) {
            crit.addEqualTo("ruleTemplateId"ruleTemplateId);
        }
        if (extensionValues != null && !extensionValues.isEmpty()) {
            for (Map.Entry<String,Stringentry : extensionValues.entrySet()) {
                if (!org.apache.commons.lang.StringUtils.isEmpty(entry.getValue())) {
                    // Criteria extensionCrit = new Criteria();
                    // extensionCrit.addEqualTo("extensionValues.key",
                    // entry.getKey());
                    // extensionCrit.addLike("extensionValues.value",
                    // "%"+(String) entry.getValue()+"%");
                    Criteria extensionCrit2 = new Criteria();
                    extensionCrit2.addEqualTo("extensionValues.key"entry.getKey());
                    extensionCrit2.addLike("UPPER(extensionValues.value)", ("%" + (Stringentry.getValue() + "%").toUpperCase());
                    // Criteria extensionCrit3 = new Criteria();
                    // extensionCrit3.addEqualTo("extensionValues.key",
                    // entry.getKey());
                    // extensionCrit3.addLike("extensionValues.value",
                    // ("%"+(String) entry.getValue()+"%").toLowerCase());
                    // extensionCrit.addOrCriteria(extensionCrit2);
                    // extensionCrit.addOrCriteria(extensionCrit3);
                    ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleExtensionBo.classextensionCrit2);
                    query.setAttributes(new String[] { "ruleBaseValuesId" });
                    crit.addIn("ruleExtensions.ruleBaseValuesId"query);
                }
            }
        }
        return crit;
    }
New to GrepCode? Check out our FAQ X