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.xml.export;
 
 
 import java.util.List;
 
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.*;
Exports org.kuali.rice.kew.rule.bo.RuleTemplateBos to XML.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
See also:
org.kuali.rice.kew.rule.bo.RuleTemplateBo
 
 public class RuleTemplateXmlExporter implements XmlExporter {
 
     protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
     
     
 	public boolean supportPrettyPrint() {
 		return true;
 	}
 
     public Element export(ExportDataSet exportDataSet) {
     	KewExportDataSet dataSet = KewExportDataSet.fromExportDataSet(exportDataSet);
         if (!dataSet.getRuleTemplates().isEmpty()) {
             Element rootElement = .renderElement(null);
             for (Iterator iterator = dataSet.getRuleTemplates().iterator(); iterator.hasNext();) {
                 RuleTemplateBo template = (RuleTemplateBo)iterator.next();
                 exportRuleTemplate(rootElementtemplate);
             }
             return rootElement;
         }
         return null;
     }
     
     private void exportRuleTemplate(Element parentRuleTemplateBo ruleTemplate) {
         Element templateElement = .renderElement(parent);
         .renderTextElement(templateElementruleTemplate.getName());
         .renderTextElement(templateElementruleTemplate.getDescription());
         if (ruleTemplate.getDelegationTemplate() != null) {
             .renderTextElement(templateElementruleTemplate.getDelegationTemplate().getName());
         }
         exportAttributes(templateElementruleTemplate.getActiveRuleTemplateAttributes());
         exportDefaults(templateElementruleTemplate);
     }
 
     private void exportAttributes(Element parentList ruleTemplateAttributes) {
         if (!ruleTemplateAttributes.isEmpty()) {
             Element attributesElement = .renderElement(parent);
             for (Iterator iterator = ruleTemplateAttributes.iterator(); iterator.hasNext();) {
                 RuleTemplateAttributeBo attribute = (RuleTemplateAttributeBoiterator.next();
                 Element attributeElement = .renderElement(attributesElement);
                 .renderTextElement(attributeElementattribute.getRuleAttribute().getName());
                 .renderBooleanElement(attributeElementattribute.getRequired(), false);
             }
         }
     }
     
     private void exportDefaults(Element parentRuleTemplateBo ruleTemplate) {
         RuleBaseValues defaultRuleValues = KEWServiceLocator.getRuleService().findDefaultRuleByRuleTemplateId(ruleTemplate.getId());
         if (defaultRuleValues != null) {
             RuleDelegationBo defaultDelegationValues = getDefaultDelegationValues(defaultRuleValues);
             Element defaultsElement = .renderElement(parent);
             if (defaultDelegationValues != null) {
                 .renderTextElement(defaultsElementdefaultDelegationValues.getDelegationType().getCode());
             }
             .renderTextElement(defaultsElementdefaultRuleValues.getDescription());
             if (defaultRuleValues.getFromDateValue() != null) {
             	.renderDateElement(defaultsElementdefaultRuleValues.getFromDateValue());
            }
            if (defaultRuleValues.getToDateValue() != null) {
            	.renderDateElement(defaultsElementdefaultRuleValues.getToDateValue());
            }
            .renderBooleanElement(defaultsElementdefaultRuleValues.isForceAction(), false);
            .renderBooleanElement(defaultsElementdefaultRuleValues.isActive(), true);
            if (defaultDelegationValues == null) {
                RuleTemplateOptionBo defaultActionOption = ruleTemplate.getDefaultActionRequestValue();
                RuleTemplateOptionBo supportsComplete = ruleTemplate.getComplete();
                RuleTemplateOptionBo supportsApprove = ruleTemplate.getApprove();
                RuleTemplateOptionBo supportsAck = ruleTemplate.getAcknowledge();
                RuleTemplateOptionBo supportsFYI = ruleTemplate.getFyi();
                if (defaultActionOption != null) {
                	String defaultActionValue = (defaultActionOption == null ? null : defaultActionOption.getValue());
                	.renderTextElement(defaultsElementdefaultActionValue);
                }
                if (supportsComplete != null) {
                	String supportsCompleteValue = supportsComplete.getValue();
                	.renderTextElement(defaultsElementsupportsCompleteValue);
                }
                if (supportsApprove != null) {
                	String supportsApproveValue = supportsApprove.getValue();
                	.renderTextElement(defaultsElementsupportsApproveValue);
                }
                if (supportsAck != null) {
                	String supportsAckValue = supportsAck.getValue();
                	.renderTextElement(defaultsElementsupportsAckValue);
                }
                if (supportsFYI != null) {
                	String supportsFYIValue = supportsFYI.getValue();
                	.renderTextElement(defaultsElementsupportsFYIValue);
                }
            }
        }
    }
    
    private RuleDelegationBo getDefaultDelegationValues(RuleBaseValues defaultRuleValues) {
        List ruleDelegations = KEWServiceLocator.getRuleDelegationService().findByDelegateRuleId(defaultRuleValues.getId());
        if (ruleDelegations.size() > 1) {
            .warn("The rule defaults has more than one associated delegation defaults.");
        }
        return (ruleDelegations.isEmpty() ? null : (RuleDelegationBo)ruleDelegations.get(0));
    }
    
New to GrepCode? Check out our FAQ X