refs #200: Create accouting-lib library

https://support.d4science.org/issues/200
Fixing model

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115549 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-06-25 13:58:26 +00:00
parent 8f15b524dd
commit d3fbcbb2db
5 changed files with 100 additions and 20 deletions

View File

@ -44,12 +44,23 @@ public abstract class BasicUsageRecord implements UsageRecord, Serializable {
private static Logger logger = LoggerFactory.getLogger(BasicUsageRecord.class); private static Logger logger = LoggerFactory.getLogger(BasicUsageRecord.class);
/**
* An unique identifier for the UsageRecord
*/
@RequiredField @NotEmpty @RequiredField @NotEmpty
public static final String ID = "id"; public static final String ID = "id";
/**
* The user (or the Consumer Identity, that in the S2S communication is
* another service) actually consuming the resource
*/
@RequiredField @NotEmpty @RequiredField @NotEmpty
public static final String CONSUMER_ID = "consumerId"; public static final String CONSUMER_ID = "consumerId";
/**
* When the UR was created
*/
@RequiredField @ValidLong @RequiredField @ValidLong
public static final String CREATION_TIME = "creationTime"; public static final String CREATION_TIME = "creationTime";
@RequiredField @NotEmpty @RequiredField @NotEmpty
protected static final String USAGE_RECORD_TYPE = "usageRecordType"; protected static final String USAGE_RECORD_TYPE = "usageRecordType";
@RequiredField @NotEmpty @RequiredField @NotEmpty

View File

@ -19,9 +19,9 @@ public class StorageUsageRecordAggregationStrategy extends AggregationStrategy<S
public StorageUsageRecordAggregationStrategy(StorageUsageRecord storageUsageRecord) { public StorageUsageRecordAggregationStrategy(StorageUsageRecord storageUsageRecord) {
super(storageUsageRecord); super(storageUsageRecord);
this.aggregationField.add(StorageUsageRecord.RESOURCE_OWNER); this.aggregationField.add(StorageUsageRecord.RESOURCE_OWNER);
this.aggregationField.add(StorageUsageRecord.OBJECT_URI); this.aggregationField.add(StorageUsageRecord.RESOURCE_SCOPE);
this.aggregationField.add(StorageUsageRecord.OPERATION_TYPE); this.aggregationField.add(StorageUsageRecord.OPERATION_TYPE);
this.aggregationField.add(StorageUsageRecord.QUALIFIER); this.aggregationField.add(StorageUsageRecord.OBJECT_URI);
this.aggregationField.add(StorageUsageRecord.DATA_TYPE); this.aggregationField.add(StorageUsageRecord.DATA_TYPE);
} }

View File

@ -4,6 +4,7 @@
package org.gcube.accounting.datamodel.implementations; package org.gcube.accounting.datamodel.implementations;
import java.io.Serializable; import java.io.Serializable;
import java.net.URI;
import java.util.Map; import java.util.Map;
import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.BasicUsageRecord;
@ -14,6 +15,7 @@ import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
import org.gcube.accounting.datamodel.validations.annotations.ValidIP; import org.gcube.accounting.datamodel.validations.annotations.ValidIP;
import org.gcube.accounting.datamodel.validations.annotations.ValidLong; import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationType; import org.gcube.accounting.datamodel.validations.annotations.ValidOperationType;
import org.gcube.accounting.datamodel.validations.annotations.ValidURI;
import org.gcube.accounting.exception.InvalidValueException; import org.gcube.accounting.exception.InvalidValueException;
/** /**
@ -27,29 +29,30 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
*/ */
private static final long serialVersionUID = 1381025822586583326L; private static final long serialVersionUID = 1381025822586583326L;
/*
* Actually workspace uses
* DOWNLOAD, UPLOAD, COPY, MOVE, DELETE,
*/
public enum OperationType { public enum OperationType {
GET, PUT, UPDATE, DELETE CREATE, READ, UPDATE, DELETE, COPY, MOVE
} }
@NotEmpty @RequiredField @NotEmpty
public static final String RESOURCE_OWNER = "resourceOwner"; public static final String RESOURCE_OWNER = "resourceOwner";
@RequiredField @NotEmpty
public static final String RESOURCE_SCOPE = "resourceScope";
/*
@NotEmptyIfNotNull @NotEmptyIfNotNull
public static final String PROVIDER_ID = "providerId"; public static final String PROVIDER_ID = "providerId";
@NotEmptyIfNotNull */
@RequiredField @NotEmptyIfNotNull @ValidURI
public static final String OBJECT_URI = "objectURI"; public static final String OBJECT_URI = "objectURI";
@RequiredField @ValidOperationType @RequiredField @ValidOperationType
public static final String OPERATION_TYPE = "operationType"; public static final String OPERATION_TYPE = "operationType";
@NotEmpty @RequiredField @NotEmpty
public static final String QUALIFIER = "qualifier";
@NotEmpty
public static final String DATA_TYPE = "dataType"; public static final String DATA_TYPE = "dataType";
@RequiredField @ValidLong @RequiredField @ValidLong
public static final String DATA_VOLUME = "dataVolume"; public static final String DATA_VOLUME = "dataVolume";
@NotEmpty
public static final String QUALIFIER = "qualifier";
@ValidIP @ValidIP
public static final String CALLER_IP = "callerIP"; public static final String CALLER_IP = "callerIP";
@ -62,27 +65,43 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
} }
/** /**
* Return the identity id of the accounting owner * Return the identity id of the storage resource owner
* @return The identity id of the accounting owner * @return the identity id of the accounting owner
*/ */
public String getResourceOwner() { public String getResourceOwner() {
return (String) this.resourceProperties.get(RESOURCE_OWNER); return (String) this.resourceProperties.get(RESOURCE_OWNER);
} }
/** /**
* Set the identity id of the accounting owner * Set the identity id of the storage resource owner
* @param ownerID The identity id of the accounting owner * @param ownerID the identity id of the storage resource owner
* @throws InvalidValueException * @throws InvalidValueException
*/ */
public void setResourceOwner(String owner) throws InvalidValueException { public void setResourceScope(String owner) throws InvalidValueException {
setResourceProperty(RESOURCE_OWNER, owner); setResourceProperty(RESOURCE_OWNER, owner);
} }
/**
* Return the scope of the storage resource
* @return The scope id of the storage resource
*/
public String getResourceScope() {
return (String) this.resourceProperties.get(RESOURCE_OWNER);
}
public String getObjectURI() { /**
return (String) this.resourceProperties.get(OBJECT_URI); * Set the scope of the storage resource
* @param scope the scope of the storage resource
* @throws InvalidValueException
*/
public void setResourceOwner(String scope) throws InvalidValueException {
setResourceProperty(RESOURCE_SCOPE, scope);
}
public URI getObjectURI() {
return (URI) this.resourceProperties.get(OBJECT_URI);
} }
public void setObjectURI(String objectURI) throws InvalidValueException { public void setObjectURI(URI objectURI) throws InvalidValueException {
setResourceProperty(OBJECT_URI, objectURI); setResourceProperty(OBJECT_URI, objectURI);
} }
@ -102,6 +121,7 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
setResourceProperty(CALLER_IP, callerIP); setResourceProperty(CALLER_IP, callerIP);
} }
/*
public String getProviderId() { public String getProviderId() {
return (String) this.resourceProperties.get(PROVIDER_ID); return (String) this.resourceProperties.get(PROVIDER_ID);
} }
@ -109,6 +129,7 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
public void setProviderId(String providerId) throws InvalidValueException { public void setProviderId(String providerId) throws InvalidValueException {
setResourceProperty(PROVIDER_ID, providerId); setResourceProperty(PROVIDER_ID, providerId);
} }
*/
public String getQualifier() { public String getQualifier() {
return (String) this.resourceProperties.get(QUALIFIER); return (String) this.resourceProperties.get(QUALIFIER);

View File

@ -0,0 +1,16 @@
package org.gcube.accounting.datamodel.validations.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
import org.gcube.accounting.datamodel.validations.validators.ValidURIValidator;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@FieldDecorator(managed=ValidURIValidator.class)
public @interface ValidURI {
}

View File

@ -0,0 +1,32 @@
package org.gcube.accounting.datamodel.validations.validators;
import java.io.Serializable;
import java.net.URI;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.decorators.FieldAction;
import org.gcube.accounting.exception.InvalidValueException;
public class ValidURIValidator implements FieldAction {
private static final String ERROR = "Not Valid URI";
/**
* {@inheritDoc}
*/
@Override
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
try {
if(value instanceof URI){
return value;
}
if(value instanceof String){
return new URI((String) value);
}
}catch (Exception e) {
throw new InvalidValueException(ERROR, e.getCause());
}
throw new InvalidValueException(ERROR);
}
}