Subversion Repositories DevTools

Rev

Rev 7022 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%
'=====================================================
'    Common Subs for DAEMON INSTRUCTIONS
'=====================================================
%>
<%
'--------------------------------------------------------------------------------------------
' Indicates if the specified daemon instruction is in progress
'--------------------------------------------------------------------------------------------
Function DaemonInstructionInProgress( nInstId )
   Dim rsQry

   DaemonInstructionInProgress = False

   If NOT IsNull(nInstId) AND nInstId <> "" Then

      Set rsQry = OraDatabase.DbCreateDynaset( "SELECT IN_PROGRESS"&_
                                               "  FROM DAEMON_INSTRUCTIONS "&_
                                               " WHERE DAEMON_INSTRUCTIONS_ID = "& nInstId, ORADYN_DEFAULT )
      If (NOT rsQry.BOF) AND (NOT rsQry.EOF) Then

         If (NOT IsNull(rsQry("IN_PROGRESS"))) AND (rsQry("IN_PROGRESS") = "1") Then
            DaemonInstructionInProgress = True
         End If
      End If

      rsQry.Close
      Set rsQry = nothing
   End If
End Function

'--------------------------------------------------------------------------------------------
' Assign the inout parameter to an array containing the list of all human readable op-code
' strings, in ascending op-code value order. This list will be used to form a drop-down list
' control on an html form
'--------------------------------------------------------------------------------------------
Sub GetDaemonInstructionOperationNameArray(nArray)
   ' append new op-codes to this list when they are invented
   nArray = array(OP_CODE_0_STR, _
                  OP_CODE_1_STR, _
                  OP_CODE_2_STR)
End Sub

'--------------------------------------------------------------------------------------------
' Convert a Daemon Instruction operation code into a meaningful string
' NOTE: could replace this with a global scripting dicitonary, but the code would be no clearer
' for doing so.
'--------------------------------------------------------------------------------------------
Function DaemonInstructionOperationName(nOpCode)
   Select Case nOpCode
   Case OP_CODE_0_RIPPLE_BUILD_PACKAGE
      DaemonInstructionOperationName = OP_CODE_0_STR

   Case OP_CODE_1_TEST_BUILD_PACKAGE
      DaemonInstructionOperationName = OP_CODE_1_STR

   Case OP_CODE_2_FUTURE_BUILD
      DaemonInstructionOperationName = OP_CODE_2_STR

   Case Else
      DaemonInstructionOperationName = "Undefined (" & nOpCode & ")"
   End Select
End Function

'--------------------------------------------------------------------------------------------
' Convert a Daemon Instruction operation name into an op-code value
' NOTE: could replace this with a global scripting dicitonary, but the code would be no clearer
' for doing so.
'--------------------------------------------------------------------------------------------
Function DaemonInstructionOperationValue(nOpName)
   Select Case nOpName
   Case OP_CODE_0_STR
      DaemonInstructionOperationValue = OP_CODE_0_RIPPLE_BUILD_PACKAGE

   Case OP_CODE_1_STR
      DaemonInstructionOperationValue = OP_CODE_1_TEST_BUILD_PACKAGE

   Case OP_CODE_2_STR
      DaemonInstructionOperationValue = OP_CODE_2_FUTURE_BUILD

   Case Else
      DaemonInstructionOperationValue = ""
   End Select
End Function

'--------------------------------------------------------------------------------------------
' Determines if a daemon instruction op-code value indicates that a PV_ID is required to be
' specified for the instruction.
'--------------------------------------------------------------------------------------------
Function DaemonInstructionNeedsPV_ID(nOpCode)
   Select Case nOpCode
   Case OP_CODE_0_RIPPLE_BUILD_PACKAGE
      DaemonInstructionNeedsPV_ID = True

   Case OP_CODE_1_TEST_BUILD_PACKAGE
      DaemonInstructionNeedsPV_ID = True

   Case OP_CODE_2_FUTURE_BUILD
      DaemonInstructionNeedsPV_ID = True

   Case Else
      DaemonInstructionNeedsPV_ID = False
   End Select
End Function

'--------------------------------------------------------------------------------------------
' Determines if a daemon instruction op-code value indicates that a repeat value is required
' to be specified for the instruction.
'--------------------------------------------------------------------------------------------
Function DaemonInstructionNeedsRepeat(nOpCode)
   ' currently - no op-codes need a repeat value
   DaemonInstructionNeedsRepeat = False
End Function

'--------------------------------------------------------------------------------------------
' Convert a Repeat Seconds value into a meaningful string. This takes account of the
' daemon instruction op-code too - a repeat seconds value is only relevant for certain
' op-codes
'--------------------------------------------------------------------------------------------
Function DaemonInstructionRepeatString(nOpCode, nRepeatSecs)
   DaemonInstructionRepeatString = "N/A"

   ' uncomment this when we are ready to introduce the "get release metrics" instruction
   'Select Case nOpCode
   'Case OP_CODE_?_GET_RELEASE_METRICS
   '   Select Case nRepeatSecs
   '   Case 86400
   '      DaemonInstructionRepeatString = "24Hrs"
   '   Case Else
   '      DaemonInstructionRepeatString = "NO"
   '   End Select
   '
   'Case Else
   '   DaemonInstructionRepeatString = "N/A"
   'End Select

End Function
'--------------------------------------------------------------------------------------'--------------------------------------------------------------------------------------------
' Function to inform caller of whether the user is allowed to reset the daemon instructions
' in-progress flag
'--------------------------------------------------------------------------------------------
Function UserAllowedToResetInProgress
   UserAllowedToResetInProgress = True
   If objAccessControl.UserLogedIn Then
      If NOT canActionControlInProject("ResetDaemonInstInProgress") Then
         UserAllowedToResetInProgress = False
      End If
   Else
      UserAllowedToResetInProgress = False
   End If
End Function

'--------------------------------------------------------------------------------------------
' Daemon Instruction validation function
'--------------------------------------------------------------------------------------------
Function HandleValidateDaemonInstructionError(nOpCode, retERRmsg, ByRef sErrorMsg)
   Dim s

   s = ""
'retERRmsg = "enum_MSG_BROKEN_DEPENDENCIES_FOUND"
   HandleValidateDaemonInstructionError = True

   If NOT IsNull(retERRmsg) Then
      ' Exclusions -
      ' 1) Ignore "unit tests not supplied" error for ripple build package daemon instruction
      If NOT ((nOpCode = OP_CODE_0_RIPPLE_BUILD_PACKAGE) AND (retERRmsg = "enum_MSG_UNIT_TESTS_NOT_SUPPLIED"))  Then

         ' Re-interpret the error message that has been returned from the queries. We do this because normally,
         ' these errors are associated with individual message files but the messsages in those files are slightly
         ' inappropriate for the context of adding a daemon instruction so we will provide our own message display
         ' using the generic enum_WMSG_ERROR file with a bespoke error string.
         Select Case retERRmsg
         Case "enum_MSG_MISSING_DEPENDENCIES"
            s = "Some dependencies of this package are missing from a release."
         Case "enum_MSG_PACKAGE_INFORMATION_INCOMPLETE"
            s = "Package information section on Release Notes tab is not fully complete."
         Case "enum_MSG_AUTOBUILD_PACKAGE_REQUIRES_BUILD_STD_AND_ENV"
            s = "Package must have a build standard and build environment."
         Case "enum_MSG_REASON_FOR_THIS_VERSION_NOT_SUPLIED"
            s = "A reason for this version must be supplied."
         Case "enum_MSG_UNIT_TESTS_NOT_SUPPLIED"
            s = "There are no unit tests supplied for this package."
         Case "enum_MSG_PACKAGE_CHANGETYPE_INCOMPLETE"
            s = "Package change type in Release Notes Tab is not defined."
         Case "enum_MSG_BROKEN_DEPENDENCIES_FOUND"
            s = "Some of the packages dependencies are broken. Fix them first before trying to add a daemon instruction to this package."
         Case "enum_MSG_UNOFFICIAL_DEPENDENCIES_FOUND"
            s = "Some dependencies of this package are still not released. Release them first before trying to add a daemon instruction to this package."
         Case Else
            s = "Correct any errors in the release notes, and try again."
         End Select

         sErrorMsg = "Cannot add this daemon instruction<br>" & s

         HandleValidateDaemonInstructionError = False
      End If
   End If
End Function

Function ValidateDaemonInstruction(nOpCode, nRtag_id, nPv_id, ByRef sErrorMsg)
   Dim retERRmsg
   Dim retALRTmsg
   Dim retParameters
   Dim pkgType
   Dim s
   s = ""
   pkgType = 0

   ValidateDaemonInstruction = True

   Select Case nOpCode
   Case OP_CODE_0_RIPPLE_BUILD_PACKAGE
      ' Note: cannot use CheckRequirementsForMakeApproved here because it fails on the change_type check. This seems
      ' to be because a daemon ripple build results in a new package version that has null in the change_type column
      ' so we cannot validate that column in the package_versions table.

      ' check missing dependencies, bad package info, missing build std/env, reason for version, unit test
      Call CheckRequirementsForMakePending ( nPv_id, nRtag_id, pkgType, retERRmsg, retALRTmsg, retParameters )
      If IsNull(retERRmsg) Then
         ' Check broken dependencies, missing dependencies, unofficial dependencies, bad package info, reason for version, unit test
         Call CheckRequirementsForMakeRelease( nPv_id, nRtag_id, pkgType, retERRmsg, retALRTmsg, retParameters )
      End If

      ' Process retERRmsg into an error message 
      ValidateDaemonInstruction = HandleValidateDaemonInstructionError(nOpCode,retERRmsg,sErrorMsg)

   Case OP_CODE_1_TEST_BUILD_PACKAGE
      ValidateDaemonInstruction = True ' no validation checks for this instruction

   Case OP_CODE_2_FUTURE_BUILD
      ValidateDaemonInstruction = True ' no validation checks for this instruction

   Case Else

      sErrorMsg = "Attempt to add an unknown daemon instruction type"
      ValidateDaemonInstruction = False
   End Select

End Function
'------------------------------------------------------------------------------------------------------------------------------------------
Function DaemonInstructionPreventsEditing(nRtag_id, nPv_id)

   Dim rsQry
   Dim QryStr

   DaemonInstructionPreventsEditing = FALSE

   If (NOT IsNull(nRtag_id)) AND (nRtag_id <> "") AND (NOT IsNull(nPv_id)) AND (nPv_id <> "") Then

      QryStr = "SELECT COUNT(*) AS record_count"&_
               "  FROM DAEMON_INSTRUCTIONS "&_
               " WHERE (OP_CODE = "& OP_CODE_1_TEST_BUILD_PACKAGE &")"&_
               "   AND RTAG_ID = "& nRtag_id&_
               "   AND PV_ID = "& nPv_id

      Set rsQry = OraDatabase.DbCreateDynaset( QryStr, ORADYN_DEFAULT )

      If rsQry("record_count") <> 0 Then
        DaemonInstructionPreventsEditing = TRUE
      End If

      rsQry.Close
      Set rsQry = nothing
   End If

End Function

'------------------------------------------------------------------------------------------------------------------------------------------
Function DaemonInstructionPresent(nRtag_id, nPv_id, nOpCode)

   Dim rsQry
   Dim QryStr

   DaemonInstructionPresent = FALSE

   If (NOT IsNull(nRtag_id)) AND (nRtag_id <> "") AND (NOT IsNull(nPv_id)) AND (nPv_id <> "") AND (NOT IsNull(nOpCode)) AND (nOpCode <> "") Then

      QryStr = "SELECT COUNT(*) AS record_count"&_
               "  FROM DAEMON_INSTRUCTIONS "&_
               " WHERE (OP_CODE = "& nOpCode &")"&_
               "   AND RTAG_ID = "& nRtag_id&_
               "   AND PV_ID = "& nPv_id

      Set rsQry = OraDatabase.DbCreateDynaset( QryStr, ORADYN_DEFAULT )

      If rsQry("record_count") <> 0 Then
        DaemonInstructionPresent = TRUE
      End If

      rsQry.Close
      Set rsQry = nothing
   End If

End Function

'------------------------------------------------------------------------------------------------------------------------------------------
Function DaemonInstructionPreventsReleaseDeletion(nRtag_id)

   Dim rsQry
   Dim QryStr

   DaemonInstructionPreventsReleaseDeletion = FALSE

   If (NOT IsNull(nRtag_id)) AND (nRtag_id <> "") Then

      QryStr = "SELECT COUNT(*) AS record_count"&_
               "  FROM DAEMON_INSTRUCTIONS "&_
               " WHERE RTAG_ID = "& nRtag_id

      Set rsQry = OraDatabase.DbCreateDynaset( QryStr, ORADYN_DEFAULT )

      If rsQry("record_count") <> 0 Then
        DaemonInstructionPreventsReleaseDeletion = TRUE
      End If

      rsQry.Close
      Set rsQry = nothing
   End If

End Function
'------------------------------------------------------------------------------------------------------------------------------------------
Function UserCanAddOrEditThisDaemonInst(nProjId, nReleaseMode, nOpCode)

   UserCanAddOrEditThisDaemonInst = TRUE

   If objAccessControl.UserLogedIn Then
      If NOT canActionInProject() Then
         UserCanAddOrEditThisDaemonInst = False
      ElseIf (( ReleaseMode <> enumDB_RELEASE_IN_OPEN_MODE ) AND (nOpCode = OP_CODE_0_RIPPLE_BUILD_PACKAGE) ) Then
         If NOT canActionControlInProject("ApproveForAutoBuild") Then
            UserCanAddOrEditThisDaemonInst = False
         End If
      End If
   Else
      UserCanAddOrEditThisDaemonInst = False
   End If

End Function
'------------------------------------------------------------------------------------------------------------------------------------------
%>