Last update: 2011-06-23

org.proteios.core
Class Annotator

java.lang.Object
  extended by org.proteios.core.Annotator

public class Annotator
extends Object

Use this class whenever you want to add or list annotations of an Annotatable item.

Author:
gregory

Constructor Summary
Annotator(ItemFactory factory)
          Make sure the factory has a connected DbControl
 
Method Summary
 void addAddedParamAnnotation(Annotatable item, String value, String atName, Type atType, String addedParamType, String addedParamName, String addedParamValue)
          Stores variable values as addedParam annotation.
 void addAnnotation(Annotatable item, String atName, Type atType, Object value)
          Add an annotation.
 AnnotationType createAddedParamAnnotationType(Annotatable item, String atName, Type atType, String addedParamType, String addedParamName, String addedParamValue)
          Creates added parameter annotation type for storing variable values as annotations.
 AnnotationType createAnnotationType(Annotatable item, String name, Type type)
           
 AnnotationType createAnnotationType(String atName, Type atType, Item atItem)
          Creates annotation type for storing variable values as annotations.
 AnnotationType getAddedParamAnnotationType(String atName, Type atType, Item atItem, String addedParamType, String addedParamName, String addedParamValue)
          Fetches annotation type for storing variable values as annotations.
 Annotation getAnnotation(Annotatable item, AnnotationType annotationType)
          Get the Annotation object of the specified annotation type.
 AnnotationSet getAnnotationSet(Annotatable item)
          Get existing AnnotationSet or create a new one, and save it to the database.
 AnnotationType getAnnotationType(Annotatable item, String name, Type type)
           
 AnnotationType getAnnotationType(String atName, Type atType, Item atItem)
          Fetches annotation type for storing variable values as annotations.
 Item getType(Annotatable item)
           
 boolean isAnnotated(Annotatable item)
           
 void removeAnnotations(Annotatable item)
          Removes the entire AnnotationSet of the item
 void setDc(DbControl dc)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Annotator

public Annotator(ItemFactory factory)
Make sure the factory has a connected DbControl

Parameters:
factory -
Throws:
InvalidUseOfNullException - if the Dbcontrol of the ItemFactory is null or closed
Method Detail

getAnnotation

public Annotation getAnnotation(Annotatable item,
                                AnnotationType annotationType)
                         throws PermissionDeniedException,
                                InvalidDataException,
                                BaseException
Get the 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. Remember to save the returned annotation using the same DbControl as in your ItemFactory.

Parameters:
annotationType - The annotation type
Returns:
An Annotation object, either existing one or a new one
Throws:
PermissionDeniedException - If a new annotation must be created and the logged in user doesn't have write permission
InvalidDataException - If a new annotation must be created and the annotation type isn't valid for this type of item
BaseException - If there is another error

isAnnotated

public boolean isAnnotated(Annotatable item)
                    throws BaseException
Parameters:
item -
Returns:
true if the item already has an AnnotationSet
Throws:
BaseException

removeAnnotations

public void removeAnnotations(Annotatable item)
                       throws PermissionDeniedException,
                              BaseException
Removes the entire AnnotationSet of the item

Parameters:
item -
Throws:
PermissionDeniedException
BaseException

getAnnotationSet

public AnnotationSet getAnnotationSet(Annotatable item)
                               throws PermissionDeniedException,
                                      BaseException
Get existing AnnotationSet or create a new one, and save it to the database.

Parameters:
item -
Returns:
The current AnnotationSet or a newly created and saved one.
Throws:
PermissionDeniedException
BaseException

getType

public Item getType(Annotatable item)
Parameters:
item -
Returns:
the Item matching the annotatable item or null if item doesn't implement Identifiable

addAnnotation

public void addAnnotation(Annotatable item,
                          String atName,
                          Type atType,
                          Object value)
                   throws PermissionDeniedException,
                          InvalidDataException,
                          BaseException
Add an annotation. Checks are first performed so that duplicate annotationTypes will not be generated. If the item is not annotated before this method creates and saves an AnnotationSet first.

Parameters:
atName - String the name of the annotationType
atType - Type the type of the annotationType
value - Object the annotation value as a String
Throws:
PermissionDeniedException
InvalidDataException
BaseException

createAnnotationType

public AnnotationType createAnnotationType(Annotatable item,
                                           String name,
                                           Type type)
Parameters:
item -
name -
type -
Returns:
new AnnotationType that's saved to the database but not commited

createAnnotationType

public AnnotationType createAnnotationType(String atName,
                                           Type atType,
                                           Item atItem)
Creates annotation type for storing variable values as annotations.

Parameters:
atName - String the name of annotationType
atType - Type the type of the annotationType
atItem - Item the Item the annotationType should be enabled for
Returns:
at AnnotationType the created annotationType

createAddedParamAnnotationType

public AnnotationType createAddedParamAnnotationType(Annotatable item,
                                                     String atName,
                                                     Type atType,
                                                     String addedParamType,
                                                     String addedParamName,
                                                     String addedParamValue)
Creates added parameter annotation type for storing variable values as annotations. An added parameter annotation is an annotation, tagged by having annotationtype AddedParameterType set to addedParamType, and where data for addedParamName and addedParamValue are stored as String attributes in the annotationType for the annotation.

Parameters:
atName - String the name of the AnnotationType
atType - Type the type of the AnnotationType
addedParamType - String the annotation added parameter type as a String
addedParamName - String the annotation added parameter name as a String
addedParamValue - String the annotation added parameter value as a String
Returns:
at AnnotationType the created AnnotationType

addAddedParamAnnotation

public void addAddedParamAnnotation(Annotatable item,
                                    String value,
                                    String atName,
                                    Type atType,
                                    String addedParamType,
                                    String addedParamName,
                                    String addedParamValue)
Stores variable values as addedParam annotation. A cvParam annotation is an annotation, tagged by having annotationtype AddedParameterType set to "cvParam", and where data for cvLabel and accession are stored as String attributes in the annotationType for the annotation. A cvLookup annotation is an annotation, tagged by having annotationtype AddedParameterType set to "cvLookup", AddedParameterName set to the name of the source vocabulary, for example "psi", and the "addedParameterValue" is set to the accessionNumber. data for version and fullName are stored as String attributes in the annotationType for the annotation. A userParam annotation has the annotationType set to "userParam" and the name is annotationtype AddedParameterType set to "userParam" Data for cvLabel and address are used as name and value for the annotation, as this information is viewable by the user.

Parameters:
value - String the value to store in the annotation
atName - String the name of the AnnotationType.
atType - Type the type of the AnnotationType
addedParamType - String the annotation added parameter value as a String
addedParamName - String the annotation added parameter name as a String
addedParamValue - String the annotation value as a String

getAddedParamAnnotationType

public AnnotationType getAddedParamAnnotationType(String atName,
                                                  Type atType,
                                                  Item atItem,
                                                  String addedParamType,
                                                  String addedParamName,
                                                  String addedParamValue)
Fetches annotation type for storing variable values as annotations. This method tries to find an existing AnnotationType with the desired specifications in the database. If one is found, it is returned, otherwise the cache is consolidated which contains newly created but uncommited AnnotationTypes. If the cache doesn't contain any AnnotationType matching the name, type and item a new one is created and put into the cache.

Parameters:
atName - String the name of annotationType
atType - Type the type of the annotationType
atItem - Item the Item the annotationType should be enabled for
Returns:
at AnnotationType the fetched annotationType, or null if none is found.

getAnnotationType

public AnnotationType getAnnotationType(Annotatable item,
                                        String name,
                                        Type type)

getAnnotationType

public AnnotationType getAnnotationType(String atName,
                                        Type atType,
                                        Item atItem)
Fetches annotation type for storing variable values as annotations. This method tries to find an existing AnnotationType with the desired specifications in the database. If one is found, it is returned, otherwise the cache is consolidated which contains newly created but uncommited AnnotationTypes. If the cache doesn't contain any AnnotationType matching the name, type and item a new one is created and put into the cache.

Parameters:
atName - String the name of annotationType
atType - Type the type of the annotationType
atItem - Item the Item the annotationType should be enabled for
Returns:
at AnnotationType the fetched annotationType, or null if none is found.

setDc

public void setDc(DbControl dc)

Last update: 2011-06-23