From 32356675a0193a3cb18f3f38c430d2704cc23782 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 9 Jun 2015 08:41:32 +0000 Subject: [PATCH] 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 --- .../accounting/datamodel/RawUsageRecord.java | 20 ++++++++++---- .../accounting/datamodel/UsageRecord.java | 26 +++++++++++++++--- .../datamodel/decorators/AggregatedField.java | 4 +++ .../datamodel/decorators/ComputedField.java | 17 ++++++++++++ .../annotations/DeprecatedWarning.java | 4 +-- .../MoveToAggregatedUsageRecordId.java | 16 +++++++++++ .../DeprecatedWarningValidator.java | 2 +- ...oveToAggregatedUsageRecordIdValidator.java | 27 +++++++++++++++++++ .../implementations/JobUsageRecord.java | 3 ++- .../implementations/PortletUsageRecord.java | 2 +- .../implementations/ServiceUsageRecord.java | 2 +- .../implementations/TaskUsageRecord.java | 2 +- 12 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/gcube/accounting/datamodel/decorators/ComputedField.java rename src/main/java/org/gcube/accounting/datamodel/{validations => deprecationmanagement}/annotations/DeprecatedWarning.java (69%) create mode 100644 src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java rename src/main/java/org/gcube/accounting/datamodel/{validations => deprecationmanagement}/validators/DeprecatedWarningValidator.java (92%) create mode 100644 src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java diff --git a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java index dbdf776..d0dae81 100644 --- a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java @@ -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); } diff --git a/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java index 258a28e..ac06d30 100644 --- a/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java @@ -180,20 +180,38 @@ public interface UsageRecord extends Comparable{ 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 diff --git a/src/main/java/org/gcube/accounting/datamodel/decorators/AggregatedField.java b/src/main/java/org/gcube/accounting/datamodel/decorators/AggregatedField.java index 536edc2..baa5944 100644 --- a/src/main/java/org/gcube/accounting/datamodel/decorators/AggregatedField.java +++ b/src/main/java/org/gcube/accounting/datamodel/decorators/AggregatedField.java @@ -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 { diff --git a/src/main/java/org/gcube/accounting/datamodel/decorators/ComputedField.java b/src/main/java/org/gcube/accounting/datamodel/decorators/ComputedField.java new file mode 100644 index 0000000..0a512cd --- /dev/null +++ b/src/main/java/org/gcube/accounting/datamodel/decorators/ComputedField.java @@ -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 { + +} diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/DeprecatedWarning.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java similarity index 69% rename from src/main/java/org/gcube/accounting/datamodel/validations/annotations/DeprecatedWarning.java rename to src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java index b637d14..97ac63d 100644 --- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/DeprecatedWarning.java +++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java @@ -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) diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java new file mode 100644 index 0000000..168cee4 --- /dev/null +++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java @@ -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 { + +} diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/DeprecatedWarningValidator.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningValidator.java similarity index 92% rename from src/main/java/org/gcube/accounting/datamodel/validations/validators/DeprecatedWarningValidator.java rename to src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningValidator.java index 239f9a6..c76a114 100644 --- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/DeprecatedWarningValidator.java +++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningValidator.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.accounting.datamodel.validations.validators; +package org.gcube.accounting.datamodel.deprecationmanagement.validators; import java.io.Serializable; diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java new file mode 100644 index 0000000..997f048 --- /dev/null +++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java @@ -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; + } + +} diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java index 047621d..5da2758 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java @@ -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(){ diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/PortletUsageRecord.java index 4772a23..a5547e3 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/PortletUsageRecord.java @@ -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; diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java index 4fb80dc..af231ae 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java @@ -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; diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/TaskUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/TaskUsageRecord.java index 3d31eed..6427d9e 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/TaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/TaskUsageRecord.java @@ -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;