Coverage Report - org.kuali.rice.krms.impl.validation.ValidationAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationAction
0%
0/17
0%
0/4
2
 
 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.krms.impl.validation;
 17  
 
 18  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 19  
 import org.kuali.rice.krms.framework.engine.Action;
 20  
 import org.kuali.rice.krms.framework.type.ValidationActionType;
 21  
 import org.kuali.rice.krms.framework.type.ValidationActionTypeService;
 22  
 
 23  
 /**
 24  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 25  
  */
 26  
 public class ValidationAction implements Action {
 27  
 
 28  
 
 29  
     private final ValidationActionType type;
 30  
     private final String message;
 31  
 
 32  0
     public ValidationAction(ValidationActionType type, String message) {
 33  0
         if (type == null) throw new IllegalArgumentException("type must not be null");
 34  
 
 35  0
         this.type = type;
 36  0
         this.message = message;
 37  0
     }
 38  
 
 39  
     @Override
 40  
     public void execute(ExecutionEnvironment environment) {
 41  
         // create or extend an existing attribute on the EngineResults to communicate the selected Validation and
 42  
         // action
 43  
 
 44  0
         Object value = environment.getEngineResults().getAttribute(ValidationActionTypeService.VALIDATIONS_ACTION_ATTRIBUTE);
 45  0
         StringBuilder selectedAttributesStringBuilder = new StringBuilder();
 46  
 
 47  0
         if (value != null) {
 48  
             // assume the value is what we think it is
 49  0
             selectedAttributesStringBuilder.append(value.toString());
 50  
             // we need a comma after the initial value
 51  0
             selectedAttributesStringBuilder.append(",");
 52  
         }
 53  
 
 54  
         // add our people flow action to the string using our convention
 55  0
         selectedAttributesStringBuilder.append(type.getCode());
 56  0
         selectedAttributesStringBuilder.append(":");
 57  0
         selectedAttributesStringBuilder.append(message);
 58  
 
 59  
         // set our attribute on the engine results
 60  0
         environment.getEngineResults().setAttribute(ValidationActionTypeService.VALIDATIONS_ACTION_ATTRIBUTE,
 61  
                 selectedAttributesStringBuilder.toString()
 62  
         );
 63  0
     }
 64  
 
 65  
     @Override
 66  
     public void executeSimulation(ExecutionEnvironment environment) {
 67  
         // our action doesn't need special handling during simulations
 68  0
         execute(environment);
 69  0
     }
 70  
 }