From a9da7ea865096417e73c5780ef775e2993661e7b Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 5 Jun 2015 07:47:48 +0000 Subject: [PATCH] refs #200: Create accouting-lib library https://support.d4science.org/issues/200 Fixing data model git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115233 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../accounting/datamodel/RawUsageRecord.java | 24 ++++++++++++++----- .../accounting/datamodel/UsageRecord.java | 3 ++- .../StorageUsageUsageRecord.java | 16 +++++++++++++ .../datamodel/validators/UsageRecordType.java | 15 ------------ .../validators/UsageRecordTypeValidator.java | 23 ------------------ 5 files changed, 36 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordType.java delete mode 100644 src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordTypeValidator.java diff --git a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java index a8997d7..e6af6cc 100644 --- a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java @@ -55,6 +55,9 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { public static final String RESOURCE_OWNER = "resourceOwner"; @NotEmptyIfNotNull protected static final String AGGREGATED_ID = "aggregatedId"; + @NotEmptyIfNotNull + protected static final String AGGREGATED_USAGE_RECORD_ID = "aggregatedUsageRecordId"; + @ValidOperationResult public static final String OPERATION_RESULT = "operationResult"; @@ -98,7 +101,7 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { } - public RawUsageRecord(){ + protected RawUsageRecord(){ this.resourceSpecificProperties = new HashMap(); this.validation = new HashMap>>(); initializeValidation(); @@ -108,7 +111,7 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { this.resourceSpecificProperties.put(CREATION_TIME, calendar.getTimeInMillis()); } - public RawUsageRecord(Map properties) throws InvalidValueException { + protected RawUsageRecord(Map properties) throws InvalidValueException { this.validation = new HashMap>>(); initializeValidation(); setResourceSpecificProperties(properties); @@ -219,7 +222,6 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { */ protected void setStartTime(Calendar startTime) throws InvalidValueException { setResourceSpecificProperty(START_TIME, startTime.getTimeInMillis()); - } /* * @@ -342,6 +344,15 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { setResourceSpecificProperty(AGGREGATED_ID, aggregatedId); } + + public String getAggregatedUsageRecordId() { + return (String) this.resourceSpecificProperties.get(AGGREGATED_USAGE_RECORD_ID); + } + + public void setAggregatedUsageRecordId(String aggregatedId) throws InvalidValueException { + setResourceSpecificProperty(AGGREGATED_USAGE_RECORD_ID, aggregatedId); + } + /** * {@inheritDoc} */ @@ -389,7 +400,7 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { } protected void validate(Map properties) throws InvalidValueException{ - // TODO Change the behaviour. Get the list of validator and check the + // TODO Change the behavior. Get the list of validators and check the // field in properties Map for(String key : properties.keySet()){ Serializable serializable = properties.get(key); @@ -438,10 +449,11 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable { /** * {@inheritDoc} + * @throws InvalidValueException */ @Override - public void setOperationResult(OperationResult operationResult) { - + public void setOperationResult(OperationResult operationResult) throws InvalidValueException { + setResourceSpecificProperty(OPERATION_RESULT, operationResult); } diff --git a/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java index 42219b6..258a28e 100644 --- a/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/UsageRecord.java @@ -245,8 +245,9 @@ public interface UsageRecord extends Comparable{ /** * Set the Operation Result related to the accounted Usage Record * @param operationResult the Operation Result to set + * @throws InvalidValueException */ - public void setOperationResult(OperationResult operationResult); + public void setOperationResult(OperationResult operationResult) throws InvalidValueException; /** diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/StorageUsageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/StorageUsageUsageRecord.java index 0cba896..9655987 100644 --- a/src/main/java/org/gcube/accounting/datamodel/implementations/StorageUsageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/implementations/StorageUsageUsageRecord.java @@ -107,5 +107,21 @@ public class StorageUsageUsageRecord extends StorageStatusUsageRecord { public void setDataCount(int dataCount) throws InvalidValueException { setResourceSpecificProperty(DATA_COUNT, dataCount); } + + /** + * {@inheritDoc} + */ + @Override + public String getResourceOwner() { + return (String) this.resourceSpecificProperties.get(RESOURCE_OWNER); + } + + /** + * {@inheritDoc} + */ + @Override + public void setResourceOwner(String owner) throws InvalidValueException { + setResourceSpecificProperty(RESOURCE_OWNER, owner); + } } diff --git a/src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordType.java b/src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordType.java deleted file mode 100644 index 1b89308..0000000 --- a/src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordType.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.gcube.accounting.datamodel.validators; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.gcube.common.validator.annotations.ValidityChecker; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -@ValidityChecker(managed=UsageRecordTypeValidator.class) -public @interface UsageRecordType { - -} diff --git a/src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordTypeValidator.java b/src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordTypeValidator.java deleted file mode 100644 index 271eb4c..0000000 --- a/src/main/java/org/gcube/accounting/datamodel/validators/UsageRecordTypeValidator.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.gcube.accounting.datamodel.validators; - -import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.common.validator.annotations.FieldValidator; - -public class UsageRecordTypeValidator implements FieldValidator{ - - public Class annotation() { - return UsageRecordType.class; - } - - public boolean isValid(Object toValidate) { - if (toValidate.getClass().isInstance(UsageRecord.class)) { - return true; - } - return false; - } - - public String getErrorSuffix() { - return String.format("not instace of %s", UsageRecord.class.getSimpleName()); - } - -}