org.tigris.scarab.om
Class Attachment

java.lang.Object
  extended byorg.apache.torque.om.BaseObject
      extended byorg.tigris.scarab.om.BaseAttachment
          extended byorg.tigris.scarab.om.Attachment
All Implemented Interfaces:
org.apache.torque.om.Persistent, org.apache.fulcrum.intake.Retrievable, java.io.Serializable

public class Attachment
extends BaseAttachment
implements org.apache.torque.om.Persistent

Attachments contain data associated with an issue. It used to be that an issue could have multiple attachments of a given type but only one value for a given Attribute. Attributes are now multi-valued, so the difference is blurred in some cases. A comment given as a reason for a modification to attribute values is considered an Attachment. Notes and urls are also considered attachments, though these two could probably be implemented as attributes (with some ui redesign). The obvious form of attachment is a file uploaded and associated with an issue, such as a screenshot showing an error or a patch.

Version:
$Id: Attachment.java 9977 2005-12-09 00:40:59Z hair $
Author:
John McNally, Jon S. Stevens
See Also:
Serialized Form

Field Summary
static java.lang.Integer COMMENT__PK
          ObjectKey for a note/comment type attachment
static java.lang.Integer FILE__PK
          ObjectKey for a file type attachment
static java.lang.Integer MODIFICATION__PK
          ObjectKey for a reason for modification type attachment
static java.lang.Integer URL__PK
          ObjectKey for a url type attachment
 
Fields inherited from class org.tigris.scarab.om.BaseAttachment
collActivitys, collActivitySets
 
Fields inherited from class org.apache.torque.om.BaseObject
NEW_ID
 
Constructor Summary
Attachment()
           
 
Method Summary
 Attachment copy()
          Makes a copy of this object.
 void copyFileFromTo(java.lang.String from, java.lang.String path)
           
 void copyFileTo(java.lang.String path)
           
 boolean deletePhysicalAttachment()
          Delete the attachment file on disk
 java.lang.String doMakeURLFromData()
          This is a little method that uses getData() to make a http url if it isn't already prefixed with "htt://"
 Activity getActivity()
          Retrieves the Activity in which this attachment was created.
 org.apache.commons.fileupload.FileItem getFile()
          There is no reason to reconstruct the FileItem, always returns null.
 java.lang.String getFullPath()
           
 java.lang.String getRelativePath()
          The path to an attachment file relative to the base file repository.
static java.lang.String getRepositoryDirectory()
          Get the repository path info as given in the configuration.
 long getSize()
          Get the attachment file size.
 void save(java.sql.Connection dbCon)
          Calls super.save(Connection) and also checks for a FileItem.
protected static void setConfiguration(org.apache.commons.configuration.Configuration configuration)
           
 void setFile(org.apache.commons.fileupload.FileItem v)
          Set the value of file.
 void setFileName(java.lang.String name)
          Makes sure to only save the simple filename which is the part following the last path separator.
 void setTextFields(ScarabUser user, Issue issue, java.lang.Integer typeId)
          Populates fields for a text (non-file) type of attachment.
 
Methods inherited from class org.tigris.scarab.om.BaseAttachment
addActivity, addActivitySet, copyInto, getActivitys, getActivitys, getActivitys, getActivitys, getActivitySets, getActivitySets, getActivitySets, getActivitySets, getActivitySetsJoinActivitySetType, getActivitySetsJoinAttachment, getActivitySetsJoinScarabUserImpl, getActivitysJoinActivitySet, getActivitysJoinAttachment, getActivitysJoinAttribute, getActivitysJoinAttributeOptionRelatedByNewOptionId, getActivitysJoinAttributeOptionRelatedByOldOptionId, getActivitysJoinDepend, getActivitysJoinIssue, getActivitysJoinScarabUserImplRelatedByNewUserId, getActivitysJoinScarabUserImplRelatedByOldUserId, getAttachmentId, getAttachmentType, getAttachmentType, getByName, getByPeerName, getByPosition, getCreatedBy, getCreatedDate, getData, getDeleted, getFieldNames, getFileName, getIssue, getIssue, getIssueId, getMimeType, getModifiedBy, getModifiedDate, getName, getPeer, getPrimaryKey, getQueryKey, getScarabUserRelatedByCreatedBy, getScarabUserRelatedByCreatedBy, getScarabUserRelatedByModifiedBy, getScarabUserRelatedByModifiedBy, getTypeId, initActivitys, initActivitySets, isCacheOnSave, save, save, setAttachmentId, setAttachmentType, setAttachmentTypeKey, setCreatedBy, setCreatedDate, setData, setDeleted, setIssue, setIssueId, setIssueKey, setMimeType, setModifiedBy, setModifiedDate, setName, setPrimaryKey, setPrimaryKey, setQueryKey, setScarabUserRelatedByCreatedBy, setScarabUserRelatedByCreatedByKey, setScarabUserRelatedByModifiedBy, setScarabUserRelatedByModifiedByKey, setTypeId, toString
 
Methods inherited from class org.apache.torque.om.BaseObject
equals, equals, getLog, hashCode, isModified, isNew, resetModified, setModified, setNew, setPrimaryKey
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.torque.om.Persistent
getPrimaryKey, isModified, isNew, save, save, setModified, setNew, setPrimaryKey, setPrimaryKey
 

Field Detail

FILE__PK

public static final java.lang.Integer FILE__PK
ObjectKey for a file type attachment


COMMENT__PK

public static final java.lang.Integer COMMENT__PK
ObjectKey for a note/comment type attachment


URL__PK

public static final java.lang.Integer URL__PK
ObjectKey for a url type attachment


MODIFICATION__PK

public static final java.lang.Integer MODIFICATION__PK
ObjectKey for a reason for modification type attachment

Constructor Detail

Attachment

public Attachment()
Method Detail

setFileName

public void setFileName(java.lang.String name)
Makes sure to only save the simple filename which is the part following the last path separator. This is appended as the last part of the the path returned by getRelativePath() following the It would generally be set to original filename as given on the client that uploaded the file. Spaces are replaced by underscores.

Overrides:
setFileName in class BaseAttachment
Parameters:
name - new value

getFile

public org.apache.commons.fileupload.FileItem getFile()
There is no reason to reconstruct the FileItem, always returns null. This is not used, but required by the bean introspector used by intake.

Returns:
value of file.

setFile

public void setFile(org.apache.commons.fileupload.FileItem v)
Set the value of file.

Parameters:
v - Value to assign to file.

setTextFields

public void setTextFields(ScarabUser user,
                          Issue issue,
                          java.lang.Integer typeId)
                   throws org.apache.torque.TorqueException
Populates fields for a text (non-file) type of attachment.

Throws:
org.apache.torque.TorqueException

doMakeURLFromData

public java.lang.String doMakeURLFromData()
This is a little method that uses getData() to make a http url if it isn't already prefixed with "htt://"


save

public void save(java.sql.Connection dbCon)
          throws org.apache.torque.TorqueException
Calls super.save(Connection) and also checks for a FileItem. if one exists the file is moved to its final location.

Specified by:
save in interface org.apache.torque.om.Persistent
Overrides:
save in class BaseAttachment
Parameters:
dbCon - a DBConnection value
Throws:
org.apache.torque.TorqueException - if an error occurs

deletePhysicalAttachment

public boolean deletePhysicalAttachment()
                                 throws org.apache.torque.TorqueException,
                                        ScarabException
Delete the attachment file on disk

Returns:
true if the file was deleted, false otherwise
Throws:
org.apache.torque.TorqueException
ScarabException

getRelativePath

public java.lang.String getRelativePath()
                                 throws org.apache.torque.TorqueException,
                                        ScarabException
The path to an attachment file relative to the base file repository. Files are saved according to: moduleId/(issue_IdCount/1000)/issueID_attID_filename where moduleId and attId are primary keys of the related module and this attachment. issueID is the unique id generally used to specify the issue within the ui. issue_IdCount is the numerical suffix of the unique id. So if the pk of module PACS is 201 and this attachment pk is 123 the path would be: 201/0/PACS5_123_diff.txt or if the issue count were higher: 201/2/PACS2115_123_diff.txt. The first two directories are used to keep the number of files per directory reasonable while the issue unique id and the final textual filename allow someone browsing the file system to be better able to pick out relevant files.

Throws:
org.apache.torque.TorqueException
ScarabException

getFullPath

public java.lang.String getFullPath()
                             throws org.apache.torque.TorqueException,
                                    ScarabException
Returns:
Prepends the base repository path to the path returned by getRelativePath(), returns null getRelativePath() does.
Throws:
org.apache.torque.TorqueException
ScarabException

getRepositoryDirectory

public static java.lang.String getRepositoryDirectory()
Get the repository path info as given in the configuration. if the path begins with a '/', it is assumed to be absolute. Otherwise the path is constructed relative to the webapp directory.


setConfiguration

protected static void setConfiguration(org.apache.commons.configuration.Configuration configuration)

copyFileTo

public void copyFileTo(java.lang.String path)
                throws org.apache.torque.TorqueException,
                       ScarabException,
                       java.io.FileNotFoundException,
                       java.io.IOException
Throws:
org.apache.torque.TorqueException
ScarabException
java.io.FileNotFoundException
java.io.IOException

getSize

public long getSize()
             throws org.apache.torque.TorqueException,
                    ScarabException
Get the attachment file size. It reads this information from the FileSystem (this information is not saved into the database)

Returns:
the number of bytes or -1 if there's some kind of problem
Throws:
org.apache.torque.TorqueException
ScarabException

copyFileFromTo

public void copyFileFromTo(java.lang.String from,
                           java.lang.String path)
                    throws org.apache.torque.TorqueException,
                           java.io.FileNotFoundException,
                           java.io.IOException
Throws:
org.apache.torque.TorqueException
java.io.FileNotFoundException
java.io.IOException

copy

public Attachment copy()
                throws org.apache.torque.TorqueException
Makes a copy of this object. It creates a new object filling in the simple attributes.

Overrides:
copy in class BaseAttachment
Throws:
org.apache.torque.TorqueException

getActivity

public Activity getActivity()
                     throws org.apache.torque.TorqueException
Retrieves the Activity in which this attachment was created.

Throws:
org.apache.torque.TorqueException


Copyright © 2000-2004 Tigris.org. All Rights Reserved.