Coverage Report - org.kuali.rice.krad.datadictionary.validation.constraint.FixedPointPatternConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
FixedPointPatternConstraint
68%
20/29
33%
2/6
1.375
 
 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.krad.datadictionary.validation.constraint;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 22  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 23  
 import org.kuali.rice.krad.uif.UifConstants;
 24  
 
 25  
 /**
 26  
  * TODO delyea don't forget to fill this in.
 27  
  * 
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  55
 public class FixedPointPatternConstraint extends ValidDataPatternConstraint {
 31  
 
 32  
     protected boolean allowNegative;
 33  
     protected int precision;
 34  
     protected int scale;
 35  
 
 36  
     /**
 37  
      * Overriding retrieval of
 38  
      * 
 39  
      * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString()
 40  
      */
 41  
     @Override
 42  
     protected String getRegexString() {
 43  10
         StringBuilder regex = new StringBuilder();
 44  
 
 45  10
         if (isAllowNegative()) {
 46  4
             regex.append("-?");
 47  
         }
 48  
         // final patter will be: -?([0-9]{0,p-s}\.[0-9]{1,s}|[0-9]{1,p-s}) where p = precision, s=scale
 49  10
         regex.append("(");
 50  10
         regex.append("[0-9]{0," + (getPrecision() - getScale()) + "}");
 51  10
         regex.append("\\.");
 52  10
         regex.append("[0-9]{1," + getScale() + "}");
 53  10
         regex.append("|[0-9]{1," + (getPrecision() - getScale()) + "}");
 54  10
         regex.append(")");
 55  10
         return regex.toString();
 56  
     }
 57  
 
 58  
     /**
 59  
      * @return the allowNegative
 60  
      */
 61  
     public boolean isAllowNegative() {
 62  10
         return this.allowNegative;
 63  
     }
 64  
 
 65  
     /**
 66  
      * @param allowNegative the allowNegative to set
 67  
      */
 68  
     public void setAllowNegative(boolean allowNegative) {
 69  11
         this.allowNegative = allowNegative;
 70  11
     }
 71  
 
 72  
     /**
 73  
      * @return the precision
 74  
      */
 75  
     public int getPrecision() {
 76  20
         return this.precision;
 77  
     }
 78  
 
 79  
     /**
 80  
      * @param precision the precision to set
 81  
      */
 82  
     public void setPrecision(int precision) {
 83  55
         this.precision = precision;
 84  55
     }
 85  
 
 86  
     /**
 87  
      * @return the scale
 88  
      */
 89  
     public int getScale() {
 90  30
         return this.scale;
 91  
     }
 92  
 
 93  
     /**
 94  
      * @param scale the scale to set
 95  
      */
 96  
     public void setScale(int scale) {
 97  55
         this.scale = scale;
 98  55
     }
 99  
 
 100  
     /**
 101  
      * This overridden method ...
 102  
      * 
 103  
      * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidDataPatternConstraint#getValidationMessageParams()
 104  
      */
 105  
     @Override
 106  
     public List<String> getValidationMessageParams() {
 107  0
         if(validationMessageParams == null){
 108  0
             validationMessageParams = new ArrayList<String>();
 109  0
             ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
 110  0
             if (allowNegative) {
 111  0
                 validationMessageParams.add(configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
 112  
                         + "positiveOrNegative"));
 113  
             } else {
 114  0
                 validationMessageParams.add(configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
 115  
                         + "positive"));
 116  
             }
 117  
     
 118  0
             validationMessageParams.add(Integer.toString(precision));
 119  0
             validationMessageParams.add(Integer.toString(scale));
 120  
         }
 121  0
         return validationMessageParams;
 122  
     }
 123  
 
 124  
 }