File: eaf_n_cst_businessprocess.sru
Size: 9224
Date: Tue, 22 Jan 2008 23:40:37 +0100
$PBExportHeader$eaf_n_cst_businessprocess.sru
forward
global type eaf_n_cst_businessprocess from n_cst_businessobject
end type
end forward

global type eaf_n_cst_businessprocess from n_cst_businessobject
end type
global eaf_n_cst_businessprocess eaf_n_cst_businessprocess

type variables
Protected:
n_cst_updatemanager           inv_updatemanager
end variables

forward prototypes
public function long update (ref s_mimedataset astr_mimedataset)
protected function long updatemain (ref n_cst_businessobjectattrib anv_boattrib)
public function long initializeupdatemanager ()
end prototypes

public function long update (ref s_mimedataset astr_mimedataset);////////////////////////////////////////////////////////////////
// Description:
//    Update processing
//
//    Contains Start and End processing
// Revisions
//    3.0   - Initial version
// Arguments:  
//    astr_mimedataset : holds the information that is to be updated
// Returns: 
//     1 - Success
//     0 - Nothing to update
//    -1 - Failure
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft Technology, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "update ( REF s_mimedataset )"

inv_log.traceLog (METHOD_NAME,  "")

// Declare local variables 
long                             ll_rc
long                             ll_start_rc
long                             ll_end_rc
long                             ll_update_rc
string                           ls_updateinformation
string                           ls_describeresult
string                           ls_updateaction
string                           ls_characterset
string                           ls_runtimeerror

n_cst_businessobjectattrib       lnv_boattrib

try
   //Add messages to the instance message service
   inv_messaging.parse( astr_mimedataset.messages )
   
   // Validate arguments
   If isNull(astr_mimedataset) Or Not isValid(astr_mimedataset) Then
      addError(METHOD_NAME,  "Invalid astr_mimedataset argument")
      Return -1   
   End If
      
   //create the attribute object
   lnv_boattrib = create n_cst_businessobjectattrib

   //Create the ArgumentService
   lnv_boattrib.inv_argumentservice = create n_cst_argumentservice
   inv_log.propagateSettings( lnv_boattrib.inv_argumentservice )
   
   //Parse arguments
   if lnv_boattrib.inv_argumentservice.initialize( astr_mimedataset.arguments ) = -1 then
      inv_messaging.append( lnv_boattrib.inv_argumentservice.inv_messaging )
      return -1
   end if

   //Get the Character Set
   lnv_boattrib.inv_argumentservice.getArgument( inv_constants.EAF_CHARACTER_SET_ARGUMENT_NAME, ls_characterset )

   //See if session id exists
   lnv_boattrib.inv_argumentservice.getArgument( inv_constants.EAF_SESSION_ID_ARGUMENT_NAME, is_sessionid )
   
   // Create the working datastore
   If isNull(is_datastore) Or len(trim(is_datastore)) = 0 Then
      addError(METHOD_NAME,  "Error on is_datastore value")
      Return -1      
   End If
   
   lnv_boattrib.ids_working = create using is_datastore
   inv_log.propagateSettings( lnv_boattrib.ids_working )
   
   is_dataset = astr_mimedataset.name
    
   inv_log.traceLog (METHOD_NAME,  "(astr_mimedataset.name = "+astr_mimedataset.name+")")
      
   // Apply the passed in changes to the working datastore
   If lnv_boattrib.ids_working.SetFullState (astr_mimedataset.data.state) < 0 Then
      addError(METHOD_NAME,  "Invalid setfullstate operation")
      Return -1
   End If
   
   // If appropriate create the DataAccess object
   If isNull(inv_dataaccess) Or Not isValid(inv_dataaccess) Then
      // An specific DataAccess object was not requested
      If setDataAccess(is_dataaccessservice) <= 0 Then
         addError(METHOD_NAME,  "Unexpected failure of setDataAccess() operation")
         Return -1                     
      End If
   End If      
   
   // Invoke the Start processing method
   ll_start_rc = this.updateStart(lnv_boattrib)
   If ll_start_rc <= 0 Then 
      addError( METHOD_NAME, "Update failed!  Update was cancelled by updateStart processing. returned rc=" + String(ll_start_rc) )
      Return -1
   End if
   
   // Perform the actual update (skipped if ll_start_rc =2)
   If ll_start_rc = 1 Then
      // Invoke the updateValidate processing method
      ll_rc = this.updateValidate(lnv_boattrib)
      If ll_rc <= -1 Then 
         addError(METHOD_NAME,  "Update Failed.  Failure in validation processing.")
         this.setAbort()
         Return -1
      ElseIf ll_rc = 0 Then
         addError(METHOD_NAME,  "Update Failed.  Validation criteria not met.")
         this.setAbort()
         Return -1
      End if
      
      // Invoke the updatePrepare processing method
      ll_rc = this.updatePrepare(lnv_boattrib)
      If ll_rc <= -1 Then 
         addError(METHOD_NAME,  "Update failed.  Failure in update prepare processing.")
         this.setAbort()
         Return -1
      ElseIf ll_rc = 0 Then
         this.setAbort()
         Return -1   
      End if   
      
      // Report about the update about to take place
      inv_log.debuglog(METHOD_NAME, inv_constants.MESSAGE_TYPE_EAF_DEBUG, "About to request update:~r~n"+&
         "   lnv_boattrib.ids_working.rowCount()            = "+string(lnv_boattrib.ids_working.rowCount())+ "~r~n" +&
         "   lnv_boattrib.ids_working.modifiedCount()       = "+string(lnv_boattrib.ids_working.modifiedCount())+ "~r~n" +&            
         "   lnv_boattrib.ids_working.deletedCount()        = "+string(lnv_boattrib.ids_working.deletedCount())+ "~r~n" +&    
         "   lnv_boattrib.ids_working.filteredCount()      = "+string(lnv_boattrib.ids_working.filteredCount()))
      
      // Invoke the updateMain processing method
      ll_update_rc = this.updateMain(lnv_boattrib)
      If isNull(ll_update_rc) Or ll_update_rc <= 0 Then
         addError (METHOD_NAME,  "Update failed.  Update failed in updateMain() processing.")
         this.setAbort()                  
         Return -1
      End If   
   End If   
   
   inv_log.debugLog(METHOD_NAME,  inv_constants.MESSAGE_TYPE_EAF_DEBUG, "Executed inv_dataaccess.update() with rc="+String(ll_update_rc))
   
   // Invoke the End processing method
   ll_end_rc = updateEnd(lnv_boattrib)
   If ll_end_rc < 0 Then
      addError(METHOD_NAME,  "Update failed!  Update was prevented by updateEnd processing.")
      this.setAbort()
      Return -1   
   End If
   
   // We need to send the updates back to the client so get the contents of lnv_boattrib.ids_working and put them back into the update buffers
   ll_rc = lnv_boattrib.ids_working.getfullstate(astr_mimedataset.data.state )

catch ( RuntimeError re )
   ls_runtimeerror = "Runtime Error:" + inv_constants.CRLF + inv_constants.CRLF
   ls_runtimeerror += "Error Code: " + string(re.number) + inv_constants.CRLF
   ls_runtimeerror += "Object: " + re.objectName + inv_constants.CRLF
   ls_runtimeerror += "Class: " + re.class + inv_constants.CRLF
   ls_runtimeerror += "Function/Event: " + re.routineName + inv_constants.CRLF
   ls_runtimeerror += "Line: " + string(re.line) + inv_constants.CRLF
   ls_runtimeerror += "Message: " + re.getMessage() + inv_constants.CRLF
   inv_log.addError( METHOD_NAME, "Runtime Error: " + ls_runtimeerror, inv_messaging )

   this.setAbort()
   
   return -1
finally
   //Place all messages onto the reference structure
   inv_messaging.toXML( ls_characterset, astr_mimedataset.messages )

   if isValid( inv_dataaccess ) then
      inv_dataaccess.inv_messaging.reset()
   end if
   
   //Perform cleanup
   if isValid(lnv_boattrib) Then 
      destroy lnv_boattrib
   end if
end try

Return ll_update_rc
end function

protected function long updatemain (ref n_cst_businessobjectattrib anv_boattrib);////////////////////////////////////////////////////////////////
// Description:
//    Invoked by the Framework from the update().
// Revisions
//    3.0   - Initial version
// Arguments:  
//    anv_boattrib - attribute object containing all objects
// Returns: 
//     1 - Success 
//    -1 - Failure - Fail the update process
////////////////////////////////////////////////////////////////
// Copyright © 2000 - 2007 Youngsoft Technology, Inc.  All rights reserved.
// Any distribution of the Youngsoft, Inc. Enterprise Application Framework
// source code in whole or part by other than Youngsoft, Inc. is prohibited.
//////////////////////////////////////////////////////////////// 

constant string METHOD_NAME = "updateMain ( REF n_cst_boattrib )"

inv_log.traceLog (METHOD_NAME,  "")

return 1
end function

public function long initializeupdatemanager ();if not IsValid(inv_updatemanager) then
   inv_updatemanager = create n_cst_updatemanager
   inv_updatemanager.inv_argument.addArgument( inv_constants.EAF_CHARACTER_SET_ARGUMENT_NAME, "ISO-8859-1" )
   inv_updatemanager.inv_argument.addArgument( inv_constants.EAF_INTERFACEMANAGER_COMPONENT_ARGUMENT_NAME, GetComponentName() )
   inv_updatemanager.inv_argument.addArgument( inv_constants.EAF_LANGUAGEID_ARGUMENT_NAME, String(GetLanguageID()) )
   inv_updatemanager.inv_argument.addArgument( inv_constants.EAF_USERID_ARGUMENT_NAME, GetUserName() )
end if

return 1
end function

on eaf_n_cst_businessprocess.create
call super::create
end on

on eaf_n_cst_businessprocess.destroy
call super::destroy
end on

event destructor;call super::destructor;if IsValid(inv_updatemanager) then
   destroy inv_updatemanager
end if
end event