 | Level: Introductory Rational staff, Staff, IBM
18 May 2004 This is an example of a policy enforcement hook for ClearQuest.
This item was originally published in May, 2002.
NOTE: This hook is presented only as an example of how to customize your use of IBM® Rational® ClearQuest®. It has not been formally tested, and is not supported by IBM.
Description
IBM® Rational® ClearQuest® Web supports uploading and viewing attachments just like native clients do, but is built in such a way that all other concurrent ClearQuest Web users on the same Web server will be frozen until the file upload/download is complete. One solution is to limit the size of the attachments before they are ever stored in the database. To accomplish this, we will depend on knowing a few facts about the inner workings of ClearQuest.
- Attachments can be added whether the record is in an editable state or not, and through the API, but in all cases adding an attachment performs an action on the record.
- The file upload is not done until that action is committed.
- Between the time that the file was attached and the action is committed, that attachment's size when accessed via the CQ API returns 0 (this is how we can tell which attachments have just been added).
By creating a Base Action, we can create a single Validation hook that executes during the context of all other actions. We will inspect the file size of the attachment(s), and prohibit the action from being committed if any is over a certain limit.
First we iterate through all attachments, checking their size with the attachment.FileSize method. If it returns 0, we know that the file has been added during the current action, and is still on the local drive, so we check the FileSystemObject's filesize. If this size is larger than the limit, we return an error string from the validation hook, that aborts the commit. Returning an empty string allows the commit to proceed.
Script Language
VB Script
Code
Base Action Validation hook:
Function Defect_Validation(actionname, actiontype)
' actionname As String
' actiontype As Long
' Defect_Validation As String
' action is AttachAuthorization
' record type name is ChangeRequest
REM Return a non-empty string explaining why the action
REM cannot commit with the current values.
REM Or, if it is valid, return an empty string value.
REM Example:
REM Dim value_info
REM Set value_info = GetFieldValue("some field")
REM If Len(value_info.GetValue()) 10 Then
REM Defect_Validation = "Must be at least 10 chars long"
REM End If
Dim fso, f, s
Defect_Validation = ""
set session = GetSession()
set attachFields = AttachmentFields
' Iterate over the attachment fields on an Entity.
For Each attachField In attachFields
set attaches = attachField.Attachments
' iterate over the attachment's field attachments
For Each myAttach In attaches
filename = myAttach.FileName
filesize = myAttach.FileSize
' INFO "filenmae is " & filename
' File size is always 0 before a first commit
If (filesize = 0) Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filename)
filesize = f.size
End if
' INFO "filename is " & filename & " size is " & filesize
If (filesize 1500000) Then
Defect_Validation = "File " & filename & " is too big "
Exit Function
End If
Next
Next
End Function |
Hook Submitter:
Francois Salazar
francois.salazar@comtech-software.fr
About the author  | |  | This article is brought to you by the Rational staff at developerWorks. |
Rate this page
|  |