accounting-lib/src/main/java/org/gcube/accounting/datamodel/implementations/StorageUsageRecord.java

240 lines
7.0 KiB
Java
Raw Normal View History

/**
*
*/
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.net.URI;
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;
import org.gcube.accounting.datamodel.decorators.RequiredField;
import org.gcube.accounting.datamodel.deprecationmanagement.annotations.DeprecatedWarning;
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;
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationType;
import org.gcube.accounting.datamodel.validations.annotations.ValidURI;
import org.gcube.accounting.datamodel.validations.validators.ValidURIValidator;
import org.gcube.accounting.exception.InvalidValueException;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageRecord {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 1381025822586583326L;
public enum OperationType {
CREATE, READ, UPDATE, DELETE, COPY, MOVE
}
/**
* 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
*/
@RequiredField @NotEmpty
public static final String RESOURCE_OWNER = "resourceOwner";
/**
* KEY for : The Scope where the Resource was stored
*/
@RequiredField @NotEmpty
public static final String RESOURCE_SCOPE = "resourceScope";
/*
@NotEmptyIfNotNull
public static final String PROVIDER_ID = "providerId";
*/
@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}
*/
@RequiredField @ValidOperationType
public static final String OPERATION_TYPE = "operationType";
/**
* 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}
*/
@RequiredField @NotEmpty
public static final String DATA_TYPE = "dataType";
/**
* Quantity of data in terms of KB
*/
@RequiredField @ValidLong
public static final String DATA_VOLUME = "dataVolume";
/**
* KEY for : Qualifies the data in terms of data (e.g. MIME type for the
* Storage, domain for a database)
*/
@NotEmptyIfNotNull
public static final String QUALIFIER = "qualifier";
/**
* KEY for : IP address that originated the service call
*/
@ValidIP
public static final String CALLER_IP = "callerIP";
public StorageUsageRecord(){
super();
}
public StorageUsageRecord(Map<String, Serializable> properties) throws InvalidValueException {
super(properties);
}
/**
* Return the identity id of the storage resource owner
* @return the identity id of the accounting owner
*/
public String getResourceOwner() {
return (String) this.resourceProperties.get(RESOURCE_OWNER);
}
/**
* Set the identity id of the storage resource owner
* @param ownerID the identity id of the storage resource owner
* @throws InvalidValueException
*/
public void setResourceScope(String owner) throws InvalidValueException {
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);
}
/**
* 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 String getProviderId() {
return (String) this.resourceProperties.get(PROVIDER_ID);
}
public void setProviderId(String providerId) throws InvalidValueException {
setResourceProperty(PROVIDER_ID, providerId);
}
*/
public URI getResourceURI() {
return (URI) this.resourceProperties.get(RESOURCE_URI);
}
public void setResourceURI(URI resourceURI) throws InvalidValueException {
setResourceProperty(RESOURCE_URI, resourceURI);
}
public OperationType getOperationType() {
return (OperationType) this.resourceProperties.get(OPERATION_TYPE);
}
public void setOperationType(OperationType operationType) throws InvalidValueException {
setResourceProperty(OPERATION_TYPE, operationType);
}
public String getDataType() {
return (String) this.resourceProperties.get(DATA_TYPE);
}
public void setDataType(String dataType) throws InvalidValueException {
setResourceProperty(DATA_TYPE, dataType);
}
public long getDataVolume() {
return (Long) this.resourceProperties.get(DATA_VOLUME);
}
public void setDataVolume(long dataVolume) throws InvalidValueException {
setResourceProperty(DATA_VOLUME, dataVolume);
}
public String getQualifier() {
return (String) this.resourceProperties.get(QUALIFIER);
}
public void setQualifier(String qualifier) throws InvalidValueException {
setResourceProperty(QUALIFIER, qualifier);
}
public String getCallerIP() {
return (String) this.resourceProperties.get(CALLER_IP);
}
public void setCallerIP(String callerIP) throws InvalidValueException {
setResourceProperty(CALLER_IP, callerIP);
}
}