Subversion Repositories DevTools

Rev

Rev 125 | Blame | Last modification | View Log | RSS feed

<%
'=====================================================
'               COMMON MAKE RELEASE BUTTON SUBs
'=====================================================
'
' Conventions within this code
'
'   1) Where a paramter list contains both RTAG_ID and PV_ID, the RTAG_ID will precede the PV_ID parameter
'   2) Functions/Subs that are not used externally, are name decorated PRIVATE_
'   3) Functions/Subs that are used extennally, are name decorated PUBLIC_
'
'
'
%>
<%
Dim AutoBuildPermissionDenied
Dim ManualBuildPermissionDenied
Dim RaiseWIPExists

AutoBuildPermissionDenied   = FALSE
ManualBuildPermissionDenied = FALSE


'-----------------------------------------------------------------------------------------------------------------------------
' This is the pattern for approval determination. If the release is in open mode, permission is given. If the release is
' in restrictive/ccb mode, permission is given dependent on the accessControlObjectName being granted for the user.
'
Function PRIVATE_Is_Allowed_To(NNrtag_id, accessControlObjectName)
   Dim ReleaseMode

   ReleaseMode = GetReleaseMode ( NNrtag_id )

   PRIVATE_Is_Allowed_To = FALSE

   If ReleaseMode <> enumDB_RELEASE_IN_CLOSED_MODE AND ReleaseMode <> enumDB_RELEASE_IN_ARCHIVE_MODE Then
      If ( ReleaseMode = enumDB_RELEASE_IN_OPEN_MODE ) Then
         PRIVATE_Is_Allowed_To = TRUE
      Else
         If objAccessControl.IsActive(accessControlObjectName) Then
            PRIVATE_Is_Allowed_To = TRUE
         End If
      End If
   End If
End Function
'-----------------------------------------------------------------------------------------------------------------------------
Function PRIVATE_Is_Allowed_To_Approve_Merge(NNrtag_id)

   PRIVATE_Is_Allowed_To_Approve_Merge = PRIVATE_Is_Allowed_To(NNrtag_id, "ApproveForAutoBuild") _
                                      OR PRIVATE_Is_Allowed_To(NNrtag_id, "ApproveForManualBuild")
End Function
'----------------------------------------------------------------------------------------------------------------------------------------
Function PRIVATE_Is_Allowed_To_Approve_ManualBuild(NNrtag_id)

   PRIVATE_Is_Allowed_To_Approve_ManualBuild = PRIVATE_Is_Allowed_To(NNrtag_id, "ApproveForManualBuild")
End Function
'----------------------------------------------------------------------------------------------------------------------------------------
Function PRIVATE_Is_Allowed_To_Approve_AutoBuild(NNrtag_id)

   PRIVATE_Is_Allowed_To_Approve_AutoBuild = PRIVATE_Is_Allowed_To(NNrtag_id, "ApproveForAutoBuild")
End Function


'=============================================================================================================================
' APPROVING PENDING MERGE OPERATIONS - Used from _approve_merge.asp as well as from within this file itself
'
' All functions in this section originally came from _approve_merge.asp and were placed here to support their use in more
' than the original singular context. Being relocated here allows them to be used in the additional "Bulk Release" context.
'=============================================================================================================================

'-----------------------------------------------------------------------------------------------------------------------------
' USED to approve a pending merge operation. Used internally by the bulk release operation
Sub PRIVATE_ApproveMerge ( NNrtag_id, NNpv_id )
   On Error Resume Next
   objEH.ErrorRedirect = TRUE

   OraDatabase.Parameters.Add "PV_ID",   NNpv_id,    ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "RTAG_ID", NNrtag_id,  ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "USER_ID", objAccessControl.UserId,   ORAPARM_INPUT, ORATYPE_NUMBER

   objEH.TryORA ( OraSession )

   OraDatabase.ExecuteSQL _
      "BEGIN "&_
      " PK_ENVIRONMENT.APPROVE_MERGE ( :PV_ID, :RTAG_ID, :USER_ID );"&_
      "END; "

   objEH.CatchORA ( OraSession )

   OraDatabase.Parameters.Remove "PV_ID"
   OraDatabase.Parameters.Remove "RTAG_ID"
   OraDatabase.Parameters.Remove "USER_ID"
End Sub

'-----------------------------------------------------------------------------------------------------------------------------
' USED to approve a pending merge operation. Used externally from the _approve_merge.asp file, loaded when the btnApproveMerge
' action button is pressed.
Sub PUBLIC_ApproveMerge ( NNrtag_id, NNpv_id )
   ' validate before carrying out the merge
   If PRIVATE_Is_A_Valid_Pending_Merge(NNrtag_id, NNpv_id, "A") OR PRIVATE_Is_A_Valid_Pending_Merge(NNrtag_id, NNpv_id, "S") Then
      If PRIVATE_Is_Allowed_To_Approve_Merge(NNrtag_id) Then
         Call PRIVATE_ApproveMerge(parRtag_id, NNpv_id)
      End If
   End If
End Sub

'-----------------------------------------------------------------------------------------------------------------------------
' USED to validate an attempt to approve a pending merge operation
Function PRIVATE_Is_A_Valid_Pending_Merge(NNrtag_id, NNpv_id, op)
   Dim rsQry

   OraDatabase.Parameters.Add "PV_ID",   NNpv_id,   ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "RTAG_ID", NNrtag_id, ORAPARM_INPUT, ORATYPE_NUMBER

   Set rsQry = OraDatabase.DbCreateDynaset( GetQuery("PlannedPackageVersionDetails.sql"), cint(0))

   If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
      ' Does the actual operation field in the database match that specified as a parameter?
      If (rsQry.Fields("operation") = op) Then
         PRIVATE_Is_A_Valid_Pending_Merge = TRUE
                Else
         PRIVATE_Is_A_Valid_Pending_Merge = FALSE
                End If
   Else
      PRIVATE_Is_A_Valid_Pending_Merge = FALSE
   End If

   OraDatabase.Parameters.Remove "PV_ID"
   OraDatabase.Parameters.Remove "RTAG_ID"

   rsQry.Close()
   Set rsQry = Nothing
End Function


'=============================================================================================================================
' APPROVING MANUAL BUILD PENDING VERSIONS - Used from _make_released.asp as well as from within this file itself
'
' All functions in this section originally came from _make_released.asp and were placed here to support their use in more
' than the original singular context. Being relocated here allows them to be used in the additional "Bulk Release" context.
'=============================================================================================================================


'----------------------------------------------------------------------------------------------------------------------------------------
' This function came from _make_released.asp and is very similar to the PRIVATE_NotifyInterestAutoBuild, except the subject/body
' text is different. Unlike its auto-build counterpart, this one is called during the process of making a manual build release
' official.
' One question arises... can we not harmonize the email notification code somewhat, between manual and autobuild releases?
'
' Currently, the function is called internally as part of the bulk release operation, and from _generate_release_notes.asp,
' loaded by _make_released.asp which in turn is loaded when a user presses the btnMakeReleased action button for manual
' built pending versions.
Sub PUBLIC_NotifyInterestManualBuild( NNrtag_id, NNpv_id )
   Err.Clear
   On Error Resume Next
   Dim Query_String, rsQry, myMail

   Query_String = _
   "   SELECT * FROM PACKAGE_INTEREST PI, PACKAGES PKG, PACKAGE_VERSIONS PV, USERS U,"&_
   "   RELEASE_TAGS RT, PROJECTS PRJ WHERE PKG.PKG_ID = PI.PKG_ID AND "&_
   "   RT.RTAG_ID = "& NNrtag_id &""&_
   "   AND PV.PV_ID = "& NNpv_id &" AND PV.PKG_ID = PKG.PKG_ID AND "&_
   "   PRJ.PROJ_ID = RT.PROJ_ID AND PRJ.PROJ_ID = PI.PROJ_ID AND U.USER_ID = PI.USER_ID"

   Set rsQry = OraDatabase.DbCreateDynaset( Query_String , cint(0) )

   If rsQry.RecordCount <> "" Then
      While ((NOT rsQry.BOF) AND (NOT rsQry.EOF))
         If rsQry("user_email") <> "" Then
            Set myMail=Server.CreateObject("Persits.MailSender")
            myMail.Host = SMTP_HOST
            myMail.Subject="Version "& rsQry("pkg_version") &" of Package "& rsQry("pkg_name") &" in Project " & rsQry("proj_name") &" on Release Branch " & rsQry("rtag_name") &" has been released."
            myMail.Body = "You have received this email as a result of your interest in this package. If you do not wish to receive further emails then remove your package interest from the notifications area in Release Manager."
            myMail.From=ADMIN_EMAIL
            myMail.AddAddress rsQry("user_email")
            myMail.Send
            set myMail=nothing
         End If
         rsQry.MoveNext
      Wend

   End If

   rsQry.Close()
   set rsQry = nothing
End Sub

'----------------------------------------------------------------------------------------------------------------------------------------
' Currently, this function is called internally as part of the bulk release operation, and from _generate_release_notes.asp,
' loaded by _make_released.asp which in turn is loaded when a user presses the btnMakeReleased action button for manual
' built pending versions. It initiates the execution of the windows script file that performs additional database updates
' that are needed to make official a package version that has already been built and published into dpkg_archive. This includes
' collecting info on all files that were published to dpkg_archive, and inserting that info into the RELEASED_COMPONENTS table.
Function PUBLIC_Run_onMakeOfficial ( nRtag_id, nPv_id )

   Dim objWSH, proj_id, Qry, sRtagName

   PUBLIC_Run_onMakeOfficial = FALSE

   On Error Resume Next

   objEH.TryORA ( OraSession )

   OraDatabase.ExecuteSQL " UPDATE package_versions "&_
                          " SET release_notes_info = '"& enum_RELEASE_NOTES_GENERATING &"'"&_
                          " WHERE pv_id = "& nPv_id

   objEH.CatchORA ( OraSession )

   If objEH.LastOraFailed = FALSE Then

      Set objWSH = Server.CreateObject("WScript.Shell")
      'Used for getting the package name and package version
      OraDatabase.Parameters.Add "RTAG_ID", nRtag_id, ORAPARM_INPUT, ORATYPE_NUMBER

      Set Qry = OraDatabase.DbCreateDynaset( "SELECT * FROM RELEASE_TAGS WHERE RTAG_ID = :RTAG_ID", 0 )

      proj_id = Qry("proj_id")
      sRtagName = UCase( Qry("rtag_name") )

      Qry.Close()
      Set Qry = Nothing

      OraDatabase.Parameters.Remove "RTAG_ID"

      'If proj_id = 281 Or proj_id = 221 Then
      '  objWSH.Run   "cmd.exe /c cscript.exe //B //NoLogo "& rootPath & SCRIPTS_FOLDER_STEP &"\on_Make_Official.wsf //job:GetComponents //job:GenerateReleaseNotes //job:PostRun "&_
      '                 "/pv_id:"& nPv_id , _
      '                 0, False
      'Else
         objWSH.Run   "cmd.exe /c cscript.exe //B //NoLogo "& rootPath & SCRIPTS_FOLDER &"\on_Make_Official.wsf //job:GetComponents //job:GenerateReleaseNotes //job:PostRun "&_
                     "/pv_id:"& nPv_id & " /proj_id:"& proj_id &" /rtag_name:"""&sRtagName&"", _
                     0, False
      'End If
      Set objWSH = nothing

      PUBLIC_Run_onMakeOfficial = TRUE
   End If

End Function
'-----------------------------------------------------------------------------------------------------------------------------
' This sub is used from _make_released.asp, loaded when a user presses the btnMakeReleased action button, as well as from
' internally within this file as part of the bulk release operation.
' This function basically removes the PV_ID entry from the WIP/PLANNED table, and adds it to the RELEASE_CONTENT table.
Function PUBLIC_MakeRelease ( NNrtag_id, NNpv_id  )

   On Error Resume Next
   objEH.ErrorRedirect = TRUE

   OraDatabase.Parameters.Add "PV_ID",   NNpv_id,                 ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "RTAG_ID", NNrtag_id,               ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "USER_ID", objAccessControl.UserId, ORAPARM_INPUT, ORATYPE_NUMBER

   objEH.TryORA ( OraSession )

   OraDatabase.ExecuteSQL _
     "BEGIN "&_
     " PK_ENVIRONMENT.MAKE_RELEASE ( :PV_ID, :RTAG_ID, :USER_ID );"&_
     "END; "

   objEH.CatchORA ( OraSession )

   OraDatabase.Parameters.Remove "PV_ID"
   OraDatabase.Parameters.Remove "RTAG_ID"
   OraDatabase.Parameters.Remove "USER_ID"

   ' return TRUE if operation was successful, else FALSE
   If objEH.LastOraFailed Then
      PUBLIC_MakeRelease = FALSE
   Else
      PUBLIC_MakeRelease = TRUE
   End If

End Function


'=============================================================================================================================
' APPROVING AUTO/MANUAL BUILD PENDING VERSIONS - Used from _make_approved.asp as well as from within this file itself
'
' All functions in this section originally came from _make_approved.asp and were placed here to support their use in more
' than the original singular context. Being relocated here allows them to be used in the additional "Bulk Release" context.
'=============================================================================================================================

'----------------------------------------------------------------------------------------------------------------------------------------
Function PRIVATE_Get_CQ_Issues ( SSsql, OOrsCQ )
   'On Error Resume Next
   OOrsCQ.ActiveConnection = CQ_conn
   OOrsCQ.Source = SSsql
   OOrsCQ.CursorType = 0
   OOrsCQ.CursorLocation = 2
   OOrsCQ.LockType = 3
   OOrsCQ.Open()
   PRIVATE_Get_CQ_Issues = Err.Number
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' Currently, this function does not seem to be used. The call to it was commented out in the _make_approved.asp file from where it was
' originally called from.
'
Sub PRIVATE_NotifyInterestAutoBuild( NNrtag_id, NNpv_id )
   On Error Resume Next
   Dim Query_String, rsQry, myMail

   Query_String = _
   "   SELECT * FROM PACKAGE_INTEREST PI, PACKAGES PKG, PACKAGE_VERSIONS PV, USERS U,"&_
   "   RELEASE_TAGS RT, PROJECTS PRJ WHERE PKG.PKG_ID = PI.PKG_ID AND "&_
   "   RT.RTAG_ID = "& NNrtag_id &""&_
   "   AND PV.PV_ID = "& NNpv_id &" AND PV.PKG_ID = PKG.PKG_ID AND "&_
   "   PRJ.PROJ_ID = RT.PROJ_ID AND PRJ.PROJ_ID = PI.PROJ_ID AND U.USER_ID = PI.USER_ID"

   Set rsQry = OraDatabase.DbCreateDynaset( Query_String , cint(0) )

   If rsQry.RecordCount <> "" Then
      While ((NOT rsQry.BOF) AND (NOT rsQry.EOF))
         If rsQry("user_email") <> "" Then
            Set myMail=Server.CreateObject("Persits.MailSender")
            myMail.Host = SMTP_HOST
            myMail.Subject="New Version of Package "& rsQry("pkg_name") &" in Project " & rsQry("proj_name") &" on Release Branch " & rsQry("rtag_name") &" would be autobuild soon."
            myMail.From=ADMIN_EMAIL
            myMail.AddAddress rsQry("user_email")
            myMail.Send
            set myMail=nothing
         End If
         rsQry.MoveNext
      Wend
   End If

   rsQry.Close()
   set rsQry = nothing
End Sub
'-------------------------------------------------------------------------------------
Sub PRIVATE_Get_Package_Issues(NNpv_id, SSsql)
   Dim sqlstr, rsTemp, DEVIiss, TDSEiss, VT5DMiss, VTSUPiss

   sqlstr = "SELECT iss_db, iss_id, iss_state, notes FROM CQ_ISSUES WHERE pv_id="& NNpv_id &"  AND iss_state = 1"

   Set rsTemp = OraDatabase.DbCreateDynaset( sqlstr, cint(0))

   DEVIiss = "-1"
   TDSEiss  = "-1"
   VT5DMiss = "-1"
   VTSUPiss = "-1"

   While ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF))
      If CInt(rsTemp("iss_db")) = CInt(enumCLEARQUEST_DEVI_ID) Then
         DEVIiss = DEVIiss &","& rsTemp("iss_id")
      ElseIf CInt(rsTemp("iss_db")) = CInt(enumCLEARQUEST_TDSE_ID) Then
         TDSEiss = TDSEiss &","& rsTemp("iss_id")
      ElseIf CInt(rsTemp("iss_db")) = CInt(enumCLEARQUEST_VT5DM_ID) Then
         VT5DMiss = VT5DMiss &","& rsTemp("iss_id")
      ElseIf CInt(rsTemp("iss_db")) = CInt(enumCLEARQUEST_VTSUP_ID) Then
         VTSUPiss = VTSUPiss &","& rsTemp("iss_id")
      End If

      rsTemp.MoveNext
   WEnd

   ' Construct SQL statement for CQ database
   If Len(DEVIiss) <> 1 OR Len(TDSEiss) <> 1 Then
      SSsql = ReadFile( rootPath & "queries\cq_issues.sql" )
      SSsql = Replace( SSsql, "/*enumCLEARQUEST_DEVI_ID*/", enumCLEARQUEST_DEVI_ID)
      SSsql = Replace( SSsql, "/*enumCLEARQUEST_TDSE_ID*/", enumCLEARQUEST_TDSE_ID)
      SSsql = Replace( SSsql, "/*enumCLEARQUEST_VT5DM_ID*/", enumCLEARQUEST_VT5DM_ID)
      SSsql = Replace( SSsql, "/*enumCLEARQUEST_VTSUP_ID*/", enumCLEARQUEST_VTSUP_ID)
      SSsql = Replace( SSsql, "/*DEVIiss*/", DEVIiss)
      SSsql = Replace( SSsql, "/*TDSEiss*/", TDSEiss)
      SSsql = Replace( SSsql, "/*VT5DMiss*/", VT5DMiss)
      SSsql = Replace( SSsql, "/*VTSUPiss*/", VTSUPiss)
   End If

   rsTemp.Close
   Set rsTemp = nothing

End Sub
'-------------------------------------------------------------------------------------
Function PRIVATE_MakeApproved (NNrtag_id, NNpv_id)

   OraDatabase.Parameters.Add "PV_ID",   NNpv_id,                 ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "RTAG_ID", NNrtag_id,               ORAPARM_INPUT, ORATYPE_NUMBER
   OraDatabase.Parameters.Add "USER_ID", objAccessControl.UserId, ORAPARM_INPUT, ORATYPE_NUMBER

   objEH.TryORA ( OraSession )
   On Error Resume Next

   OraDatabase.ExecuteSQL _
   "BEGIN "&_
   "   PK_ENVIRONMENT.MAKE_APPROVED ( :PV_ID, :RTAG_ID, :USER_ID ); "&_
   "END; "

   objEH.CatchORA ( OraSession )

   OraDatabase.Parameters.Remove "PV_ID"
   OraDatabase.Parameters.Remove "RTAG_ID"
   OraDatabase.Parameters.Remove "USER_ID"

   ' return TRUE if operation was successful, else FALSE
   If objEH.LastOraFailed Then
      PRIVATE_MakeApproved = FALSE
   Else
      PRIVATE_MakeApproved = TRUE
   End If

End Function
'-------------------------------------------------------------------------------------
' This function is called from _make_approved.asp, which is loaded when the btnApprovePackage
' action button is pressed. It is also called as part of the bulk release operation.
Function PUBLIC_ApproveRelease(NNrtag_id, NNpv_id, ByRef retParameters, isBulk)

   Dim retERRmsg
   Dim retALRTmsg
   Dim pkgType

   retParameters = ""
   pkgType = 0

   Set pkgInfoHash = CreateObject("Scripting.Dictionary")

   ' default return value
   PUBLIC_ApproveRelease = FALSE

   If ( NNrtag_id <> "") AND (NNpv_id <> "") Then

     '-- Get Package details
     Call Get_Pkg_Info ( NNpv_id, NNrtag_id )

     If pkgInfoHash.Item("build_type") = "A" Then
        'Check If There Already Exists A WIP Instance Of The Package In The Release
        If Check_Package_WIP_Already_Exists(NNrtag_id, NNpv_id) > 0 Then
          RaiseWIPExists = TRUE
        End If

        If PRIVATE_Is_Allowed_To_Approve_AutoBuild(NNrtag_id) Then
           '-- Approve Automatic-build package
           Call CheckRequirementsForMakeApproved ( NNpv_id, NNrtag_id, pkgType, retERRmsg, retALRTmsg, retParameters )
           If IsNull(retERRmsg) Then
              Dim EmailBody

              If PRIVATE_MakeApproved (NNrtag_id, NNpv_id) = TRUE Then

                  If ( RaiseWIPExists = TRUE ) AND ( isBulk = FALSE ) Then
                     Call RaiseMsg ( enum_MSG_PACKAGE_WIP_EXISTS&"?rtag_id="& NNrtag_id & "&pv_id="& NNpv_id & "", NNpv_id )
                     ' RaiseMsg redirects loaded web page, so no return
                     ' Deal with BulkMakeRelease elsewhere
                  End If
                  ' indicate success
                  PUBLIC_ApproveRelease = TRUE
              End If
           Else
              Call RaiseMsg ( Eval(retERRmsg), NNrtag_id & "|" & NNpv_id & "|" & retParameters & "|" & "N" )
           End If
        Else
           ' Indicate an auto-build permission problem was detected in the global variable.
           ' This is only used within the context of a bulk release.
           AutoBuildPermissionDenied = TRUE
        End If
     Else
        If PRIVATE_Is_Allowed_To_Approve_ManualBuild(NNrtag_id) Then
           '-- Approve a Manual Build Release
           Call CheckRequirementsForMakeRelease ( NNpv_id, NNrtag_id, pkgType, retERRmsg, retALRTmsg, retParameters )
           If IsNull(retERRmsg) Then

              If PUBLIC_MakeRelease ( NNrtag_id, NNpv_id ) = TRUE Then
              ' If all went well, initiate the generation of release notes, and email any interested parties
                 If PUBLIC_Run_onMakeOfficial ( NNrtag_id, NNpv_id ) = TRUE Then
                    Call PUBLIC_NotifyInterestManualBuild( NNrtag_id, NNpv_id )

                    ' indicate success
                    PUBLIC_ApproveRelease = TRUE
                 End If
              End If
           Else
              Call RaiseMsg ( Eval(retERRmsg), NNrtag_id & "|" & NNpv_id & "|" & retParameters & "|" & "N" )
           End If
        Else
           ' Indicate a manual-build permission problem was detected in the global variable
           ' This is only used within the context of a bulk release.
           ManualBuildPermissionDenied = TRUE
        End If
     End If
   End If
End Function
'-----------------------------------------------------------------------------------------------------------------------------


'=============================================================================================================================
' MAKING A BULK RELEASE from a list of PV_IDs for a specified release
'
' This section contains the new "Bulk Release' code. This function is tied to the use of the make bulk release button.
'
'=============================================================================================================================

'-----------------------------------------------------------------------------------------------------------------------------
' This public function is called from the make_bulk_release.asp file, loaded when a user presses the Make Bulk Release
' button when viewing items on the Pending Tab of a release area.
'
' The function processes a list of PV_ID's that cam from the pending tab of a release, formed from each item whose checkbox
' was checked. There are 3 different types of item to deal with, and this function will deal with them in the order shown
' below:
'    1) Subtractive merge operations
'    2) Additive merge operations
'    3) Manual/Auto build items
'
' This order was chosen by design to ensure that in the end effect upon a release, the manual and auto build items
' take precedence over merge candidates. This occurs naturally if we process manual/auto build items last.
'
' Parameters:
'   NNrtag_id       The release area
'   NN_pv_id_list   A list of PV_IDs representing pending items to be approved for release or merge.
'
Sub PUBLIC_MakeBulkRelease (NNrtag_id, NN_pv_id_list)
   Dim initialList         ' holds all items
   Dim remainingList1()    ' To hold additive merge items
   Dim remainingList2()    ' To hold auto/manual build items
   Dim len_remainingList
   Dim pvId
   Dim retParameters
   Dim allowedToApproveMerge

   ' determine in advance if user is allowed to approve merges
   allowedToApproveMerge = PRIVATE_Is_Allowed_To_Approve_Merge(NNrtag_id)

   ' ready the remaining list index to extract additive merges and manual/auto build items
   len_remainingList = 0

   AutoBuildPermissionDenied   = FALSE
   ManualBuildPermissionDenied = FALSE

   ' Remove any spaces and split the pv_id list into a string array
   initialList = Split ( Replace(NN_pv_id_list, " ", "" ), "," )

   ' Process each subtractive merge item in the string array.
   ' We do these first to cleanup the release somewhat before we start adding new stuff in
   For Each pvId In initialList
      If IsNumeric(pvId) Then
         ' Test to see if this PV_ID represents a pending SUBTRACTIVE merge operation, and proceed with it if permissions allow
         If PRIVATE_Is_A_Valid_Pending_Merge(NNrtag_id, pvId, "S") Then
            If allowedToApproveMerge Then
               Call PRIVATE_ApproveMerge(NNrtag_id, pvId)
            Else
               AutoBuildPermissionDenied   = TRUE
               ManualBuildPermissionDenied = TRUE
            End If
         Else
            ' add item to the remaining list for the next loop to process
            len_remainingList = len_remainingList + 1
            ReDim Preserve remainingList1(len_remainingList)
            remainingList1(len_remainingList - 1) = pvId
         End If
      End If
   Next

   ' ready the remaining list index to extract manual/auto build items
   len_remainingList = 0

   ' Now process each additive merge item in the string array
   ' We do these before finally processing any auto/manual build items so that the latter take precedence in their eventual
   ' effect upon the release.
   For Each pvId In remainingList1
      ' Test to see if this PV_ID represents a pending ADDITIVE merge operation, and proceed with it if permissions allow
      If PRIVATE_Is_A_Valid_Pending_Merge(NNrtag_id, pvId, "A") Then
         If allowedToApproveMerge Then
            Call PRIVATE_ApproveMerge(NNrtag_id, pvId)
         Else
            AutoBuildPermissionDenied   = TRUE
            ManualBuildPermissionDenied = TRUE
         End If
      Else
         ' add item to the remaining list for the next loop to process
         len_remainingList = len_remainingList + 1
         ReDim Preserve remainingList2(len_remainingList)
         remainingList2(len_remainingList - 1) = pvId
      End If
   Next

   ' Now process each new Auto/Manaul build item in the string array
   RaiseWIPExists = FALSE
   For Each pvId In remainingList2
      Call PUBLIC_ApproveRelease(NNrtag_id, pvId, retParameters, TRUE)
   Next
   If ( RaiseWIPExists = TRUE ) Then
     Call RaiseMsg ( enum_MSG_PACKAGE_WIP_EXISTS&"?rtag_id="& NNrtag_id & "&pv_id="& pvId & "", pvId )
     ' RaiseMsg redirects loaded web page, so no return
   End If


   ' If any items were not approved for release due to permission errors, issue an alert to the user
   If AutoBuildPermissionDenied = TRUE OR ManualBuildPermissionDenied = TRUE Then
      Call RaiseMsg( enum_MSG_ERROR, "One of more items could not be approved due to missing permissions (either ApproveForAutoBuild or ApproveForManualBuild).<p>"_
                                   & "NOTE : All items that could be approved, have been.</p>" )
   End If

End Sub
'-----------------------------------------------------------------------------------------------------------------------------




%>