package eu.dzhw.fdz.metadatamanagement.data.variablemanagement.documents.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import eu.dzhw.fdz.metadatamanagement.data.variablemanagement.documents.VariableDocument;
import eu.dzhw.fdz.metadatamanagement.data.variablemanagement.documents.validation.enums.DataType;

/**
 * The validator checks for a not null scale level field, if a data type is numeric.
 * 
 * @author Daniel Katzberg
 *
 */
public class NotNullScaleLevelOnNumericDataTypeValidator
    implements ConstraintValidator<NotNullScaleLevelOnNumericDataType, VariableDocument> {

  /*
   * (non-Javadoc)
   * 
   * @see javax.validation.ConstraintValidator#initialize(java.lang.annotation.Annotation)
   */
  @Override
  public void initialize(NotNullScaleLevelOnNumericDataType constraintAnnotation) {
    // Do nothing
  }

  /*
   * (non-Javadoc)
   * 
   * @see javax.validation.ConstraintValidator#isValid(java.lang.Object,
   * javax.validation.ConstraintValidatorContext)
   */
  @Override
  public boolean isValid(VariableDocument value, ConstraintValidatorContext context) {

    // check for null
    if (value.getDataType() == null) {
      return true;
    }

    // check numeric field
    if (value.getDataType().trim().equalsIgnoreCase(DataType.NUMERIC.getI18nValue())) {

      // empty scale level
      if (value.getScaleLevel() == null) {
        return false;
      }
    }

    // not a numeric field
    return true;
  }

}

@@ -1257,24 +1257,57 @@
 umeric field
+ with look for a null scale level
 %0A    if (val
@@ -1383,50 +1383,20 @@
 e())
-) %7B%0A
 %0A      
-// empty scale level%0A      if (
+  && 
 valu
@@ -1426,26 +1426,24 @@
 ll) %7B%0A      
-  
 return false
@@ -1448,16 +1448,8 @@
 se;%0A
-      %7D%0A
     

fix the build. remove pmd alert.