/** * */ package org.gcube.accounting.datamodel; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToCreationTime; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToScope; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToUsageRecordType; import org.gcube.accounting.datamodel.deprecationmanagement.DeprecatedWarning; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord; import org.gcube.accounting.datamodel.validations.annotations.NotEmpty; import org.gcube.accounting.datamodel.validations.annotations.NotEmptyIfNotNull; import org.gcube.documentstore.exception.InvalidValueException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ @Deprecated public class RawUsageRecord extends BasicUsageRecord implements UsageRecord { /** * Generated Serial Version UID */ private static final long serialVersionUID = 1203390363640634895L; private static Logger logger = LoggerFactory.getLogger(RawUsageRecord.class); @DeprecatedWarning @MoveToScope @NotEmpty public static final String RESOURCE_SCOPE = "resourceScope"; @DeprecatedWarning @NotEmptyIfNotNull public static final String CREATOR_ID = "creatorId"; @DeprecatedWarning @NotEmptyIfNotNull protected static final String RESOURCE_OWNER = "resourceOwner"; @DeprecatedWarning @MoveToCreationTime protected static final String CREATE_TIME = "createTime"; public final static Map resourceTypeMapping; private final static String JOB = "job"; private final static String TASK = "task"; private final static String PORTLET = "portlet"; private final static String SERVICE = "service"; private final static String STORAGE_USAGE = "storage-usage"; static { resourceTypeMapping = new HashMap(); resourceTypeMapping.put(JOB, JobUsageRecord.class.getSimpleName()); resourceTypeMapping.put(TASK, TaskUsageRecord.class.getSimpleName()); resourceTypeMapping.put(PORTLET, PortletUsageRecord.class.getSimpleName()); resourceTypeMapping.put(SERVICE, ServiceUsageRecord.class.getSimpleName()); resourceTypeMapping.put(STORAGE_USAGE, StorageUsageRecord.class.getSimpleName()); } @DeprecatedWarning @MoveToUsageRecordType protected static final String RESOURCE_TYPE = "resourceType"; @DeprecatedWarning //@MoveToAggregatedUsageRecordId protected static final String AGGREGATED_ID = "aggregatedId"; /** * Redeclared to allow @MoveToUsageRecordTypeAction to access it */ public static final String USAGE_RECORD_TYPE = BasicUsageRecord.USAGE_RECORD_TYPE; /* @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @FieldDecorator(managed=MoveToAggregatedUsageRecordIdAction.class) protected @interface MoveToAggregatedUsageRecordId { } protected class MoveToAggregatedUsageRecordIdAction implements FieldAction { @Override public Serializable validate(String key, Serializable value, UsageRecord usageRecord) throws InvalidValueException { NotEmptyIfNotNullValidator neinnv = new NotEmptyIfNotNullValidator(); value = neinnv.validate(key, value, usageRecord); usageRecord.setAggregatedUsageRecordId((String) value); return value; } } */ @NotEmptyIfNotNull @DeprecatedWarning protected static final String FULLY_QUALIFIED_CONSUMER_ID = "fullyQualifiedConsumerId"; @Deprecated public RawUsageRecord(){ super(); this.resourceProperties.remove(USAGE_RECORD_TYPE); } @Deprecated public RawUsageRecord(Map> properties) throws InvalidValueException { super(properties); } /** * Return the identity of the entity creating this {#UsageRecord} * @return Creator ID */ @Deprecated public String getCreatorId() { return (String) this.resourceProperties.get(CREATOR_ID); } /** * Set the identity of the entity creating this {#UsageRecord} * @param creatorId Creator ID * @throws InvalidValueException */ @Deprecated public void setCreatorId(String creatorId) throws InvalidValueException { setResourceProperty(CREATOR_ID, creatorId); } /** * {@inheritDoc} */ @Override @Deprecated public void setConsumerId(String consumerId) { try{ super.setConsumerId(consumerId); } catch(Exception e){ logger.error("Unable to Set {}", CONSUMER_ID); } } /** * Set the scope of the {#UsageRecord} * @param scope the scope of the {#UsageRecord} */ @Deprecated public void setResourceScope(String scope) { try{ setResourceProperty(RESOURCE_SCOPE, scope); }catch(Exception e){ logger.error("Unable to Set {}", RESOURCE_SCOPE); } } /** * Use {#getUsageRecordType} instead * @param resourceType * @return Usage Record Type */ @Deprecated public String getResourceType(){ return (String) this.resourceProperties.get(RESOURCE_TYPE); } /** * This method is not valid due to Resource Type is derived by * the Usage Record Implementation class. The method is deprecated and * the implementations in known classes is a NoOperation. * @param resourceType */ @Deprecated public void setResourceType(String resourceType){ try { setResourceProperty(RESOURCE_TYPE, resourceType); }catch(InvalidValueException e){ logger.error("Unable to Set {}", RESOURCE_TYPE); } } /** * Return the creation time for this {#UsageRecord} * @return the creation time for this {#UsageRecord} */ @Deprecated public Date getCreateTime() { long millis = (Long) this.resourceProperties.get(AggregatedUsageRecord.CREATION_TIME); return timestampStringToCalendar(millis).getTime(); } /** * Use {{@link #setCreationTime(Calendar)}} instead * @param createTime * @throws InvalidValueException */ @Deprecated public void setCreateTime(Date createTime) { /* Calendar calendar = Calendar.getInstance(); calendar.setTime(createTime); setCreationTime(calendar); */ //logger.warn("The method is deprecated. Please modify your code as soon as possible"); } /** * Return the left end of the time interval covered by this usage record * @return Start Time */ @Deprecated public Date getStartTime() { long millis = (Long) this.resourceProperties.get(AggregatedUsageRecord.START_TIME); return timestampStringToCalendar(millis).getTime(); } /** * @param createTime * @throws InvalidValueException */ @Deprecated public void setStartTime(Date startTime) throws InvalidValueException { Calendar calendar = Calendar.getInstance(); calendar.setTime(startTime); setStartTime(calendar); } /** * Return the right end of the time interval covered by this usage record * @return End Time */ @Deprecated public Date getEndTime() { long millis = (Long) this.resourceProperties.get(AggregatedUsageRecord.END_TIME); return timestampStringToCalendar(millis).getTime(); } /** * @param endTime * @throws InvalidValueException */ @Deprecated public void setEndTime(Date endTime) throws InvalidValueException { Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); setEndTime(calendar); } /** * Return the identity id of the owner * @return The identity id of the owner */ @Deprecated public String getResourceOwner() { return (String) this.resourceProperties.get(RESOURCE_OWNER); } /** * Set the identity id of the owner * @param ownerID The identity id of the owner * @throws InvalidValueException */ @Deprecated public void setResourceOwner(String owner) { try { setResourceProperty(RESOURCE_OWNER, owner); } catch (InvalidValueException e) { logger.error("Unable to Set {}", RESOURCE_OWNER); } } /** * Return the id of the usage record aggregating this, null if this record * has not been aggregated by any record. * This method id deprecated. Use {@link #getAggregatedUsageRecordId()} * instead. * @return Aggregated Id The ID of the aggregation Record */ @Deprecated public String getAggregatedId() { return (String) this.resourceProperties.get(AGGREGATED_ID); } /** * Set the id of the usage record aggregating this. * This method id deprecated. Use {@link #setAggregatedUsageRecordId()} * instead. * @param aggregatedId The ID of the aggregation Record * @throws InvalidValueException */ @Deprecated public void setAggregatedId(String aggregatedId) throws InvalidValueException { setResourceProperty(AGGREGATED_ID, aggregatedId); } /** * Return all resource properties * Use {@link #getResourceSpecificProperties()} * @return a Map containing the properties */ @Deprecated public Map getResourceSpecificProperties() { Map ret = new HashMap(); for(String key : this.resourceProperties.keySet()){ String value = this.resourceProperties.get(key).toString(); ret.put(key, value); } return ret; } /** * Set all resource properties, replacing existing ones * Use {@link #setResourceSpecificProperties()} */ @Deprecated public void setResourceSpecificProperties(Map properties) throws InvalidValueException { Map> map = new HashMap>(properties); setResourceProperties(map); } /** * Return the value of the given resource property. * @param key the key of the requested property * @return the value of the given resource property */ @Deprecated public String getResourceSpecificProperty(String key) { return getResourceProperty(key).toString(); } /** * Set the value of the given resource property. * If the key has the value of one of the predefined property, the value * is validated. * @param key the key of the requested property * @param value the value of the given resource property */ @Deprecated public void setResourceSpecificProperty(String key, Comparable value) { try { setResourceProperty(key, value); } catch (InvalidValueException e) { logger.error("Unable to Set {}", key); } } /** * The method is deprecated and the implementations in known classes * return Consumer ID * @return Consumer ID */ @Deprecated public String getFullyQualifiedConsumerId() { return (String) this.resourceProperties.get(FULLY_QUALIFIED_CONSUMER_ID); } /** * The method is deprecated and the implementations in known classes is * a NoOperation. * @param fqcid Fully Qualified Consumer Id */ @Deprecated public void setFullyQualifiedConsumerId(String fqcid) { try { setResourceProperty(FULLY_QUALIFIED_CONSUMER_ID, fqcid); } catch (InvalidValueException e) { logger.error("Unable to Set {}", FULLY_QUALIFIED_CONSUMER_ID); } } /** * {@inheritDoc} */ @Override protected String giveMeUsageRecordType() { // This implementation is just a placeholder return this.getClass().getSimpleName(); } }