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: 2019-04-11 09:31:26 +0200 (tors, 11 apr. 2019) $
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
      Constant Field Values
    • source

      private transient Annotation.Source 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

      private transient Type valueType
    • lastUpdate

      private transient long lastUpdate
    • values

      private transient List<? extends Serializable> values
    • itemId

      private transient int itemId
    • itemType

      private transient Item itemType
    • inheritedFrom

      private transient AnnotationSnapshot inheritedFrom
  • Constructor Details

    • AnnotationSnapshot

      public AnnotationSnapshot()
      Create a new, empty annotation snapshot.
  • Method Details

    • sortByAnnotationType

      public static Comparator<AnnotationSnapshot> sortByAnnotationType​(DbControl dc)
      Create a comparator for sorting annotation snapshots by the name of the annotation type.
      Since:
      3.6
    • init

      void init​(AnnotationData a)
      Initialize the snapshot with information from the given annotation.
      Parameters:
      a - An annotation
    • getSource

      public Annotation.Source 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

      public Annotation getThisAnnotation​(DbControl dc)
      Get the annotation this is a snapshot of.
      Returns:
      An Annotation object
      Since:
      3.6
    • getInheritedAnnotation

      public Annotation getInheritedAnnotation​(DbControl dc)
      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

      public boolean hasPermission​(DbControl dc, Permission permission)
      Check if the logged in user has the request permission on this annotation or annotation set.
      Parameters:
      dc - The DbControl to use for database access
      permission - 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

      public AnnotationSet getThisAnnotationSet​(DbControl dc)
      Get the annotation set this annotation belongs to.
      Since:
      3.6
    • getInheritedAnnotationSet

      public AnnotationSet getInheritedAnnotationSet​(DbControl dc)
      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

      public AnnotationType getAnnotationType​(DbControl dc)
      Get the annotation type.
      Returns:
      An AnnotationType object or null if this snapshot is from an inherited annotation set
    • getInheritedFrom

      public AnnotationSnapshot getInheritedFrom()
      Get a snapshot for the annotation this is inherited from. NOTE! This is only available for inherited annotations returned by SnapshotManager.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
    • 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

      public Unit getThisUnit​(DbControl dc)
      Get the unit the annotatation values should use for display. NOTE! The unit is only available for primary and cloned annotations. Use getActualUnit(DbControl) or getInheritedFrom().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

      public Unit getActualUnit​(DbControl dc)
      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

      public <T extends Serializable> List<T> getThisValues()
      Get the annotation values for this annotation. NOTE! The values are only available for primary and cloned annotations. Use getActualValues() or getInheritedFrom().getThisValues() to get values also for inherited annotations.
      Returns:
      A list with the values or null
    • getActualValues

      public <T extends Serializable> List<T> 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

      public <T extends Serializable> List<T> getActualValues​(UnitConverter converter, Type valueType)
      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 by getActualUnit(DbControl): this.getActualUnit(dc).getUnitConverter(this.getAnnotationType(dc).getDefaultUnit())
      Parameters:
      converter - A converter for converting (numerical) values, or null to not convert the values
      valueType - The return type of the converted values (ignored if no converter is specified)
      Returns:
      A list with the values
      Since:
      3.6
    • getThisLastUpdate

      public Date 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

      public Annotatable getThisItem​(DbControl dc)
      Get the item that this annotation belongs to.
      Returns:
      The item, or null if the item is not know
      Since:
      3.6
    • getThisItemType

      public Item 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

      void setItem​(int itemId, Item itemType)
    • setInheritedFrom

      void setInheritedFrom​(AnnotationSnapshot inheritedFrom)
      Set the primary annotation for an inherited annotation.
    • serializeObject

      void serializeObject​(ObjectOutputStream out) throws IOException
      Throws:
      IOException
    • writeObject

      private void writeObject​(ObjectOutputStream out) throws IOException
      Throws:
      IOException
    • deserializeObject

      void deserializeObject​(ObjectInputStream in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • readObject

      private void readObject​(ObjectInputStream in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException