11 Templates

  1. Template to define Extended DTO validator
    • DTO name: com.ofss.digx.app.test.TestDTO
    • Default validator: com.ofss.digx.app.test.TestDTOValidator
    • Extended DTO validator: com.ofss.cz.app.test.ExtTestDTOValidator
      package com.ofss.cz.app.finlimit.dto.limitpackage; 
      import java.util.List; 
      import com.ofss.digx.app.dto.validator.IDTOValidator;
      import com.ofss.fc.app.dto.validation.IValidatable;
      import com.ofss.fc.infra.validation.error.ValidationError; 
      public class ExtTestDTOValidator extends com.ofss.digx.app.test.TestDTOValidator        
      implements IDTOValidator
        {         
          protected ExtTestDTOValidator()
          {    
          }     
          public static ExtTestDTOValidator getInstance()
          {        
          return ExtTestDTOValidatorHolder.INSTANCE;    
          }        
          private static class ExtTestDTOValidatorHolder
          {        
          private static final ExtTestDTOValidator INSTANCE = new ExtTestDTOValidator();    
          }     
           @Override public void validateInput
          (
              IValidatable validatable,
              String key, String parentName,            
              List<ValidationError>
              validationErrors
           ) 
           {        
            LOGGER.log(Level.SEVERE,
            FORMATTER.formatMessage
           (                
             "Class : %s, Entering into the customized class and calling digx class ", 
             THIS_COMPONENT_NAME));        
             super.validateInput(validatable, key, parentName, validationErrors);                
             // Provide the required addiotion validation for the DTO. Add the required errors
              in validationErrors for the failed cases.    
            }
        }
             
  2. Template to define taxonomy data type validator

    Data Type: TESTTYPE

    Validator: TestTypeValidator

    package com.ofss.digx.app.dto.validator.taxonomy; 
     import java.util.List;
     import com.ofss.digx.app.dto.validator.ITaxonomyValidator;
     import com.ofss.digx.app.dto.validator.ValidationData;
     import com.ofss.fc.infra.validation.error.ValidationError; public class TestTypeValidator
     implements ITaxonomyValidator 
      {    
       private TestTypeValidator() 
       {   
       }   
       private static class TestTypeValidatorHolder 
        {        
         private static final TestTypeValidator INSTANCE = new TestTypeValidator();   
         }   
         /**     
         * @return unique instance of {@link TestTypeValidator} */   
         public static TestTypeValidator getInstance() 
          {        
          return TestTypeValidatorHolder.INSTANCE;   
          }   
           @Override  public void validate
            (
            ValidationData data, Object val, String parentName,String fieldKey,            
            List<ValidationError> validationErrors)
            {        
            if (val != null) 
              {            
               if (val instanceof <Type of the object>)
                {                
                < Type of the object > value = (<Type of the object >) val;                
                if (<validation_case>) 
                {                    
                validationErrors.add
                (new ValidationError(parentName, fieldKey, null, data.getErrorCode(), null));                
                }            
                } 
                 else 
                { 
                validationErrors.add
                (new ValidationError(parentName, fieldKey, null, "DIGX_INVALID_VALUE_TYPE",null));            
                }        
              }   
            }
          }
  3. Template to define validator for custom data type
    package com.ofss.digx.app.dto.validator.taxonomy; 
     import java.util.List;
     import java.util.logging.Level;
     import java.util.logging.Logger;
     import java.util.prefs.Preferences; 
     import com.ofss.digx.app.dto.validator.ITaxonomyValidator;
     import com.ofss.digx.app.dto.validator.TaxonomyHandler;
     import com.ofss.digx.app.dto.validator.TaxonomyValidatorFactory;
     import com.ofss.digx.app.dto.validator.ValidationData;
     import com.ofss.digx.enumeration.validator.TaxonomyCategory;
     import com.ofss.fc.datatype.PostalAddress;
     import com.ofss.fc.infra.config.ConfigurationFactory;
     import com.ofss.fc.infra.log.impl.MultiEntityLogger;
     import com.ofss.fc.infra.validation.error.ValidationError; 
     /** * Validation class for complex type @AmountRange */public class PostalAddressValidator implements ITaxonomyValidator {    
      private static final String THIS_COMPONENT_NAME = PostalAddressValidator.class.getName();    
     private static final Logger LOGGER = MultiEntityLogger.getUniqueInstance().getLogger(THIS_COMPONENT_NAME);    
     private static final MultiEntityLogger FORMATTER = MultiEntityLogger.getUniqueInstance();    
     /**     * Constant to hold validation configuration preference name     */   
      private static final String VALIDATION_CONFIGURATION = "ValidationConfig";    
     /**     * Fully qualified name of the default length validator class     */   
     private static final String LENGTH_VALIDATOR = "LENGTH_VALIDATOR";  /**     
     * Fully qualified name of the default length validator class     */   
     private static final String DEFAULT_LENGTH_VALIDATOR = "com.ofss.digx.app.dto.validator.taxonomy.LengthValidator";    
      /**     * private Constructor     */   
      private PostalAddressValidator() 
      {    
      }    
      private static class PostalAddressValidatorHolder 
      {        
       private static final PostalAddressValidator INSTANCE = new PostalAddressValidator();   
       }   
       /**     * @return unique instance of {@link PostalAddressValidator}     */   
        public static PostalAddressValidator getInstance() 
       {        
        return PostalAddressValidatorHolder.INSTANCE;   
       }    
       /**     *      */   
       @Override public void validate
        (ValidationData data, Object val, String parentName, 
                        String fieldKey, 
                        List<ValidationError> validationErrors)
                          {        
                            if (LOGGER.isLoggable(Level.FINE)) 
                           {            
                          LOGGER.log(Level.FINE,FORMATTER.formatMessage
                         ( "Complex Data Type validation inside Class : %s, for Field : %s",THIS_COMPONENT_NAME, fieldKey));        
                           }        
                          PostalAddress v = (PostalAddress) val;        
                          validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line1." + data.getLocale()),                
                            v.getLine1(), parentName, fieldKey + ".line1", validationErrors);       
                            validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line2." + data.getLocale()),                
                            v.getLine2(), parentName, fieldKey + ".line2", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line3." + data.getLocale()),                
                            v.getLine3(), parentName, fieldKey + ".line3",validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line4." + data.getLocale()),                
                            v.getLine4(), parentName, fieldKey + ".line4",validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line5." + data.getLocale()),                
                            v.getLine5(), parentName, fieldKey + ".line5",validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line6." + data.getLocale()),                
                            v.getLine6(), parentName, fieldKey + ".line6", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line7." + data.getLocale()),                
                            v.getLine7(), parentName, fieldKey + ".line7", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line8." + data.getLocale()),                
                            v.getLine8(), parentName, fieldKey + ".line8", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line9." + data.getLocale()),                        
                            v.getLine9(), parentName, fieldKey + ".line9",  validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line10." + data.getLocale()),                
                            v.getLine10(), parentName, fieldKey + ".line10", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line11." + data.getLocale()),                
                            v.getLine11(), parentName, fieldKey + ".line11", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.line12." + data.getLocale()),                
                            v.getLine12(), parentName, fieldKey + ".line12", validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.city." + data.getLocale()),                
                            v.getCity(), parentName, fieldKey + ".city",validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.state." + data.getLocale()),                
                            v.getState(), parentName, fieldKey + ".state",    validationErrors);       
                        validateField(TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.country." + data.getLocale()),                
                            v.getCountry(), parentName, fieldKey + ".country", validationErrors);        
                        validateField(  TaxonomyHandler.getInstance().getValidationMap().get("POSTALADDRESS.postalCode." + data.getLocale()),                        
                             v.getPostalCode(), parentName, fieldKey + ".postalCode", validationErrors);    
                        }    
      /**     * Validate individual field of the complex data type {@link PostalAddress}     *      * 
       @param data     * @param value     * @param parentName     * @param key     * @param validationErrors     */   
      private void validateField(ValidationData data, String value, String parentName,String key, List<ValidationError> validationErrors)
       {         
        Preferences validationFactoryConfigurator = ConfigurationFactory.getInstance() 
        .getConfigurations(VALIDATION_CONFIGURATION);         
         ITaxonomyValidator lengthValidator = TaxonomyValidatorFactory.getInstance()               
         .getValidator(validationFactoryConfigurator.get(LENGTH_VALIDATOR,
        DEFAULT_LENGTH_VALIDATOR));        
           if (value == null) 
            {            
            if (data.isMandatory()
            ) 
             {                
              validationErrors.add(new ValidationError(parentName, key, null, data.getMandatoryErrorCode(), null));  
              }        
               } 
              else 
               {            
               if (data.getMinLength() != null || data.getMaxLength() != null) 
                {                
                lengthValidator.validate(data, value, parentName,key, validationErrors);            
                 }             
                 ITaxonomyValidator validator = TaxonomyValidatorFactory.getInstance().getValidator(data.getClassName());            
                 if (validator != null) 
                  {                
                  validator.validate(data, value, parentName, key, validationErrors);           
                   }        
                  }    
                   }    
                   @Override public final TaxonomyCategory getCategory() 
                    {        
                    return TaxonomyCategory.OTHER;   
                     }
                }