From 75c59a89955d3a771dd59509c0ff0092efdf5a84 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 1 Jul 2015 10:09:11 +0000 Subject: [PATCH] refs #200: Create accouting-lib library https://support.d4science.org/issues/200 Reorganizing library git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115748 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../aggregation/JobUsageRecord.java | 4 +- .../aggregation/PortletUsageRecord.java | 4 +- .../aggregation/ServiceUsageRecord.java | 7 +-- .../aggregation/StorageUsageRecord.java | 7 +-- .../aggregation/TaskUsageRecord.java | 49 +++++++++++++++++++ ...ServiceUsageRecordAggregationStrategy.java | 2 +- ...StorageUsageRecordAggregationStrategy.java | 2 +- .../datamodel/AggregationStrategy.java | 23 ++++++--- .../accounting/datamodel/TestUsageRecord.java | 4 +- .../datamodel/basetype/JobUsageRecord.java | 3 +- .../basetype/PortletUsageRecord.java | 3 +- .../basetype/ServiceUsageRecord.java | 3 +- .../basetype/StorageUsageRecord.java | 3 +- .../datamodel/basetype/TaskUsageRecord.java | 3 +- ...iceUsageRecordAggregationStrategyTest.java | 3 +- ...ageUsageRecordAggregationStrategyTest.java | 2 +- .../ServiceUsageRecordTest.java | 2 +- 17 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java diff --git a/src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java index 8c122a8..3d0b13c 100644 --- a/src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/JobUsageRecord.java @@ -13,7 +13,7 @@ import org.gcube.accounting.exception.InvalidValueException; * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class JobUsageRecord extends org.gcube.accounting.datamodel.basetype.JobUsageRecord implements AggregatedUsageRecord { +public class JobUsageRecord extends org.gcube.accounting.datamodel.basetype.JobUsageRecord implements AggregatedUsageRecord { /** * Generated Serial Version UID @@ -39,7 +39,7 @@ public class JobUsageRecord extends org.gcube.accounting.datamodel.basetype.JobU */ @Override public JobUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.basetype.JobUsageRecord b) + org.gcube.accounting.datamodel.usagerecord.JobUsageRecord b) throws InvalidValueException { // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java index add5fca..fb86ffd 100644 --- a/src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/PortletUsageRecord.java @@ -13,7 +13,7 @@ import org.gcube.accounting.exception.InvalidValueException; * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetype.PortletUsageRecord implements AggregatedUsageRecord { +public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetype.PortletUsageRecord implements AggregatedUsageRecord { /** @@ -40,7 +40,7 @@ public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetype. */ @Override public PortletUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.basetype.PortletUsageRecord b) + org.gcube.accounting.datamodel.usagerecord.PortletUsageRecord usageRecord) throws InvalidValueException { // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java index b6acd38..0acd3c0 100644 --- a/src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/ServiceUsageRecord.java @@ -17,7 +17,7 @@ import org.gcube.accounting.exception.InvalidValueException; * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetype.ServiceUsageRecord implements AggregatedUsageRecord { +public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetype.ServiceUsageRecord implements AggregatedUsageRecord { /** * Generated Serial Version UID @@ -91,11 +91,8 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetype. */ @Override public ServiceUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.basetype.ServiceUsageRecord usageRecord) + org.gcube.accounting.datamodel.usagerecord.ServiceUsageRecord usageRecord) throws InvalidValueException { - if(usageRecord instanceof ServiceUsageRecord){ - return (ServiceUsageRecord) usageRecord; - } return new ServiceUsageRecord(usageRecord); } diff --git a/src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java index c32f76e..907cc21 100644 --- a/src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/aggregation/StorageUsageRecord.java @@ -17,7 +17,7 @@ import org.gcube.accounting.exception.InvalidValueException; * This Class is for library internal use only * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ */ -public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetype.StorageUsageRecord implements AggregatedUsageRecord { +public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetype.StorageUsageRecord implements AggregatedUsageRecord { /** * Generated Serial Version UID @@ -68,11 +68,8 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetype. */ @Override public StorageUsageRecord getAggregatedUsageRecord( - org.gcube.accounting.datamodel.basetype.StorageUsageRecord usageRecord) + org.gcube.accounting.datamodel.usagerecord.StorageUsageRecord usageRecord) throws InvalidValueException { - if(usageRecord instanceof StorageUsageRecord){ - return (StorageUsageRecord) usageRecord; - } return new StorageUsageRecord(usageRecord); } diff --git a/src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java b/src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java new file mode 100644 index 0000000..3075c41 --- /dev/null +++ b/src/main/java/org/gcube/accounting/aggregation/TaskUsageRecord.java @@ -0,0 +1,49 @@ +/** + * + */ +package org.gcube.accounting.aggregation; + +import java.io.Serializable; +import java.util.Map; + +import org.gcube.accounting.datamodel.AggregatedUsageRecord; +import org.gcube.accounting.exception.InvalidValueException; + +/** + * This Class is for library internal use only + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + */ +public class TaskUsageRecord extends org.gcube.accounting.datamodel.basetype.TaskUsageRecord implements AggregatedUsageRecord { + + + /** + * Generated Serial version UID + */ + private static final long serialVersionUID = 7445526162102677455L; + + private void init(){ + this.resourceProperties.put(AGGREGATED, true); + } + + public TaskUsageRecord(){ + super(); + init(); + } + + public TaskUsageRecord(Map properties) throws InvalidValueException{ + super(properties); + init(); + } + + /** + * {@inheritDoc} + */ + @Override + public TaskUsageRecord getAggregatedUsageRecord( + org.gcube.accounting.datamodel.usagerecord.TaskUsageRecord usageRecord) + throws InvalidValueException { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java b/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java index 7791bb7..dd30dd6 100644 --- a/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategy.java @@ -11,7 +11,7 @@ import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy{ +public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy{ /** * @param serviceUsageRecord diff --git a/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategy.java b/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategy.java index bf21726..679fd7a 100644 --- a/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategy.java @@ -11,7 +11,7 @@ import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class StorageUsageRecordAggregationStrategy extends AggregationStrategy{ +public class StorageUsageRecordAggregationStrategy extends AggregationStrategy{ /** * @param serviceUsageRecord diff --git a/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java b/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java index 18acc01..4a9f74e 100644 --- a/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java +++ b/src/main/java/org/gcube/accounting/datamodel/AggregationStrategy.java @@ -10,6 +10,7 @@ import java.util.Calendar; import java.util.HashSet; import java.util.Set; +import org.gcube.accounting.exception.InvalidValueException; import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; /** @@ -65,28 +66,26 @@ public abstract class AggregationStrategy, protected abstract T reallyAggregate(T t) throws NotAggregatableRecordsExceptions; - public T aggregate(B record) throws NotAggregatableRecordsExceptions { + public T aggregate(T record) throws NotAggregatableRecordsExceptions { try{ if(!isAggregable(record)){ throw new NotAggregatableRecordsExceptions("The Record provided as argument has different values for field wich must be common to be aggragatable"); } - T convertedRecord = t.getAggregatedUsageRecord(record); - - Calendar convertedStartTime = ((BasicUsageRecord) convertedRecord).getStartTimeAsCalendar(); + Calendar convertedStartTime = ((BasicUsageRecord) record).getStartTimeAsCalendar(); Calendar actualStartTime = ((BasicUsageRecord) t).getStartTimeAsCalendar(); if(convertedStartTime.before(actualStartTime)){ ((BasicUsageRecord) t).setStartTime(convertedStartTime); } - Calendar convertedEndTime = ((BasicUsageRecord) convertedRecord).getEndTimeAsCalendar(); + Calendar convertedEndTime = ((BasicUsageRecord) record).getEndTimeAsCalendar(); Calendar actualEndTime = ((BasicUsageRecord) t).getEndTimeAsCalendar(); if(convertedEndTime.after(actualEndTime)){ ((BasicUsageRecord) t).setEndTime(convertedEndTime); } Calendar newCreationTime = Calendar.getInstance(); - t = reallyAggregate(convertedRecord); + t = reallyAggregate(record); ((BasicUsageRecord) t).setCreationTime(newCreationTime); @@ -96,7 +95,17 @@ public abstract class AggregationStrategy, }catch(Exception ex){ throw new NotAggregatableRecordsExceptions(ex.getCause()); } - + } + + public T aggregate(B record) throws NotAggregatableRecordsExceptions { + T convertedRecord; + try { + convertedRecord = t.getAggregatedUsageRecord(record); + return aggregate(convertedRecord); + } catch (InvalidValueException e) { + throw new NotAggregatableRecordsExceptions(e.getCause()); + } + } } diff --git a/src/main/java/org/gcube/accounting/datamodel/TestUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/TestUsageRecord.java index 3a0ccaa..35f8e57 100644 --- a/src/main/java/org/gcube/accounting/datamodel/TestUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/TestUsageRecord.java @@ -7,8 +7,8 @@ import java.net.URI; import java.net.URISyntaxException; import org.gcube.accounting.datamodel.UsageRecord.OperationResult; -import org.gcube.accounting.datamodel.basetype.ServiceUsageRecord; -import org.gcube.accounting.datamodel.basetype.StorageUsageRecord; +import org.gcube.accounting.datamodel.usagerecord.ServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecord.StorageUsageRecord; import org.gcube.accounting.datamodel.basetype.StorageUsageRecord.DataType; import org.gcube.accounting.datamodel.basetype.StorageUsageRecord.OperationType; import org.gcube.accounting.exception.InvalidValueException; diff --git a/src/main/java/org/gcube/accounting/datamodel/basetype/JobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetype/JobUsageRecord.java index f14ce55..733faee 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetype/JobUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetype/JobUsageRecord.java @@ -12,7 +12,6 @@ import java.util.Calendar; import java.util.Map; import org.gcube.accounting.datamodel.BasicUsageRecord; -import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.decorators.ComputedField; import org.gcube.accounting.datamodel.decorators.FieldAction; @@ -30,7 +29,7 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class JobUsageRecord extends BasicUsageRecord implements SingleUsageRecord { +public abstract class JobUsageRecord extends BasicUsageRecord { private static Logger logger = LoggerFactory.getLogger(JobUsageRecord.class); diff --git a/src/main/java/org/gcube/accounting/datamodel/basetype/PortletUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetype/PortletUsageRecord.java index ff5d857..5f17500 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetype/PortletUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetype/PortletUsageRecord.java @@ -11,7 +11,6 @@ import java.lang.annotation.Target; import java.util.Map; import org.gcube.accounting.datamodel.BasicUsageRecord; -import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.decorators.FieldAction; import org.gcube.accounting.datamodel.decorators.FieldDecorator; @@ -26,7 +25,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class PortletUsageRecord extends BasicUsageRecord implements SingleUsageRecord { +public abstract class PortletUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/basetype/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetype/ServiceUsageRecord.java index 0aa4ba1..a912b4c 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetype/ServiceUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetype/ServiceUsageRecord.java @@ -7,7 +7,6 @@ import java.io.Serializable; import java.util.Map; import org.gcube.accounting.datamodel.BasicUsageRecord; -import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.decorators.RequiredField; import org.gcube.accounting.datamodel.validations.annotations.NotEmpty; import org.gcube.accounting.datamodel.validations.annotations.ValidLong; @@ -17,7 +16,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class ServiceUsageRecord extends BasicUsageRecord implements SingleUsageRecord { +public abstract class ServiceUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/basetype/StorageUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetype/StorageUsageRecord.java index 4ba1243..379dc19 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetype/StorageUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetype/StorageUsageRecord.java @@ -8,7 +8,6 @@ import java.net.URI; import java.util.Map; import org.gcube.accounting.datamodel.BasicUsageRecord; -import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.decorators.RequiredField; import org.gcube.accounting.datamodel.validations.annotations.NotEmpty; import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull; @@ -22,7 +21,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageRecord { +public abstract class StorageUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID diff --git a/src/main/java/org/gcube/accounting/datamodel/basetype/TaskUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/basetype/TaskUsageRecord.java index eb00088..5ad86e7 100644 --- a/src/main/java/org/gcube/accounting/datamodel/basetype/TaskUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/basetype/TaskUsageRecord.java @@ -8,7 +8,6 @@ import java.util.Calendar; import java.util.Map; import org.gcube.accounting.datamodel.BasicUsageRecord; -import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.decorators.RequiredField; import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning; import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToOperationResult; @@ -21,7 +20,7 @@ import org.gcube.accounting.exception.InvalidValueException; * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class TaskUsageRecord extends BasicUsageRecord implements SingleUsageRecord { +public abstract class TaskUsageRecord extends BasicUsageRecord { /** * Generated Serial Version UID diff --git a/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategyTest.java b/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategyTest.java index 86ee142..7e92923 100644 --- a/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategyTest.java +++ b/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/ServiceUsageRecordAggregationStrategyTest.java @@ -3,9 +3,8 @@ */ package org.gcube.accounting.aggregation.aggregationstrategy; -import org.gcube.accounting.aggregation.aggregationstrategy.ServiceUsageRecordAggregationStrategy; import org.gcube.accounting.datamodel.TestUsageRecord; -import org.gcube.accounting.datamodel.basetype.ServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecord.ServiceUsageRecord; import org.gcube.accounting.exception.InvalidValueException; import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; import org.junit.Assert; diff --git a/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategyTest.java b/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategyTest.java index 40be188..54da675 100644 --- a/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategyTest.java +++ b/src/test/java/org/gcube/accounting/aggregation/aggregationstrategy/StorageUsageRecordAggregationStrategyTest.java @@ -5,7 +5,7 @@ package org.gcube.accounting.aggregation.aggregationstrategy; import org.gcube.accounting.aggregation.aggregationstrategy.StorageUsageRecordAggregationStrategy; import org.gcube.accounting.datamodel.TestUsageRecord; -import org.gcube.accounting.datamodel.basetype.StorageUsageRecord; +import org.gcube.accounting.datamodel.usagerecord.StorageUsageRecord; import org.gcube.accounting.exception.InvalidValueException; import org.gcube.accounting.exception.NotAggregatableRecordsExceptions; import org.junit.Assert; diff --git a/src/test/java/org/gcube/accounting/datamodel/implementation/ServiceUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/implementation/ServiceUsageRecordTest.java index f704304..ca2db1f 100644 --- a/src/test/java/org/gcube/accounting/datamodel/implementation/ServiceUsageRecordTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/implementation/ServiceUsageRecordTest.java @@ -4,7 +4,7 @@ package org.gcube.accounting.datamodel.implementation; import org.gcube.accounting.datamodel.TestUsageRecord; -import org.gcube.accounting.datamodel.basetype.ServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecord.ServiceUsageRecord; import org.gcube.accounting.exception.InvalidValueException; import org.gcube.accounting.persistence.Persistence; import org.junit.Test;