IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
    
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerworks > My developerWorks >  Dashboard > Configuration Management > ... > ClearQuest > 1.5.1.1.7. BASE (Perl)
developerWorks
Log In   View a printable version of the current page.
Overview Connect Spaces Forums Wikis
1.5.1.1.7. BASE (Perl)
Added by bobdorenfeld, last edited by bobdorenfeld on Mar 26, 2009  (view change)
Labels: 
(None)

Introduction

This section is for BASE Action hooks for Perl code.

1. Field Size Limit

BaseActionFieldSizeLimit.pl         Contributed by Leesa Hicks

sub changerequest_Validation {
    my($actionname, $actiontype) = @_;
    my $result;
    # $actionname as string scalar
    # $actiontype as long scalar
    # $result as string scalar
    # action is CR_BaseAction2
    # record type name is ChangeRequest
    # Return a non-empty string explaining why the action cannot commit
    # with its current values. If it is valid, return an empty string.
    # Example:
    #    my $value_info = $entity->GetFieldValue("some field");
    #    if (length($value_info->GetValue()) < 10) {
    #        $result = "Must be at least 10 chars long";
    #    }

    # Checking attachment size.  Size will vary depending upon if attachment is
    # added on Unix or Windows (different upper limit size restrictions).

    $megaByteLength        = 1048576;  # 1 Mbyte
    $kiloByteLength        = 1024;        # 1 Kbyte

    # First we need to check which platform this request is originating.  Creating
    # a session variable to track whether we have captured this info before.  If
    # we have, then don't check which platform, but simply check session variable.

    if (!($session->GetNameValue("CreatedOnPlatform"))) {
        my $cqobject = CQClearQuest::Build();
        my $platformIsWindows = $cqobject->IsWindows();

        # Checking to see if above "IsWindows()" assignment is TRUE, is so, set a
        # session variable, CreatedOnPlatform, to Windows, otherwise set it to Unix.
         if ($platformIsWindows) {
            $session->SetNameValue("CreatedOnPlatform", "Windows");
        }
        else {
            $session->SetNameValue("CreatedOnPlatform", "Unix");
        }
        CQClearQuest::Unbuild($cqobject);
    }

    # Setting local variables...

    my $whichPlatform = $session->GetNameValue("CreatedOnPlatform");
    my $maxWinFileSize  = 10485760;        # Wins upper limit:  10 MBytes
    my $maxUnixFileSize = 65536;         # Unix upper limit:  64k Bytes
    my ($attachmentFields, $attachmentField, $attachments, $i,
        $numAttachFields,  $numAttachments,  $attachment,  $j);
    $result = "";

    # Get the list of the attachment fields in this record type.
    $attachmentFields = $entity->GetAttachmentFields();
    $numAttachFields  = $attachmentFields->Count() ;

    # Iterate over the attachment fields; for each one, validate the
    # size of each attachment contained within each attachment field.
    for ($i = 0; $i < $numAttachFields; $i++) {
        $attachmentField = $attachmentFields->Item($i) ;

          # Obtain the attachments contained within this attachment field.
          $attachments    = $attachmentField->GetAttachments() ;
          $numAttachments = $attachments->Count() ;

          # Validate the size of each attachment.
          for ($j = 0; $j < $numAttachments; $j++) {
             $attachment = $attachments->Item($j) ;
             $fileName   = $attachment->GetFileName() ;

             # Get size of the file.  CQ file size is zero before the first commit,
            # so if that is the case, get the file size from the O/S.
             if (0 == ($fileSize = $attachment->GetFileSize())) {
                $fileSize = (-s $fileName) ;
            }

             # Checking whether platform is Windows or Unix.  If platform is windows
            # and the filesize is greater than max Windows file size, display error,
            # else if platform is Unix and file size is greater than maz Unix file
            # size, display error.  WE STILL NEED A CHECK WHEN PLATFORM eq Linux!

            # if ($session->GetNameValue("CreatedOnPlatform") eq "Windows" &&
            if ($whichPlatform eq "Windows" && $fileSize > $maxWinFileSize) {   

                $result = $result . "File '$fileName' in " .
                          $attachmentField->GetFieldName() .
                          " exceeds the maximum length of " . ($maxWinFileSize / $megaByteLength) . " MBytes.\n" ;
            }
            elsif ($whichPlatform eq "Unix" && $fileSize > $maxUnixFileSize) {   

                $result = $result . "File '$fileName' in " .
                          $attachmentField->GetFieldName() .
                          " exceeds the maximum length of " . ($maxUnixFileSize / $kiloByteLength) . " KBytes.\n" ;
            }
        }
    }

    # If the Description, ResolutionDesc, VerificationDesc, or the Notes_Log field
    # have changed, make sure they haven't exceeded their maximum allowed length
    my ($maxLength, $changedFields, $changedField, $fieldName, $index);

    $maxNoteLogLength    = 1048576;  # 1 MByte
    $maxMultiLineStrLen    = 524288;   # .5 Mbyte

    $changedFields = $entity->GetFieldsUpdatedThisAction();

    for ($index = 0; $index < $changedFields->Count(); $index++) {
         $changedField = $changedFields->Item($index);
         $fieldName    = $changedField->GetName();

        if ($fieldName eq "Description" && length($entity->GetFieldStringValue("Description")) > $maxMultiLineStrLen) {
            $result = $result . "The Description field cannot be larger than " . ($maxMultiLineStrLen / $megaByteLength) . " MBytes\n" ;
        }

        if ($fieldName eq "ResolutionDesc" && length($entity->GetFieldStringValue("ResolutionDesc")) > $maxMultiLineStrLen) {
            $result = $result . "The ResolutionDesc field cannot be larger than " . ($maxMultiLineStrLen / $megaByteLength) . " MBytes\n" ;
        }

        if ($fieldName eq "VerificationDesc" && length($entity->GetFieldStringValue("VerificationDesc")) > $maxMultiLineStrLen) {
            $result = $result . "The VerificationDesc field cannot be larger than " . ($maxMultiLineStrLen / $megaByteLength) . " MBytes\n" ;
        }

        if ($fieldName eq "Notes_Log" && length($entity->GetFieldStringValue("Notes_Log")) > $maxNoteLogLength) {
            $result = $result . "The Notes_Log field cannot be larger than " . ($maxNoteLogLength / $megaByteLength) . " MBytes\n" ;
        }
    }
    return $result;
}

See also

  •  


 
    About IBM Privacy Contact