email_event backend

This commit is contained in:
marcelo.cuiza
2015-06-18 18:12:35 -04:00
parent 1efc67a0f7
commit 1af7b5865e
10 changed files with 2004 additions and 0 deletions

View File

@@ -0,0 +1,273 @@
<?php
namespace ProcessMaker\BusinessModel;
class EmailEvent
{
/*private $arrayFieldDefinition = array(
"EMAIL_EVENT_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "emailEventUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"ACT_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUid"),
"EMAIL_EVENT_FROM" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeUid"),
"EMAIL_EVENT_TO" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "EmailEventUserUid"),
"EMAIL_EVENT_SUBJECT" => array("type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "EmailEventVariables"),
"EMAIL_EVENT_BODY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "EmailEventCorrelation")
);
*/
/**
* Get the email accounts of the current workspace
*
* return array
*/
public function getEmailEventAccounts()
{
try {
$criteria = new \Criteria("workflow");
$criteria->clearSelectColumns();
$criteria->addSelectColumn(\UsersPeer::USR_UID);
$criteria->addSelectColumn(\UsersPeer::USR_EMAIL);
$criteria->add(\UsersPeer::USR_STATUS, "ACTIVE");
$result = \UsersPeer::doSelectRS($criteria);
$result->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$result->next();
$accountsArray = array();
while ($aRow = $result->getRow()) {
if (($aRow['USR_EMAIL'] != null) || ($aRow['USR_EMAIL'] != "")) {
$accountsArray[] = array_change_key_case($aRow, CASE_LOWER);
}
$result->next();
}
return $accountsArray;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the Email-Event data
* @var string $act_uid. uid for activity
* return array
*/
public function getEmailEventData($act_uid)
{
try {
//Get data
$criteria = $this->getEmailEventCriteria();
$criteria->add(\EmailEventPeer::ACT_UID, $act_uid, \Criteria::EQUAL);
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
if(is_array($row)) {
$row = array_change_key_case($row, CASE_LOWER);
}
return $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Save Data for Email-Event
* @var string $prj_uid. Uid for Process
* @var string $arrayData. Data for Trigger
*
* return array
*/
public function save($prj_uid = '', $arrayData = array())
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
//Verify data
$process->throwExceptionIfNotExistsProcess($prj_uid, "projectUid");
//Create
$db = \Propel::getConnection("workflow");
try {
$emailEvent = new \EmailEvent();
$emailEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$emailEventUid = \ProcessMaker\Util\Common::generateUID();
$emailEvent->setEmailEventUid($emailEventUid);
$emailEvent->setProUid($prj_uid);
$db->begin();
$result = $emailEvent->save();
$db->commit();
return $this->getEmailEvent($emailEventUid);
} catch (\Exception $e) {
$db->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Update Email-Event
*
* @param string $emailEventUid Unique id of Email-Event
* @param array $arrayData Data
*
* return array Return data of the Email-Event updated
*/
public function update($emailEventUid, array $arrayData)
{
try {
//Verify data
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
$arrayDataBackup = $arrayData;
//Set variables
$arrayEmailEventData = $this->getEmailEvent($emailEventUid);
//Verify data
$this->verifyIfEmailEventExists($emailEventUid);
//Update
$db = \Propel::getConnection("workflow");
try {
$emailEvent = \EmailEventPeer::retrieveByPK($emailEventUid);
$emailEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$db->begin();
$result = $emailEvent->save();
$db->commit();
$arrayData = $arrayDataBackup;
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
return $arrayData;
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Email-Event
*
* @param string $emailEventUid Unique id of Email-Event
*
* return void
*/
public function delete($emailEventUid)
{
try {
//Verify data
$this->verifyIfEmailEventExists($emailEventUid);
//Delete
$criteria = new \Criteria("workflow");
$criteria->add(\EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, \Criteria::EQUAL);
$result = \EmailEventPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Email-Event
*
* @param string $emailEventUid Unique id of Email-Event
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Email-Event
*/
public function getEmailEvent($emailEventUid)
{
try {
//Verify data
$this->verifyIfEmailEventExists($emailEventUid);
//Get data
$criteria = $this->getEmailEventCriteria();
$criteria->add(\EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, \Criteria::EQUAL);
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Return
return $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Email-Event
*
* @param string $emailEventUid Unique id of Email-Event
*
* return bool Return true if exists the Email-Event, false otherwise
*/
public function exists($emailEventUid)
{
try {
$obj = \EmailEventPeer::retrieveByPK($emailEventUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Email-Event
*
* return object
*/
public function getEmailEventCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_UID);
$criteria->addSelectColumn(\EmailEventPeer::PRO_UID);
$criteria->addSelectColumn(\EmailEventPeer::ACT_UID);
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_FROM);
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_TO);
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_SUBJECT);
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_BODY);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
public function verifyIfEmailEventExists($emailEventUid)
{
if (!$this->exists($emailEventUid)) {
throw new \Exception(\G::LoadTranslation("ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST", array("Email Event Uid", $emailEventUid)));
}
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace ProcessMaker\Services\Api\Project;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Project\EmailEvent Api Controller
*
* @protected
*/
class EmailEvent extends Api
{
private $EmailEvent;
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
$this->EmailEvent = new \ProcessMaker\BusinessModel\EmailEvent();
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/email-event/accounts
*
* @param string $prj_uid {@min 1} {@max 32}
*/
public function doGetEmailEventAccounts($prj_uid)
{
try {
$response = $this->EmailEvent->GetEmailEventAccounts();
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url GET /:prj_uid/email-event/:act_uid
*
* @param string $prj_uid {@min 1} {@max 32}
* @param string $act_uid {@min 1} {@max 32}
*/
public function doGetEmailEvent($prj_uid, $act_uid )
{
try {
$response = $this->EmailEvent->getEmailEventData($act_uid);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url POST /:prj_uid/email-event
*
* @param string $prj_uid {@min 1} {@max 32}
*/
public function doPostEmailEvent($prj_uid, array $request_data)
{
try {
$response = $this->EmailEvent->save($prj_uid, $request_data);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url PUT /:prj_uid/email-event/:email_event_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $email_event_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPutEmailEvent($prj_uid, $email_event_uid, array $request_data)
{
try {
$arrayData = $this->EmailEvent->update($email_event_uid, $request_data);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url DELETE /:prj_uid/email-event/:email_event_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $email_event_uid {@min 32}{@max 32}
*/
public function doDeleteEmailEvent($prj_uid, $email_event_uid)
{
try {
$this->EmailEvent->delete($email_event_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}

View File

@@ -41,6 +41,7 @@ debug = 1
message-type-variable = "ProcessMaker\Services\Api\Project\MessageType\Variable"
web-entry-event = "ProcessMaker\Services\Api\Project\WebEntryEvent"
message-event-definition = "ProcessMaker\Services\Api\Project\MessageEventDefinition"
email-event = "ProcessMaker\Services\Api\Project\EmailEvent"
[alias: projects]
project = "ProcessMaker\Services\Api\Project"