Package net.sf.basedb.core.snapshot
Class AnnotationSnapshot
java.lang.Object
net.sf.basedb.core.snapshot.AnnotationSnapshot
- All Implemented Interfaces:
Serializable
public class AnnotationSnapshot extends Object implements Serializable
Stores information about a single primary or inherited
annotation or an inherited annotation set. Actual
annotation values are only stored for primary annotations.
IMPORTANT NOTE TO DEVELOPERS!!
Do not forget to synchronize all serialization code and to increment
the AnnotationSetSnapshot.FILE_VERSION
in case the number of variables
that needs serialization in this class or in the AnnotationSetSnapshot
changes.
- Version:
- 2.14
- Author:
- Nicklas
- See Also:
- Serialized Form
- Last modified
- $Date: 2022-07-28 14:30:36 +0200 (Thu, 28 Jul 2022) $
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AnnotationSnapshot.AnnotationTypeComparator
Comparator implementation for sorting snapshots by name of annotation type.(package private) static class
AnnotationSnapshot.ProjectComparator
Comparator implementation for sorting snapshots by name of project. -
Field Summary
Fields Modifier and Type Field Description private int
annotationId
private int
annotationSetId
private int
annotationTypeId
private AnnotationSnapshot
inheritedFrom
private int
inheritedFromId
private int
inheritedFromSetId
private int
itemId
private Item
itemType
private long
lastUpdate
private int
overrideId
private int
projectId
private static long
serialVersionUID
private Annotation.Source
source
private int
unitId
private List<? extends Serializable>
values
private Type
valueType
-
Constructor Summary
Constructors Constructor Description AnnotationSnapshot()
Create a new, empty annotation snapshot. -
Method Summary
Modifier and Type Method Description (package private) void
deserializeObject(ObjectInputStream in)
Unit
getActualUnit(DbControl dc)
Get the unit that is most relevant for this annotation.<T extends Serializable>
List<T>getActualValues()
Get the annotation values that are most relevant for this annotation.<T extends Serializable>
List<T>getActualValues(UnitConverter converter, Type valueType)
Get the annotations values, optionally converted to some specific unit and type of values.AnnotationType
getAnnotationType(DbControl dc)
Get the annotation type.int
getAnnotationTypeId()
Get the id of the annotation type.Annotation
getInheritedAnnotation(DbControl dc)
Get the parent annotation this annotation is inherited from.int
getInheritedAnnotationId()
Get the ID of the annotation this annotation is inherited from.AnnotationSet
getInheritedAnnotationSet(DbControl dc)
Get the annotation set this annotation is inherited from.int
getInheritedAnnotationSetId()
Get the ID of the annotation set this annotation is inherited from.AnnotationSnapshot
getInheritedFrom()
Get a snapshot for the annotation this is inherited from.int
getOverrideId()
Get the id of the default annotation that this project-specific annotation is overriding.Project
getProject(DbControl dc)
Get the project that a project-specific annotation belongs to.int
getProjectId()
Get the id of the project that this project-specific annotation belongs to.(package private) String
getProjectName(DbControl dc)
Get the name of project if the annotation is a project-specific value.Annotation.Source
getSource()
Get the source of the annotation.Annotation
getThisAnnotation(DbControl dc)
Get the annotation this is a snapshot of.int
getThisAnnotationId()
Get the id of the annotation this is a snapshot of.AnnotationSet
getThisAnnotationSet(DbControl dc)
Get the annotation set this annotation belongs to.int
getThisAnnotationSetId()
Get the id of the annotation set this is a snapshot of.Annotatable
getThisItem(DbControl dc)
Get the item that this annotation belongs to.int
getThisItemId()
Get the id of the item this annotation belongs to.Item
getThisItemType()
Get the item type of the item this annotation belongs to.Date
getThisLastUpdate()
Get the date+time this annotation was last updated.Unit
getThisUnit(DbControl dc)
Get the unit the annotatation values should use for display.int
getThisUnitId()
Get the id of the unit that the annotation values should use when displayed.<T extends Serializable>
List<T>getThisValues()
Get the annotation values for this annotation.boolean
hasPermission(DbControl dc, Permission permission)
Check if the logged in user has the request permission on this annotation or annotation set.(package private) void
init(AnnotationData a)
Initialize the snapshot with information from the given annotation.boolean
isUpToDate()
A primary or inherited annotation is always up-to-date.private void
readObject(ObjectInputStream in)
(package private) void
serializeObject(ObjectOutputStream out)
(package private) void
setInheritedFrom(AnnotationSnapshot inheritedFrom)
Set the primary annotation for an inherited annotation.(package private) void
setItem(int itemId, Item itemType)
static Comparator<AnnotationSnapshot>
sortByAnnotationType(DbControl dc)
Create a comparator for sorting annotation snapshots by the name of the annotation type.static Comparator<AnnotationSnapshot>
sortByProject(DbControl dc, boolean defaultFirst)
Create a comparator for sorting annotation snapshots by the name of the project.private void
writeObject(ObjectOutputStream out)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
- Constant Field Values
-
source
-
annotationId
private transient int annotationId -
annotationSetId
private transient int annotationSetId -
annotationTypeId
private transient int annotationTypeId -
inheritedFromId
private transient int inheritedFromId -
inheritedFromSetId
private transient int inheritedFromSetId -
unitId
private transient int unitId -
projectId
private transient int projectId -
overrideId
private transient int overrideId -
valueType
-
lastUpdate
private transient long lastUpdate -
values
-
itemId
private transient int itemId -
itemType
-
inheritedFrom
-
-
Constructor Details
-
AnnotationSnapshot
public AnnotationSnapshot()Create a new, empty annotation snapshot.
-
-
Method Details
-
sortByAnnotationType
Create a comparator for sorting annotation snapshots by the name of the annotation type.- Since:
- 3.6
-
sortByProject
Create a comparator for sorting annotation snapshots by the name of the project. Default values can be sorted first or last.- Since:
- 3.19.4
-
init
Initialize the snapshot with information from the given annotation.- Parameters:
a
- An annotation
-
getSource
Get the source of the annotation.- Since:
- 3.6
-
getThisAnnotationId
public int getThisAnnotationId()Get the id of the annotation this is a snapshot of.- Returns:
- The id of this annotation
- Since:
- 3.6
-
getInheritedAnnotationId
public int getInheritedAnnotationId()Get the ID of the annotation this annotation is inherited from. NOTE! This may return 0 for cloned annotations that has lost their parent annotation.- Returns:
- The id of the inherited annotation or 0 if this is primary annotation (or a cloned annotation that has lost it's parent)
- Since:
- 3.6
-
getThisAnnotation
Get the annotation this is a snapshot of.- Returns:
- An Annotation object
- Since:
- 3.6
-
getInheritedAnnotation
Get the parent annotation this annotation is inherited from. NOTE! This may return null for cloned annotations that has lost their parent annotation.- Returns:
- The inherited annotation or null if this is primary annotation (or a cloned annotation that has lost it's parent)
- Since:
- 3.6
-
hasPermission
Check if the logged in user has the request permission on this annotation or annotation set.- Parameters:
dc
- The DbControl to use for database accesspermission
- The requested permission- Returns:
- TRUE if the logged in user has the requested permission, FALSE otherwise
- Since:
- 3.1.1
-
getThisAnnotationSetId
public int getThisAnnotationSetId()Get the id of the annotation set this is a snapshot of.- Returns:
- The id of this annotation set
- Since:
- 3.6
-
getInheritedAnnotationSetId
public int getInheritedAnnotationSetId()Get the ID of the annotation set this annotation is inherited from. NOTE! This may return 0 for cloned annotations that has lost their parent annotation.- Returns:
- The id of the inherited annotation set or 0 if this is primary annotation (or a cloned annotation that has lost it's parent)
- Since:
- 3.6
-
getThisAnnotationSet
Get the annotation set this annotation belongs to.- Since:
- 3.6
-
getInheritedAnnotationSet
Get the annotation set this annotation is inherited from. NOTE! This may return null for cloned annotations that has lost their parent annotation.- Since:
- 3.6
-
getAnnotationTypeId
public int getAnnotationTypeId()Get the id of the annotation type.- Returns:
- The annotation type id, or 0 if this snapshot is from an inherited annotation set
-
getAnnotationType
Get the annotation type.- Returns:
- An AnnotationType object or null if this snapshot is from an inherited annotation set
-
getInheritedFrom
Get a snapshot for the annotation this is inherited from. NOTE! This is only available for inherited annotations returned bySnapshotManager.findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
but may be missing for cloned annotations if the parent has been deleted.- Since:
- 3.6
-
getProjectId
public int getProjectId()Get the id of the project that this project-specific annotation belongs to.- Returns:
- The project id, or 0 if this a default annotation
- Since:
- 3.10
-
getProject
Get the project that a project-specific annotation belongs to. Returns null if the annotation is a default value or if the project no longer exists.- Throws:
PermissionDeniedException
- If the logged in user doesn't have access to the project- Since:
- 3.19.4
-
getProjectName
Get the name of project if the annotation is a project-specific value. -
getOverrideId
public int getOverrideId()Get the id of the default annotation that this project-specific annotation is overriding.- Since:
- 3.10
-
getThisUnitId
public int getThisUnitId()Get the id of the unit that the annotation values should use when displayed.- Since:
- 3.6
-
getThisUnit
Get the unit the annotatation values should use for display. NOTE! The unit is only available for primary and cloned annotations. UsegetActualUnit(DbControl)
orgetInheritedFrom()
.getThisUnit() to get the unit also for inherited annotations.- Returns:
- A Unit object or null if this annotation doesn't use units
- Since:
- 3.6
-
getActualUnit
Get the unit that is most relevant for this annotation. Eg. a unit that is defined by this annotation (primary and cloned) are used before inherited unit.- Since:
- 3.6
-
getThisValues
Get the annotation values for this annotation. NOTE! The values are only available for primary and cloned annotations. UsegetActualValues()
orgetInheritedFrom()
.getThisValues() to get values also for inherited annotations.- Returns:
- A list with the values or null
-
getActualValues
Get the annotation values that are most relevant for this annotation. Eg. values that are defined by this annotation (primary and cloned) are used before inherited values.- Since:
- 3.6
-
getActualValues
Get the annotations values, optionally converted to some specific unit and type of values. NOTE! To create a unit converter that converts that values to the unit specified bygetActualUnit(DbControl)
: this.getActualUnit(dc).getUnitConverter(this.getAnnotationType(dc).getDefaultUnit())- Parameters:
converter
- A converter for converting (numerical) values, or null to not convert the valuesvalueType
- The return type of the converted values (ignored if no converter is specified)- Returns:
- A list with the values
- Since:
- 3.6
-
getThisLastUpdate
Get the date+time this annotation was last updated.- Returns:
- The date or null if this annotation doesn't contain any values
- Since:
- 3.6
-
isUpToDate
public boolean isUpToDate()A primary or inherited annotation is always up-to-date. A cloned annotation is up-to-date if the link to the source annotation exists and the source annotation has a date equal to or before the cloned annotation.- Since:
- 3.6
-
getThisItemId
public int getThisItemId()Get the id of the item this annotation belongs to. NOTE! this value is only available on annotations returned from the call to:SnapshotManager.findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
-
getThisItem
Get the item that this annotation belongs to.- Returns:
- The item, or null if the item is not know
- Since:
- 3.6
-
getThisItemType
Get the item type of the item this annotation belongs to. NOTE! this value is only available on annotations returned from the call to:SnapshotManager.findAnnotations(DbControl, AnnotationSetSnapshot, Filter, boolean)
- Returns:
- The item type, or null if not known
- Since:
- 3.6
-
setItem
-
setInheritedFrom
Set the primary annotation for an inherited annotation. -
serializeObject
- Throws:
IOException
-
writeObject
- Throws:
IOException
-
deserializeObject
- Throws:
IOException
ClassNotFoundException
-
readObject
- Throws:
IOException
ClassNotFoundException
-