refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Implementing library git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115257 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0b1b2db21d
commit
32356675a0
|
@ -21,6 +21,8 @@ import org.gcube.accounting.datamodel.decorators.AggregatedField;
|
|||
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToAggregatedUsageRecordId;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
|
||||
|
@ -53,12 +55,13 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
protected static final String RESOURCE_TYPE = "resourceType";
|
||||
@RequiredField @NotEmpty
|
||||
public static final String RESOURCE_SCOPE = "resourceScope";
|
||||
@NotEmpty
|
||||
@DeprecatedWarning @NotEmpty
|
||||
protected static final String RESOURCE_OWNER = "resourceOwner";
|
||||
@AggregatedField @NotEmptyIfNotNull
|
||||
protected static final String AGGREGATED_ID = "aggregatedId";
|
||||
@NotEmptyIfNotNull
|
||||
protected static final String AGGREGATED_USAGE_RECORD_ID = "aggregatedUsageRecordId";
|
||||
@NotEmptyIfNotNull @MoveToAggregatedUsageRecordId
|
||||
protected static final String AGGREGATED_ID = "aggregatedId";
|
||||
|
||||
@RequiredField @ValidOperationResult
|
||||
public static final String OPERATION_RESULT = "operationResult";
|
||||
|
||||
|
@ -345,11 +348,18 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
|
|||
setResourceSpecificProperty(AGGREGATED_ID, aggregatedId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getAggregatedUsageRecordId() {
|
||||
return (String) this.resourceSpecificProperties.get(AGGREGATED_USAGE_RECORD_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setAggregatedUsageRecordId(String aggregatedId) throws InvalidValueException {
|
||||
setResourceSpecificProperty(AGGREGATED_USAGE_RECORD_ID, aggregatedId);
|
||||
}
|
||||
|
|
|
@ -180,20 +180,38 @@ public interface UsageRecord extends Comparable<UsageRecord>{
|
|||
public void setResourceOwner(String ownerID) throws InvalidValueException;
|
||||
|
||||
/**
|
||||
* Return the id of the usage record aggregating this
|
||||
* @return Aggregated Id
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Set the id of the usage record aggregating this
|
||||
* @param aggregatedId
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Return the id of the usage record aggregating this, null if this record
|
||||
* has not been aggregated by any record.
|
||||
* @return Aggregated Id The ID of the aggregation Record
|
||||
*/
|
||||
public String getAggregatedUsageRecordId();
|
||||
|
||||
/**
|
||||
* Set the id of the usage record aggregating this
|
||||
* @param aggregatedId The ID of the aggregation Record
|
||||
* @throws InvalidValueException
|
||||
*/
|
||||
public void setAggregatedUsageRecordId(String aggregatedId) throws InvalidValueException;
|
||||
|
||||
/**
|
||||
* Return all resource-specific properties
|
||||
|
|
|
@ -5,6 +5,10 @@ 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 {
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
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 {
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.accounting.datamodel.validations.annotations;
|
||||
package org.gcube.accounting.datamodel.deprecationmanagement.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.validations.validators.DeprecatedWarningValidator;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.accounting.datamodel.deprecationmanagement.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.ValidatorField;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToAggregatedUsageRecordIdValidator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ValidatorField(managed=MoveToAggregatedUsageRecordIdValidator.class)
|
||||
public @interface MoveToAggregatedUsageRecordId {
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.datamodel.validations.validators;
|
||||
package org.gcube.accounting.datamodel.deprecationmanagement.validators;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.datamodel.deprecationmanagement.validators;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.ValidatorAction;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class MoveToAggregatedUsageRecordIdValidator implements ValidatorAction {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
|
||||
usageRecord.setAggregatedUsageRecordId((String) value);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.util.Calendar;
|
|||
|
||||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
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;
|
||||
|
@ -45,7 +46,7 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
|
|||
|
||||
@ValidInteger
|
||||
public static final String VMS_USED = "vmsUsed";
|
||||
@ValidLong
|
||||
@ComputedField @ValidLong
|
||||
protected static final String WALL_DURATION = "wallDuration";
|
||||
|
||||
public JobUsageRecord(){
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.implementations;
|
|||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.implementations;
|
|||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidIP;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidInteger;
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Calendar;
|
|||
import org.gcube.accounting.datamodel.RawUsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.DeprecatedWarning;
|
||||
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.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;
|
||||
|
|
Loading…
Reference in New Issue