Switched to validators added to document-store library

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@122000 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-12-21 10:50:09 +00:00
parent 6e4e3d4c93
commit 345c850de8
61 changed files with 159 additions and 1355 deletions

View File

@ -3,17 +3,16 @@
*/
package org.gcube.accounting.datamodel;
import org.gcube.accounting.datamodel.decorators.AggregatedField;
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@SuppressWarnings("rawtypes")
public interface AggregatedUsageRecord<A extends AggregatedUsageRecord, U extends UsageRecord> extends AggregatedRecord<A,U> {
public interface AggregatedUsageRecord<A extends AggregatedUsageRecord<A,U>, U extends UsageRecord> extends AggregatedRecord<A,U> {
@AggregatedField @NotEmptyIfNotNull
public static final String AGGREGATED = AggregatedRecord.AGGREGATED;

View File

@ -4,31 +4,15 @@
package org.gcube.accounting.datamodel;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.gcube.accounting.datamodel.decorators.AggregatedField;
import org.gcube.accounting.datamodel.decorators.ComputedField;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType;
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.AbstractRecord;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,7 +20,7 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public abstract class BasicUsageRecord implements UsageRecord {
public abstract class BasicUsageRecord extends AbstractRecord implements UsageRecord {
/**
* Generated Serial Version UID
@ -44,131 +28,25 @@ public abstract class BasicUsageRecord implements UsageRecord {
private static final long serialVersionUID = -2060728578456796388L;
private static Logger logger = LoggerFactory.getLogger(BasicUsageRecord.class);
@RequiredField @NotEmpty
private static final String ID = Record.ID;
@RequiredField @NotEmpty
private static final String CONSUMER_ID = UsageRecord.CONSUMER_ID;
@RequiredField @ValidLong
private static final String CREATION_TIME = Record.CREATION_TIME;
@Deprecated @MoveToRecordType
private static final String USAGE_RECORD_TYPE = "usageRecordType";
@RequiredField @NotEmpty
private static final String RECORD_TYPE = Record.RECORD_TYPE;
// TODO MOVE TO RECORD_TYPE
@Deprecated @RequiredField @NotEmpty
public static final String USAGE_RECORD_TYPE = "usageRecordType";
public static final String CONSUMER_ID = UsageRecord.CONSUMER_ID;
@RequiredField @NotEmpty
private static final String SCOPE = UsageRecord.SCOPE;
public static final String SCOPE = UsageRecord.SCOPE;
@RequiredField @ValidOperationResult
private static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
/** resource-specific properties */
protected Map<String, Comparable<? extends Serializable>> resourceProperties;
protected Map<String, List<FieldAction>> validation;
protected Set<String> requiredFields;
/**
* {@inheritDoc}
*/
@Override
public Set<String> getRequiredFields() {
return requiredFields;
}
protected Set<String> computedFields;
private static final String START_TIME = AggregatedRecord.START_TIME;
private static final String END_TIME = AggregatedRecord.END_TIME;
private static final String OPERATION_COUNT = AggregatedUsageRecord.OPERATION_COUNT;
protected Set<String> aggregatedFields;
protected static Set<Field> getAllFields(Class<?> type) {
Set<Field> fields = new HashSet<Field>();
for (Class<?> c = type; c != null; c = c.getSuperclass())
fields.addAll(Arrays.asList(c.getDeclaredFields()));
return fields;
}
protected void initializeValidation() {
//logger.trace("Initializing Field Validators");
Set<Field> fields = getAllFields(this.getClass());
for(Field field : fields){
boolean defaultAccessibility = field.isAccessible();
field.setAccessible(true);
String keyString;
try {
keyString = (String) field.get(null);
} catch (Exception e) {
continue;
}
List<FieldAction> fieldValidators = new ArrayList<FieldAction>();
validation.put(keyString, fieldValidators);
for (Annotation annotation : field.getAnnotations()){
if (annotation.annotationType().isAnnotationPresent(FieldDecorator.class)){
Class<? extends FieldAction> managedClass = ((FieldDecorator)annotation.annotationType().getAnnotation(FieldDecorator.class)).managed();
FieldAction validator;
try {
validator = managedClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
logger.error("{} {}", keyString, annotation, e);
continue;
}
fieldValidators.add(validator);
}
if(annotation.annotationType().isAssignableFrom(RequiredField.class)){
requiredFields.add(keyString);
}
if(annotation.annotationType().isAssignableFrom(AggregatedField.class)){
aggregatedFields.add(keyString);
}
if(annotation.annotationType().isAssignableFrom(ComputedField.class)){
computedFields.add(keyString);
}
}
field.setAccessible(defaultAccessibility);
}
/*
logger.trace("Required Fields {}", requiredFields);
logger.trace("Aggregated Fields {}", aggregatedFields);
logger.trace("Computed Fields {}", computedFields);
*/
}
protected void cleanExtraFields(){
Set<String> neededFields = this.requiredFields;
neededFields.addAll(this.aggregatedFields);
Set<String> keysToRemove = new HashSet<String>();
Set<String> propertyKeys = this.resourceProperties.keySet();
for(String propertyName : propertyKeys){
if(!neededFields.contains(propertyName)){
keysToRemove.add(propertyName);
}
}
for(String keyToRemove : keysToRemove){
this.resourceProperties.remove(keyToRemove);
}
}
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
/**
* Initialize variable
*/
private void init() {
this.validation = new HashMap<String, List<FieldAction>>();
this.requiredFields = new HashSet<String>();
this.aggregatedFields = new HashSet<String>();
this.computedFields = new HashSet<String>();
this.resourceProperties = new HashMap<String, Comparable<? extends Serializable>>();
initializeValidation();
protected void init() {
super.init();
// Backward compatibility
try {
this.setScope(ScopeProvider.instance.get());
} catch(Exception e) {
@ -177,59 +55,13 @@ public abstract class BasicUsageRecord implements UsageRecord {
}
public BasicUsageRecord(){
init();
this.resourceProperties.put(ID, UUID.randomUUID().toString());
this.setRecordType();
Calendar calendar = Calendar.getInstance();
this.resourceProperties.put(CREATION_TIME, calendar.getTimeInMillis());
super();
}
public BasicUsageRecord(Map<String, Comparable<? extends Serializable>> properties) throws InvalidValueException {
init();
setResourceProperties(properties);
if(this instanceof AggregatedUsageRecord){
this.resourceProperties.put(AggregatedUsageRecord.AGGREGATED, true);
cleanExtraFields();
}
}
@Deprecated
public String getUsageRecordType() {
return getRecordType();
}
@Override
public String getRecordType() {
return (String) this.resourceProperties.get(RECORD_TYPE);
}
protected abstract String giveMeUsageRecordType();
@Deprecated
protected void setUsageRecordType(){
setRecordType();
}
protected void setRecordType(){
this.resourceProperties.put(RECORD_TYPE, this.giveMeUsageRecordType());
this.resourceProperties.put(USAGE_RECORD_TYPE, this.giveMeUsageRecordType());
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return (String) this.resourceProperties.get(ID);
super();
}
/**
* {@inheritDoc}
*/
@Override
public void setId(String id) throws InvalidValueException {
setResourceProperty(ID, id);
}
/**
* {@inheritDoc}
*/
@ -246,28 +78,6 @@ public abstract class BasicUsageRecord implements UsageRecord {
setResourceProperty(CONSUMER_ID, consumerId);
}
protected Calendar timestampStringToCalendar(long millis){
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millis);
return calendar;
}
/**
* {@inheritDoc}
*/
@Override
public Calendar getCreationTime() {
long millis = (Long) this.resourceProperties.get(CREATION_TIME);
return timestampStringToCalendar(millis);
}
/**
* {@inheritDoc}
*/
@Override
public void setCreationTime(Calendar creationTime) throws InvalidValueException {
setResourceProperty(CREATION_TIME, creationTime.getTimeInMillis());
}
/**
* {@inheritDoc}
@ -285,167 +95,6 @@ public abstract class BasicUsageRecord implements UsageRecord {
setResourceProperty(SCOPE, scope);
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, Comparable<? extends Serializable>> getResourceProperties() {
return new HashMap<String, Comparable<? extends Serializable>>(this.resourceProperties);
}
/**
* {@inheritDoc}
*/
@Override
public void setResourceProperties(Map<String, Comparable<? extends Serializable>> properties) throws InvalidValueException {
Map<String, Comparable<? extends Serializable>> validated = validateProperties(properties);
this.resourceProperties = new HashMap<String, Comparable<? extends Serializable>>(validated);
}
/**
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> getResourceProperty(String key) {
return this.resourceProperties.get(key);
}
/**
* {@inheritDoc}
*/
@Override
public void setResourceProperty(String key, Comparable<? extends Serializable> value) throws InvalidValueException {
Comparable<? extends Serializable> checkedValue = validateField(key, value);
if(checkedValue == null){
this.resourceProperties.remove(key);
}else{
this.resourceProperties.put(key, checkedValue);
}
}
// AGGREGATION
/* --------------------------------------- */
/**
* Return the left end of the time interval covered by this {#UsageRecord}
* @return Start Time
*/
protected long getStartTimeInMillis() {
return (Long) this.resourceProperties.get(START_TIME);
}
/**
* Return the left end of the time interval covered by this {#UsageRecord}
* @return Start Time
*/
protected Calendar getStartTimeAsCalendar() {
long millis = getStartTimeInMillis();
return timestampStringToCalendar(millis);
}
/**
* Set the left end of the time interval covered by this {#UsageRecord}
* @param startTime Start Time
* @throws InvalidValueException
*/
protected void setStartTime(Calendar startTime) throws InvalidValueException {
setResourceProperty(START_TIME, startTime.getTimeInMillis());
}
/**
* Return the right end of the time interval covered by this {#UsageRecord}
* @return End Time
*/
protected long getEndTimeInMillis() {
return (Long) this.resourceProperties.get(END_TIME);
}
/**
* Return the right end of the time interval covered by this {#UsageRecord}
* @return End Time
*/
protected Calendar getEndTimeAsCalendar() {
long millis = getEndTimeInMillis();
return timestampStringToCalendar(millis);
}
/**
* Set the right end of the time interval covered by this {#UsageRecord}
* @param endTime End Time
* @throws InvalidValueException
*/
protected void setEndTime(Calendar endTime) throws InvalidValueException {
setResourceProperty(END_TIME, endTime.getTimeInMillis());
}
protected int getOperationCount() {
return (Integer) this.resourceProperties.get(OPERATION_COUNT);
}
protected void setOperationCount(int operationCount) throws InvalidValueException {
setResourceProperty(OPERATION_COUNT, operationCount);
}
/* --------------------------------------- */
protected Comparable<? extends Serializable> validateField(String key, Comparable<? extends Serializable> value) throws InvalidValueException {
if(key == null){
throw new InvalidValueException("The key of property to set cannot be null");
}
Comparable<? extends Serializable> checkedValue = value;
List<FieldAction> fieldValidators = validation.get(key);
if(fieldValidators!=null){
for(FieldAction fieldValidator : fieldValidators){
if(aggregatedFields.contains(key)){
// TODO
}
if(computedFields.contains(key)){
logger.debug("{} is a computed field. To be calculated all the required fields to calcutalate it MUST be set. In any case the provided value will be ignored.", key);
}
try {
checkedValue = fieldValidator.validate(key, checkedValue, this);
} catch (InvalidValueException e) {
logger.error(String.format("The provided value %s is NOT valid for field with key %s.", checkedValue.toString(), key));
throw e;
}
}
}
return checkedValue;
}
protected Map<String, Comparable<? extends Serializable>> validateProperties(Map<String, Comparable<? extends Serializable>> properties) throws InvalidValueException{
Map<String, Comparable<? extends Serializable>> validated = new HashMap<String, Comparable<? extends Serializable>>();
for(String key : properties.keySet()){
Comparable<? extends Serializable> value = properties.get(key);
validated.put(key, validateField(key, value));
}
return validated;
}
/**
* {@inheritDoc}
*/
@Override
public void validate() throws InvalidValueException {
validateProperties(this.resourceProperties);
Set<String> notPresentProperties = new HashSet<String>();
for(String key : this.requiredFields){
if(!this.resourceProperties.containsKey(key)){
notPresentProperties.add(key);
}
}
if(!notPresentProperties.isEmpty()){
String pluralManagement = notPresentProperties.size() == 1 ? "y" : "ies";
throw new InvalidValueException(String.format("The Usage Record does not contain the following required propert%s %s", pluralManagement, notPresentProperties.toString()));
}
}
@Override
public String toString(){
return resourceProperties.toString();
}
/**
* {@inheritDoc}
*/
@ -462,30 +111,5 @@ public abstract class BasicUsageRecord implements UsageRecord {
public void setOperationResult(OperationResult operationResult) throws InvalidValueException {
setResourceProperty(OPERATION_RESULT, operationResult);
}
/**
* Compare this UsageRecord instance with the one provided as argument
* @param usageRecord the Usage Record to compare
* @return 0 is and only if the UsageRecord provided as parameter
* contains all and ONLY the parameters contained in this instance.
* If the number of parameters differs, the methods return the difference
* between the number of parameter in this instance and the ones in the
* UsageRecord provided as parameter.
* If the size is the same but the UsageRecord provided as parameter does
* not contains all parameters in this instance, -1 is returned.
*/
@Override
public int compareTo(Record record) {
Set<Entry<String, Comparable<? extends Serializable>>> thisSet = this.resourceProperties.entrySet();
Set<Entry<String, Comparable<? extends Serializable>>> usageRecordSet = record.getResourceProperties().entrySet();
if(thisSet.size() != usageRecordSet.size()){
return thisSet.size() - usageRecordSet.size();
}
if(usageRecordSet.containsAll(thisSet)){
return 0;
}
return 1;
}
}

View File

@ -1,388 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToCreationTime;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToScope;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToUsageRecordType;
import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.documentstore.exception.InvalidValueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@Deprecated
public class RawUsageRecord extends BasicUsageRecord implements UsageRecord {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 1203390363640634895L;
private static Logger logger = LoggerFactory.getLogger(RawUsageRecord.class);
@DeprecatedWarning @MoveToScope @NotEmpty
public static final String RESOURCE_SCOPE = "resourceScope";
@DeprecatedWarning @NotEmptyIfNotNull
public static final String CREATOR_ID = "creatorId";
@DeprecatedWarning @NotEmptyIfNotNull
protected static final String RESOURCE_OWNER = "resourceOwner";
@DeprecatedWarning @MoveToCreationTime
protected static final String CREATE_TIME = "createTime";
public final static Map<String, String> resourceTypeMapping;
private final static String JOB = "job";
private final static String TASK = "task";
private final static String PORTLET = "portlet";
private final static String SERVICE = "service";
private final static String STORAGE_USAGE = "storage-usage";
static {
resourceTypeMapping = new HashMap<String, String>();
resourceTypeMapping.put(JOB, JobUsageRecord.class.getSimpleName());
resourceTypeMapping.put(TASK, TaskUsageRecord.class.getSimpleName());
resourceTypeMapping.put(PORTLET, PortletUsageRecord.class.getSimpleName());
resourceTypeMapping.put(SERVICE, ServiceUsageRecord.class.getSimpleName());
resourceTypeMapping.put(STORAGE_USAGE, StorageUsageRecord.class.getSimpleName());
}
@DeprecatedWarning @MoveToUsageRecordType
protected static final String RESOURCE_TYPE = "resourceType";
@DeprecatedWarning //@MoveToAggregatedUsageRecordId
protected static final String AGGREGATED_ID = "aggregatedId";
/**
* Redeclared to allow @MoveToUsageRecordTypeAction to access it
*/
public static final String USAGE_RECORD_TYPE = BasicUsageRecord.USAGE_RECORD_TYPE;
/*
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToAggregatedUsageRecordIdAction.class)
protected @interface MoveToAggregatedUsageRecordId { }
protected class MoveToAggregatedUsageRecordIdAction implements FieldAction {
@Override
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
NotEmptyIfNotNullValidator neinnv = new NotEmptyIfNotNullValidator();
value = neinnv.validate(key, value, usageRecord);
usageRecord.setAggregatedUsageRecordId((String) value);
return value;
}
}
*/
@NotEmptyIfNotNull @DeprecatedWarning
protected static final String FULLY_QUALIFIED_CONSUMER_ID = "fullyQualifiedConsumerId";
@Deprecated
public RawUsageRecord(){
super();
this.resourceProperties.remove(USAGE_RECORD_TYPE);
}
@Deprecated
public RawUsageRecord(Map<String, Comparable<? extends Serializable>> properties) throws InvalidValueException {
super(properties);
}
/**
* Return the identity of the entity creating this {#UsageRecord}
* @return Creator ID
*/
@Deprecated
public String getCreatorId() {
return (String) this.resourceProperties.get(CREATOR_ID);
}
/**
* Set the identity of the entity creating this {#UsageRecord}
* @param creatorId Creator ID
* @throws InvalidValueException
*/
@Deprecated
public void setCreatorId(String creatorId) throws InvalidValueException {
setResourceProperty(CREATOR_ID, creatorId);
}
/**
* {@inheritDoc}
*/
@Override
@Deprecated
public void setConsumerId(String consumerId) {
try{
super.setConsumerId(consumerId);
} catch(Exception e){
logger.error("Unable to Set {}", CONSUMER_ID);
}
}
/**
* Set the scope of the {#UsageRecord}
* @param scope the scope of the {#UsageRecord}
*/
@Deprecated
public void setResourceScope(String scope) {
try{
setResourceProperty(RESOURCE_SCOPE, scope);
}catch(Exception e){
logger.error("Unable to Set {}", RESOURCE_SCOPE);
}
}
/**
* Use {#getUsageRecordType} instead
* @param resourceType
* @return Usage Record Type
*/
@Deprecated
public String getResourceType(){
return (String) this.resourceProperties.get(RESOURCE_TYPE);
}
/**
* This method is not valid due to Resource Type is derived by
* the Usage Record Implementation class. The method is deprecated and
* the implementations in known classes is a NoOperation.
* @param resourceType
*/
@Deprecated
public void setResourceType(String resourceType){
try {
setResourceProperty(RESOURCE_TYPE, resourceType);
}catch(InvalidValueException e){
logger.error("Unable to Set {}", RESOURCE_TYPE);
}
}
/**
* Return the creation time for this {#UsageRecord}
* @return the creation time for this {#UsageRecord}
*/
@Deprecated
public Date getCreateTime() {
long millis = (Long) this.resourceProperties.get(AggregatedUsageRecord.CREATION_TIME);
return timestampStringToCalendar(millis).getTime();
}
/**
* Use {{@link #setCreationTime(Calendar)}} instead
* @param createTime
* @throws InvalidValueException
*/
@Deprecated
public void setCreateTime(Date createTime) {
/*
Calendar calendar = Calendar.getInstance();
calendar.setTime(createTime);
setCreationTime(calendar);
*/
//logger.warn("The method is deprecated. Please modify your code as soon as possible");
}
/**
* Return the left end of the time interval covered by this usage record
* @return Start Time
*/
@Deprecated
public Date getStartTime() {
long millis = (Long) this.resourceProperties.get(AggregatedUsageRecord.START_TIME);
return timestampStringToCalendar(millis).getTime();
}
/**
* @param createTime
* @throws InvalidValueException
*/
@Deprecated
public void setStartTime(Date startTime) throws InvalidValueException {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startTime);
setStartTime(calendar);
}
/**
* Return the right end of the time interval covered by this usage record
* @return End Time
*/
@Deprecated
public Date getEndTime() {
long millis = (Long) this.resourceProperties.get(AggregatedUsageRecord.END_TIME);
return timestampStringToCalendar(millis).getTime();
}
/**
* @param endTime
* @throws InvalidValueException
*/
@Deprecated
public void setEndTime(Date endTime) throws InvalidValueException {
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
setEndTime(calendar);
}
/**
* Return the identity id of the owner
* @return The identity id of the owner
*/
@Deprecated
public String getResourceOwner() {
return (String) this.resourceProperties.get(RESOURCE_OWNER);
}
/**
* Set the identity id of the owner
* @param ownerID The identity id of the owner
* @throws InvalidValueException
*/
@Deprecated
public void setResourceOwner(String owner) {
try {
setResourceProperty(RESOURCE_OWNER, owner);
} catch (InvalidValueException e) {
logger.error("Unable to Set {}", RESOURCE_OWNER);
}
}
/**
* Return the id of the usage record aggregating this, null if this record
* has not been aggregated by any record.
* This method id deprecated. Use {@link #getAggregatedUsageRecordId()}
* instead.
* @return Aggregated Id The ID of the aggregation Record
*/
@Deprecated
public String getAggregatedId() {
return (String) this.resourceProperties.get(AGGREGATED_ID);
}
/**
* Set the id of the usage record aggregating this.
* This method id deprecated. Use {@link #setAggregatedUsageRecordId()}
* instead.
* @param aggregatedId The ID of the aggregation Record
* @throws InvalidValueException
*/
@Deprecated
public void setAggregatedId(String aggregatedId) throws InvalidValueException {
setResourceProperty(AGGREGATED_ID, aggregatedId);
}
/**
* Return all resource properties
* Use {@link #getResourceSpecificProperties()}
* @return a Map containing the properties
*/
@Deprecated
public Map<String, String> getResourceSpecificProperties() {
Map<String, String> ret = new HashMap<String, String>();
for(String key : this.resourceProperties.keySet()){
String value = this.resourceProperties.get(key).toString();
ret.put(key, value);
}
return ret;
}
/**
* Set all resource properties, replacing existing ones
* Use {@link #setResourceSpecificProperties()}
*/
@Deprecated
public void setResourceSpecificProperties(Map<String, String> properties) throws InvalidValueException {
Map<String, Comparable<? extends Serializable>> map = new HashMap<String, Comparable<? extends Serializable>>(properties);
setResourceProperties(map);
}
/**
* Return the value of the given resource property.
* @param key the key of the requested property
* @return the value of the given resource property
*/
@Deprecated
public String getResourceSpecificProperty(String key) {
return getResourceProperty(key).toString();
}
/**
* Set the value of the given resource property.
* If the key has the value of one of the predefined property, the value
* is validated.
* @param key the key of the requested property
* @param value the value of the given resource property
*/
@Deprecated
public void setResourceSpecificProperty(String key, Comparable<? extends Serializable> value) {
try {
setResourceProperty(key, value);
} catch (InvalidValueException e) {
logger.error("Unable to Set {}", key);
}
}
/**
* The method is deprecated and the implementations in known classes
* return Consumer ID
* @return Consumer ID
*/
@Deprecated
public String getFullyQualifiedConsumerId() {
return (String) this.resourceProperties.get(FULLY_QUALIFIED_CONSUMER_ID);
}
/**
* The method is deprecated and the implementations in known classes is
* a NoOperation.
* @param fqcid Fully Qualified Consumer Id
*/
@Deprecated
public void setFullyQualifiedConsumerId(String fqcid) {
try {
setResourceProperty(FULLY_QUALIFIED_CONSUMER_ID, fqcid);
} catch (InvalidValueException e) {
logger.error("Unable to Set {}", FULLY_QUALIFIED_CONSUMER_ID);
}
}
/**
* {@inheritDoc}
*/
@Override
protected String giveMeUsageRecordType() {
// This implementation is just a placeholder
return this.getClass().getSimpleName();
}
}

View File

@ -9,12 +9,12 @@ import java.util.Map;
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
import org.gcube.accounting.datamodel.decorators.AggregatedField;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* This Class is for library internal use only

View File

@ -9,12 +9,12 @@ import java.util.Map;
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
import org.gcube.accounting.datamodel.decorators.AggregatedField;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.documentstore.records.implementation.AggregatedField;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* This Class is for library internal use only

View File

@ -8,9 +8,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToConsumerIdAction.class)
@FieldDecorator(action=MoveToConsumerIdAction.class)
public @interface MoveToConsumerId { }

View File

@ -6,16 +6,19 @@ package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.gcube.documentstore.records.implementation.validations.validators.NotEmptyIfNotNullValidator;
public class MoveToConsumerIdAction implements FieldAction {
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
NotEmptyIfNotNullValidator neinnv = new NotEmptyIfNotNullValidator();
value = neinnv.validate(key, value, usageRecord);
usageRecord.setConsumerId((String) value);
return value;
value = neinnv.validate(key, value, record);
record.setResourceProperty(UsageRecord.CONSUMER_ID, (String) value);
return null;
}
}

View File

@ -1,36 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
public class MoveToCreationTimeAction implements FieldAction {
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
if(value instanceof Date){
Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) value);
value = calendar;
}
if(value instanceof Long){
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis((Long) value);
value = calendar;
}
if(value instanceof Calendar){
usageRecord.setCreationTime((Calendar) value);
}else{
throw new InvalidValueException();
}
return value;
}
}

View File

@ -5,11 +5,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToOperationResultAction.class)
@FieldDecorator(action=MoveToOperationResultAction.class)
public @interface MoveToOperationResult {
}

View File

@ -7,9 +7,10 @@ import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -21,11 +22,11 @@ public class MoveToOperationResultAction implements FieldAction {
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
ValidOperationResultValidator vorv = new ValidOperationResultValidator();
value = vorv.validate(key, value, usageRecord);
usageRecord.setOperationResult((OperationResult) value);
return value;
value = vorv.validate(key, value, record);
record.setResourceProperty(UsageRecord.OPERATION_RESULT, (OperationResult) value);
return null;
}
}

View File

@ -8,9 +8,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToCreationTimeAction.class)
public @interface MoveToCreationTime { }
@FieldDecorator(action=MoveToRecordTypeAction.class)
public @interface MoveToRecordType { }

View File

@ -0,0 +1,22 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class MoveToRecordTypeAction implements FieldAction {
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
if(value instanceof String && value!= null && !((String) value).isEmpty()){
record.setResourceProperty(Record.RECORD_TYPE, value);
}
return null;
}
}

View File

@ -1,16 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
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.decorators.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToScopeAction.class)
public @interface MoveToScope { }

View File

@ -1,22 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
public class MoveToScopeAction implements FieldAction {
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
if(value instanceof String){
usageRecord.setScope((String) value);
}else{
throw new InvalidValueException();
}
return value;
}
}

View File

@ -12,11 +12,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToTaskEndTimeAction.class)
@FieldDecorator(action=MoveToTaskEndTimeAction.class)
public @interface MoveToTaskEndTime {
}

View File

@ -5,10 +5,10 @@ package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -21,10 +21,10 @@ public class MoveToTaskEndTimeAction implements FieldAction {
*/
@Override
public Comparable<? extends Serializable> validate(String key,
Comparable<? extends Serializable> value, UsageRecord usageRecord)
Comparable<? extends Serializable> value, Record record)
throws InvalidValueException {
usageRecord.setResourceProperty(AbstractTaskUsageRecord.TASK_END_TIME, value);
return usageRecord.getResourceProperty(AbstractTaskUsageRecord.TASK_END_TIME);
record.setResourceProperty(AbstractTaskUsageRecord.TASK_END_TIME, value);
return null;
}
}

View File

@ -12,11 +12,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToTaskStartTimeAction.class)
@FieldDecorator(action=MoveToTaskStartTimeAction.class)
public @interface MoveToTaskStartTime {
}

View File

@ -5,10 +5,10 @@ package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -21,10 +21,10 @@ public class MoveToTaskStartTimeAction implements FieldAction {
*/
@Override
public Comparable<? extends Serializable> validate(String key,
Comparable<? extends Serializable> value, UsageRecord usageRecord)
Comparable<? extends Serializable> value, Record record)
throws InvalidValueException {
usageRecord.setResourceProperty(AbstractTaskUsageRecord.TASK_START_TIME, value);
return usageRecord.getResourceProperty(AbstractTaskUsageRecord.TASK_START_TIME);
record.setResourceProperty(AbstractTaskUsageRecord.TASK_START_TIME, value);
return null;
}
}

View File

@ -1,16 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
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.decorators.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=MoveToUsageRecordTypeAction.class)
public @interface MoveToUsageRecordType { }

View File

@ -1,29 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.backwardcompatibility;
import java.io.Serializable;
import org.gcube.accounting.datamodel.RawUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
@SuppressWarnings("deprecation")
public class MoveToUsageRecordTypeAction implements FieldAction {
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
if(value instanceof String){
String newValue = RawUsageRecord.resourceTypeMapping.get(value);
if(newValue == null){
throw new InvalidValueException();
}
usageRecord.setResourceProperty(RawUsageRecord.USAGE_RECORD_TYPE, newValue);
}else{
throw new InvalidValueException();
}
return value;
}
}

View File

@ -9,13 +9,13 @@ import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToOperationResult;
import org.gcube.accounting.datamodel.decorators.ComputedField;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.documentstore.records.implementation.ComputedField;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -60,7 +60,7 @@ public abstract class AbstractJobUsageRecord extends BasicUsageRecord {
* {@inheritDoc}
*/
@Override
protected String giveMeUsageRecordType() {
protected String giveMeRecordType() {
return AbstractJobUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
}

View File

@ -8,11 +8,11 @@ import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToConsumerId;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -48,7 +48,7 @@ public abstract class AbstractPortletUsageRecord extends BasicUsageRecord {
* {@inheritDoc}
*/
@Override
protected String giveMeUsageRecordType() {
protected String giveMeRecordType() {
return AbstractPortletUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
}

View File

@ -7,10 +7,10 @@ import java.io.Serializable;
import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -73,7 +73,7 @@ public abstract class AbstractServiceUsageRecord extends BasicUsageRecord {
* {@inheritDoc}
*/
@Override
protected String giveMeUsageRecordType() {
protected String giveMeRecordType() {
return AbstractServiceUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
}

View File

@ -8,15 +8,15 @@ import java.net.URI;
import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.validations.annotations.FixDataVolumeSign;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.accounting.datamodel.validations.annotations.ValidDataType;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationType;
import org.gcube.accounting.datamodel.validations.annotations.ValidURI;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmptyIfNotNull;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -99,7 +99,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
* {@inheritDoc}
*/
@Override
protected String giveMeUsageRecordType() {
protected String giveMeRecordType() {
return AbstractStorageUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
}

View File

@ -11,12 +11,12 @@ import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToOperationResult;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToTaskEndTime;
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToTaskStartTime;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.RequiredField;
import org.gcube.documentstore.records.implementation.validations.annotations.NotEmpty;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger;
import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -83,7 +83,7 @@ public abstract class AbstractTaskUsageRecord extends BasicUsageRecord {
* {@inheritDoc}
*/
@Override
protected String giveMeUsageRecordType() {
protected String giveMeRecordType() {
return AbstractTaskUsageRecord.class.getSimpleName().replace(ABSTRACT_TO_REPLACE, "");
}

View File

@ -8,9 +8,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=CalculateWallDurationAction.class)
@FieldDecorator(action=CalculateWallDurationAction.class)
public @interface CalculateWallDuration {}

View File

@ -5,9 +5,9 @@ package org.gcube.accounting.datamodel.basetypes;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,9 +16,9 @@ public class CalculateWallDurationAction implements FieldAction {
private static final Logger logger = LoggerFactory.getLogger(CalculateWallDurationAction.class);
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
try {
long wallDuration = ((AbstractJobUsageRecord) usageRecord).calculateWallDuration();
long wallDuration = ((AbstractJobUsageRecord) record).calculateWallDuration();
if(key.compareTo(AbstractJobUsageRecord.WALL_DURATION)==0){
logger.warn("{} is automatically computed using {} and {}. This invocation has the only effect of recalculating the value. Any provided value is ignored.",
AbstractJobUsageRecord.WALL_DURATION, AbstractJobUsageRecord.JOB_START_TIME, AbstractJobUsageRecord.JOB_END_TIME);

View File

@ -1,16 +0,0 @@
package org.gcube.accounting.datamodel.decorators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotations indicates that the field is related to an aggregation
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AggregatedField {
}

View File

@ -1,17 +0,0 @@
package org.gcube.accounting.datamodel.decorators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotations indicates that the field is calculated using the
* value of other field in the instance
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ComputedField {
}

View File

@ -1,29 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.decorators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.documentstore.exception.InvalidValueException;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public interface FieldAction {
/**
* Validate (and eventually convert) the value of the property identified by
* the key.
* @param key The key of the property
* @param value The value to be validated (and eventually converted) of the
* property
* @param usageRecord the Usage Record the property is attached
* @return the validated (and eventually converted) value of the property
* @throws InvalidValueException if the validation or the eventual
* conversion fails
*/
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException;
}

View File

@ -1,23 +0,0 @@
/**
*
*/
package org.gcube.accounting.datamodel.decorators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface FieldDecorator {
Class<? extends FieldAction> managed();
}

View File

@ -1,12 +0,0 @@
package org.gcube.accounting.datamodel.decorators;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiredField {
}

View File

@ -5,11 +5,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=DeprecatedWarningAction.class)
@FieldDecorator(action=DeprecatedWarningAction.class)
public @interface DeprecatedWarning {
}

View File

@ -5,9 +5,9 @@ package org.gcube.accounting.datamodel.deprecationmanagement;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,9 +23,9 @@ public class DeprecatedWarningAction implements FieldAction {
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
logger.trace("The field {} is deprecated for {}. Anyway the field will be included in the SingleUsageRecord. The field can be lost during aggregation.",
key, usageRecord.getClass().getSimpleName());
key, record.getClass().getSimpleName());
return value;
}

View File

@ -8,8 +8,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.FixDataVolumeSignAction;
import org.gcube.documentstore.records.implementation.FieldDecorator;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -17,7 +17,7 @@ import org.gcube.accounting.datamodel.validations.validators.FixDataVolumeSignAc
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=FixDataVolumeSignAction.class)
@FieldDecorator(action=FixDataVolumeSignAction.class)
public @interface FixDataVolumeSign {
}

View File

@ -1,16 +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.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=NotEmptyValidator.class)
public @interface NotEmpty {
}

View File

@ -1,16 +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.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=NotEmptyIfNotNullValidator.class)
public @interface NotEmptyIfNotNull {
}

View File

@ -1,16 +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.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.NotNullValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=NotNullValidator.class)
public @interface NotNull {
}

View File

@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidDataTypeValidator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidDataTypeValidator.class)
@FieldDecorator(action=ValidDataTypeValidator.class)
public @interface ValidDataType {
}

View File

@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidIPValidator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidIPValidator.class)
@FieldDecorator(action=ValidIPValidator.class)
public @interface ValidIP {
}

View File

@ -1,16 +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.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidIntegerValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidIntegerValidator.class)
public @interface ValidInteger {
}

View File

@ -1,16 +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.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidLongValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidLongValidator.class)
public @interface ValidLong {
}

View File

@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidOperationResultValidator.class)
@FieldDecorator(action=ValidOperationResultValidator.class)
public @interface ValidOperationResult {
}

View File

@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationTypeValidator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidOperationTypeValidator.class)
@FieldDecorator(action=ValidOperationTypeValidator.class)
public @interface ValidOperationType {
}

View File

@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidURIValidator;
import org.gcube.documentstore.records.implementation.FieldDecorator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidURIValidator.class)
@FieldDecorator(action=ValidURIValidator.class)
public @interface ValidURI {
}

View File

@ -5,11 +5,12 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.gcube.documentstore.records.implementation.validations.validators.ValidLongValidator;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
@ -46,27 +47,27 @@ public class FixDataVolumeSignAction implements FieldAction {
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
try {
if(key.compareTo(AbstractStorageUsageRecord.DATA_VOLUME)==0){
OperationType operationType = (OperationType) usageRecord.getResourceProperty(AbstractStorageUsageRecord.OPERATION_TYPE);
OperationType operationType = (OperationType) record.getResourceProperty(AbstractStorageUsageRecord.OPERATION_TYPE);
if(operationType!=null){
ValidLongValidator validLongValidator = new ValidLongValidator();
value = validLongValidator.validate(key, value, usageRecord);
value = validLongValidator.validate(key, value, record);
Long dataVolume = new Long((Long) value);
value = checkIt(dataVolume, operationType);
}
}
if(key.compareTo(AbstractStorageUsageRecord.OPERATION_TYPE)==0){
Long dataVolume = (Long) usageRecord.getResourceProperty(AbstractStorageUsageRecord.DATA_VOLUME);
Long dataVolume = (Long) record.getResourceProperty(AbstractStorageUsageRecord.DATA_VOLUME);
if(dataVolume!=null){
ValidOperationTypeValidator v = new ValidOperationTypeValidator();
value = v.validate(key, value, usageRecord);
value = v.validate(key, value, record);
OperationType operationType = (OperationType) value;
Long newDataVolume = checkIt(dataVolume, operationType);
usageRecord.setResourceProperty(AbstractStorageUsageRecord.DATA_VOLUME, newDataVolume);
record.setResourceProperty(AbstractStorageUsageRecord.DATA_VOLUME, newDataVolume);
}
}

View File

@ -1,21 +0,0 @@
package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import java.util.Map;
public class NotEmptyIfNotNullValidator extends NotEmptyValidator {
protected boolean isValid(Serializable toValidate) {
if (toValidate == null) return true;
if (toValidate.getClass().isArray() ){
return ((Object[])toValidate).length>0;
}else if ( toValidate instanceof Iterable<?>){
return ((Iterable<?>) toValidate).iterator().hasNext();
} else if (toValidate instanceof Map<?,?>){
return ((Map<?,?>) toValidate).size()>0;
} else if (toValidate instanceof String ){
return !((String)toValidate).isEmpty();
} else return true;
}
}

View File

@ -1,42 +0,0 @@
package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import java.util.Map;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
public class NotEmptyValidator implements FieldAction{
private static final String ERROR = "Is Empty";
protected boolean isValid(Serializable toValidate) {
if (toValidate == null) return false;
if (toValidate.getClass().isArray() ){
return ((Object[])toValidate).length>0;
}else if ( toValidate instanceof Iterable<?>){
return ((Iterable<?>) toValidate).iterator().hasNext();
} else if (toValidate instanceof Map<?,?>){
return ((Map<?,?>) toValidate).size()>0;
} else if (toValidate instanceof String ){
return !((String)toValidate).isEmpty();
} else return true;
}
/**
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
try{
if(isValid((Serializable) value)){
return value;
}
}catch(Exception e){
throw new InvalidValueException(ERROR, e);
}
throw new InvalidValueException(ERROR);
}
}

View File

@ -1,24 +0,0 @@
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.documentstore.exception.InvalidValueException;
public class NotNullValidator implements FieldAction {
private static final String ERROR = "Is Null";
/**
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
if(value!=null){
return value;
}
throw new InvalidValueException(ERROR);
}
}

View File

@ -2,10 +2,10 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class ValidDataTypeValidator implements FieldAction {
@ -16,7 +16,7 @@ public class ValidDataTypeValidator implements FieldAction {
*/
@SuppressWarnings("rawtypes")
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
if(value instanceof DataType){
return value;
}

View File

@ -4,13 +4,13 @@ import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ValidIPValidator implements FieldAction{
public class ValidIPValidator implements FieldAction {
private static Logger logger = LoggerFactory.getLogger(ValidIPValidator.class);
@ -47,7 +47,7 @@ public class ValidIPValidator implements FieldAction{
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
try {
if(isIpAddress((String) value)){
return (String) value;

View File

@ -1,30 +0,0 @@
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.documentstore.exception.InvalidValueException;
public class ValidIntegerValidator 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 Integer){
return value;
}
Integer integerObj = Integer.valueOf((String) value);
if(integerObj!=null){
return integerObj;
}
throw new InvalidValueException(ERROR);
}
}

View File

@ -1,33 +0,0 @@
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.documentstore.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);
}
}

View File

@ -2,10 +2,10 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class ValidOperationResultValidator implements FieldAction {
@ -16,7 +16,7 @@ public class ValidOperationResultValidator implements FieldAction {
*/
@SuppressWarnings("rawtypes")
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
if(value instanceof OperationResult){
return value;
}

View File

@ -2,11 +2,11 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class ValidOperationTypeValidator implements FieldAction {
@ -17,7 +17,7 @@ public class ValidOperationTypeValidator implements FieldAction {
*/
@SuppressWarnings("rawtypes")
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
if(value instanceof OperationType){
return value;
}

View File

@ -3,9 +3,9 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import java.net.URI;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.implementation.FieldAction;
public class ValidURIValidator implements FieldAction {
@ -15,7 +15,7 @@ public class ValidURIValidator implements FieldAction {
* {@inheritDoc}
*/
@Override
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, UsageRecord usageRecord) throws InvalidValueException {
public Comparable<? extends Serializable> validate(String key, Comparable<? extends Serializable> value, Record record) throws InvalidValueException {
try {
if(value instanceof URI){
return value;

View File

@ -6,11 +6,9 @@ package org.gcube.accounting.datamodel.usagerecords;
import java.util.HashSet;
import java.util.Set;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
@ -23,14 +21,12 @@ import org.junit.Test;
*/
public class JobUsageRecordTest {
@SuppressWarnings("deprecation")
public static Set<String> getExpectedRequiredFields(){
Set<String> expectedRequiredFields = new HashSet<String>();
expectedRequiredFields.add(Record.ID);
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
expectedRequiredFields.add(BasicUsageRecord.USAGE_RECORD_TYPE);
expectedRequiredFields.add(UsageRecord.SCOPE);
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_ID);

View File

@ -6,11 +6,9 @@ package org.gcube.accounting.datamodel.usagerecords;
import java.util.HashSet;
import java.util.Set;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
@ -23,14 +21,12 @@ import org.junit.Test;
*/
public class ServiceUsageRecordTest {
@SuppressWarnings("deprecation")
public static Set<String> getExpectedRequiredFields(){
Set<String> expectedRequiredFields = new HashSet<String>();
expectedRequiredFields.add(Record.ID);
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
expectedRequiredFields.add(BasicUsageRecord.USAGE_RECORD_TYPE);
expectedRequiredFields.add(UsageRecord.SCOPE);
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
expectedRequiredFields.add(AbstractServiceUsageRecord.CALLER_HOST);

View File

@ -6,11 +6,9 @@ package org.gcube.accounting.datamodel.usagerecords;
import java.util.HashSet;
import java.util.Set;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.Record;
@ -41,14 +39,12 @@ public class StorageUsageRecordTest {
logger.trace("Scope reset");
}
@SuppressWarnings("deprecation")
public static Set<String> getExpectedRequiredFields(){
Set<String> expectedRequiredFields = new HashSet<String>();
expectedRequiredFields.add(Record.ID);
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
expectedRequiredFields.add(BasicUsageRecord.USAGE_RECORD_TYPE);
expectedRequiredFields.add(UsageRecord.SCOPE);
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_ID);

View File

@ -5,8 +5,8 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.validations.validators.NotEmptyIfNotNullValidator;
import org.junit.Assert;
import org.junit.Test;

View File

@ -3,8 +3,8 @@
*/
package org.gcube.accounting.datamodel.validations.validators;
import org.gcube.accounting.datamodel.validations.validators.ValidLongValidator;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.records.implementation.validations.validators.ValidLongValidator;
import org.junit.Test;
/**