34 lines
912 B
Java
34 lines
912 B
Java
package org.gcube.accounting.datamodel.validations.validators;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import org.gcube.accounting.datamodel.UsageRecord;
|
|
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
|
|
|
|
|
public class ValidLongValidator implements FieldAction {
|
|
|
|
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
|
|
if(value instanceof Long){
|
|
return value;
|
|
}
|
|
try {
|
|
Long longObj = Long.valueOf((String) value);
|
|
if(longObj!=null){
|
|
return longObj;
|
|
}
|
|
}catch (Exception e) {
|
|
throw new InvalidValueException(ERROR, e);
|
|
}
|
|
throw new InvalidValueException(ERROR);
|
|
}
|
|
|
|
}
|