Using CtCmd for UCM and HCL Compass

Perl


# Start of Global Script UCU_CQActBeforeChact


sub UCU_CQActBeforeChact {

# the English Perl module is necessary for the use of the OSNAME variable
use English;

if ( $OSNAME =~ /Win/i ) {
    # UNC path to CtCmd.pm built for Windows
    unshift ( @INC, "//testsources/\tests/Perl/site/lib/VersionVault" );
} 
else {
    # NFS path to CtCmd.pm built for Solaris
    # if other platforms will be used, this block should also check for the 
    # Unix system and Linux platform and set the include path accordingly.
    unshift ( @INC, 
"/net/solarisHost/usr1/compass/common/lib/perl5/site_perl/5.6.1/sun4-solaris-multi/VersionVault" );}
    require ("CtCmd.pm");
    my ($result);
    my ($param) = @_;
    # ---
    # This record hook is invoked by SQUID to invoke the "Perform HCL Compass
    # Action Before Changing Activity" policy. If the activity is not in
    # a single stream project, or is not in the project's integration
    # stream, the UCM change activity should fail.
    #
    # INPUT:
    #  - Param must be a string with this format:
    #     "entity-type|entity-id|project_info|stream_info" (vertical bars are 
delimeters)
    #    which represents the entity bound to the SUM_Project which was
    #    delivered, and whether the entity is valid or not

    # OUTPUT:
    #  - If the entity is valid, this returns an empty string
    #  - If the entity is not valid, this returns a string
    #    to be displayed as an error message.
    # ---
    # Parse the param string, but we will ignore project_info and stream_info 
in this example
    my $entity_type;
    my $entity_id;
    my $project_info;
    my $stream_info;
    ($entity_type, $entity_id, $project_info, $stream_info) = split ('\|', 
$param);

    # Create CtCmd instance
    my $inst_cc = VersionVault::CtCmd->new();
    # get parent stream and stream type
    my $status;
    my $stream;
    my $istream;
    my $str_type;
    my $project;

    # get the stream name from the entity_id
    ($status, $stream) = 
$inst_cc->exec("des","-fmt","%[stream]p",$entity_id);

    # get the project name from the stream
    ($status, $project) = $inst_cc->exec("des","-fmt","%[project]p",$stream);
    
  # get the name of the project's integration stream
    ($status, $istream) = $inst_cc->exec("des","-fmt","%[istream]p", 
$project);

    # get parent project type (note: model fmt is broken in MCK, returns blank 
string)
    my $proj_type;
    ($status, $proj_type) = 

$inst_cc->exec("des","-fmt","%[model]p",$project);
    # find out if project is single stream or parent stream is 
    # integration stream
    #  NOTE: if proj_type is SIMPLE, then stream should always be an 
integration stream
    
if ( ($proj_type !~ "SIMPLE") && ($stream !~ $istream) ) {
        $result = "Unable to change activity";
    }
    else {
        $result = "";
    }
    return $result;
}
# End of Global Script UCU_CQActBeforeChact