2015-06-08 17:19:09 +02:00
|
|
|
package org.gcube.accounting.datamodel.validations.validators;
|
2015-05-28 13:19:25 +02:00
|
|
|
|
2015-06-05 11:43:53 +02:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
2015-06-05 12:54:26 +02:00
|
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
2015-06-05 11:43:53 +02:00
|
|
|
|
2015-05-28 13:19:25 +02:00
|
|
|
|
2015-06-05 18:50:07 +02:00
|
|
|
public class ValidLongValidator implements FieldValidator {
|
2015-05-28 13:19:25 +02:00
|
|
|
|
2015-06-05 18:50:07 +02:00
|
|
|
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
|
2015-06-05 12:54:26 +02:00
|
|
|
|
2015-06-05 18:50:07 +02:00
|
|
|
@Override
|
2015-06-05 12:54:26 +02:00
|
|
|
public Serializable validate(Serializable toValidate) throws InvalidValueException {
|
2015-05-28 13:19:25 +02:00
|
|
|
if(toValidate instanceof Long){
|
2015-06-05 12:54:26 +02:00
|
|
|
return toValidate;
|
2015-05-28 13:19:25 +02:00
|
|
|
}
|
2015-06-05 18:50:07 +02:00
|
|
|
try {
|
|
|
|
Long longObj = Long.getLong((String) toValidate);
|
|
|
|
if(longObj!=null){
|
|
|
|
return longObj;
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
|
|
|
throw new InvalidValueException(ERROR, e.getCause());
|
2015-06-05 11:06:17 +02:00
|
|
|
}
|
2015-06-05 18:50:07 +02:00
|
|
|
throw new InvalidValueException(ERROR);
|
2015-05-28 13:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|