Coverage Report - org.kuali.rice.krms.impl.validation.ValidationRuleTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationRuleTypeServiceImpl
0%
0/19
0%
0/12
3.4
 
 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.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 20  
 import org.kuali.rice.core.api.uif.RemotableAttributeField;
 21  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
 22  
 import org.kuali.rice.krms.framework.engine.Rule;
 23  
 import org.kuali.rice.krms.framework.type.ValidationRuleType;
 24  
 import org.kuali.rice.krms.framework.type.ValidationRuleTypeService;
 25  
 import org.kuali.rice.krms.impl.provider.repository.RepositoryToEngineTranslator;
 26  
 import org.kuali.rice.krms.impl.type.KrmsTypeServiceBase;
 27  
 
 28  
 import javax.jws.WebParam;
 29  
 import java.util.List;
 30  
 
 31  
 /**
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  
 public final class ValidationRuleTypeServiceImpl extends KrmsTypeServiceBase implements ValidationRuleTypeService {
 35  
 
 36  
     private RepositoryToEngineTranslator translator;
 37  
 
 38  
     /**
 39  
      * private constructor to enforce use of static factory
 40  
      */
 41  
     private ValidationRuleTypeServiceImpl(){
 42  0
         super();
 43  0
     }
 44  
 
 45  
     /**
 46  
      * Factory method for getting a {@link ValidationRuleTypeService}
 47  
      * @return a {@link ValidationRuleTypeService} corresponding to the given {@link ValidationRuleType}.
 48  
      */
 49  
     public static ValidationRuleTypeService getInstance() {
 50  0
         return new ValidationRuleTypeServiceImpl();
 51  
     }
 52  
 
 53  
     @Override
 54  
     public Rule loadRule(RuleDefinition validationRuleDefinition) {
 55  0
         if (validationRuleDefinition == null) { throw new RiceIllegalArgumentException("validationRuleDefinition must not be null"); }
 56  0
         if (validationRuleDefinition.getAttributes() == null) { throw new RiceIllegalArgumentException("validationRuleDefinition must not be null");}
 57  
 
 58  0
         if (!validationRuleDefinition.getAttributes().containsKey(ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE)) {
 59  
 
 60  0
             throw new RiceIllegalArgumentException("validationRuleDefinition does not contain an " +
 61  
                     ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE + " attribute");
 62  
         }
 63  0
         String validationRuleTypeCode = validationRuleDefinition.getAttributes().get(ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE);
 64  
 
 65  0
         if (StringUtils.isBlank(validationRuleTypeCode)) {
 66  0
             throw new RiceIllegalArgumentException(ValidationRuleTypeService.VALIDATIONS_RULE_TYPE_CODE_ATTRIBUTE + " attribute must not be null or blank");
 67  
         }
 68  
 
 69  0
         if (ValidationRuleType.VALID.getCode().equals(validationRuleTypeCode)) {
 70  0
             return new ValidationRule(ValidationRuleType.VALID, validationRuleDefinition.getName(),
 71  
                     translator.translatePropositionDefinition(validationRuleDefinition.getProposition()),
 72  
                     translator.translateActionDefinitions(validationRuleDefinition.getActions()));
 73  
         }
 74  0
         if (ValidationRuleType.INVALID.getCode().equals(validationRuleTypeCode)) {
 75  0
             return new ValidationRule(ValidationRuleType.INVALID, validationRuleDefinition.getName(),
 76  
                     translator.translatePropositionDefinition(validationRuleDefinition.getProposition()),
 77  
                     translator.translateActionDefinitions(validationRuleDefinition.getActions()));
 78  
         }
 79  0
         return null;
 80  
     }
 81  
 
 82  
     @Override
 83  
     public List<RemotableAttributeField> getAttributeFields(@WebParam(name = "krmsTypeId") String krmsTypeId) throws RiceIllegalArgumentException {
 84  0
         RadioButtonTypeServiceUtil radioButtonTypeServiceUtil = new RadioButtonTypeServiceUtil();
 85  0
         return radioButtonTypeServiceUtil.getAttributeFields(krmsTypeId);
 86  
     }
 87  
 
 88  
     /**
 89  
      * @param translator the RepositoryToEngineTranslator to set
 90  
      */
 91  
     public void setRepositoryToEngineTranslator(RepositoryToEngineTranslator translator) {
 92  0
         this.translator = translator;
 93  0
     }
 94  
 }
 95