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.document;
 
 
 import java.util.List;
 import java.util.Map;

This is a description of what this class does - Garey don't forget to fill this in.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 
 			MaintenanceDocument document) {
 
 		boolean isValid = true;
 
 		RuleBaseValues ruleBaseValues = this.getRuleBaseValues(document);
 		RuleBaseValues oldRuleBaseValues = this.getOldRuleBaseValues(document);
 		
 		isValid &= this.populateErrorMap(ruleBaseValues);
 
 
 		return isValid;
 	}
 
 	}
 	
 	}
 	
 
 	protected void populateErrorMap(Map<String,StringerrorMap){
 		for(Map.Entry<StringStringentry : errorMap.entrySet()){
 			this.putFieldError(entry.getKey(), entry.getValue());
 		}
 	}

 
 			MaintenanceDocument documentString collectionName,
 
 		boolean isValid = true;
 
 		if(getPersonSectionName().equals(collectionName)){
 			String name = pr.getPrincipalName();
 
			if(!personExists(name)){
				isValid &= false;
				this.putFieldError(getPersonSectionName(), "error.document.personResponsibilities.principleDoesNotExist");
			}
		}else if(getGroupSectionName().equals(collectionName)){
				isValid &= false;
				this.putFieldError(getGroupSectionName(), "error.document.personResponsibilities.groupDoesNotExist");
			}
		}
		return isValid;
	}
	}
	}
	protected boolean personExists(String principalName){
		boolean bRet = false;
		try{
			KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(principalName);
			bRet = true;
		}catch(Exception ex){
			bRet = false;
			//ex.printStackTrace();
		}
		return bRet;
	}
	protected boolean groupExists(String namespaceCodeString groupName){
		boolean bRet = false;
		try{
			KEWServiceLocator.getIdentityHelperService().getGroupByName(namespaceCodegroupName);
			bRet = true;
		}catch(Exception ex){
			bRet = false;
			//ex.printStackTrace();
		}
		return bRet;
	}
	protected boolean populateErrorMap(RuleBaseValues ruleBaseValues){
		boolean isValid = true;
		if (getDocumentTypeService().findByName(ruleBaseValues.getDocTypeName()) == null) {
            this.putFieldError("docTypeName""doctype.documenttypeservice.doctypename.required");
            isValid &= false;
        }
        if(ruleBaseValues.getName() != null){
        	if(ruleExists(ruleBaseValues)){
        		this.putFieldError("name""routetemplate.ruleservice.name.unique");
            	isValid &= false;
        	}
        }
        /*
         * Logic: If both from and to dates exist, make sure toDate is after fromDate
         */
        if(ruleBaseValues.getToDateValue() != null && ruleBaseValues.getFromDateValue() != null){
        	if (ruleBaseValues.getToDateValue().before(ruleBaseValues.getFromDateValue())) {
    			this.putFieldError("toDate""error.document.maintainableItems.toDate");
    			isValid &= false;
            }
        }
		if(!setRuleAttributeErrors(ruleBaseValues)){
			isValid &= false;
		}
		// This doesn't map directly to a single field. It's either the person or the group tab
        if (ruleBaseValues.getRuleResponsibilities().isEmpty()) {
        	this.putFieldError("Responsibilities""error.document.responsibility.required");
        	isValid &= false;
        } else {
            for (RuleResponsibilityBo responsibility : ruleBaseValues.getRuleResponsibilities()) {
                if (responsibility.getRuleResponsibilityName() != null && ..equals(responsibility.getRuleResponsibilityType())) {
                    if (getGroupService().getGroup(responsibility.getRuleResponsibilityName()) == null) {
                    	this.putFieldError("Groups""routetemplate.ruleservice.workgroup.invalid");
                    	isValid &= false;
                    }
                } else if (responsibility.getPrincipal() == null && responsibility.getRole() == null) {
                	this.putFieldError("Persons""routetemplate.ruleservice.user.invalid");
                	isValid &= false;
                }
            }
        }
        return isValid;
	}
	protected boolean ruleExists(RuleBaseValues rule){
		boolean bRet = false;
		RuleBaseValues tmp = KEWServiceLocator.getRuleService().getRuleByName(rule.getName());
		if(tmp != null) {
		    if ((rule.getPreviousRuleId() == null)
		         || (rule.getPreviousRuleId() != null
		            && !rule.getPreviousRuleId().equals(tmp.getId()))) {
			    bRet = true;
		    }
		}
		return bRet;
	}
        return (DocumentTypeService) KEWServiceLocator.getService(.);
    }
	protected boolean setRuleAttributeErrors(RuleBaseValues rule){
		boolean isValid = true;
		RuleTemplate ruleTemplate = KewApiServiceLocator.getRuleService().getRuleTemplate(rule.getRuleTemplateId());

Populate rule extension values *
		for (RuleTemplateAttribute ruleTemplateAttribute : ruleTemplate.getActiveRuleTemplateAttributes()) {
            if (!RuleAttribute.isWorkflowAttribute(ruleTemplateAttribute.getRuleAttribute().getType())) {
                continue;
            }
            Map<StringStringparameterMap = WebRuleUtils.getFieldMapForRuleTemplateAttribute(ruleruleTemplateAttribute);
            WorkflowRuleAttributeRows rows =
                    KEWServiceLocator.getWorkflowRuleAttributeMediator().getRuleRows(parameterMapruleTemplateAttribute);
			// TODO hook validation of rule data into PreRules
            List<RemotableAttributeErrorerrors = rows.getValidationErrors();
			if (!errors.isEmpty()) {
                isValid = false;
				for(RemotableAttributeError errorerrors){
				    this.putFieldError("RuleAttributes".error.getMessage());
				}
			}
		}
		return isValid;
	}
New to GrepCode? Check out our FAQ X