Deprecating not needed fields
parent
ffb9220fb2
commit
248c745e69
@ -1,19 +0,0 @@
|
||||
package org.gcube.accounting.datamodel.validations.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidDataTypeValidatorVolume;
|
||||
import org.gcube.documentstore.records.implementation.FieldDecorator;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@FieldDecorator(action=ValidDataTypeValidatorVolume.class)
|
||||
public @interface ValidDataTypeVolume {
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package org.gcube.accounting.datamodel.validations.validators;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord.DataType;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.documentstore.records.implementation.FieldAction;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ValidDataTypeValidatorVolume implements FieldAction {
|
||||
|
||||
private static final String ERROR = String.format("Not Instance of %s", DataType.class.getSimpleName());
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
|
||||
if(value instanceof DataType){
|
||||
return value;
|
||||
}
|
||||
|
||||
try {
|
||||
if(value instanceof String){
|
||||
try{
|
||||
DataType dataType = DataType.valueOf((String) value);
|
||||
if(dataType !=null){
|
||||
return dataType;
|
||||
}
|
||||
} catch(Exception e){
|
||||
// Trying another way
|
||||
}
|
||||
|
||||
try{
|
||||
Integer integer = Integer.getInteger((String) value);
|
||||
if(integer!=null){
|
||||
value = integer;
|
||||
}
|
||||
} catch(Exception e){
|
||||
// Trying another way
|
||||
}
|
||||
}
|
||||
|
||||
if(value instanceof Integer){
|
||||
return DataType.values()[(Integer) value];
|
||||
}
|
||||
|
||||
if(value instanceof Enum){
|
||||
return DataType.values()[((Enum) value).ordinal()];
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
throw new InvalidValueException(ERROR, e);
|
||||
}
|
||||
|
||||
throw new InvalidValueException(ERROR);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue