public class AnnotationSet extends BasicItem implements 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.
AnnotationType
,
Annotation
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AnnotationSet.ProjectSpecificAnnotationsRestriction
Restriction for matching project-specific annotations against
the currently active project.
|
private static class |
AnnotationSet.QueryRuntimeFilterImpl |
Transactional.Action
Modifier and Type | Field and Description |
---|---|
private Annotatable |
item
The item this annotation set belongs to.
|
private static QueryRuntimeFilter |
RUNTIME_FILTER
This filter gives everybody read permission to annotations.
|
private boolean |
snapshotIsInvalid
Flag to indicate if this annotation set has been modified
and the snapshot must be removed.
|
static Item |
TYPE
The type of item represented by this class.
|
Constructor and Description |
---|
AnnotationSet(AnnotationSetData annotationSetData)
Regular constructor if the item is not known beforehand.
|
AnnotationSet(AnnotationSetData annotationSetData,
Annotatable item)
Special constructor to avoid
getItem() to hit the database
when the item is known beforehand. |
Modifier and Type | Method and Description |
---|---|
int |
autoInherit(DbControl dc,
java.util.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
set
This method will only consider parent items that the logged in user
has access to with USE permission.
|
void |
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.
|
Annotation |
getAnnotation(AnnotationType annotationType)
Get the
Annotation object of the specified annotation type. |
ItemQuery<Annotation> |
getAnnotations()
Deprecated.
In 3.6, use
getAnnotations(net.sf.basedb.core.Annotation.Source) instead |
ItemQuery<Annotation> |
getAnnotations(Annotation.Source source)
Get a query returning annotations with the specified source.
|
static AnnotationSet |
getById(DbControl dc,
int id)
Get an
AnnotationSet item when you know the id. |
(package private) AnnotationSetData |
getData()
Get the
BasicData object that holds all data for this item. |
ItemQuery<AnnotationSet> |
getInheritedAnnotationSets()
Deprecated.
In 3.6, no replacement
|
ItemQuery<AnnotationSet> |
getInheritingAnnotationSets()
Deprecated.
In 3.6, no replacement
|
Annotatable |
getItem()
Get the item this annotation set belongs to.
|
Annotatable |
getItem(DbControl dc)
Get the item this annotation set belongs to using a specific
DbControl for database access.
|
int |
getItemId()
Get the ID of the item this annotation set belongs to.
|
Item |
getItemType()
Get the
Item 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 |
getPluginPermissions() |
Annotation |
getProjectAnnotation(AnnotationType annotationType,
Project project)
Get a value for a project-specific annotation using the specified project instead
of the currently active project.
|
ItemQuery<Annotation> |
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 a
ItemQuery object configured to retrieve AnnotationSet
items. |
Item |
getType()
Get the type of item represented by the object.
|
java.util.Set<ItemProxy> |
getUsingItems()
Get the item this annotation set belongs to.
|
boolean |
hasAnnotation(AnnotationType annotationType)
Deprecated.
In 3.6, use
hasAnnotation(AnnotationType, net.sf.basedb.core.Annotation.Source) instead |
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.
|
void |
inheritAnnotation(Annotation annotation)
Deprecated.
In 3.6, use
inheritAnnotation(Annotation, boolean) instead |
Annotation |
inheritAnnotation(Annotation annotation,
boolean clone)
Inherit or clone an annotation.
|
void |
inheritAnnotationSet(AnnotationSet annotationSet)
Deprecated.
In 3.6, use
inheritAll(AnnotationSet, boolean) instead |
(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 |
isInherited(AnnotationSet annotationSet)
Deprecated.
In 3.6, no replacement
|
boolean |
isSnapshotInvalid()
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 |
removeInheritedAnnotationSet(AnnotationSet annotationSet)
Deprecated.
In 3.6, use
removeAllInherited(AnnotationSet) instead |
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 |
setSnapshotInvalid()
Mark the snapshot (if it exists) of this annotation set as
invalid.
|
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, validate
public static final Item TYPE
Item.ANNOTATIONSET
,
getType()
private static final QueryRuntimeFilter RUNTIME_FILTER
private Annotatable item
private boolean snapshotIsInvalid
AnnotationSet(AnnotationSetData annotationSetData)
AnnotationSet(AnnotationSetData annotationSetData, Annotatable item)
getItem()
to hit the database
when the item is known beforehand.AnnotatedItem.getAnnotationSet()
static AnnotationSet getNew(DbControl dc, Annotatable item) throws BaseException
BaseException
AnnotatedItem.getAnnotationSet()
public static AnnotationSet getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
AnnotationSet
item when you know the id.dc
- The DbControl
which will be used for
permission checking and database access.id
- The id of the item to loadAnnotationSet
itemItemNotFoundException
- 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 errorstatic ItemQuery<AnnotationSet> getQuery()
ItemQuery
object configured to retrieve AnnotationSet
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.ItemQuery
objectstatic int loadItemId(Session session, Item itemType, int annotationSetId)
public static AnnotationSetSnapshot createSnapshot(DbControl dc, int annotationSetId)
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.
dc
- A DbControl to use for database accessannotationSetId
- The ID of the annotation setpublic static int deleteEmptyAnnotationSets(ProgressReporter progress) throws BaseException
BaseException
- If an empty annotation set could not be deletedstatic int deleteEmptyAnnotationSets(Session session, ProgressReporter progress)
BaseException
- If an empty annotation set could not be deletedAnnotationSetData getData()
BasicItem
BasicData
object that holds all data for this item.public Item getType()
Identifiable
Item
enumeration.getType
in interface Identifiable
public boolean isUsed() throws BaseException
isUsed
in class BasicItem
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
public java.util.Set<ItemProxy> getUsingItems() throws BaseException
getUsingItems
in class BasicItem
BaseException
- If there is an error loading the itemsBasicItem.addUsingItems(Set, Item, org.hibernate.query.Query)
void initPermissions(int granted, int denied) throws BaseException
initPermissions
in class BasicItem
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem
void onBeforeCommit(Transactional.Action action) throws BaseException
onBeforeCommit
in class BasicItem
BaseException
- If there is an errorTransactional
,
Developer documentation: Transactions,
Developer documentation: Coding rules and guidelines for item classespublic Annotatable getItem() throws PermissionDeniedException, BaseException
Annotatable
itemPermissionDeniedException
- If the logged in user doesn't have
read permission to the itemBaseException
- If there is another errorpublic Annotatable getItem(DbControl dc) throws PermissionDeniedException, BaseException
dc
- An open DbControl, or null to use the current DbControl associated
with this annotation setAnnotatable
itemPermissionDeniedException
BaseException
public int getItemId()
void setItem(Annotatable item)
public Annotation getAnnotation(AnnotationType annotationType) throws PermissionDeniedException, InvalidDataException, BaseException
Annotation
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 when
DbControl.commit()
is called. To check if an annotation of a certain
annotation type exists without creating a new annotation use the
hasAnnotation(AnnotationType)
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.
annotationType
- The annotation typeAnnotation
objectPermissionDeniedException
- 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 errorpublic Annotation getProjectAnnotation(AnnotationType annotationType, Project project)
getAnnotation(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.
Calling Annotation.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).annotationType
- The annotation typeproject
- A project or null to get the default value@Deprecated public boolean hasAnnotation(AnnotationType annotationType)
hasAnnotation(AnnotationType, net.sf.basedb.core.Annotation.Source)
insteadannotationType
- An AnnotationType
objectpublic boolean hasAnnotation(AnnotationType annotationType, Annotation.Source source)
AnnotationType.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.annotationType
- An AnnotationType
objectsource
- The source type of the annotation or null if it doesn't matterpublic boolean hasProjectAnnotation(AnnotationType annotationType, Annotation.Source source, Project project)
AnnotationType.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.annotationType
- An AnnotationType
objectsource
- The source type of the annotation or null if it doesn't matterproject
- A project or null to check for the default valuepublic void removeAnnotation(AnnotationType annotationType) throws PermissionDeniedException, InvalidDataException, BaseException
AnnotationType.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)annotationType
- The type of the annotation to deletePermissionDeniedException
- If the logged in user
doesn't have write permissionInvalidDataException
- If the annotation type is nullBaseException
- If there is another errorpublic void removeProjectAnnotation(AnnotationType annotationType, Project project) throws PermissionDeniedException, InvalidDataException, BaseException
annotationType
- The type of the annotation to deleteproject
- A project or null to remove the default valuePermissionDeniedException
- If the logged in user
doesn't have write permissionInvalidDataException
- If the annotation type is nullBaseException
- If there is another errorpublic ItemQuery<Annotation> getAnnotations(Annotation.Source source)
source
- A source or null to not filter on sourcepublic ItemQuery<Annotation> getProjectAnnotations(Annotation.Source source, Project project)
source
- A source or null to not filter on sourceproject
- The project or null to query default values@Deprecated public ItemQuery<Annotation> getAnnotations()
getAnnotations(net.sf.basedb.core.Annotation.Source)
insteadItemQuery
object@Deprecated public void inheritAnnotation(Annotation annotation) throws PermissionDeniedException, InvalidDataException
inheritAnnotation(Annotation, boolean)
insteadannotation
- The annotation to inherit which must be a primary
annotationPermissionDeniedException
- 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 nullpublic Annotation inheritAnnotation(Annotation annotation, boolean clone)
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 valuesPermissionDeniedException
- 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 nullpublic void removeInheritedAnnotation(Annotation annotation) throws PermissionDeniedException, InvalidDataException
annotation
- The annotation to removePermissionDeniedException
- If the logged in user
doesn't have write permission for this annotation setInvalidDataException
- If the annotation is nullpublic boolean isInherited(Annotation annotation) throws InvalidDataException
annotation
- The annotation to checkInvalidDataException
- If the annotation is nullpublic int inheritAll(AnnotationSet annotationSet, boolean clone)
annotationSet
- The annotation set to inheritPermissionDeniedException
- 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 nullpublic int removeAllInherited(AnnotationSet annotationSet)
@Deprecated public void inheritAnnotationSet(AnnotationSet annotationSet) throws PermissionDeniedException, InvalidDataException
inheritAll(AnnotationSet, boolean)
insteadinheritAll(AnnotationSet, boolean)
annotationSet
- The annotation set to inheritPermissionDeniedException
- 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@Deprecated public void removeInheritedAnnotationSet(AnnotationSet annotationSet) throws PermissionDeniedException, InvalidDataException
removeAllInherited(AnnotationSet)
insteadremoveAllInherited(AnnotationSet)
.annotationSet
- The annotation set to removePermissionDeniedException
- If the logged in user
doesn't have write permission for this annotation setInvalidDataException
- If the annotation set is null@Deprecated public boolean isInherited(AnnotationSet annotationSet) throws InvalidDataException
annotationSet
- The annotation set to checkInvalidDataException
- If the annotation set is null@Deprecated public ItemQuery<AnnotationSet> getInheritedAnnotationSets()
ItemQuery
objectBaseException
- If there is an errorpublic int autoInherit(DbControl dc, java.util.Collection<AnnotationType> annotationTypes, SnapshotManager manager, boolean preferAnnotationSet)
This 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.
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 ignoredpublic void copyFrom(Annotatable item, boolean overwrite)
Project-specific annotations are only copied if they belong to the currently active project.
item
- The item to copy annotation fromoverwrite
- TRUE to overwrite existing values@Deprecated public ItemQuery<AnnotationSet> getInheritingAnnotationSets()
ItemQuery
objectpublic void setSnapshotInvalid()
public boolean isSnapshotInvalid()