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
This commit is contained in:
Luca Frosini 2015-07-01 10:09:11 +00:00
parent 47f8c7a74c
commit 75c59a8995
17 changed files with 85 additions and 39 deletions

View File

@ -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<JobUsageRecord, org.gcube.accounting.datamodel.basetype.JobUsageRecord> {
public class JobUsageRecord extends org.gcube.accounting.datamodel.basetype.JobUsageRecord implements AggregatedUsageRecord<JobUsageRecord, org.gcube.accounting.datamodel.usagerecord.JobUsageRecord> {
/**
* 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;

View File

@ -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<PortletUsageRecord, org.gcube.accounting.datamodel.basetype.PortletUsageRecord> {
public class PortletUsageRecord extends org.gcube.accounting.datamodel.basetype.PortletUsageRecord implements AggregatedUsageRecord<PortletUsageRecord, org.gcube.accounting.datamodel.usagerecord.PortletUsageRecord> {
/**
@ -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;

View File

@ -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<ServiceUsageRecord, org.gcube.accounting.datamodel.basetype.ServiceUsageRecord> {
public class ServiceUsageRecord extends org.gcube.accounting.datamodel.basetype.ServiceUsageRecord implements AggregatedUsageRecord<ServiceUsageRecord, org.gcube.accounting.datamodel.usagerecord.ServiceUsageRecord> {
/**
* 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);
}

View File

@ -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<StorageUsageRecord, org.gcube.accounting.datamodel.basetype.StorageUsageRecord> {
public class StorageUsageRecord extends org.gcube.accounting.datamodel.basetype.StorageUsageRecord implements AggregatedUsageRecord<StorageUsageRecord, org.gcube.accounting.datamodel.usagerecord.StorageUsageRecord> {
/**
* 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);
}

View File

@ -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<TaskUsageRecord, org.gcube.accounting.datamodel.usagerecord.TaskUsageRecord> {
/**
* 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<String, Serializable> 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;
}
}

View File

@ -11,7 +11,7 @@ import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy<ServiceUsageRecord, org.gcube.accounting.datamodel.basetype.ServiceUsageRecord>{
public class ServiceUsageRecordAggregationStrategy extends AggregationStrategy<ServiceUsageRecord, org.gcube.accounting.datamodel.usagerecord.ServiceUsageRecord>{
/**
* @param serviceUsageRecord

View File

@ -11,7 +11,7 @@ import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class StorageUsageRecordAggregationStrategy extends AggregationStrategy<StorageUsageRecord, org.gcube.accounting.datamodel.basetype.StorageUsageRecord>{
public class StorageUsageRecordAggregationStrategy extends AggregationStrategy<StorageUsageRecord, org.gcube.accounting.datamodel.usagerecord.StorageUsageRecord>{
/**
* @param serviceUsageRecord

View File

@ -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<T extends AggregatedUsageRecord<T, B>,
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<T extends AggregatedUsageRecord<T, B>,
}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());
}
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;