From 9ba2a2e788d3a2108c592d09cfc7a8b34235fb6a Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 29 Feb 2016 14:16:54 +0000 Subject: [PATCH] refs #2437: Some records accounted on fallback are not recovered in the proper way in a special case https://support.d4science.org/issues/2437 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@124667 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../accounting/datamodel/AggregatedUsageRecord.java | 11 +++++------ .../gcube/accounting/datamodel/BasicUsageRecord.java | 8 +++++++- .../aggregation/AggregatedStorageUsageRecord.java | 5 +---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java index 0cb8d80..77213a1 100644 --- a/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/AggregatedUsageRecord.java @@ -4,8 +4,7 @@ package org.gcube.accounting.datamodel; 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.ValidBoolean; import org.gcube.documentstore.records.implementation.validations.annotations.ValidInteger; import org.gcube.documentstore.records.implementation.validations.annotations.ValidLong; @@ -14,16 +13,16 @@ import org.gcube.documentstore.records.implementation.validations.annotations.Va */ public interface AggregatedUsageRecord, U extends UsageRecord> extends AggregatedRecord { - @AggregatedField @NotEmptyIfNotNull + @ValidBoolean public static final String AGGREGATED = AggregatedRecord.AGGREGATED; - @AggregatedField @ValidInteger + @ValidInteger public static final String OPERATION_COUNT = AggregatedRecord.OPERATION_COUNT; - @AggregatedField @ValidLong + @ValidLong public static final String START_TIME = AggregatedRecord.START_TIME; - @AggregatedField @ValidLong + @ValidLong public static final String END_TIME = AggregatedRecord.END_TIME; } diff --git a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java index 386230d..91a4202 100644 --- a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java @@ -8,6 +8,7 @@ import java.util.Map; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType; import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult; +import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.records.implementation.AbstractRecord; @@ -115,7 +116,12 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe */ @Override public OperationResult getOperationResult(){ - return OperationResult.valueOf((String) this.resourceProperties.get(OPERATION_RESULT)); + try { + return (OperationResult) new ValidOperationResultValidator(). + validate(OPERATION_RESULT, this.resourceProperties.get(OPERATION_RESULT), null); + } catch (Exception e) { + return null; + } } /** diff --git a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java index f10561c..8d69317 100644 --- a/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/aggregation/AggregatedStorageUsageRecord.java @@ -15,8 +15,6 @@ import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; import org.gcube.documentstore.records.aggregation.AggregationUtility; 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 @@ -29,8 +27,7 @@ public class AggregatedStorageUsageRecord extends AbstractStorageUsageRecord imp */ private static final long serialVersionUID = 1082525518686785682L; - // Redefining DATA_VOLUME to Set @AggregatedField - @RequiredField @ValidLong @AggregatedField + @AggregatedField public static final String DATA_VOLUME = AbstractStorageUsageRecord.DATA_VOLUME;