Class AnnotationSet
- All Implemented Interfaces:
AccessControlled
,Controlled
,Identifiable
,Transactional
An item can also inherit annotation from it's parents. It is possible to inherit all annotations or only specific ones. In the first case this means that if the parent gets new annotations those are automatically inherited. In the second case the inherticane is lost if the annotation is deleted. If a new annotation of the same annotation type is creted later, it is NOT automatically inherited again.
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2019-04-11 09:31:26 +0200 (tors, 11 apr. 2019) $
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Restriction for matching project-specific annotations against the currently active project.private static class
Nested classes/interfaces inherited from interface net.sf.basedb.core.Transactional
Transactional.Action
-
Field Summary
Modifier and TypeFieldDescriptionprivate Annotatable
The item this annotation set belongs to.private static final QueryRuntimeFilter
This filter gives everybody read permission to annotations.private boolean
Flag to indicate if this annotation set has been modified and the snapshot must be removed.static final Item
The type of item represented by this class. -
Constructor Summary
ConstructorDescriptionAnnotationSet
(AnnotationSetData annotationSetData) Regular constructor if the item is not known beforehand.AnnotationSet
(AnnotationSetData annotationSetData, Annotatable item) Special constructor to avoidgetItem()
to hit the database when the item is known beforehand. -
Method Summary
Modifier and TypeMethodDescriptionint
autoInherit
(DbControl dc, Collection<AnnotationType> annotationTypes, SnapshotManager manager, boolean preferAnnotationSet) Automatically inherit all annotations of one or more specified annotation types from parent items that are currntly missing from this annotation setvoid
copyFrom
(Annotatable item, boolean overwrite) Copy annotations from another annotatable item to this annotation set.static AnnotationSetSnapshot
createSnapshot
(DbControl dc, int annotationSetId) Create a new annotation snapshot for the given annotation set.static int
deleteEmptyAnnotationSets
(ProgressReporter progress) Delete all empty annotation sets.(package private) static int
deleteEmptyAnnotationSets
(Session session, ProgressReporter progress) Delete all empty annotation sets.getAnnotation
(AnnotationType annotationType) Get theAnnotation
object of the specified annotation type.getAnnotations
(Annotation.Source source) Get a query returning annotations with the specified source.static AnnotationSet
Get anAnnotationSet
item when you know the id.(package private) AnnotationSetData
getData()
Get theBasicData
object that holds all data for this item.getItem()
Get the item this annotation set belongs to.Get the item this annotation set belongs to using a specific DbControl for database access.int
Get the ID of the item this annotation set belongs to.Get theItem
type of the item this annotation set belongs to.(package private) static AnnotationSet
getNew
(DbControl dc, Annotatable item) Create a new annotation set for the specified item.(package private) PluginPermission
getProjectAnnotation
(AnnotationType annotationType, Project project) Get a value for a project-specific annotation using the specified project instead of the currently active project.getProjectAnnotations
(Annotation.Source source, Project project) Get a query returning annotations with the specified source and belonging to the specified project (or default values if projectId=0).(package private) static ItemQuery<AnnotationSet>
getQuery()
Get aItemQuery
object configured to retrieveAnnotationSet
items.getType()
Get the type of item represented by the object.Get the item this annotation set belongs to.boolean
hasAnnotation
(AnnotationType annotationType, Annotation.Source source) Check if the annotation set contains an annotation of the specified type.boolean
hasProjectAnnotation
(AnnotationType annotationType, Annotation.Source source, Project project) Check if the annotation set contains an annotation of the specified type.int
inheritAll
(AnnotationSet annotationSet, boolean clone) Utility method for inheriting or cloning all annotations from the given annotation set.inheritAnnotation
(Annotation annotation, boolean clone) Inherit or clone an annotation.(package private) void
initPermissions
(int granted, int denied) READ permission is granted to all users.boolean
isInherited
(Annotation annotation) Check if an annotation is inherited or not by this annotation set.boolean
Get the status of the 'invalid snapshot' flag.boolean
isUsed()
Always return TRUE.(package private) static int
loadItemId
(Session session, Item itemType, int annotationSetId) Load the id of the item that this annotation set belongs to.(package private) void
onBeforeCommit
(Transactional.Action action) Remove the cached snapshot if needed.int
removeAllInherited
(AnnotationSet annotationSet) Utility method to stop inheriting all annotations in the given annotation set.void
removeAnnotation
(AnnotationType annotationType) Delete the primary annotation of the specified annotation type.void
removeInheritedAnnotation
(Annotation annotation) Remove an inherited an annotation.void
removeProjectAnnotation
(AnnotationType annotationType, Project project) Delete the primary annotation of the specified annotation type.(package private) void
setItem
(Annotatable item) Set the item this annotation set belongs to.void
Mark the snapshot (if it exists) of this annotation set as invalid.Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, validate
-
Field Details
-
TYPE
The type of item represented by this class.- See Also:
-
RUNTIME_FILTER
This filter gives everybody read permission to annotations. -
item
The item this annotation set belongs to. -
snapshotIsInvalid
private boolean snapshotIsInvalidFlag to indicate if this annotation set has been modified and the snapshot must be removed.
-
-
Constructor Details
-
AnnotationSet
AnnotationSet(AnnotationSetData annotationSetData) Regular constructor if the item is not known beforehand. -
AnnotationSet
AnnotationSet(AnnotationSetData annotationSetData, Annotatable item) Special constructor to avoidgetItem()
to hit the database when the item is known beforehand.- See Also:
-
-
Method Details
-
getNew
Create a new annotation set for the specified item.- Throws:
BaseException
- See Also:
-
getById
public static AnnotationSet getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException Get anAnnotationSet
item when you know the id.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.id
- The id of the item to load- Returns:
- The
AnnotationSet
item - Throws:
ItemNotFoundException
- If an item with the specified id is not foundPermissionDeniedException
- If the logged in user doesn't have read permission to the itemBaseException
- If there is another error
-
getQuery
Get aItemQuery
object configured to retrieveAnnotationSet
items. This query may return items which the logged in user doesn't have read permission to. At the moment there is no way to solve this problem.- Returns:
- An
ItemQuery
object
-
loadItemId
Load the id of the item that this annotation set belongs to.- Since:
- 2.14
-
createSnapshot
Create a new annotation snapshot for the given annotation set. NOTE! This method will always create a new snapshot from the database. The snapshot is not saved in the cache.It is recommended that snapshots are cached as files in the static cache since they are much quiker to load. Use
SnapshotManager.getSnapshot(DbControl, int)
is instead of this method.- Parameters:
dc
- A DbControl to use for database accessannotationSetId
- The ID of the annotation set- Returns:
- A snapshot, or null if the annotation set with the given id doesn't exist
- Since:
- 2.14
-
deleteEmptyAnnotationSets
Delete all empty annotation sets. This method is intended to be executed at regular intervals by a cleanup application and will remove annotation sets that have no primary or inherited annotations.- Returns:
- The number of deleted annotation sets
- Throws:
BaseException
- If an empty annotation set could not be deleted- Since:
- 3.2
-
deleteEmptyAnnotationSets
Delete all empty annotation sets. This method is intended to be executed at regular intervals by a cleanup application and will remove annotation sets that have no primary or inherited annotations.- Returns:
- The number of deleted annotation sets
- Throws:
BaseException
- If an empty annotation set could not be deleted- Since:
- 3.2
-
getData
AnnotationSetData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this item. -
getType
Description copied from interface:Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in theItem
enumeration.- Specified by:
getType
in interfaceIdentifiable
- Returns:
- A value indicating the type of item
-
isUsed
Always return TRUE. An annotation set always has a one-to-one relation to some item. The annotation set is automatically deleted if that item is deleted.- Overrides:
isUsed
in classBasicItem
- Returns:
- TRUE if this item is used, FALSE otherwise
- Throws:
BaseException
- If not able to tell if item is used or not.- See Also:
-
getUsingItems
Get the item this annotation set belongs to.- Overrides:
getUsingItems
in classBasicItem
- Returns:
- A set containing proxies for the items, or an empty set if no items are using this item
- Throws:
BaseException
- If there is an error loading the items- Since:
- 2.2
- See Also:
-
initPermissions
READ permission is granted to all users. CREATE, WRITE and DELETE permissions are granted if the logged in user has RESTRICTED_WRITE permission on the associated item.- Overrides:
initPermissions
in classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass- Throws:
BaseException
- If the permissions couldn't be initialised
-
getPluginPermissions
PluginPermission getPluginPermissions()- Overrides:
getPluginPermissions
in classBasicItem
-
onBeforeCommit
Remove the cached snapshot if needed.- Overrides:
onBeforeCommit
in classBasicItem
- Throws:
BaseException
- If there is an error- See Also:
-
getItem
Get the item this annotation set belongs to.- Returns:
- The
Annotatable
item - Throws:
PermissionDeniedException
- If the logged in user doesn't have read permission to the itemBaseException
- If there is another error
-
getItem
Get the item this annotation set belongs to using a specific DbControl for database access. If the item has already been loaded it is re-loaded by the given DbControl.- Parameters:
dc
- An open DbControl, or null to use the current DbControl associated with this annotation set- Returns:
- The
Annotatable
item - Throws:
PermissionDeniedException
BaseException
- Since:
- 2.9
-
getItemId
public int getItemId()Get the ID of the item this annotation set belongs to. This may need to hit the database unless the id is already known.- Since:
- 2.14
-
setItem
Set the item this annotation set belongs to. -
getItemType
Get theItem
type of the item this annotation set belongs to. -
getAnnotation
public Annotation getAnnotation(AnnotationType annotationType) throws PermissionDeniedException, InvalidDataException, BaseException Get theAnnotation
object of the specified annotation type. If the annotation set doesn't contain an annotation of the specified type a new object is created and automatically saved to the database whenDbControl.commit()
is called. To check if an annotation of a certain annotation type exists without creating a new annotation use thehasAnnotation(AnnotationType, Annotation.Source)
method.If the annotation type has enabled project-specific annotations (see
AnnotationType.getProjectAnnotations()
), this method will return the annotation for the currently enabled project or the default annotation if no specific annotation exists. If a new annotation is created it is assigned to the currently active project.- Parameters:
annotationType
- The annotation type- Returns:
- An
Annotation
object - Throws:
PermissionDeniedException
- If a new annotation must be created and the logged in user doesn't have write permissionInvalidDataException
- If a new annotation must be created and the annotation type isn't valid for this type of itemBaseException
- If there is another error
-
getProjectAnnotation
Get a value for a project-specific annotation using the specified project instead of the currently active project. Note that this method behaves differently than thegetAnnotation(AnnotationType)
method. If the annotation type is not using project annotations, the project is ignored If project=null the default annotation value is returned (new or existing) If project!=null a project-specific annotation value is returned (new or existing, the default value is never returned) The returned annotation is always locked to the project it has been defined for. CallingAnnotation.setValuesIfDifferent(List, Unit)
will always modify the existing value (it will not create a new project-specific value when trying to change the default value).- Parameters:
annotationType
- The annotation typeproject
- A project or null to get the default value- Since:
- 3.11
-
hasAnnotation
Check if the annotation set contains an annotation of the specified type. If the annotation type has enabled project-specific annotations (seeAnnotationType.getProjectAnnotations()
), this method will only check if a default annotation or a project-specific annotation for the current project exists. Annotations that are specific for other projects are ignored.- Parameters:
annotationType
- AnAnnotationType
objectsource
- The source type of the annotation or null if it doesn't matter- Returns:
- TRUE if the annotation set contains an annotation of the specified type, FALSE otherwise
- Since:
- 3.6
-
hasProjectAnnotation
public boolean hasProjectAnnotation(AnnotationType annotationType, Annotation.Source source, Project project) Check if the annotation set contains an annotation of the specified type. If the annotation type has enabled project-specific annotations (seeAnnotationType.getProjectAnnotations()
), this method will only check if an annotation for the given project exists (or the default value if projectId=0). Annotations that are specific for other projects are ignored.- Parameters:
annotationType
- AnAnnotationType
objectsource
- The source type of the annotation or null if it doesn't matterproject
- A project or null to check for the default value- Returns:
- TRUE if the annotation set contains an annotation of the specified type, FALSE otherwise
- Since:
- 3.11
-
removeAnnotation
public void removeAnnotation(AnnotationType annotationType) throws PermissionDeniedException, InvalidDataException, BaseException Delete the primary annotation of the specified annotation type. If the annotation type has enabled project-specific annotations (seeAnnotationType.getProjectAnnotations()
), this method will only remove an annotation if it is specific to the currently active project (or the default annotation if no project is active)- Parameters:
annotationType
- The type of the annotation to delete- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the annotation type is nullBaseException
- If there is another error
-
removeProjectAnnotation
public void removeProjectAnnotation(AnnotationType annotationType, Project project) throws PermissionDeniedException, InvalidDataException, BaseException Delete the primary annotation of the specified annotation type. Note that this method is intended to be used with project-specific annotation and will only remove the value for the given project (or the default value if projectId=0).- Parameters:
annotationType
- The type of the annotation to deleteproject
- A project or null to remove the default value- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the annotation type is nullBaseException
- If there is another error- Since:
- 3.11
-
getAnnotations
Get a query returning annotations with the specified source. If the annotation type is using project-specific annotations the query will load project-specific values where they exists and otherwise default values.- Parameters:
source
- A source or null to not filter on source
-
getProjectAnnotations
Get a query returning annotations with the specified source and belonging to the specified project (or default values if projectId=0).- Parameters:
source
- A source or null to not filter on sourceproject
- The project or null to query default values- Since:
- 3.11
-
inheritAnnotation
Inherit or clone an annotation. NOTE! If the annotation is already inherited or cloned, and the clone parameter is not matching, the existing annotations is deleted and replaced with a new annotation.- Parameters:
annotation
- The annotation to inherit which must be a primary annotationclone
- TRUE to clone the values, FALSE to only keep the link to the original values- Returns:
- The new annotation instance (or the old if it already was inherited)
- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permission for this annotation set or use permission for the annotation or if the annotation type is not enabled for inheritanceInvalidDataException
- If the annotation is null- Since:
- 3.6
-
removeInheritedAnnotation
public void removeInheritedAnnotation(Annotation annotation) throws PermissionDeniedException, InvalidDataException Remove an inherited an annotation. The specified annotation can be either a CLONED or INHERITED annotation in this set or the PRIMARY annotation of another annotation set that is inherited/cloned by this set.- Parameters:
annotation
- The annotation to remove- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permission for this annotation setInvalidDataException
- If the annotation is null
-
isInherited
Check if an annotation is inherited or not by this annotation set.- Parameters:
annotation
- The annotation to check- Returns:
- TRUE if inherited, FALSE otherwise.
- Throws:
InvalidDataException
- If the annotation is null
-
inheritAll
Utility method for inheriting or cloning all annotations from the given annotation set.- Parameters:
annotationSet
- The annotation set to inherit- Returns:
- The number of added annotations
- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permission for this annotation set or use permission for the annotation set to inheritInvalidDataException
- If the annotation set is null- Since:
- 3.6
-
removeAllInherited
Utility method to stop inheriting all annotations in the given annotation set.- Returns:
- The number of removed annotations
- Since:
- 3.6
-
autoInherit
public int autoInherit(DbControl dc, Collection<AnnotationType> annotationTypes, SnapshotManager manager, boolean preferAnnotationSet) Automatically inherit all annotations of one or more specified annotation types from parent items that are currntly missing from this annotation setThis method will only consider parent items that the logged in user has access to with USE permission.
This method may result in inheriting multiple annotations (from different parent items) of the specified annotation type.
- Parameters:
dc
- The DbControl to use for database accessannotationTypes
- The annotation type to look formanager
- A snapshot manager that is used to look up annotationspreferAnnotationSet
- If TRUE, the entire annotation set containing the found annotation is inherited, otherwise only the found annotation is inherited NOTE! Since BASE 3.6 this parameter is ignored- Since:
- 2.15
-
copyFrom
Copy annotations from another annotatable item to this annotation set. This method will copy all primary annotations with an annotation type that is valid for this item type. The logged in user doesn't need to have access to all annotation types. The copy will still work. The logged in user must have write permission on this annotation set.Project-specific annotations are only copied if they belong to the currently active project.
- Parameters:
item
- The item to copy annotation fromoverwrite
- TRUE to overwrite existing values- Since:
- 2.5
-
setSnapshotInvalid
public void setSnapshotInvalid()Mark the snapshot (if it exists) of this annotation set as invalid. The snapshot will be removed when the transaction is committed. Once the snapshot has been marked as invalid it can't be unmarked.- Since:
- 2.14
-
isSnapshotInvalid
public boolean isSnapshotInvalid()Get the status of the 'invalid snapshot' flag.- Returns:
- TRUE if the snapshot has been marked as invalid, FALSE if not
- Since:
- 2.14
-