31 lines
677 B
Java
31 lines
677 B
Java
package org.gcube.accounting.datamodel.validators;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import org.gcube.accounting.datamodel.annotations.NotNull;
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
|
|
|
|
|
public class NotNullValidator implements FieldValidator<NotNull>{
|
|
|
|
public Class<NotNull> annotation() {
|
|
return NotNull.class;
|
|
}
|
|
|
|
public boolean isValid(Serializable toValidate) {
|
|
return toValidate!=null;
|
|
}
|
|
|
|
public Serializable validate(Serializable toValidate) throws InvalidValueException {
|
|
if(isValid(toValidate)){
|
|
return toValidate;
|
|
}
|
|
throw new InvalidValueException(getErrorSuffix());
|
|
}
|
|
|
|
public String getErrorSuffix() {
|
|
return "is null";
|
|
}
|
|
|
|
}
|