diff --git a/pom.xml b/pom.xml
index 0c063f6..38dc2d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,12 @@
4.11
test
+
+ ch.qos.logback
+ logback-classic
+ 1.0.13
+ test
+
diff --git a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java
index 5a0917a..055d7c7 100644
--- a/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java
+++ b/src/main/java/org/gcube/accounting/datamodel/RawUsageRecord.java
@@ -20,9 +20,10 @@ import java.util.Set;
import java.util.UUID;
import org.gcube.accounting.datamodel.decorators.AggregatedField;
+import org.gcube.accounting.datamodel.decorators.ComputedField;
import org.gcube.accounting.datamodel.decorators.RequiredField;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToAggregatedUsageRecordId;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
@@ -83,8 +84,10 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
/** resource-specific properties */
protected Map resourceProperties;
- protected Map> validation;
+ protected Map> validation;
protected Set requiredFields;
+ protected Set aggregatedFields;
+ protected Set computedFields;
protected void initializeValidation() {
logger.debug("Initializing Field Validators");
@@ -96,12 +99,12 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
} catch (Exception e) {
continue;
}
- List fieldValidators = new ArrayList();
+ List fieldValidators = new ArrayList();
validation.put(keyString, fieldValidators);
for (Annotation annotation : field.getAnnotations()){
- if (annotation.annotationType().isAnnotationPresent(ValidatorField.class)){
- Class extends ValidatorAction> managedClass = ((ValidatorField)annotation.annotationType().getAnnotation(ValidatorField.class)).managed();
- ValidatorAction validator;
+ if (annotation.annotationType().isAnnotationPresent(FieldDecorator.class)){
+ Class extends FieldAction> managedClass = ((FieldDecorator)annotation.annotationType().getAnnotation(FieldDecorator.class)).managed();
+ FieldAction validator;
try {
validator = managedClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
@@ -109,9 +112,15 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
}
fieldValidators.add(validator);
}
- if(annotation.getClass().isAssignableFrom(RequiredField.class)){
+ if(annotation.annotationType().isAssignableFrom(RequiredField.class)){
requiredFields.add(keyString);
}
+ if(annotation.annotationType().isAssignableFrom(AggregatedField.class)){
+ aggregatedFields.add(keyString);
+ }
+ if(annotation.annotationType().isAssignableFrom(ComputedField.class)){
+ computedFields.add(keyString);
+ }
}
}
}
@@ -120,7 +129,7 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
* Initialize variable
*/
private void init() {
- this.validation = new HashMap>();
+ this.validation = new HashMap>();
this.requiredFields = new HashSet();
initializeValidation();
}
@@ -456,10 +465,14 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
throw new InvalidValueException("The key of property to set cannot be null");
}
Serializable checkedValue = serializable;
- List fieldValidators = validation.get(key);
+ List fieldValidators = validation.get(key);
if(fieldValidators!=null){
- for(ValidatorAction fieldValidator : fieldValidators){
+ for(FieldAction fieldValidator : fieldValidators){
checkedValue = fieldValidator.validate(key, checkedValue, this);
+ /*
+ * Check here if the key is for a ComputedField or for an
+ * AggregatedField
+ */
}
}
return checkedValue;
@@ -589,7 +602,10 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
*/
public static UsageRecord getUsageRecord(Map usageRecordMap) throws Exception {
String className = (String) usageRecordMap.get(USAGE_RECORD_TYPE);
- boolean aggregated = (Boolean) usageRecordMap.get(AGGREGATED);
+ boolean aggregated = false;
+ try {
+ aggregated = (Boolean) usageRecordMap.get(AGGREGATED);
+ }catch(Exception e){}
Class extends UsageRecord> clz = getClass(className, aggregated);
logger.debug("Trying to instantiate {}", clz.getClass().getSimpleName());
@@ -599,7 +615,11 @@ public abstract class RawUsageRecord implements UsageRecord, Serializable {
Constructor extends UsageRecord> usageRecordConstructor = clz.getDeclaredConstructor(usageRecordArgTypes);
Object[] usageRecordArguments = {usageRecordMap};
- return usageRecordConstructor.newInstance(usageRecordArguments);
+ UsageRecord usageRecord = usageRecordConstructor.newInstance(usageRecordArguments);
+
+ logger.debug("Created Usage Record : {}", usageRecord);
+
+ return usageRecord;
}
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/decorators/ValidatorAction.java b/src/main/java/org/gcube/accounting/datamodel/decorators/FieldAction.java
similarity index 96%
rename from src/main/java/org/gcube/accounting/datamodel/decorators/ValidatorAction.java
rename to src/main/java/org/gcube/accounting/datamodel/decorators/FieldAction.java
index a104858..bf0eb48 100644
--- a/src/main/java/org/gcube/accounting/datamodel/decorators/ValidatorAction.java
+++ b/src/main/java/org/gcube/accounting/datamodel/decorators/FieldAction.java
@@ -11,7 +11,7 @@ import org.gcube.accounting.exception.InvalidValueException;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
-public interface ValidatorAction {
+public interface FieldAction {
/**
* Validate (and eventually convert) the value of the property identified by
diff --git a/src/main/java/org/gcube/accounting/datamodel/decorators/ValidatorField.java b/src/main/java/org/gcube/accounting/datamodel/decorators/FieldDecorator.java
similarity index 84%
rename from src/main/java/org/gcube/accounting/datamodel/decorators/ValidatorField.java
rename to src/main/java/org/gcube/accounting/datamodel/decorators/FieldDecorator.java
index 3403a14..a7a20aa 100644
--- a/src/main/java/org/gcube/accounting/datamodel/decorators/ValidatorField.java
+++ b/src/main/java/org/gcube/accounting/datamodel/decorators/FieldDecorator.java
@@ -16,8 +16,8 @@ import java.lang.annotation.Target;
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
-public @interface ValidatorField {
+public @interface FieldDecorator {
- Class extends ValidatorAction> managed();
+ Class extends FieldAction> managed();
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java
index 97ac63d..b62d149 100644
--- a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java
+++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/DeprecatedWarning.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
-import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningValidator;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
+import org.gcube.accounting.datamodel.deprecationmanagement.validators.DeprecatedWarningAction;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=DeprecatedWarningValidator.class)
+@FieldDecorator(managed=DeprecatedWarningAction.class)
public @interface DeprecatedWarning {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java
index 168cee4..456940e 100644
--- a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java
+++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToAggregatedUsageRecordId.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
-import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToAggregatedUsageRecordIdValidator;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
+import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToAggregatedUsageRecordIdAction;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=MoveToAggregatedUsageRecordIdValidator.class)
+@FieldDecorator(managed=MoveToAggregatedUsageRecordIdAction.class)
public @interface MoveToAggregatedUsageRecordId {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToOperationResult.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToOperationResult.java
index b017334..80b79f9 100644
--- a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToOperationResult.java
+++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/annotations/MoveToOperationResult.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
-import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToOperationResultValidator;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
+import org.gcube.accounting.datamodel.deprecationmanagement.validators.MoveToOperationResultAction;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=MoveToOperationResultValidator.class)
+@FieldDecorator(managed=MoveToOperationResultAction.class)
public @interface MoveToOperationResult {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningValidator.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningAction.java
similarity index 82%
rename from src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningValidator.java
rename to src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningAction.java
index c76a114..1656138 100644
--- a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/DeprecatedWarningAction.java
@@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.deprecationmanagement.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -15,9 +15,9 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
-public class DeprecatedWarningValidator implements ValidatorAction {
+public class DeprecatedWarningAction implements FieldAction {
- private static Logger logger = LoggerFactory.getLogger(DeprecatedWarningValidator.class);
+ private static Logger logger = LoggerFactory.getLogger(DeprecatedWarningAction.class);
/**
* {@inheritDoc}
diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdAction.java
similarity index 83%
rename from src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java
rename to src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdAction.java
index 0e5e451..954d692 100644
--- a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToAggregatedUsageRecordIdAction.java
@@ -6,7 +6,7 @@ package org.gcube.accounting.datamodel.deprecationmanagement.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
import org.gcube.accounting.exception.InvalidValueException;
@@ -14,7 +14,7 @@ import org.gcube.accounting.exception.InvalidValueException;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
-public class MoveToAggregatedUsageRecordIdValidator implements ValidatorAction {
+public class MoveToAggregatedUsageRecordIdAction implements FieldAction {
/**
* {@inheritDoc}
diff --git a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToOperationResultValidator.java b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToOperationResultAction.java
similarity index 85%
rename from src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToOperationResultValidator.java
rename to src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToOperationResultAction.java
index 445bdf2..20085a5 100644
--- a/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToOperationResultValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/deprecationmanagement/validators/MoveToOperationResultAction.java
@@ -7,7 +7,7 @@ import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
import org.gcube.accounting.exception.InvalidValueException;
@@ -15,7 +15,7 @@ import org.gcube.accounting.exception.InvalidValueException;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
-public class MoveToOperationResultValidator implements ValidatorAction {
+public class MoveToOperationResultAction implements FieldAction {
/**
* {@inheritDoc}
diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java
index 8e7a4a8..cd34b9e 100644
--- a/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java
+++ b/src/main/java/org/gcube/accounting/datamodel/implementations/JobUsageRecord.java
@@ -4,12 +4,19 @@
package org.gcube.accounting.datamodel.implementations;
import java.io.Serializable;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.util.Calendar;
import java.util.Map;
import org.gcube.accounting.datamodel.RawUsageRecord;
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;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.MoveToOperationResult;
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
@@ -39,9 +46,9 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
public static final String JOB_QUALIFIER = "jobQualifier";
@RequiredField @NotEmpty
public static final String JOB_NAME = "jobName";
- @RequiredField @ValidLong
+ @RequiredField @ValidLong @CalculateWallDuration
public static final String JOB_START_TIME = "jobStartTime";
- @RequiredField @ValidLong
+ @RequiredField @ValidLong @CalculateWallDuration
public static final String JOB_END_TIME = "jobEndTime";
@ValidOperationResult @MoveToOperationResult
@@ -49,9 +56,41 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
@ValidInteger
public static final String VMS_USED = "vmsUsed";
- @ComputedField @ValidLong
+ @ComputedField @ValidLong @CalculateWallDuration
protected static final String WALL_DURATION = "wallDuration";
+
+ @Target(ElementType.FIELD)
+ @Retention(RetentionPolicy.RUNTIME)
+ @FieldDecorator(managed=CalculateWallDurationAction.class)
+ protected @interface CalculateWallDuration {
+
+ }
+
+ protected class CalculateWallDurationAction implements FieldAction {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
+ try {
+ long wallDuration = calculateWallDuration();
+ if(key.compareTo(WALL_DURATION)==0){
+ value = wallDuration;
+ }
+ }catch(InvalidValueException e){
+ if(key.compareTo(WALL_DURATION)==0){
+ throw new InvalidValueException(String.format("Unable to set %s. %s and %s MUST be set before.", WALL_DURATION,
+ JOB_START_TIME, JOB_END_TIME));
+ }
+ }
+ return value;
+ }
+
+ }
+
+
public JobUsageRecord(){
super();
}
@@ -129,22 +168,25 @@ public class JobUsageRecord extends RawUsageRecord implements SingleUsageRecord
setResourceProperty(VMS_USED, vmsUsed);
}
- protected void calculateWallDuration() throws InvalidValueException {
+ protected long calculateWallDuration() throws InvalidValueException {
try {
long endTime = (Long) this.resourceProperties.get(JOB_END_TIME);
long startTime = (Long) this.resourceProperties.get(JOB_START_TIME);
long wallDuration = endTime - startTime;
setResourceProperty(WALL_DURATION, wallDuration);
+ return wallDuration;
}catch(Exception e){
throw new InvalidValueException(String.format("To calculate Wall Duration both %s and %s must be set",
START_TIME, END_TIME), e.getCause());
}
}
- public long getWallDuration() throws InvalidValueException {
+ public long getWallDuration() {
Long wallDuration = (Long) this.resourceProperties.get(WALL_DURATION);
if(wallDuration == null){
- calculateWallDuration();
+ try {
+ wallDuration = calculateWallDuration();
+ } catch(Exception e){}
}
return wallDuration;
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java
index 6f0055d..cae4a21 100644
--- a/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java
+++ b/src/main/java/org/gcube/accounting/datamodel/implementations/ServiceUsageRecord.java
@@ -41,9 +41,9 @@ public class ServiceUsageRecord extends RawUsageRecord implements SingleUsageRec
protected static final String INVOCATION_COUNT = "invocationCount";
@ValidInteger @AggregatedField
protected static final String AVERAGE_INVOCATION_COUNT = "averageInvocationTime";
- @NotEmpty
+ @RequiredField @NotEmpty
public static final String SERVICE_CLASS = "serviceClass";
- @NotEmpty
+ @RequiredField @NotEmpty
public static final String SERVICE_NAME = "serviceName";
public ServiceUsageRecord(){
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmpty.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmpty.java
index ac961f1..f6f49e0 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmpty.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmpty.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=NotEmptyValidator.class)
+@FieldDecorator(managed=NotEmptyValidator.class)
public @interface NotEmpty {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmptyIfNotNull.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmptyIfNotNull.java
index ad1abd1..dbc0630 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmptyIfNotNull.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotEmptyIfNotNull.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.NotEmptyIfNotNullValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=NotEmptyIfNotNullValidator.class)
+@FieldDecorator(managed=NotEmptyIfNotNullValidator.class)
public @interface NotEmptyIfNotNull {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotNull.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotNull.java
index d2e1006..86dda9c 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotNull.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/NotNull.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.NotNullValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=NotNullValidator.class)
+@FieldDecorator(managed=NotNullValidator.class)
public @interface NotNull {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidIP.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidIP.java
index 2f02d33..e051944 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidIP.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidIP.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidIPValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=ValidIPValidator.class)
+@FieldDecorator(managed=ValidIPValidator.class)
public @interface ValidIP {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidInteger.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidInteger.java
index 02868b1..3433519 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidInteger.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidInteger.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidIntegerValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=ValidIntegerValidator.class)
+@FieldDecorator(managed=ValidIntegerValidator.class)
public @interface ValidInteger {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidLong.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidLong.java
index f24789d..684a319 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidLong.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidLong.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidLongValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=ValidLongValidator.class)
+@FieldDecorator(managed=ValidLongValidator.class)
public @interface ValidLong {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidOperationResult.java b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidOperationResult.java
index 70c824c..46f62c2 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidOperationResult.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/annotations/ValidOperationResult.java
@@ -5,12 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.gcube.accounting.datamodel.decorators.ValidatorField;
+import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
-@ValidatorField(managed=ValidOperationResultValidator.class)
+@FieldDecorator(managed=ValidOperationResultValidator.class)
public @interface ValidOperationResult {
}
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotEmptyValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotEmptyValidator.java
index 70aacd4..12d63e0 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotEmptyValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotEmptyValidator.java
@@ -4,10 +4,10 @@ import java.io.Serializable;
import java.util.Map;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
-public class NotEmptyValidator implements ValidatorAction{
+public class NotEmptyValidator implements FieldAction{
private static final String ERROR = "Is Empty";
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotNullValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotNullValidator.java
index 3147ea5..4cfef99 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotNullValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/NotNullValidator.java
@@ -3,10 +3,10 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
-public class NotNullValidator implements ValidatorAction {
+public class NotNullValidator implements FieldAction {
private static final String ERROR = "Is Null";
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIPValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIPValidator.java
index 8134c88..45f02f1 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIPValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIPValidator.java
@@ -5,12 +5,12 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ValidIPValidator implements ValidatorAction{
+public class ValidIPValidator implements FieldAction{
private static Logger logger = LoggerFactory.getLogger(ValidIPValidator.class);
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIntegerValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIntegerValidator.java
index c094e8f..b4fae9b 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIntegerValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidIntegerValidator.java
@@ -3,11 +3,11 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
-public class ValidIntegerValidator implements ValidatorAction {
+public class ValidIntegerValidator implements FieldAction {
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidLongValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidLongValidator.java
index 64d9ce3..4e34eae 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidLongValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidLongValidator.java
@@ -3,11 +3,11 @@ package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
-public class ValidLongValidator implements ValidatorAction {
+public class ValidLongValidator implements FieldAction {
private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName());
diff --git a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationResultValidator.java b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationResultValidator.java
index cf709b0..eccdf2d 100644
--- a/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationResultValidator.java
+++ b/src/main/java/org/gcube/accounting/datamodel/validations/validators/ValidOperationResultValidator.java
@@ -4,10 +4,10 @@ import java.io.Serializable;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
-import org.gcube.accounting.datamodel.decorators.ValidatorAction;
+import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
-public class ValidOperationResultValidator implements ValidatorAction {
+public class ValidOperationResultValidator implements FieldAction {
private static final String ERROR = String.format("Not Instance of %s", OperationResult.class.getSimpleName());
diff --git a/src/main/java/org/gcube/accounting/persistence/Persistence.java b/src/main/java/org/gcube/accounting/persistence/Persistence.java
index c6f78d9..6555228 100644
--- a/src/main/java/org/gcube/accounting/persistence/Persistence.java
+++ b/src/main/java/org/gcube/accounting/persistence/Persistence.java
@@ -87,29 +87,35 @@ public abstract class Persistence {
}
}
- public static UsageRecord createTestRawUsageRecord(){
- UsageRecord usageRecord = new ServiceUsageRecord();
+ public static UsageRecord createTestUsageRecord(){
+ ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord();
try {
- usageRecord.setCreatorId("accounting");
- usageRecord.setConsumerId("accounting");
+ serviceUsageRecord.setCreatorId("accounting");
+ serviceUsageRecord.setConsumerId("accounting");
- usageRecord.setResourceScope("/gcube/devsec");
+ serviceUsageRecord.setResourceScope("/gcube/devsec");
Calendar creatingTime = new GregorianCalendar();
//Calendar startTime = new GregorianCalendar();
//Calendar endTime = new GregorianCalendar();
- usageRecord.setCreationTime(creatingTime);
+ serviceUsageRecord.setCreationTime(creatingTime);
//usageRecord.setStartTime(startTime);
//usageRecord.setEndTime(endTime);
- usageRecord.setResourceProperty("ConnectionTest", "Test");
+ serviceUsageRecord.setResourceProperty("ConnectionTest", "Test");
+
+ serviceUsageRecord.setServiceClass("Accounting");
+ serviceUsageRecord.setServiceName("Accounting-Lib");
+ serviceUsageRecord.setRefHost("localhost");
+ serviceUsageRecord.setRefVM("local");
+ serviceUsageRecord.setCallerScope("/gcube/devsec");
} catch (InvalidValueException e1) {
}
- return usageRecord;
+ return serviceUsageRecord;
}
@@ -146,7 +152,7 @@ public abstract class Persistence {
*/
public void connect() throws Exception {
prepareConnection();
- this.account(createTestRawUsageRecord());
+ this.account(createTestUsageRecord());
}
/**
diff --git a/src/test/java/org/gcube/accounting/datamodel/RawUsageRecordTest.java b/src/test/java/org/gcube/accounting/datamodel/RawUsageRecordTest.java
index efc031a..3171415 100644
--- a/src/test/java/org/gcube/accounting/datamodel/RawUsageRecordTest.java
+++ b/src/test/java/org/gcube/accounting/datamodel/RawUsageRecordTest.java
@@ -15,7 +15,7 @@ public class RawUsageRecordTest {
@Test
public void testCompareToSameObject(){
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
UsageRecord ur = usageRecord;
Assert.assertEquals(0, usageRecord.compareTo(ur));
Assert.assertEquals(0, ur.compareTo(usageRecord));
@@ -23,7 +23,7 @@ public class RawUsageRecordTest {
@Test
public void testCompareToEqualsObject() throws Exception {
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
UsageRecord ur = RawUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
Assert.assertEquals(0, usageRecord.compareTo(ur));
Assert.assertEquals(0, ur.compareTo(usageRecord));
@@ -31,7 +31,7 @@ public class RawUsageRecordTest {
@Test
public void testCompareToComparedAddedProperty() throws Exception {
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
UsageRecord ur = RawUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
for(int i=1; i<31; i++){
ur.setResourceProperty(Integer.toString(i), i);
@@ -42,7 +42,7 @@ public class RawUsageRecordTest {
@Test
public void testCompareToDifferentForAddedProperties() throws Exception {
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
UsageRecord ur = RawUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
usageRecord.setResourceProperty(Integer.toString(1), 2);
ur.setResourceProperty(Integer.toString(2), 2);
@@ -52,8 +52,8 @@ public class RawUsageRecordTest {
@Test
public void testCompareToDifferentFromCreation() throws Exception {
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
- UsageRecord ur = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
+ UsageRecord ur = Persistence.createTestUsageRecord();
Assert.assertEquals(1, usageRecord.compareTo(ur));
Assert.assertEquals(1, ur.compareTo(usageRecord));
}
diff --git a/src/test/java/org/gcube/accounting/datamodel/persistence/CouchDBPersistenceTest.java b/src/test/java/org/gcube/accounting/datamodel/persistence/CouchDBPersistenceTest.java
index 580f396..2769b0c 100644
--- a/src/test/java/org/gcube/accounting/datamodel/persistence/CouchDBPersistenceTest.java
+++ b/src/test/java/org/gcube/accounting/datamodel/persistence/CouchDBPersistenceTest.java
@@ -22,7 +22,7 @@ public class CouchDBPersistenceTest {
@Test
public void TestJsonNodeUsageRecordConversions() throws Exception {
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
logger.debug("UsageRecord : {}", usageRecord.toString());
JsonNode node = CouchDBPersistence.usageRecordToJsonNode(usageRecord);
logger.debug("Node : {}", node.toString());
diff --git a/src/test/java/org/gcube/accounting/datamodel/persistence/PersistenceTest.java b/src/test/java/org/gcube/accounting/datamodel/persistence/PersistenceTest.java
index 9b4a55e..5a9e09a 100644
--- a/src/test/java/org/gcube/accounting/datamodel/persistence/PersistenceTest.java
+++ b/src/test/java/org/gcube/accounting/datamodel/persistence/PersistenceTest.java
@@ -33,7 +33,7 @@ public class PersistenceTest {
int quantity = 3000;
Calendar startTestTime = new GregorianCalendar();
for(int i=0; i< quantity; i++){
- UsageRecord usageRecord = Persistence.createTestRawUsageRecord();
+ UsageRecord usageRecord = Persistence.createTestUsageRecord();
persistence.account(usageRecord);
}
Calendar stopTestTime = new GregorianCalendar();
diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..4f36cc8
--- /dev/null
+++ b/src/test/resources/logback-test.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file