2015-05-28 13:19:25 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.datamodel.implementations;
|
|
|
|
|
2015-06-09 15:53:21 +02:00
|
|
|
import java.io.Serializable;
|
2015-06-26 12:21:28 +02:00
|
|
|
import java.lang.annotation.ElementType;
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
import java.lang.annotation.Target;
|
2015-06-25 15:58:26 +02:00
|
|
|
import java.net.URI;
|
2015-06-09 15:53:21 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2015-06-10 17:36:50 +02:00
|
|
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
2015-06-05 14:43:04 +02:00
|
|
|
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
2015-06-26 12:21:28 +02:00
|
|
|
import org.gcube.accounting.datamodel.UsageRecord;
|
|
|
|
import org.gcube.accounting.datamodel.decorators.FieldAction;
|
|
|
|
import org.gcube.accounting.datamodel.decorators.FieldDecorator;
|
2015-06-08 17:30:08 +02:00
|
|
|
import org.gcube.accounting.datamodel.decorators.RequiredField;
|
2015-06-26 12:21:28 +02:00
|
|
|
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
|
2015-06-08 17:19:09 +02:00
|
|
|
import org.gcube.accounting.datamodel.validations.annotations.NotEmpty;
|
|
|
|
import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull;
|
|
|
|
import org.gcube.accounting.datamodel.validations.annotations.ValidIP;
|
|
|
|
import org.gcube.accounting.datamodel.validations.annotations.ValidLong;
|
2015-06-10 16:40:24 +02:00
|
|
|
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationType;
|
2015-06-25 15:58:26 +02:00
|
|
|
import org.gcube.accounting.datamodel.validations.annotations.ValidURI;
|
2015-06-26 12:21:28 +02:00
|
|
|
import org.gcube.accounting.datamodel.validations.validators.ValidURIValidator;
|
2015-05-29 16:08:21 +02:00
|
|
|
import org.gcube.accounting.exception.InvalidValueException;
|
2015-05-28 13:19:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
2015-06-10 17:36:50 +02:00
|
|
|
public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageRecord {
|
2015-05-28 13:19:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generated Serial Version UID
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 1381025822586583326L;
|
|
|
|
|
2015-06-10 16:40:24 +02:00
|
|
|
public enum OperationType {
|
2015-06-25 15:58:26 +02:00
|
|
|
CREATE, READ, UPDATE, DELETE, COPY, MOVE
|
2015-06-10 16:40:24 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 17:41:56 +02:00
|
|
|
/**
|
2015-06-26 12:21:28 +02:00
|
|
|
* Predefined DATA TYPE
|
|
|
|
*/
|
|
|
|
public static final String STORAGE_DATA_TYPE = "STORAGE";
|
|
|
|
/**
|
|
|
|
* Predefined DATA TYPE
|
|
|
|
*/
|
|
|
|
public static final String TREE_DATA_TYPE = "TREE";
|
|
|
|
/**
|
|
|
|
* Predefined DATA TYPE
|
|
|
|
*/
|
|
|
|
public static final String GEO_DATA_TYPE = "GEO";
|
|
|
|
/**
|
|
|
|
* Predefined DATA TYPE
|
|
|
|
*/
|
|
|
|
public static final String DATABASE_DATA_TYPE = "DATABASE";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* KEY for : The Owner of the stored Resource
|
2015-06-25 17:41:56 +02:00
|
|
|
*/
|
2015-06-25 15:58:26 +02:00
|
|
|
@RequiredField @NotEmpty
|
2015-06-15 11:28:19 +02:00
|
|
|
public static final String RESOURCE_OWNER = "resourceOwner";
|
2015-06-26 12:21:28 +02:00
|
|
|
/**
|
|
|
|
* KEY for : The Scope where the Resource was stored
|
|
|
|
*/
|
2015-06-25 15:58:26 +02:00
|
|
|
@RequiredField @NotEmpty
|
|
|
|
public static final String RESOURCE_SCOPE = "resourceScope";
|
|
|
|
|
|
|
|
/*
|
2015-06-05 18:50:07 +02:00
|
|
|
@NotEmptyIfNotNull
|
|
|
|
public static final String PROVIDER_ID = "providerId";
|
2015-06-25 15:58:26 +02:00
|
|
|
*/
|
2015-06-26 12:21:28 +02:00
|
|
|
|
|
|
|
@DeprecatedWarning @MoveToResourceURI
|
|
|
|
protected static final String OBJECT_URI = "objectURI";
|
|
|
|
@Target(ElementType.FIELD)
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
@FieldDecorator(managed=MoveToResourceURIAction.class)
|
|
|
|
protected @interface MoveToResourceURI { }
|
|
|
|
protected class MoveToResourceURIAction implements FieldAction {
|
|
|
|
@Override
|
|
|
|
public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException {
|
|
|
|
ValidURIValidator neinnv = new ValidURIValidator();
|
|
|
|
value = neinnv.validate(key, value, usageRecord);
|
|
|
|
((StorageUsageRecord) usageRecord).setResourceURI((URI) value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* KEY for : The URI of the Stored Resource
|
|
|
|
*/
|
|
|
|
@RequiredField @ValidURI //@NotEmptyIfNotNull
|
|
|
|
public static final String RESOURCE_URI = "resourceURI";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* KEY for : The operation performed over the stored resource.
|
|
|
|
* The value is a controlled dictionary by
|
|
|
|
* {@link #StorageUsageRecord.OperationType}
|
|
|
|
*/
|
2015-06-10 16:40:24 +02:00
|
|
|
@RequiredField @ValidOperationType
|
2015-05-28 13:19:25 +02:00
|
|
|
public static final String OPERATION_TYPE = "operationType";
|
2015-06-26 12:21:28 +02:00
|
|
|
/**
|
|
|
|
* KEY for : type of data accessed.
|
|
|
|
* Even this field is not a controlled dictionary some type are defined
|
|
|
|
* i.e. STORAGE, TREE, GEO, DATABASE.
|
|
|
|
* Check the constant on this class:
|
|
|
|
* {@link #STORAGE_DATA_TYPE}, {@link #TREE_DATA_TYPE},
|
|
|
|
* {@link #GEO_DATA_TYPE}, {@link #DATABASE_DATA_TYPE}
|
|
|
|
*/
|
2015-06-25 15:58:26 +02:00
|
|
|
@RequiredField @NotEmpty
|
2015-06-04 18:52:29 +02:00
|
|
|
public static final String DATA_TYPE = "dataType";
|
2015-06-25 17:41:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Quantity of data in terms of KB
|
|
|
|
*/
|
2015-06-24 15:24:57 +02:00
|
|
|
@RequiredField @ValidLong
|
2015-06-04 18:52:29 +02:00
|
|
|
public static final String DATA_VOLUME = "dataVolume";
|
2015-06-24 15:24:57 +02:00
|
|
|
|
2015-06-26 12:21:28 +02:00
|
|
|
/**
|
|
|
|
* KEY for : Qualifies the data in terms of data (e.g. MIME type for the
|
|
|
|
* Storage, domain for a database)
|
|
|
|
*/
|
|
|
|
@NotEmptyIfNotNull
|
2015-06-25 15:58:26 +02:00
|
|
|
public static final String QUALIFIER = "qualifier";
|
2015-06-26 12:21:28 +02:00
|
|
|
/**
|
|
|
|
* KEY for : IP address that originated the service call
|
|
|
|
*/
|
2015-06-05 18:50:07 +02:00
|
|
|
@ValidIP
|
|
|
|
public static final String CALLER_IP = "callerIP";
|
2015-05-28 13:19:25 +02:00
|
|
|
|
2015-06-26 12:21:28 +02:00
|
|
|
|
2015-06-10 16:13:28 +02:00
|
|
|
public StorageUsageRecord(){
|
2015-05-28 13:19:25 +02:00
|
|
|
super();
|
|
|
|
}
|
2015-05-29 16:08:21 +02:00
|
|
|
|
2015-06-10 16:13:28 +02:00
|
|
|
public StorageUsageRecord(Map<String, Serializable> properties) throws InvalidValueException {
|
2015-06-09 15:53:21 +02:00
|
|
|
super(properties);
|
|
|
|
}
|
|
|
|
|
2015-06-15 11:28:19 +02:00
|
|
|
/**
|
2015-06-25 15:58:26 +02:00
|
|
|
* Return the identity id of the storage resource owner
|
|
|
|
* @return the identity id of the accounting owner
|
2015-06-15 11:28:19 +02:00
|
|
|
*/
|
|
|
|
public String getResourceOwner() {
|
|
|
|
return (String) this.resourceProperties.get(RESOURCE_OWNER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:58:26 +02:00
|
|
|
* Set the identity id of the storage resource owner
|
|
|
|
* @param ownerID the identity id of the storage resource owner
|
2015-06-15 11:28:19 +02:00
|
|
|
* @throws InvalidValueException
|
|
|
|
*/
|
2015-06-25 15:58:26 +02:00
|
|
|
public void setResourceScope(String owner) throws InvalidValueException {
|
2015-06-15 11:28:19 +02:00
|
|
|
setResourceProperty(RESOURCE_OWNER, owner);
|
|
|
|
}
|
2015-06-25 15:58:26 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2015-06-15 11:28:19 +02:00
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
/*
|
|
|
|
public String getProviderId() {
|
|
|
|
return (String) this.resourceProperties.get(PROVIDER_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setProviderId(String providerId) throws InvalidValueException {
|
|
|
|
setResourceProperty(PROVIDER_ID, providerId);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-06-26 12:21:28 +02:00
|
|
|
public URI getResourceURI() {
|
|
|
|
return (URI) this.resourceProperties.get(RESOURCE_URI);
|
2015-05-29 16:08:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 12:21:28 +02:00
|
|
|
public void setResourceURI(URI resourceURI) throws InvalidValueException {
|
|
|
|
setResourceProperty(RESOURCE_URI, resourceURI);
|
2015-05-29 16:08:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 17:41:56 +02:00
|
|
|
public OperationType getOperationType() {
|
|
|
|
return (OperationType) this.resourceProperties.get(OPERATION_TYPE);
|
2015-05-29 16:08:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 17:41:56 +02:00
|
|
|
public void setOperationType(OperationType operationType) throws InvalidValueException {
|
2015-06-09 14:54:14 +02:00
|
|
|
setResourceProperty(OPERATION_TYPE, operationType);
|
2015-05-29 16:08:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
public String getDataType() {
|
|
|
|
return (String) this.resourceProperties.get(DATA_TYPE);
|
2015-05-29 16:08:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
public void setDataType(String dataType) throws InvalidValueException {
|
|
|
|
setResourceProperty(DATA_TYPE, dataType);
|
2015-05-29 16:08:21 +02:00
|
|
|
}
|
2015-06-04 18:52:29 +02:00
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
public long getDataVolume() {
|
|
|
|
return (Long) this.resourceProperties.get(DATA_VOLUME);
|
2015-06-04 18:52:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
public void setDataVolume(long dataVolume) throws InvalidValueException {
|
|
|
|
setResourceProperty(DATA_VOLUME, dataVolume);
|
2015-06-04 18:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getQualifier() {
|
2015-06-09 14:54:14 +02:00
|
|
|
return (String) this.resourceProperties.get(QUALIFIER);
|
2015-06-04 18:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setQualifier(String qualifier) throws InvalidValueException {
|
2015-06-09 14:54:14 +02:00
|
|
|
setResourceProperty(QUALIFIER, qualifier);
|
2015-06-04 18:52:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
public String getCallerIP() {
|
|
|
|
return (String) this.resourceProperties.get(CALLER_IP);
|
2015-06-04 18:52:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-25 16:21:56 +02:00
|
|
|
public void setCallerIP(String callerIP) throws InvalidValueException {
|
|
|
|
setResourceProperty(CALLER_IP, callerIP);
|
2015-06-04 18:52:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 15:24:57 +02:00
|
|
|
|
2015-06-05 09:47:48 +02:00
|
|
|
|
2015-05-28 13:19:25 +02:00
|
|
|
}
|