Last update: 2011-06-23

org.proteios.core
Class ItemFactory

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

public class ItemFactory
extends Object

Used to create persistent item instances

Author:
gregory

Constructor Summary
ItemFactory()
          Remember to set the DbControl before using the factory
ItemFactory(DbControl dc)
           
 
Method Summary
<D extends BasicItem<?>>
D
create(Class<D> template, Object... extraParameters)
          Creates an instance of the given template class.
 AnnotationType createAnnotationType(Type valueType)
          Create a new AnnotationType item.
 CreationEvent createCreationEvent(MeasuredBioMaterial<?> bioMaterial, MeasuredBioMaterial<?> sourceMaterial, Float usedQuantity)
          Create a new BioMaterialEvent of the Type#OTHER type.
 GelImageAnalysisEvent createGelImageAnalysisEvent(MeasuredBioMaterial<?> bioMaterial)
          Create a new GelImageAnalysisEvent of the Type#OTHER type.
 GelScanEvent createGelScanEvent(MeasuredBioMaterial<?> bioMaterial)
          Create a new GelScanEvent of the Type#OTHER type.
 GlobalDefaultSetting createGlobalDefaultSetting(String name, String value)
          Create a new GlobalDefaultSetting item.
 Directory createHomeDirectory(User user)
          Creates and saves a home directory for the supplied user
 Job createJob(PluginDefinition plugin, PluginConfiguration config)
          TODO this method does two things, create and configures a job to a starting state.
 LabeledExtract createLabeledExtract(Label label)
          Create a new LabeledExtract with label.
 Message createMessage(User to, String fromName, User fromUser, Job job)
          Create a new Message item.
 SeparationEvent createSeparationEvent(MeasuredBioMaterial<?> bioMaterial, Float usedQuantity)
          Create a new SeparationEvent of the Type#OTHER type.
 SeparationMethod<?> createSeparationMethod(String externalId)
          Create a new SeparationMethod item.
 StainingEvent createStainingEvent(MeasuredBioMaterial<?> bioMaterial)
          Create a new StainingEvent of the Type#OTHER type.
 UpdateEvent createUpdateEvent(MeasuredBioMaterial<?> bioMaterial)
          Create a new UpdateEvent of the Type#OTHER type.
 User createUser(String login, String password)
          Create a new User item.
<T extends BasicItem<?>>
T
getById(Class<T> name, Integer id)
           
 Directory getByPath(Path path)
          Get a Directory item when you know the path.
 File getByPath(Path path, boolean create)
          Get a File item when you know the path.
<T extends BasicItem<?>>
T
getBySystemId(Class<T> name, String id)
           
 DbControl getDc()
           
 void setDc(DbControl dc)
          We allow outside change of DbControl in use to enable factory reuse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ItemFactory

public ItemFactory()
Remember to set the DbControl before using the factory


ItemFactory

public ItemFactory(DbControl dc)
Parameters:
dc - initial DbControl to use
Method Detail

getDc

public DbControl getDc()
Returns:
currently use DbControled or null if none is set

setDc

public void setDc(DbControl dc)
We allow outside change of DbControl in use to enable factory reuse

Parameters:
dc -

create

public <D extends BasicItem<?>> D create(Class<D> template,
                                         Object... extraParameters)
Creates an instance of the given template class. Default values are set wherever possible. The returned objects are not saved and you should make sure to call dc.saveItem(item) for each item created by this method.

Type Parameters:
D -
Parameters:
template - item class to create
extraParameters - optional Object[] array of extra arguments
Returns:
object of type D or null if item couldn't be created

createJob

public Job createJob(PluginDefinition plugin,
                     PluginConfiguration config)
              throws BaseException
TODO this method does two things, create and configures a job to a starting state. Split this up and move the configure part into the Job class itself. Create a new Job item.

Parameters:
config - The plugin configuration this job should use or null if the job is executed by an external program
Returns:
The new Job item
Throws:
BaseException - If there is an error

createUser

public User createUser(String login,
                       String password)
                throws BaseException
Create a new User item.

Parameters:
login - The login for the user (required)
password - The password for the user (required)
Returns:
The new User item
Throws:
BaseException - If there is an error

createCreationEvent

public CreationEvent createCreationEvent(MeasuredBioMaterial<?> bioMaterial,
                                         MeasuredBioMaterial<?> sourceMaterial,
                                         Float usedQuantity)
                                  throws BaseException
Create a new BioMaterialEvent of the Type#OTHER type. If only a single BioMaterial was used it can be given as parameter optionally with the used amount of the biomaterial

Parameters:
bioMaterial - The affected biomaterial
Returns:
The new BioMaterialEvent item
Throws:
BaseException - If there is an error

createHomeDirectory

public Directory createHomeDirectory(User user)
                              throws PermissionDeniedException,
                                     BaseException
Creates and saves a home directory for the supplied user

Parameters:
user -
Returns:
created directory
Throws:
PermissionDeniedException
BaseException

createLabeledExtract

public LabeledExtract createLabeledExtract(Label label)
                                    throws BaseException
Create a new LabeledExtract with label.

Parameters:
label - The labeling compound used for labeling the extract
Returns:
The new LabeledExtract item
Throws:
BaseException - If there is an error

createAnnotationType

public AnnotationType createAnnotationType(Type valueType)
                                    throws BaseException
Create a new AnnotationType item.

Parameters:
valueType - The type of values to use
Returns:
The new AnnotationType item
Throws:
BaseException - If there is an error

createGelImageAnalysisEvent

public GelImageAnalysisEvent createGelImageAnalysisEvent(MeasuredBioMaterial<?> bioMaterial)
                                                  throws BaseException
Create a new GelImageAnalysisEvent of the Type#OTHER type.

Parameters:
bioMaterial - The affected biomaterial
Returns:
The new GelImageAnalysisEvent item
Throws:
BaseException - If there is an error

createGelScanEvent

public GelScanEvent createGelScanEvent(MeasuredBioMaterial<?> bioMaterial)
                                throws BaseException
Create a new GelScanEvent of the Type#OTHER type.

Parameters:
bioMaterial - The affected biomaterial
Returns:
The new GelScanEvent item
Throws:
BaseException - If there is an error

createSeparationEvent

public SeparationEvent createSeparationEvent(MeasuredBioMaterial<?> bioMaterial,
                                             Float usedQuantity)
                                      throws BaseException
Create a new SeparationEvent of the Type#OTHER type.

Parameters:
bioMaterial - The affected biomaterial
Returns:
The new SeparationEvent item
Throws:
BaseException - If there is an error

createStainingEvent

public StainingEvent createStainingEvent(MeasuredBioMaterial<?> bioMaterial)
                                  throws BaseException
Create a new StainingEvent of the Type#OTHER type.

Parameters:
bioMaterial - The affected biomaterial
Returns:
The new StainingEvent item
Throws:
BaseException - If there is an error

createUpdateEvent

public UpdateEvent createUpdateEvent(MeasuredBioMaterial<?> bioMaterial)
                              throws BaseException
Create a new UpdateEvent of the Type#OTHER type.

Parameters:
bioMaterial - The affected biomaterial
Returns:
The new UpdateEvent item
Throws:
BaseException - If there is an error

createSeparationMethod

public SeparationMethod<?> createSeparationMethod(String externalId)
                                           throws BaseException
Create a new SeparationMethod item.

Parameters:
externalId - The external id of the new item
Returns:
The new SeparationMethod item
Throws:
BaseException - If there is an error

createGlobalDefaultSetting

public GlobalDefaultSetting createGlobalDefaultSetting(String name,
                                                       String value)
                                                throws BaseException
Create a new GlobalDefaultSetting item.

Parameters:
name - The name of the setting
value - The value of the setting
Returns:
The new ClientDefaultSetting item
Throws:
BaseException - If there is an error

createMessage

public Message createMessage(User to,
                             String fromName,
                             User fromUser,
                             Job job)
                      throws BaseException
Create a new Message item.

Parameters:
to - the user the message shuold be sent to
fromName - the name of the sender of the message
fromUser - the user sending the message
job - the job this message is about
Returns:
return The new Message item
Throws:
BaseException - If there is an error

getById

public <T extends BasicItem<?>> T getById(Class<T> name,
                                          Integer id)

getByPath

public File getByPath(Path path,
                      boolean create)
               throws ItemNotFoundException,
                      PermissionDeniedException,
                      BaseException
Get a File item when you know the path. Use the create parameter to specify if a new file should be create if it doesn't exists. The directory part of the path must still be an existing path, otherwise an ItemNotFoundException is thrown.

Parameters:
path - The path to the file to load
create - TRUE if a new file should be created if one doesn't eixts, FALSE to throw an exception (DbControl.saveItem must always be called)
Returns:
The File item
Throws:
ItemNotFoundException - If an item with the specified path is not found and create is FALSE
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getBySystemId

public <T extends BasicItem<?>> T getBySystemId(Class<T> name,
                                                String id)

getByPath

public Directory getByPath(Path path)
                    throws ItemNotFoundException,
                           PermissionDeniedException,
                           BaseException
Get a Directory item when you know the path.

Parameters:
path - The path to the directory to load
Returns:
The Directory item
Throws:
ItemNotFoundException - If an item with the specified path is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

Last update: 2011-06-23