Coverage Report - org.kuali.rice.kew.document.RoutingRuleDelegationMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
RoutingRuleDelegationMaintainable
0%
0/57
0%
0/10
1.412
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.document;
 17  
 
 18  
 import java.util.Collections;
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 23  
 import org.kuali.rice.kew.rule.RuleBaseValues;
 24  
 import org.kuali.rice.kew.rule.RuleDelegationBo;
 25  
 import org.kuali.rice.kew.rule.web.WebRuleUtils;
 26  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 27  
 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
 28  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 29  
 import org.kuali.rice.kns.web.ui.Section;
 30  
 import org.kuali.rice.krad.document.MaintenanceLock;
 31  
 import org.kuali.rice.kns.maintenance.Maintainable;
 32  
 
 33  
 /**
 34  
  * This class is the maintainable implementation for Routing Rules 
 35  
  * in KEW (represented by the {@link RuleBaseValues} business object). 
 36  
  * 
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  *
 39  
  */
 40  0
 public class RoutingRuleDelegationMaintainable extends KualiMaintainableImpl {
 41  
         
 42  
         /**
 43  
          * Override the getSections method on this maintainable so that the Section Containing the various Rule Attributes
 44  
          * can be dynamically generated based on the RuleTemplate which is selected.
 45  
          */
 46  
         @Override
 47  
         public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
 48  0
                 List<Section> sections = super.getSections(document, oldMaintainable);
 49  0
                 return WebRuleUtils.customizeSections(getThisRule(), sections, true);
 50  
         }
 51  
         
 52  
         /**
 53  
          * On creation of a new rule document, we must validate that a rule template and document type are set. 
 54  
          */
 55  
         @Override
 56  
         public void processAfterNew(MaintenanceDocument document,
 57  
                         Map<String, String[]> parameters) {
 58  0
                 initializeBusinessObjects(document);
 59  0
                 WebRuleUtils.validateRuleAndResponsibility(getOldRuleDelegation(document), getNewRuleDelegation(document), parameters);
 60  0
                 WebRuleUtils.validateRuleTemplateAndDocumentType(getOldRule(document), getNewRule(document), parameters);
 61  0
                 WebRuleUtils.establishDefaultRuleValues(getNewRule(document));
 62  0
                 getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber());
 63  0
         }
 64  
                 
 65  
         /**
 66  
          * Creates the initial structure of the new business object so that it can be properly
 67  
          * populated with non-null object references.
 68  
          */
 69  
         private void initializeBusinessObjects(MaintenanceDocument document) {
 70  0
                 RuleDelegationBo oldRuleDelegation = getOldRuleDelegation(document);
 71  0
                 RuleDelegationBo newRuleDelegation = getNewRuleDelegation(document);
 72  0
                 if (oldRuleDelegation.getDelegationRule() == null) {
 73  0
                         oldRuleDelegation.setDelegationRule(new RuleBaseValues());
 74  
                 }
 75  0
                 if (newRuleDelegation.getDelegationRule() == null) {
 76  0
                         newRuleDelegation.setDelegationRule(new RuleBaseValues());
 77  
                 }
 78  0
         }
 79  
         
 80  
         /**
 81  
          * This is a hack to get around the fact that when a document is first created, this value is
 82  
           * true which causes issues if you want to be able to initialize fields on  the document using
 83  
           * request parameters.  See SectionBridge.toSection for the "if" block where it populates
 84  
           * Field.propertyValue to see why this causes problems
 85  
          */
 86  
         @Override
 87  
         public void setGenerateDefaultValues(String docTypeName) {                
 88  
                 
 89  0
         }
 90  
         
 91  
         /**
 92  
      * A complete override of the implementation for saving a Rule
 93  
      */
 94  
     @Override
 95  
     public void saveBusinessObject() {
 96  0
             WebRuleUtils.clearKeysForSave(getThisRuleDelegation());
 97  0
             WebRuleUtils.translateResponsibilitiesForSave(getThisRule());
 98  0
             WebRuleUtils.translateFieldValuesForSave(getThisRule());
 99  0
             WebRuleUtils.processRuleForDelegationSave(getThisRuleDelegation());
 100  0
             KEWServiceLocator.getRuleService().makeCurrent(getThisRuleDelegation(), true);
 101  0
     }
 102  
 
 103  
     /**
 104  
      * A complete override of the implementation for saving a Rule
 105  
      */
 106  
     @Override
 107  
     public void saveDataObject() {
 108  0
             WebRuleUtils.clearKeysForSave(getThisRuleDelegation());
 109  0
             WebRuleUtils.translateResponsibilitiesForSave(getThisRule());
 110  0
             WebRuleUtils.translateFieldValuesForSave(getThisRule());
 111  0
             WebRuleUtils.processRuleForDelegationSave(getThisRuleDelegation());
 112  0
             KEWServiceLocator.getRuleService().makeCurrent(getThisRuleDelegation(), true);
 113  0
     }
 114  
     
 115  
     @Override
 116  
     public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> parameters) {
 117  0
             WebRuleUtils.processRuleForCopy(document.getDocumentNumber(), getOldRule(document), getNewRule(document));
 118  0
         super.processAfterCopy(document, parameters);
 119  0
     }
 120  
     
 121  
         @Override
 122  
         public void processAfterEdit(MaintenanceDocument document,
 123  
                         Map<String, String[]> parameters) {
 124  0
                 if (!getOldRule(document).getCurrentInd()) {
 125  0
                         throw new RiceRuntimeException("Cannot edit a non-current version of a rule.");
 126  
                 }
 127  0
                 WebRuleUtils.populateForCopyOrEdit(getOldRule(document), getNewRule(document));
 128  0
                 getNewRule(document).setPreviousRuleId(getOldRule(document).getId());
 129  0
                 getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber());
 130  0
                 super.processAfterEdit(document, parameters);
 131  0
         }
 132  
 
 133  
     
 134  
         @Override
 135  
         public List<MaintenanceLock> generateMaintenanceLocks() {
 136  0
                 if (getThisRule().getId() == null) {
 137  0
                         return Collections.emptyList();
 138  
                 }
 139  0
                 return super.generateMaintenanceLocks();
 140  
         }
 141  
     
 142  
     @Override
 143  
         public String getDocumentTitle(MaintenanceDocument document) {
 144  0
                 StringBuffer title = new StringBuffer();
 145  0
         RuleBaseValues rule = getThisRule();
 146  0
         if (rule.getPreviousRuleId() != null) {
 147  0
             title.append("Editing Rule Delegation '").append(rule.getDescription()).append("'");
 148  
         } else {
 149  0
             title.append("Adding Rule Delegation '").append(rule.getDescription()).append("'");
 150  
         }
 151  0
         return title.toString();
 152  
         }
 153  
         
 154  
         protected RuleDelegationBo getNewRuleDelegation(MaintenanceDocument document) {
 155  0
                 return (RuleDelegationBo)document.getNewMaintainableObject().getBusinessObject();
 156  
         }
 157  
         
 158  
         protected RuleDelegationBo getOldRuleDelegation(MaintenanceDocument document) {
 159  0
                 return (RuleDelegationBo)document.getOldMaintainableObject().getBusinessObject();
 160  
         }
 161  
 
 162  
         protected RuleDelegationBo getThisRuleDelegation() {
 163  0
                 return (RuleDelegationBo)getDataObject();
 164  
         }
 165  
 
 166  
         protected RuleBaseValues getNewRule(MaintenanceDocument document) {
 167  0
                 return getNewRuleDelegation(document).getDelegationRule();
 168  
         }
 169  
 
 170  
         protected RuleBaseValues getOldRule(MaintenanceDocument document) {
 171  0
                 return getOldRuleDelegation(document).getDelegationRule();
 172  
         }
 173  
 
 174  
         protected RuleBaseValues getThisRule() {
 175  0
                 return getThisRuleDelegation().getDelegationRule();
 176  
         }
 177  
         
 178  
         /**
 179  
          * This overridden method ...
 180  
          *
 181  
          * @see org.kuali.rice.krad.maintenance.KualiMaintainableImpl#prepareForSave()
 182  
          */
 183  
         @Override
 184  
         public void prepareForSave() {
 185  0
                 super.prepareForSave();
 186  0
                 WebRuleUtils.translateResponsibilitiesForSave(getThisRule());
 187  0
         }
 188  
         
 189  
 
 190  
         
 191  
         
 192  
 }