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
This commit is contained in:
Luca Frosini 2015-06-05 07:47:48 +00:00
parent 7b74ab0d03
commit a9da7ea865
5 changed files with 36 additions and 45 deletions

View File

@ -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<String, Serializable>();
this.validation = new HashMap<String, List<FieldValidator<? extends Annotation>>>();
initializeValidation();
@ -108,7 +111,7 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
this.resourceSpecificProperties.put(CREATION_TIME, calendar.getTimeInMillis());
}
public RawUsageRecord(Map<String, Serializable> properties) throws InvalidValueException {
protected RawUsageRecord(Map<String, Serializable> properties) throws InvalidValueException {
this.validation = new HashMap<String, List<FieldValidator<? extends Annotation>>>();
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<String, Serializable> 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);
}

View File

@ -245,8 +245,9 @@ public interface UsageRecord extends Comparable<UsageRecord>{
/**
* 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;
/**

View File

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

View File

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

View File

@ -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<UsageRecordType>{
public Class<UsageRecordType> 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());
}
}