Class AbstractRecord
- java.lang.Object
-
- org.gcube.documentstore.records.implementation.AbstractRecord
-
- All Implemented Interfaces:
Serializable,Comparable<Record>,Record
public abstract class AbstractRecord extends Object implements Record
- Author:
- Luca Frosini (ISTI - CNR)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>aggregatedFieldsprotected Map<String,List<FieldAction>>computationprotected Set<String>computedFieldsprotected static StringCREATION_TIMEprotected static StringIDprotected Set<String>requiredFieldsprotected Map<String,Serializable>resourcePropertiesresource-specific propertiesprotected Map<String,List<FieldAction>>validation-
Fields inherited from interface org.gcube.documentstore.records.Record
RECORD_TYPE
-
-
Constructor Summary
Constructors Constructor Description AbstractRecord()AbstractRecord(Map<String,? extends Serializable> properties)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcleanExtraFields()intcompareTo(Record record)Compare this Record instance with the one provided as argumentprotected voidcomputeField(String key)Set<String>getAggregatedFields()protected static Set<Field>getAllFields(Class<?> type)Set<String>getComputedFields()CalendargetCreationTime()Return the instant when thisRecordwas created.protected CalendargetEndTimeAsCalendar()Return the right end of the time interval covered by this Recordprotected longgetEndTimeInMillis()Return the right end of the time interval covered by this RecordStringgetId()Return the unique id for thisRecordprotected intgetOperationCount()SortedSet<String>getQuerableKeys()Set<String>getRequiredFields()Map<String,Serializable>getResourceProperties()Return all resource-specific properties.SerializablegetResourceProperty(String key)Return the value of the given resource property.protected CalendargetStartTimeAsCalendar()Return the left end of the time interval covered by this Recordprotected longgetStartTimeInMillis()Return the left end of the time interval covered by this Recordprotected voidinit()Initialize variableprotected voidinitializeValidation()protected BooleanisAggregated()voidremoveResourceProperty(String key)Remove a property from Record.protected voidsetAggregated(Boolean aggregate)Set the boolean aggregate by this RecordvoidsetCreationTime(Calendar creationTime)The CreationTime is automatically created by the implementation Class.protected voidsetEndTime(Calendar endTime)Set the right end of the time interval covered by this RecordvoidsetId(String id)The ID SHOULD be automatically created by the implementation Class.protected voidsetOperationCount(int operationCount)voidsetResourceProperties(Map<String,? extends Serializable> properties)Set all resource-specific properties, replacing existing onesvoidsetResourceProperty(String key, Serializable value)Set the value of the given resource property.protected voidsetStartTime(Calendar startTime)Set the left end of the time interval covered by this Recordstatic CalendartimestampToCalendar(long millis)StringtoString()voidvalidate()Validate the Resource Record.protected SerializablevalidateField(String key, Serializable value)protected Map<String,? extends Serializable>validateProperties(Map<String,? extends Serializable> properties)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.gcube.documentstore.records.Record
getRecordType
-
-
-
-
Field Detail
-
ID
protected static final String ID
- See Also:
- Constant Field Values
-
CREATION_TIME
protected static final String CREATION_TIME
- See Also:
- Constant Field Values
-
resourceProperties
protected Map<String,Serializable> resourceProperties
resource-specific properties
-
validation
protected Map<String,List<FieldAction>> validation
-
computation
protected Map<String,List<FieldAction>> computation
-
-
Constructor Detail
-
AbstractRecord
public AbstractRecord()
-
AbstractRecord
public AbstractRecord(Map<String,? extends Serializable> properties) throws InvalidValueException
- Throws:
InvalidValueException
-
-
Method Detail
-
initializeValidation
protected void initializeValidation()
-
getQuerableKeys
public SortedSet<String> getQuerableKeys() throws Exception
- Specified by:
getQuerableKeysin interfaceRecord- Returns:
- Querable Keys as SortedSet
- Throws:
Exception
-
cleanExtraFields
protected void cleanExtraFields()
-
init
protected void init()
Initialize variable
-
getRequiredFields
public Set<String> getRequiredFields()
- Specified by:
getRequiredFieldsin interfaceRecord- Returns:
- a Set containing the keys of required fields The returned Set MUST be a copy of the internal representation. Any modification to the returned Set MUST not affect the object
-
getComputedFields
public Set<String> getComputedFields()
- Specified by:
getComputedFieldsin interfaceRecord- Returns:
- a Set containing the keys of computed fields The returned Set MUST be a copy of the internal representation. Any modification to the returned Set MUST not affect the object
-
setId
public void setId(String id) throws InvalidValueException
The ID SHOULD be automatically created by the implementation Class. Set the ID only if you really know what you are going to do. Set the unique id for thisRecord- Specified by:
setIdin interfaceRecord- Parameters:
id- Unique ID- Throws:
InvalidValueException
-
timestampToCalendar
public static Calendar timestampToCalendar(long millis)
-
getCreationTime
public Calendar getCreationTime()
Return the instant when thisRecordwas created.- Specified by:
getCreationTimein interfaceRecord- Returns:
- the creation time for this
Record
-
setCreationTime
public void setCreationTime(Calendar creationTime) throws InvalidValueException
The CreationTime is automatically created by the implementation Class. Set the CreationTime only if you really know what you are going to do. Set the instant when thisRecordwas created.- Specified by:
setCreationTimein interfaceRecord- Parameters:
creationTime- Creation Time- Throws:
InvalidValueException
-
getResourceProperties
public Map<String,Serializable> getResourceProperties()
Return all resource-specific properties. The returned Map is a copy of the internal representation. Any modification to the returned Map MUST not affect the object- Specified by:
getResourcePropertiesin interfaceRecord- Returns:
- a Map containing the properties
-
setResourceProperties
public void setResourceProperties(Map<String,? extends Serializable> properties) throws InvalidValueException
Set all resource-specific properties, replacing existing ones- Specified by:
setResourcePropertiesin interfaceRecord- Throws:
InvalidValueException
-
getResourceProperty
public Serializable getResourceProperty(String key)
Return the value of the given resource property.- Specified by:
getResourcePropertyin interfaceRecord- Parameters:
key- the key of the requested property- Returns:
- the value of the given resource property
-
removeResourceProperty
public void removeResourceProperty(String key)
Description copied from interface:RecordRemove a property from Record. This API is intended for intern use only.- Specified by:
removeResourcePropertyin interfaceRecord- Parameters:
key- the key of the requested property to remove
-
setResourceProperty
public void setResourceProperty(String key, Serializable value) throws InvalidValueException
Set the value of the given resource property. If the key has the value of one of the predefined property, the value is validated.- Specified by:
setResourcePropertyin interfaceRecord- Parameters:
key- the key of the requested propertyvalue- the value of the given resource property- Throws:
InvalidValueException
-
setEndTime
protected void setEndTime(Calendar endTime) throws InvalidValueException
Set the right end of the time interval covered by this Record- Parameters:
endTime- End Time- Throws:
InvalidValueException
-
getEndTimeInMillis
protected long getEndTimeInMillis()
Return the right end of the time interval covered by this Record- Returns:
- End Time
-
getEndTimeAsCalendar
protected Calendar getEndTimeAsCalendar()
Return the right end of the time interval covered by this Record- Returns:
- End Time
-
getOperationCount
protected int getOperationCount()
-
setOperationCount
protected void setOperationCount(int operationCount) throws InvalidValueException- Throws:
InvalidValueException
-
getStartTimeInMillis
protected long getStartTimeInMillis()
Return the left end of the time interval covered by this Record- Returns:
- Start Time
-
getStartTimeAsCalendar
protected Calendar getStartTimeAsCalendar()
Return the left end of the time interval covered by this Record- Returns:
- Start Time
-
setStartTime
protected void setStartTime(Calendar startTime) throws InvalidValueException
Set the left end of the time interval covered by this Record- Parameters:
startTime- Start Time- Throws:
InvalidValueException
-
setAggregated
protected void setAggregated(Boolean aggregate) throws InvalidValueException
Set the boolean aggregate by this Record- Parameters:
aggregate-- Throws:
InvalidValueException
-
isAggregated
protected Boolean isAggregated()
-
validateField
protected Serializable validateField(String key, Serializable value) throws InvalidValueException
- Throws:
InvalidValueException
-
computeField
protected void computeField(String key) throws InvalidValueException
- Throws:
InvalidValueException
-
validateProperties
protected Map<String,? extends Serializable> validateProperties(Map<String,? extends Serializable> properties) throws InvalidValueException
- Throws:
InvalidValueException
-
validate
public void validate() throws InvalidValueExceptionValidate the Resource Record. The validation check if all the Required Field are set and has valid value.- Specified by:
validatein interfaceRecord- Throws:
InvalidValueException
-
compareTo
public int compareTo(Record record)
Compare this Record instance with the one provided as argument- Specified by:
compareToin interfaceComparable<Record>- Parameters:
record- the Record to compare- Returns:
- 0 is and only if the Record provided as parameter contains all and ONLY the parameters contained in this instance. If the number of parameters differs, the methods return the difference between the number of parameter in this instance and the ones in the Record provided as parameter. If the size is the same but the Record provided as parameter does not contains all parameters in this instance, -1 is returned.
-
-