Coverage Report - org.kuali.rice.krad.datadictionary.validation.constraint.IntegerPatternConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegerPatternConstraint
0%
0/35
0%
0/22
2.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 org.kuali.rice.core.api.config.property.ConfigurationService;
 19  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 20  
 import org.kuali.rice.krad.uif.UifConstants;
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * TODO Administrator don't forget to fill this in. 
 27  
  * 
 28  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 29  
  */
 30  0
 public class IntegerPatternConstraint extends ValidDataPatternConstraint{
 31  
     protected boolean allowNegative;
 32  
     protected boolean onlyNegative;
 33  
     protected boolean omitZero;
 34  
 
 35  
     /**
 36  
      * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString()
 37  
      */
 38  
     @Override
 39  
     protected String getRegexString() {
 40  0
         StringBuffer regex = new StringBuffer();
 41  
 
 42  0
         if (isAllowNegative() && !onlyNegative) {
 43  0
             regex.append("((-?");
 44  
         }
 45  0
         else if(onlyNegative){
 46  0
             regex.append("((-");
 47  
         }
 48  
         else {
 49  0
             regex.append("((");
 50  
         }
 51  0
         if(omitZero){
 52  0
             regex.append("[1-9][0-9]*))");
 53  
         }
 54  
         else{
 55  0
             regex.append("[1-9][0-9]*)|[0]*)");
 56  
         }
 57  
 
 58  0
         return regex.toString();
 59  
     }
 60  
     
 61  
     /**
 62  
      * @return the allowNegative
 63  
      */
 64  
     public boolean isAllowNegative() {
 65  0
         return this.allowNegative;
 66  
     }
 67  
 
 68  
     /**
 69  
      * @param allowNegative the allowNegative to set
 70  
      */
 71  
     public void setAllowNegative(boolean allowNegative) {
 72  0
         this.allowNegative = allowNegative;
 73  0
     }
 74  
 
 75  
     public boolean isOnlyNegative() {
 76  0
         return onlyNegative;
 77  
     }
 78  
 
 79  
     /**
 80  
      * When set to true, only allows negative numbers (and zero if allowZero is still true)
 81  
      * @param onlyNegative
 82  
      */
 83  
     public void setOnlyNegative(boolean onlyNegative) {
 84  0
         this.onlyNegative = onlyNegative;
 85  0
     }
 86  
 
 87  
     public boolean isOmitZero() {
 88  0
         return omitZero;
 89  
     }
 90  
 
 91  
     /**
 92  
      * When set to true, zero is not allowed in the set of allowed numbers.
 93  
      * @param omitZero
 94  
      */
 95  
     public void setOmitZero(boolean omitZero) {
 96  0
         this.omitZero = omitZero;
 97  0
     }
 98  
 
 99  
     /**
 100  
      * This overridden method ...
 101  
      * 
 102  
      * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidDataPatternConstraint#getValidationMessageParams()
 103  
      */
 104  
     @Override
 105  
     public List<String> getValidationMessageParams() {
 106  0
         if (validationMessageParams == null) {
 107  0
             validationMessageParams = new ArrayList<String>();
 108  0
             ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
 109  0
             if (allowNegative && !onlyNegative) {
 110  0
                 if(omitZero){
 111  0
                     validationMessageParams.add(configService
 112  
                             .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
 113  
                                     + "positiveOrNegative"));
 114  
                 }
 115  
                 else{
 116  0
                     validationMessageParams.add(configService
 117  
                             .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
 118  
                                     + "positiveOrNegativeOrZero"));
 119  
                 }
 120  
             }
 121  0
             else if(onlyNegative){
 122  0
                 if(omitZero){
 123  0
                     validationMessageParams.add(configService
 124  
                             .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negative"));
 125  
                 }
 126  
                 else{
 127  0
                     validationMessageParams.add(configService
 128  
                             .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negativeOrZero"));
 129  
                 }
 130  
             }
 131  
             else {
 132  0
                 if(omitZero){
 133  0
                     validationMessageParams.add(configService
 134  
                             .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
 135  
                 }
 136  
                 else{
 137  0
                     validationMessageParams.add(configService
 138  
                             .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrZero"));
 139  
                 }
 140  
             }
 141  
         }
 142  0
         return validationMessageParams;
 143  
     }
 144  
 }