Author Topic: Anyone has example to update transaction data in CME using cfgTransaction?  (Read 3665 times)

Offline nikhiltrivedi84

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Does anyone have a sample code to update Transaction Data in CME using crgTransaction? Any other method is also fine.


Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Anyone has example to update transaction data in CME using cfgTransaction?
« Reply #1 on: February 19, 2016, 11:01:19 PM »
Hi,

I am not really a developer, so my code may be out of the usual standards... anyway find in the link below an example on how to get the CfgTransaction objects from Configuration Server.

http://owncloud.sujdik.com.br/index.php/s/NY0ZfphDmVSDWOH


To change a Transaction is simple... just retrieve it from the configuration server, make the changes to the CfgTransaction object as you wish and call the method save().

I also added a piece of code showing how to subscribe to Configuration Server notifications for when objects of an specific type change - a thing that I find very difficult due to not being a programmer.

Hope this helps

Offline JungGiCho

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: Anyone has example to update transaction data in CME using cfgTransaction?
« Reply #2 on: February 22, 2016, 08:19:44 AM »
Below is my transaction update code with xml.

    public boolean updateAnnexOption(String pSection, String pOption, String pValue)
    {
        Document    confObject = null ;
        String      xml = null ;
        boolean retval = true ;

        logger.info("Starts...." + pSection + "," + pOption + "," + pValue) ;

        try {
            xml =  "<ConfData>" +
                        "<CfgDeltaTransaction>" +
                            "<CfgTransaction>" +
                                "<DBID value='" + mTransactionDBID + "'/>" +
                            "</CfgTransaction>" +
                            "<changedUserProperties>" +
                                "<list_pair key='" + pSection + "'>" +
                                    "<str_pair key='" + pOption + "' value='" + pValue +"'/>" +
                                "</list_pair>" +
                            "</changedUserProperties>" +
                        "</CfgDeltaTransaction>" +
                    "</ConfData>";

            logger.info("Update annex option...." + xml) ;

            confObject = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml))) ;

            retval = updateObjects(CfgObjectType.CFGTransaction , confObject, null ) ;

        } catch (Exception ex) {

            logger.warning(CtiLogger.logstr("Exception....",ex)) ;

            retval = false ;
        }

        return retval ;
    }


    boolean updateObjects(GEnum pObjectType, Document pConfObject, KeyValueCollection pFilter)
    {

        RequestUpdateObject message ;          // Configuration Server에 변경을 요청 객체
        Message            response ;          // Configuration Server에 변경을 결과 응답 메시지

boolean retval = true ;

        //TreeMap retMap = new TreeMap() ;  // Return 값 저장 변수

        logger.info("Starts...." + pObjectType + "," + pConfObject + "," + pFilter) ;

        try
        {
            // Configuration Server가 연결이 될 때까지 기다린다.
            if( mConfServerProtocol.getState().equals(ChannelState.Opened))
            {
                // request message를 만든다
                message = RequestUpdateObject.create(new Integer(pObjectType.ordinal()), pConfObject , pFilter);

                logger.info("RequestUpdateObject....\n"+message) ;

                // 정보 조회를 요청한다
                response = mConfServerProtocol.request(message) ;

                // 결과값이 왔는지 확인한다
                if( response == null || !(response instanceof EventObjectUpdated) )
                {
                    // 결과값이 없거나 object를 읽었다는 Event가 아니면
                    if( response == null )
                    {
                        logger.info("RequestUpdateObject response - no object updated....") ;
                    } else
                    {
                        logger.info("RequestUpdateObject response - no object updated....\n" + decode(response.toString()) ) ;

switch(response.messageId())
{
                    case EventError.ID  :

EventError eventError = (EventError)response ;

if ( eventError.getErrorCode() == 29 )
{
mReadOnlyMode = true ;

logger.warning("Configuration server working mode is changed to Read-Only Mode....") ;
}
break ;
default:
break ;
}
                    }

                    retval = false ;
                } else
                {
                retval = true ;
               
                    logger.info("RequestReadObjects response - object  updated....\n" + decode(response.toString()) ) ;
                }
            } else
            {
            retval = false ;
           
            logger.info("RequestUpdateObject response - no object updated because cfg server is not connected....") ;
            }
        } catch (Exception ex)
        {
            logger.warning(CtiLogger.logstr("Exception....",ex)) ;

            retval = false ;
        }

        return retval;
    }
« Last Edit: February 22, 2016, 08:22:51 AM by JungGiCho »

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Anyone has example to update transaction data in CME using cfgTransaction?
« Reply #3 on: February 23, 2016, 06:15:04 PM »
I have updated the code that I have posted before, that includes changing a Transaction's Annex specified option inside a specified section, done directly on the objects by using the ConfService. At least to me (not a real developer) it is easier than using the low-level functions and xml with delta objects as our friend JungGiCho posted.
Also, one must be careful while using Delta Objects on a RequestUpdateObject, because if you send an option with the same value that already exists, it actually deletes the option instead of updating it to the same value.