Strategic Software Consultant

I'm the partner of choice for many of the world's leading enterprises. I help businesses elevate their value through solution discovery, software development, design, QA, and consultancy services. As your Strategic Software Consultant, I work across many technology products and delivery teams. The scope of technology is broad, and it is my job to understand how your technology applications holistically support and connect to create a sustainable technology ecosystem. The ecosystem of technologies may span to 3rd party applications, in-house developed solutions, business intelligence, data integrations, and of course, SaaS applications.

Oracle Certified Specialist
Custom Process Model (CPM) Oracle B2C Service Cloud

Oracle Service Cloud Custom Process Model (CPM) Template

<?php
/**
 * CPMObjectEventHandler: IncidentAysnc
 * Package: OracleServiceCloud
 * Objects: Incident
 * Actions: Create, Update
 * Version: 1.4
 * Purpose: A starting template for an asynchronous Incident CPM
 */
use \RightNow\Connect\v1_4 as RNCPHP;
use \RightNow\CPM\v1 as RNCPM;

class IncidentAysnc implements RNCPM\ObjectEventHandler
{
    public static function apply($runMode, $action, $incident, $cycle)
    {
        if($cycle !== 0)
        {
            return;
        }

        $context = RNCPHP\ConnectAPI::getCurrentContext();
        $context->ApplicationContext = "Incident Integrations";


        if(cfg_get((120)) == "productionInterface")
        {
            $isProduction = TRUE;
        }
        else
        {
            $isProduction = FALSE;
        }

        if($isProduction)
        {
            $endpoint_base = RNCPHP\Configuration::fetch("CUSTOM_CFG_OIC_BASE_ENDPOINT_PROD")->Value;
            $endpoint_username = RNCPHP\Configuration::fetch("CUSTOM_CFG_OIC_LOGIN_PROD")->Value;
            $endpoint_password = RNCPHP\Configuration::fetch("CUSTOM_CFG_OIC_PASSWORD_PROD")->Value;
        }
        else
        {
            $endpoint_base = RNCPHP\Configuration::fetch("CUSTOM_CFG_OIC_BASE_ENDPOINT_DEV")->Value;
            $endpoint_username = RNCPHP\Configuration::fetch("CUSTOM_CFG_OIC_LOGIN_DEV")->Value;
            $endpoint_password = RNCPHP\Configuration::fetch("CUSTOM_CFG_OIC_PASSWORD_DEV")->Value;
        }

        try
        {
            if(!function_exists("curl_init"))
            {
                load_curl();
            }
            $ch = curl_init();
            $incidentID = $incident->ID;
            $contactID = $incident->PrimaryContact->ID;
            $contact = $incident->PrimaryContact;
            $cfields = $incident->CustomFields;
            $assigned = $incident->AssignedTo->Account;

            $payload['attribute1'] = $cfields->CO->attribute1;
            $payload['attribute2'] = $cfields->CO->attribute2;

            // send primary inspection data
            $reqContent["items"][0] = $payload;
            $content = json_encode($reqContent);
            $endpoint = $endpoint_base . '/SOME/RANDOM/ENDPOINT/1.0/';
            curl_setopt_array($ch, array(
                CURLOPT_URL => $endpoint,
                CURLOPT_FOLLOWLOCATION => 1,
                CURLOPT_CUSTOMREQUEST => "POST",
                CURLOPT_POSTFIELDS => $content,
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_CONNECTTIMEOUT => 20,
                CURLOPT_SSL_VERIFYPEER => 0,
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_USERPWD => "$endpoint_username:$endpoint_password",
                CURLINFO_HEADER_OUT => 1,
                CURLOPT_HTTPHEADER => array(
                    'Accept: application/json',
                    'Content-Type: application/json;'
                )
            ));

            $response = trim(curl_exec($ch));
            self::log($content);
            self::log($response);
            curl_close($ch);

        }
        catch(RNCPHP\ConnectAPIError $err)
        {
            self::log("Connect API ERROR-> " . $err->getCode() . "::" . $err->getMessage());
        }
        catch(\Exception $err)
        {
            self::log("PHP Exception-> " . $err->getCode() . "::" . $err->getMessage());
        }
    }

    static function log($msg)
    {
        file_put_contents("/tmp/IncidentAsync" . date("Y-m-d-H") . ".log", date("m/d/Y H:i:s") . ": " . $msg . "\n", FILE_APPEND);
    }

}

class IncidentAysnc_TestHarness implements RNCPM\ObjectEventHandler_TestHarness
{
    static $incident_id = null;

    public static function setup()
    {
        $contact = new RNCPHP\Contact();
        $contact->Name->First = "CPM";
        $contact->Name->Last = "CPM";
        $contact->save();

        $incident = new RNCPHP\Incident();
        $incident->Subject = 'CPM Test';
        $incident->PrimaryContact = $contact;
        $incident->save();

        self::$incident_id = $incident->ID;
    }

    public static function fetchObject($action, $object_type)
    {
        $Incident = $object_type::fetch(self::$incident_id);
        return array(
            $Incident
        );
    }

    public static function validate($action, $obj)
    {
        return true;
    }

    public static function cleanup()
    {
        $Incident = RNCPHP\Incident::fetch(self::$incident_id);
        $Incident->destroy();
        self::$incident_id = null;
    }
}

?>