Using CAL methods in Rational ClearQuest hook scripts

This section shows how to include CAL (ClearCase® Automation Library) methods in hook scripts to customize the behavior of the Rational® ClearQuest® integration with UCM.

This example is a modified version of the UCM_CQActBeforeChact Visual Basic script, which implements the Perform ClearQuest Action Before Changing Activity policy. When this policy is set, the integration executes the script when a developer initiates a Finish Activity operation, either from the GUI or by entering the command cleartool chactivity -cqact.

The modified script uses CAL methods to determine whether the developer is working in a single-stream project or a multiple-stream project. If the developer is working in a single-stream project, the script allows the Finish Activity operation. Otherwise, the script returns an error message and cancels the Finish Activity operation.

VBScript

REM Start of Global Script UCM_CQActBeforeChact

Function UCM_CQActBeforeChact (entity_type, entity_id, project_info, stream_info)

' This is the script that implements the "Perform Action Before
' Changing Activity" policy. When initially installed, it invokes a 
' default script. If users want to customize this policy, they should
' edit this script to use their code rather than invoking the default
' script. The default script code can be used as an example.
'
' INPUT:
' - entity_type: name of the type of entity on which action 
'                will be executed (for example, "defect")
' - entity_id: id (e.g. "SAMPL0000001") of entity on which action will
'              be executed

' OUTPUT:
' - If the action was successfully executed, this must return an empty
' string

' - If the action was not successfully executed, this must return a
' string to be displayed as an error message.

' Allow chact only if activity is in a single stream project

proj_model = "DEFAULT"

' Get hook's session context

Set session = GetSession()

' Get the entity

Set entity = session.GetEntity(entity_type, entity_id)

' Get the entity's ucm_vob_object field value. This value is a string
' that includes the UCM project's object ID and the PVOB's UUID. 

ucm_vob_object = entity.GetFieldValue("ucm_vob_object").GetValue()

Dim pvob_uuid

' Strip the project's object ID from the string and return the PVOB's
' UUID.

pvob_uuid = Right(ucm_vob_object, 40)

' Initialize ClearCase.Application COM object

' Create a ClearCase application object. A ClearCase application
' object must exist before you can use CAL methods. The remaining
' steps in the script use CAL methods.

On Error Resume Next

Set CC = CreateObject("ClearCase.Application")

If Err.Number <> 0 Then
   MsgBox "ClearCase.Application Error 1:" & Err.Description
End if

On Error Resume Next

' Using the PVOB's UUID, get a ClearCase PVOB object of the activity.
Set PVOB = CC.ProjectVOB(pvob_uuid)

If Err.Number <> 0 Then
   MsgBox "ClearCase.Application Error 2:" & Err.Description
End if

On Error Resume Next

' Create a ClearCase activity object (CCActivity) based on the PVOB and
' entity ID (equals UCM activity name).

Set Act = PVOB.Activity(entity_id)

If Err.Number <> 0 Then
   MsgBox "ClearCase.Application Error 3:" & Err.Description
End if

On Error Resume Next

' Return the stream in which the activity was created.
set stream = Act.Stream

If Err.Number <> 0 Then
   MsgBox "ClearCase.Application Error 4:" & Err.Description
End if

On Error Resume Next

' Return the project that contains the stream.
set project = stream.Project

If Err.Number <> 0 Then
  MsgBox "ClearCase.Application Error 5:" & Err.Description
End if

On Error Resume Next

' Return the project model.
proj_model = project.Model

If Err.Number <> 0 Then
   MsgBox "ClearCase.Application Error 6:" & Err.Description
End if

' Test the value of the project model.
' model = SIMPLE: single stream project

' If it is SIMPLE, meaning single-stream, the script returns an 
' empty string and the developer is allowed to complete the Finish 

' Activity operation.

' model = DEFAULT: hierarchical project

' If it is DEFAULT, meaning multiple-stream, the script returns an 
' error message and cancels the Finish Activity operation.

If proj_model = "SIMPLE" Then
' single stream model, allow change act
   UCM_CQActBeforeChact = ""
Else
' hierarchical project, fail
UCM_CQActBeforeChact = "Must be in a single stream project."
End if   

End Function

REM End of Global Script UCM_CQActBeforeChact 

Feedback