40 lines
886 B
Java
40 lines
886 B
Java
package org.gcube.accounting.datamodel.validators;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import org.gcube.accounting.datamodel.annotations.ValidLong;
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
|
|
|
|
|
public class ValidLongValidator implements FieldValidator<ValidLong>{
|
|
|
|
public Class<ValidLong> annotation() {
|
|
return ValidLong.class;
|
|
}
|
|
|
|
public boolean isValid(Serializable toValidate) {
|
|
try {
|
|
validate(toValidate);
|
|
} catch (InvalidValueException e) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public Serializable validate(Serializable toValidate) throws InvalidValueException {
|
|
if(toValidate instanceof Long){
|
|
return toValidate;
|
|
}
|
|
Long longObj = Long.getLong((String) toValidate);
|
|
if(longObj!=null){
|
|
return longObj;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public String getErrorSuffix() {
|
|
return String.format("not instace of %s", Long.class.getSimpleName());
|
|
}
|
|
|
|
}
|