PM-939 "Support for Message-Event (Endpoints and Backend)"

- Se han implementado los siguientes Endpoints:
    GET    /api/1.0/{workspace}/project/{prj_uid}/message-event-definitions
    GET    /api/1.0/{workspace}/project/{prj_uid}/message-event-definition/{msged_uid}
    GET    /api/1.0/{workspace}/project/{prj_uid}/message-event-definition/event/{evn_uid}
    POST   /api/1.0/{workspace}/project/{prj_uid}/message-event-definition
    PUT    /api/1.0/{workspace}/project/{prj_uid}/message-event-definition/{msged_uid}
    DELETE /api/1.0/{workspace}/project/{prj_uid}/message-event-definition/{msged_uid}
- Se han implementado los metodos necesarios/requeridos para el backend
  del DESIGNER para esta nueva funcionalidad
This commit is contained in:
Victor Saisa Lopez
2015-02-13 16:32:43 -04:00
parent 8b18dda574
commit b83718f295
32 changed files with 8344 additions and 58 deletions

View File

@@ -0,0 +1,706 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageEventDefinition
{
private $arrayFieldDefinition = array(
"MSGED_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"EVN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUid"),
"MSGT_UID" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageTypeUid"),
"MSGED_USR_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionUserUid"),
"MSGED_VARIABLES" => array("type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionVariables"),
"MSGED_CORRELATION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionCorrelation")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array();
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
*
* return bool Return true if exists the Message-Event-Definition, false otherwise
*/
public function exists($messageEventDefinitionUid)
{
try {
$obj = \MessageEventDefinitionPeer::retrieveByPK($messageEventDefinitionUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Event of a Message-Event-Definition
*
* @param string $projectUid Unique id of Project
* @param string $eventUid Unique id of Event
* @param string $messageEventDefinitionUidToExclude Unique id of Message-Event-Definition to exclude
*
* return bool Return true if exists the Event of a Message-Event-Definition, false otherwise
*/
public function existsEvent($projectUid, $eventUid, $messageEventDefinitionUidToExclude = "")
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_UID);
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
if ($messageEventDefinitionUidToExclude != "") {
$criteria->add(\MessageEventDefinitionPeer::MSGED_UID, $messageEventDefinitionUidToExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\MessageEventDefinitionPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
return ($rsCriteria->next())? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exists the Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exists the Message-Event-Definition
*/
public function throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $fieldNameForException)
{
try {
if (!$this->exists($messageEventDefinitionUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_DOES_NOT_EXIST", array($fieldNameForException, $messageEventDefinitionUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if is registered the Event
*
* @param string $projectUid Unique id of Project
* @param string $eventUid Unique id of Event
* @param string $fieldNameForException Field name for the exception
* @param string $messageEventDefinitionUidToExclude Unique id of Message-Event-Definition to exclude
*
* return void Throw exception if is registered the Event
*/
public function throwExceptionIfEventIsRegistered($projectUid, $eventUid, $fieldNameForException, $messageEventDefinitionUidToExclude = "")
{
try {
if ($this->existsEvent($projectUid, $eventUid, $messageEventDefinitionUidToExclude)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_ALREADY_REGISTERED", array($fieldNameForException, $eventUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageEventDefinitionUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageEventDefinitionData = ($messageEventDefinitionUid == "")? array() : $this->getMessageEventDefinition($messageEventDefinitionUid, true);
$flagInsert = ($messageEventDefinitionUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageEventDefinitionData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$messageType = new \ProcessMaker\BusinessModel\MessageType();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["EVN_UID"])) {
$this->throwExceptionIfEventIsRegistered($projectUid, $arrayData["EVN_UID"], $this->arrayFieldNameForException["eventUid"], $messageEventDefinitionUid);
}
if (isset($arrayData["EVN_UID"])) {
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
$bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayData["EVN_UID"]);
if (is_null($bpmnEvent)) {
throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_EXIST", array($this->arrayFieldNameForException["eventUid"], $arrayData["EVN_UID"])));
}
if (!in_array($bpmnEvent->getEvnType(), $arrayEventType) || !in_array($bpmnEvent->getEvnMarker(), $arrayEventMarker)) {
throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_IS_MESSAGE_EVENT", array($this->arrayFieldNameForException["eventUid"], $arrayData["EVN_UID"])));
}
}
if (isset($arrayData["MSGT_UID"]) && $arrayData["MSGT_UID"] . "" != "") {
if (!$messageType->exists($arrayData["MSGT_UID"])) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_TYPE_NOT_EXIST", array($this->arrayFieldNameForException["messageTypeUid"], $arrayData["MSGT_UID"])));
}
}
$flagCheckData = false;
$flagCheckData = (isset($arrayData["MSGT_UID"]) && $arrayData["MSGT_UID"] . "" != "")? true : $flagCheckData;
$flagCheckData = (isset($arrayData["MSGED_VARIABLES"]))? true : $flagCheckData;
if ($flagCheckData && $arrayFinalData["MSGT_UID"] . "" != "") {
$arrayMessageTypeVariable = array();
$arrayMessageTypeData = $messageType->getMessageType($arrayFinalData["MSGT_UID"], true);
foreach ($arrayMessageTypeData["MSGT_VARIABLES"] as $value) {
$arrayMessageTypeVariable[$value["MSGTV_NAME"]] = $value["MSGTV_DEFAULT_VALUE"];
}
if (count($arrayMessageTypeVariable) != count($arrayFinalData["MSGED_VARIABLES"]) || count(array_diff_key($arrayMessageTypeVariable, $arrayFinalData["MSGED_VARIABLES"])) > 0) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_VARIABLES_DO_NOT_MEET_DEFINITION"));
}
}
if (isset($arrayData["MSGED_USR_UID"])) {
$process->throwExceptionIfNotExistsUser($arrayData["MSGED_USR_UID"], $this->arrayFieldNameForException["messageEventDefinitionUserUid"]);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Event-Definition for a Project
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Event-Definition created
*/
public function create($projectUid, array $arrayData)
{
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);
unset($arrayData["MSGED_UID"]);
unset($arrayData["PRJ_UID"]);
//Verify data
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageEventDefinition = new \MessageEventDefinition();
if (!isset($arrayData["MSGT_UID"]) || $arrayData["MSGT_UID"] . "" == "") {
$arrayData["MSGT_UID"] = "";
$arrayData["MSGED_VARIABLES"] = array();
}
if (!isset($arrayData["MSGED_VARIABLES"])) {
$arrayData["MSGED_VARIABLES"] = array();
}
$messageEventDefinitionUid = \ProcessMaker\Util\Common::generateUID();
$messageEventDefinition->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageEventDefinition->setMsgedUid($messageEventDefinitionUid);
$messageEventDefinition->setPrjUid($projectUid);
if (isset($arrayData["MSGED_VARIABLES"])) {
$messageEventDefinition->setMsgedVariables(serialize($arrayData["MSGED_VARIABLES"]));
}
if ($messageEventDefinition->validate()) {
$cnn->begin();
$result = $messageEventDefinition->save();
$cnn->commit();
//Task - User
if (isset($arrayData["MSGED_USR_UID"])) {
$bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayData["EVN_UID"]);
//Event - START-MESSAGE-EVENT
if (is_null($bpmnEvent) && $bpmnEvent->getEvnType() == "START" && $bpmnEvent->getEvnMarker() == "MESSAGECATCH") {
//Message-Event-Task-Relation - Get Task
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $projectUid,
\MessageEventTaskRelationPeer::EVN_UID => $bpmnEvent->getEvnUid()
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
//Assign
$task = new \Tasks();
$result = $task->assignUser($arrayMessageEventTaskRelationData["TAS_UID"], $arrayData["MSGED_USR_UID"], 1);
}
}
}
//Return
return $this->getMessageEventDefinition($messageEventDefinitionUid);
} else {
$msg = "";
foreach ($messageEventDefinition->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Update Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param array $arrayData Data
*
* return array Return data of the Message-Event-Definition updated
*/
public function update($messageEventDefinitionUid, array $arrayData)
{
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);
$arrayDataBackup = $arrayData;
unset($arrayData["MSGED_UID"]);
unset($arrayData["PRJ_UID"]);
//Set variables
$arrayMessageEventDefinitionData = $this->getMessageEventDefinition($messageEventDefinitionUid, true);
//Verify data
$this->throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $this->arrayFieldNameForException["messageEventDefinitionUid"]);
$this->throwExceptionIfDataIsInvalid($messageEventDefinitionUid, $arrayMessageEventDefinitionData["PRJ_UID"], $arrayData);
//Update
$cnn = \Propel::getConnection("workflow");
try {
$messageEventDefinition = \MessageEventDefinitionPeer::retrieveByPK($messageEventDefinitionUid);
if (isset($arrayData["MSGT_UID"]) && $arrayData["MSGT_UID"] . "" == "") {
$arrayData["MSGED_VARIABLES"] = array();
}
$messageEventDefinition->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if (isset($arrayData["MSGED_VARIABLES"])) {
$messageEventDefinition->setMsgedVariables(serialize($arrayData["MSGED_VARIABLES"]));
}
if ($messageEventDefinition->validate()) {
$cnn->begin();
$result = $messageEventDefinition->save();
$cnn->commit();
//Task - User
if (isset($arrayData["MSGED_USR_UID"]) && $arrayData["MSGED_USR_UID"] != $arrayMessageEventDefinitionData["MSGED_USR_UID"]) {
$bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayMessageEventDefinitionData["EVN_UID"]);
//Event - START-MESSAGE-EVENT
if (is_null($bpmnEvent) && $bpmnEvent->getEvnType() == "START" && $bpmnEvent->getEvnMarker() == "MESSAGECATCH") {
//Message-Event-Task-Relation - Get Task
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $arrayMessageEventDefinitionData["PRJ_UID"],
\MessageEventTaskRelationPeer::EVN_UID => $bpmnEvent->getEvnUid()
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
//Unassign
$taskUser = new \TaskUser();
$criteria = new \Criteria("workflow");
$criteria->add(\TaskUserPeer::TAS_UID, $arrayMessageEventTaskRelationData["TAS_UID"]);
$rsCriteria = \TaskUserPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$result = $taskUser->remove($row["TAS_UID"], $row["USR_UID"], $row["TU_TYPE"], $row["TU_RELATION"]);
}
//Assign
$task = new \Tasks();
$result = $task->assignUser($arrayMessageEventTaskRelationData["TAS_UID"], $arrayData["MSGED_USR_UID"], 1);
}
}
}
//Return
$arrayData = $arrayDataBackup;
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} else {
$msg = "";
foreach ($messageEventDefinition->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
*
* return void
*/
public function delete($messageEventDefinitionUid)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $this->arrayFieldNameForException["messageEventDefinitionUid"]);
//Delete
$criteria = new \Criteria("workflow");
$criteria->add(\MessageEventDefinitionPeer::MSGED_UID, $messageEventDefinitionUid, \Criteria::EQUAL);
$result = \MessageEventDefinitionPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set Message-Event-Definition-Variables by Message-Type for a record
*
* @param array $record Record
*
* return array Return the record
*/
public function setMessageEventDefinitionVariablesForRecordByMessageType(array $record)
{
try {
$record["MSGED_VARIABLES"] = ($record["MSGED_VARIABLES"] . "" != "")? unserialize($record["MSGED_VARIABLES"]) : array();
if ($record["MSGT_UID"] . "" != "") {
$arrayMessageTypeVariable = array();
$messageType = new \ProcessMaker\BusinessModel\MessageType();
if ($messageType->exists($record["MSGT_UID"])) {
$arrayMessageTypeData = $messageType->getMessageType($record["MSGT_UID"], true);
foreach ($arrayMessageTypeData["MSGT_VARIABLES"] as $value) {
$arrayMessageTypeVariable[$value["MSGTV_NAME"]] = (isset($record["MSGED_VARIABLES"][$value["MSGTV_NAME"]]))? $record["MSGED_VARIABLES"][$value["MSGTV_NAME"]] : $value["MSGTV_DEFAULT_VALUE"];
}
}
$record["MSGED_VARIABLES"] = $arrayMessageTypeVariable;
}
//Return
return $record;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Event-Definition
*
* return object
*/
public function getMessageEventDefinitionCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::EVN_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGT_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_USR_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_VARIABLES);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_CORRELATION);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Definition from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Event-Definition
*/
public function getMessageEventDefinitionDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGED_UID") => $record["MSGED_UID"],
$this->getFieldNameByFormatFieldName("EVN_UID") => $record["EVN_UID"],
$this->getFieldNameByFormatFieldName("MSGT_UID") => $record["MSGT_UID"] . "",
$this->getFieldNameByFormatFieldName("MSGED_USR_UID") => $record["MSGED_USR_UID"] . "",
$this->getFieldNameByFormatFieldName("MSGED_VARIABLES") => $record["MSGED_VARIABLES"],
$this->getFieldNameByFormatFieldName("MSGED_CORRELATION") => $record["MSGED_CORRELATION"] . ""
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Message-Event-Definitions
*
* @param string $projectUid Unique id of Project
*
* return array Return an array with all Message-Event-Definitions
*/
public function getMessageEventDefinitions($projectUid)
{
try {
$arrayMessageEventDefinition = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
//Get data
$criteria = $this->getMessageEventDefinitionCriteria();
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $this->setMessageEventDefinitionVariablesForRecordByMessageType($rsCriteria->getRow());
$arrayMessageEventDefinition[] = $this->getMessageEventDefinitionDataFromRecord($row);
}
//Return
return $arrayMessageEventDefinition;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Definition
*/
public function getMessageEventDefinition($messageEventDefinitionUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $this->arrayFieldNameForException["messageEventDefinitionUid"]);
//Get data
$criteria = $this->getMessageEventDefinitionCriteria();
$criteria->add(\MessageEventDefinitionPeer::MSGED_UID, $messageEventDefinitionUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $this->setMessageEventDefinitionVariablesForRecordByMessageType($rsCriteria->getRow());
//Return
return (!$flagGetRecord)? $this->getMessageEventDefinitionDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Definition by unique id of Event
*
* @param string $projectUid Unique id of Project
* @param string $eventUid Unique id of Event
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Definition by unique id of Event
*/
public function getMessageEventDefinitionByEvent($projectUid, $eventUid, $flagGetRecord = false)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
if (!$this->existsEvent($projectUid, $eventUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_DOES_NOT_IS_REGISTERED", array($this->arrayFieldNameForException["eventUid"], $eventUid)));
}
//Get data
$criteria = $this->getMessageEventDefinitionCriteria();
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
$criteria->add(\MessageEventDefinitionPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $this->setMessageEventDefinitionVariablesForRecordByMessageType($rsCriteria->getRow());
//Return
return (!$flagGetRecord)? $this->getMessageEventDefinitionDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,408 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageEventRelation
{
private $arrayFieldDefinition = array(
"MSGER_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventRelationUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"EVN_UID_THROW" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUidThrow"),
"EVN_UID_CATCH" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUidCatch")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array();
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Message-Event-Relation
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
*
* return bool Return true if exists the Message-Event-Relation, false otherwise
*/
public function exists($messageEventRelationUid)
{
try {
$obj = \MessageEventRelationPeer::retrieveByPK($messageEventRelationUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Event-Relation of a Message-Event-Relation
*
* @param string $projectUid Unique id of Project
* @param string $eventUidThrow Unique id of Event (throw)
* @param string $eventUidCatch Unique id of Event (catch)
* @param string $messageEventRelationUidToExclude Unique id of Message-Event-Relation to exclude
*
* return bool Return true if exists the Event-Relation of a Message-Event-Relation, false otherwise
*/
public function existsEventRelation($projectUid, $eventUidThrow, $eventUidCatch, $messageEventRelationUidToExclude = "")
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventRelationPeer::MSGER_UID);
$criteria->add(\MessageEventRelationPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
if ($messageEventRelationUidToExclude != "") {
$criteria->add(\MessageEventRelationPeer::MSGER_UID, $messageEventRelationUidToExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\MessageEventRelationPeer::EVN_UID_THROW, $eventUidThrow, \Criteria::EQUAL);
$criteria->add(\MessageEventRelationPeer::EVN_UID_CATCH, $eventUidCatch, \Criteria::EQUAL);
$rsCriteria = \MessageEventRelationPeer::doSelectRS($criteria);
return ($rsCriteria->next())? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exists the Message-Event-Relation
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exists the Message-Event-Relation
*/
public function throwExceptionIfNotExistsMessageEventRelation($messageEventRelationUid, $fieldNameForException)
{
try {
if (!$this->exists($messageEventRelationUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_RELATION_DOES_NOT_EXIST", array($fieldNameForException, $messageEventRelationUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if is registered the Event-Relation
*
* @param string $projectUid Unique id of Project
* @param string $eventUidThrow Unique id of Event (throw)
* @param string $eventUidCatch Unique id of Event (catch)
* @param string $messageEventRelationUidToExclude Unique id of Message-Event-Relation to exclude
*
* return void Throw exception if is registered the Event-Relation
*/
public function throwExceptionIfEventRelationIsRegistered($projectUid, $eventUidThrow, $eventUidCatch, $messageEventRelationUidToExclude = "")
{
try {
if ($this->existsEventRelation($projectUid, $eventUidThrow, $eventUidCatch, $messageEventRelationUidToExclude)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_RELATION_ALREADY_REGISTERED"));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageEventRelationUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageEventRelationData = ($messageEventRelationUid == "")? array() : $this->getMessageEventRelation($messageEventRelationUid, true);
$flagInsert = ($messageEventRelationUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageEventRelationData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["EVN_UID_THROW"]) || isset($arrayData["EVN_UID_CATCH"])) {
$this->throwExceptionIfEventRelationIsRegistered($projectUid, $arrayFinalData["EVN_UID_THROW"], $arrayFinalData["EVN_UID_CATCH"], $messageEventRelationUid);
}
if (isset($arrayData["EVN_UID_THROW"]) || isset($arrayData["EVN_UID_CATCH"])) {
//Flow
$bpmnFlow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_TYPE => "MESSAGE",
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $arrayFinalData["EVN_UID_THROW"],
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnEvent",
\BpmnFlowPeer::FLO_ELEMENT_DEST => $arrayFinalData["EVN_UID_CATCH"],
\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => "bpmnEvent"
));
if (is_null($bpmnFlow)) {
throw new \Exception(\G::LoadTranslation(
"ID_MESSAGE_EVENT_RELATION_DOES_NOT_EXIST_MESSAGE_FLOW",
array(
$this->arrayFieldNameForException["eventUidThrow"], $arrayFinalData["EVN_UID_THROW"],
$this->arrayFieldNameForException["eventUidCatch"], $arrayFinalData["EVN_UID_CATCH"]
)
));
}
//Check and validate Message Flow
$bpmn = new \ProcessMaker\Project\Bpmn();
$bpmn->throwExceptionFlowIfIsAnInvalidMessageFlow(array(
"FLO_TYPE" => "MESSAGE",
"FLO_ELEMENT_ORIGIN" => $arrayFinalData["EVN_UID_THROW"],
"FLO_ELEMENT_ORIGIN_TYPE" => "bpmnEvent",
"FLO_ELEMENT_DEST" => $arrayFinalData["EVN_UID_CATCH"],
"FLO_ELEMENT_DEST_TYPE" => "bpmnEvent"
));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Event-Relation for a Project
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Event-Relation created
*/
public function create($projectUid, array $arrayData)
{
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);
unset($arrayData["MSGER_UID"]);
unset($arrayData["PRJ_UID"]);
//Verify data
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageEventRelation = new \MessageEventRelation();
$messageEventRelationUid = \ProcessMaker\Util\Common::generateUID();
$messageEventRelation->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageEventRelation->setMsgerUid($messageEventRelationUid);
$messageEventRelation->setPrjUid($projectUid);
if ($messageEventRelation->validate()) {
$cnn->begin();
$result = $messageEventRelation->save();
$cnn->commit();
//Return
return $this->getMessageEventRelation($messageEventRelationUid);
} else {
$msg = "";
foreach ($messageEventRelation->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Message-Event-Relation
*
* @param array $arrayCondition Conditions
*
* return void
*/
public function deleteWhere(array $arrayCondition)
{
try {
//Delete
$criteria = new \Criteria("workflow");
foreach ($arrayCondition as $key => $value) {
$criteria->add($key, $value, \Criteria::EQUAL);
}
$result = \MessageEventRelationPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Event-Relation
*
* return object
*/
public function getMessageEventRelationCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventRelationPeer::MSGER_UID);
$criteria->addSelectColumn(\MessageEventRelationPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageEventRelationPeer::EVN_UID_THROW);
$criteria->addSelectColumn(\MessageEventRelationPeer::EVN_UID_CATCH);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Relation from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Event-Relation
*/
public function getMessageEventRelationDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGER_UID") => $record["MSGER_UID"],
$this->getFieldNameByFormatFieldName("EVN_UID_THROW") => $record["EVN_UID_THROW"],
$this->getFieldNameByFormatFieldName("EVN_UID_CATCH") => $record["EVN_UID_CATCH"]
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Relation
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Relation
*/
public function getMessageEventRelation($messageEventRelationUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventRelation($messageEventRelationUid, $this->arrayFieldNameForException["messageEventRelationUid"]);
//Get data
$criteria = $this->getMessageEventRelationCriteria();
$criteria->add(\MessageEventRelationPeer::MSGER_UID, $messageEventRelationUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventRelationDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,352 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageEventTaskRelation
{
private $arrayFieldDefinition = array(
"MSGETR_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventTaskRelationUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"EVN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUid"),
"TAS_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "taskUid")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array();
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Message-Event-Task-Relation
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
*
* return bool Return true if exists the Message-Event-Task-Relation, false otherwise
*/
public function exists($messageEventTaskRelationUid)
{
try {
$obj = \MessageEventTaskRelationPeer::retrieveByPK($messageEventTaskRelationUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exists the Message-Event-Task-Relation
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exists the Message-Event-Task-Relation
*/
public function throwExceptionIfNotExistsMessageEventTaskRelation($messageEventTaskRelationUid, $fieldNameForException)
{
try {
if (!$this->exists($messageEventTaskRelationUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_TASK_RELATION_DOES_NOT_EXIST", array($fieldNameForException, $messageEventTaskRelationUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageEventTaskRelationUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageEventTaskRelationData = ($messageEventTaskRelationUid == "")? array() : $this->getMessageEventTaskRelation($messageEventTaskRelationUid, true);
$flagInsert = ($messageEventTaskRelationUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageEventTaskRelationData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Event-Task-Relation for a Project
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Event-Task-Relation created
*/
public function create($projectUid, array $arrayData)
{
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);
unset($arrayData["MSGETR_UID"]);
unset($arrayData["PRJ_UID"]);
//Verify data
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageEventTaskRelation = new \MessageEventTaskRelation();
$messageEventTaskRelationUid = \ProcessMaker\Util\Common::generateUID();
$messageEventTaskRelation->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageEventTaskRelation->setMsgetrUid($messageEventTaskRelationUid);
$messageEventTaskRelation->setPrjUid($projectUid);
if ($messageEventTaskRelation->validate()) {
$cnn->begin();
$result = $messageEventTaskRelation->save();
$cnn->commit();
//Return
return $this->getMessageEventTaskRelation($messageEventTaskRelationUid);
} else {
$msg = "";
foreach ($messageEventTaskRelation->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Message-Event-Task-Relation
*
* @param array $arrayCondition Conditions
*
* return void
*/
public function deleteWhere(array $arrayCondition)
{
try {
//Delete
$criteria = new \Criteria("workflow");
foreach ($arrayCondition as $key => $value) {
$criteria->add($key, $value, \Criteria::EQUAL);
}
$result = \MessageEventTaskRelationPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Event-Task-Relation
*
* return object
*/
public function getMessageEventTaskRelationCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::MSGETR_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::EVN_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::TAS_UID);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Task-Relation from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Event-Task-Relation
*/
public function getMessageEventTaskRelationDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGETR_UID") => $record["MSGETR_UID"],
$this->getFieldNameByFormatFieldName("EVN_UID") => $record["EVN_UID"],
$this->getFieldNameByFormatFieldName("TAS_UID") => $record["TAS_UID"]
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Task-Relation
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Task-Relation
*/
public function getMessageEventTaskRelation($messageEventTaskRelationUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventTaskRelation($messageEventTaskRelationUid, $this->arrayFieldNameForException["messageEventTaskRelationUid"]);
//Get data
$criteria = $this->getMessageEventTaskRelationCriteria();
$criteria->add(\MessageEventTaskRelationPeer::MSGETR_UID, $messageEventTaskRelationUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventTaskRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventTaskRelationDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Task-Relation
*
* @param array $arrayCondition Conditions
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Task-Relation
*/
public function getMessageEventTaskRelationWhere(array $arrayCondition, $flagGetRecord = false)
{
try {
//Get data
$criteria = $this->getMessageEventTaskRelationCriteria();
foreach ($arrayCondition as $key => $value) {
$criteria->add($key, $value, \Criteria::EQUAL);
}
$rsCriteria = \MessageEventTaskRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventTaskRelationDataFromRecord($row) : $row;
} else {
//Return
return null;
}
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -359,9 +359,11 @@ class WebEntryEvent
//Task
$task = new \Task();
$prefix = "wee-";
$this->webEntryEventWebEntryTaskUid = $task->create(
array(
"TAS_UID" => \ProcessMaker\Util\Common::generateUID(),
"TAS_UID" => $prefix . substr(\ProcessMaker\Util\Common::generateUID(), (32 - strlen($prefix)) * -1),
"PRO_UID" => $projectUid,
"TAS_TYPE" => "WEBENTRYEVENT",
"TAS_TITLE" => "WEBENTRYEVENT",
@@ -765,6 +767,8 @@ class WebEntryEvent
throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
$this->deleteWebEntry($this->webEntryEventWebEntryUid, $this->webEntryEventWebEntryTaskUid);
throw $e;

View File

@@ -22,6 +22,15 @@ class BpmnWorkflow extends Project\Bpmn
const BPMN_GATEWAY_INCLUSIVE = "INCLUSIVE";
const BPMN_GATEWAY_EXCLUSIVE = "EXCLUSIVE";
private $arrayTaskAttribute = array(
"gateway-to-gateway" => array("type" => "GATEWAYTOGATEWAY", "prefix" => "gtg-"),
"start-message-event" => array("type" => "START-MESSAGE-EVENT", "prefix" => "sme-"),
"end-message-event" => array("type" => "END-MESSAGE-EVENT", "prefix" => "eme-"),
"intermediate-start-message-event" => array("type" => "INTERMEDIATE-START-MESSAGE-EVENT", "prefix" => "isme-"),
"intermediate-end-message-event" => array("type" => "INTERMEDIATE-END-MESSAGE-EVENT", "prefix" => "ieme-")
);
private $arrayMessageEventTaskRelation = array();
/**
* OVERRIDES
@@ -247,18 +256,19 @@ class BpmnWorkflow extends Project\Bpmn
//WebEntry-Event - Update
$this->updateWebEntryEventByEvent($data["FLO_ELEMENT_ORIGIN"], array("ACT_UID" => $data["FLO_ELEMENT_DEST"]));
break;
case "bpmnEvent":
$messageEventRelationUid = $this->createMessageEventRelationByBpmnFlow(\BpmnFlowPeer::retrieveByPK($floUid));
break;
}
break;
case "bpmnActivity":
switch ($data["FLO_ELEMENT_DEST_TYPE"]) {
case "bpmnEvent":
$actUid = $data["FLO_ELEMENT_ORIGIN"];
$evnUid = $data["FLO_ELEMENT_DEST"];
$event = \BpmnEventPeer::retrieveByPK($evnUid);
$event = \BpmnEventPeer::retrieveByPK($data["FLO_ELEMENT_DEST"]);
// setting as end task
if ($event && $event->getEvnType() == "END") {
$this->wp->setEndTask($actUid);
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
$this->wp->setEndTask($data["FLO_ELEMENT_ORIGIN"]);
}
break;
}
@@ -306,7 +316,7 @@ class BpmnWorkflow extends Project\Bpmn
) {
$event = \BpmnEventPeer::retrieveByPK($flowBefore->getFloElementDest());
if (!is_null($event) && $event->getEvnType() == "END") {
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
//Remove as end task
$this->wp->setEndTask($flowBefore->getFloElementOrigin(), false);
@@ -322,7 +332,7 @@ class BpmnWorkflow extends Project\Bpmn
) {
$event = \BpmnEventPeer::retrieveByPK($flowBefore->getFloElementDest());
if (!is_null($event) && $event->getEvnType() == "END") {
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
//Remove as end task
$this->wp->setEndTask($flowBefore->getFloElementOrigin(), false);
}
@@ -336,6 +346,27 @@ class BpmnWorkflow extends Project\Bpmn
) {
$this->wp->removeRouteFromTo($flowBefore->getFloElementOrigin(), $flowBefore->getFloElementDest());
}
//Verify case: Event1(message) -> Event2(message) -----Update-to----> Event(message) -> Event(message)
if ($flowBefore->getFloType() == "MESSAGE" &&
$flowBefore->getFloElementOriginType() == "bpmnEvent" && $flowBefore->getFloElementDestType() == "bpmnEvent"
) {
//Delete Message-Event-Relation
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$messageEventRelation->deleteWhere(array(
\MessageEventRelationPeer::PRJ_UID => $flowBefore->getPrjUid(),
\MessageEventRelationPeer::EVN_UID_THROW => $flowBefore->getFloElementOrigin(),
\MessageEventRelationPeer::EVN_UID_CATCH => $flowBefore->getFloElementDest()
));
//Create Message-Event-Relation
if ($flowCurrent->getFloType() == "MESSAGE" &&
$flowCurrent->getFloElementOriginType() == "bpmnEvent" && $flowCurrent->getFloElementDestType() == "bpmnEvent"
) {
$messageEventRelationUid = $this->createMessageEventRelationByBpmnFlow($flowCurrent);
}
}
}
public function removeFlow($floUid)
@@ -379,7 +410,7 @@ class BpmnWorkflow extends Project\Bpmn
// => find the corresponding task and unset it as start task
$event = \BpmnEventPeer::retrieveByPK($flow->getFloElementDest());
if (! is_null($event) && $event->getEvnType() == "END") {
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
$activity = \BpmnActivityPeer::retrieveByPK($flow->getFloElementOrigin());
if (! is_null($activity)) {
@@ -396,6 +427,23 @@ class BpmnWorkflow extends Project\Bpmn
break;
}
break;
case "bpmnEvent":
switch ($flow->getFloElementDestType()) {
//Event1 -> Event2
case "bpmnEvent":
if ($flow->getFloType() == "MESSAGE") {
//Delete Message-Event-Relation
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$messageEventRelation->deleteWhere(array(
\MessageEventRelationPeer::PRJ_UID => $flow->getPrjUid(),
\MessageEventRelationPeer::EVN_UID_THROW => $flow->getFloElementOrigin(),
\MessageEventRelationPeer::EVN_UID_CATCH => $flow->getFloElementDest()
));
}
break;
}
break;
}
}
@@ -411,12 +459,12 @@ class BpmnWorkflow extends Project\Bpmn
$eventUid = parent::addEvent($data);
$event = \BpmnEventPeer::retrieveByPK($eventUid);
//Delete case scheduler
// create case scheduler
if ($event && $event->getEvnMarker() == "TIMER" && $event->getEvnType() == "START") {
$this->wp->addCaseScheduler($eventUid);
}
//Delete WebEntry-Event
// create web entry
if ($event && $event->getEvnMarker() == "MESSAGE" && $event->getEvnType() == "START") {
$this->wp->addWebEntry($eventUid);
}
@@ -428,19 +476,63 @@ class BpmnWorkflow extends Project\Bpmn
{
$event = \BpmnEventPeer::retrieveByPK($eventUid);
// delete case scheduler
//Delete case scheduler
if ($event && $event->getEvnMarker() == "TIMER" && $event->getEvnType() == "START") {
$this->wp->removeCaseScheduler($eventUid);
}
// delete web entry
if (!is_null($event) && $event->getEvnType() == "START") {
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
if (!is_null($event)) {
//WebEntry-Event - Delete
if ($event->getEvnType() == "START") {
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
if ($webEntryEvent->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayWebEntryEventData = $webEntryEvent->getWebEntryEventByEvent($event->getPrjUid(), $eventUid, true);
if ($webEntryEvent->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayWebEntryEventData = $webEntryEvent->getWebEntryEventByEvent($event->getPrjUid(), $eventUid, true);
$webEntryEvent->delete($arrayWebEntryEventData["WEE_UID"]);
$webEntryEvent->delete($arrayWebEntryEventData["WEE_UID"]);
}
}
//Message-Event-Definition - Delete
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
if (!is_null($event) &&
in_array($event->getEvnType(), $arrayEventType) && in_array($event->getEvnMarker(), $arrayEventMarker)
) {
$messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
if ($messageEventDefinition->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayMessageEventDefinitionData = $messageEventDefinition->getMessageEventDefinitionByEvent($event->getPrjUid(), $eventUid, true);
$messageEventDefinition->delete($arrayMessageEventDefinitionData["MSGED_UID"]);
}
}
//Message-Event-Task-Relation - Delete
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $event->getPrjUid(),
\MessageEventTaskRelationPeer::EVN_UID => $event->getEvnUid()
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
//Task - Delete
$arrayTaskData = $this->wp->getTask($arrayMessageEventTaskRelationData["TAS_UID"]);
if (!is_null($arrayTaskData)) {
$this->wp->removeTask($arrayMessageEventTaskRelationData["TAS_UID"]);
}
//Message-Event-Task-Relation - Delete
$messageEventTaskRelation->deleteWhere(array(\MessageEventTaskRelationPeer::MSGETR_UID => $arrayMessageEventTaskRelationData["MSGETR_UID"]));
//Array - Delete element
unset($this->arrayMessageEventTaskRelation[$eventUid]);
}
}
@@ -462,6 +554,84 @@ class BpmnWorkflow extends Project\Bpmn
//}
}
public function createTaskByElement($elementUid, $elementType, $key)
{
try {
if (isset($this->arrayMessageEventTaskRelation[$elementUid])) {
$taskUid = $this->arrayMessageEventTaskRelation[$elementUid];
} else {
$taskPosX = 0;
$taskPosY = 0;
$flow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $elementUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => $elementType
));
if (!is_null($flow)) {
$arrayFlowData = $flow->toArray();
$taskPosX = (int)($arrayFlowData["FLO_X1"]);
$taskPosY = (int)($arrayFlowData["FLO_Y1"]);
} else {
$flow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_ELEMENT_DEST => $elementUid,
\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => $elementType
));
if (!is_null($flow)) {
$arrayFlowData = $flow->toArray();
$taskPosX = (int)($arrayFlowData["FLO_X2"]);
$taskPosY = (int)($arrayFlowData["FLO_Y2"]);
}
}
$prefix = $this->arrayTaskAttribute[$key]["prefix"];
$taskType = $this->arrayTaskAttribute[$key]["type"];
$taskUid = $this->wp->addTask(array(
"TAS_UID" => $prefix . substr(Util\Common::generateUID(), (32 - strlen($prefix)) * -1),
"TAS_TYPE" => $taskType,
"TAS_TITLE" => $taskType,
"TAS_POSX" => $taskPosX,
"TAS_POSY" => $taskPosY
));
if ($elementType == "bpmnEvent" &&
in_array($key, array("start-message-event", "end-message-event", "intermediate-start-message-event"))
) {
if ($key == "intermediate-start-message-event") {
//Task - User
//Assign to admin
$task = new \Tasks();
$result = $task->assignUser($taskUid, "00000000000000000000000000000001", 1);
}
//Message-Event-Task-Relation - Create
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayResult = $messageEventTaskRelation->create(
$this->wp->getUid(),
array(
"EVN_UID" => $elementUid,
"TAS_UID" => $taskUid
)
);
//Array - Add element
$this->arrayMessageEventTaskRelation[$elementUid] = $taskUid;
}
}
//Return
return $taskUid;
} catch (\Exception $e) {
throw $e;
}
}
public function mapBpmnGatewayToWorkflowRoutes($activityUid, $gatewayUid)
{
try {
@@ -509,16 +679,17 @@ class BpmnWorkflow extends Project\Bpmn
break;
}
$arrayGatewayFlowData = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $gatewayUid,
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $gatewayUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnGateway"
));
if ($arrayGatewayFlowData > 0) {
if ($arrayFlow > 0) {
$this->wp->resetTaskRoutes($activityUid);
}
foreach ($arrayGatewayFlowData as $value) {
foreach ($arrayFlow as $value) {
$arrayFlowData = $value->toArray();
$routeDefault = (array_key_exists("FLO_TYPE", $arrayFlowData) && $arrayFlowData["FLO_TYPE"] == "DEFAULT")? 1 : 0;
@@ -526,37 +697,59 @@ class BpmnWorkflow extends Project\Bpmn
switch ($arrayFlowData["FLO_ELEMENT_DEST_TYPE"]) {
case "bpmnActivity":
case "bpmnEvent":
//Gateway ----> Activity
//Gateway ----> Event
if ($arrayFlowData["FLO_ELEMENT_DEST_TYPE"] == "bpmnEvent") {
$event = \BpmnEventPeer::retrieveByPK($arrayFlowData["FLO_ELEMENT_DEST"]);
if ($event->getEvnType() == "END") {
$result = $this->wp->addRoute($activityUid, -1, $routeType, $routeCondition, $routeDefault);
}
} else {
$result = $this->wp->addRoute($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
}
$result = $this->wp->addRoute($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
break;
case "bpmnGateway":
//Gateway ----> Gateway
$taskUid = $this->wp->addTask(array(
"TAS_TYPE" => "GATEWAYTOGATEWAY",
"TAS_TITLE" => "GATEWAYTOGATEWAY",
"TAS_POSX" => (int)($arrayFlowData["FLO_X1"]),
"TAS_POSY" => (int)($arrayFlowData["FLO_Y1"])
));
$taskUid = $this->createTaskByElement(
$gatewayUid,
"bpmnGateway",
"gateway-to-gateway"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$this->mapBpmnGatewayToWorkflowRoutes($taskUid, $arrayFlowData["FLO_ELEMENT_DEST"]);
break;
case "bpmnEvent":
//Gateway ----> Event
$event = \BpmnEventPeer::retrieveByPK($arrayFlowData["FLO_ELEMENT_DEST"]);
if (!is_null($event)) {
switch ($event->getEvnType()) {
case "START":
throw new \LogicException("Incorrect design" . PHP_EOL . "Given: bpmnGateway -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]);
break;
case "END":
//$event->getEvnMarker(): EMPTY or MESSAGETHROW
switch ($event->getEvnMarker()) {
case "EMPTY":
$result = $this->wp->addRoute($activityUid, -1, $routeType, $routeCondition, $routeDefault);
break;
case "MESSAGETHROW":
$taskUid = $this->createTaskByElement(
$event->getEvnUid(),
"bpmnEvent",
"end-message-event"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$result = $this->wp->addRoute($taskUid, -1, "SEQUENTIAL");
break;
}
break;
case "INTERMEDIATE":
$this->mapBpmnEventToWorkflowRoutes($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
break;
}
}
break;
default:
//For processmaker is only allowed flows between: "gateway -> activity", "gateway -> gateway"
//For ProcessMaker is only allowed flows between: "gateway -> activity", "gateway -> gateway", "gateway -> event"
//any another flow is considered invalid
throw new \LogicException(
"For ProcessMaker is only allowed flows between: \"gateway -> activity\", \"gateway -> gateway\" " . PHP_EOL .
"For ProcessMaker is only allowed flows between: \"gateway -> activity\", \"gateway -> gateway\", \"gateway -> event\"" . PHP_EOL .
"Given: bpmnGateway -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]
);
}
@@ -566,29 +759,192 @@ class BpmnWorkflow extends Project\Bpmn
}
}
public function mapBpmnEventToWorkflowRoutes($activityUid, $eventUid, $routeType = "SEQUENTIAL", $routeCondition = "", $routeDefault = 0)
{
try {
$arrayEventData = \BpmnEvent::findOneBy(\BpmnEventPeer::EVN_UID, $eventUid)->toArray();
$arrayEventType = array("START", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
if (!is_null($arrayEventData) &&
in_array($arrayEventData["EVN_TYPE"], $arrayEventType) && in_array($arrayEventData["EVN_MARKER"], $arrayEventMarker)
) {
//Event - INTERMEDIATE-START-MESSAGE-EVENT
if ($arrayEventData["EVN_TYPE"] == "INTERMEDIATE" && $arrayEventData["EVN_MARKER"] == "MESSAGECATCH") {
$taskUid = $this->createTaskByElement(
$eventUid,
"bpmnEvent",
"intermediate-start-message-event"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$activityUid = $taskUid;
}
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $eventUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnEvent"
));
foreach ($arrayFlow as $value) {
$arrayFlowData = $value->toArray();
switch ($arrayFlowData["FLO_ELEMENT_DEST_TYPE"]) {
case "bpmnActivity":
//Event ----> Activity
$result = $this->wp->addRoute($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], "SEQUENTIAL");
break;
case "bpmnGateway":
//Event ----> Gateway
$this->mapBpmnGatewayToWorkflowRoutes($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"]);
break;
case "bpmnEvent":
//Event ----> Event
$event = \BpmnEventPeer::retrieveByPK($arrayFlowData["FLO_ELEMENT_DEST"]);
if (!is_null($event)) {
switch ($event->getEvnType()) {
case "START":
throw new \LogicException("Incorrect design" . PHP_EOL . "Given: bpmnEvent -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]);
break;
case "END":
//$event->getEvnMarker(): EMPTY or MESSAGETHROW
switch ($event->getEvnMarker()) {
case "EMPTY":
$result = $this->wp->addRoute($activityUid, -1, "SEQUENTIAL");
break;
case "MESSAGETHROW":
$taskUid = $this->createTaskByElement(
$event->getEvnUid(),
"bpmnEvent",
"end-message-event"
);
$result = $this->wp->addRoute($activityUid, $taskUid, "SEQUENTIAL");
$result = $this->wp->addRoute($taskUid, -1, "SEQUENTIAL");
break;
}
break;
case "INTERMEDIATE":
$this->mapBpmnEventToWorkflowRoutes($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"]);
break;
}
}
break;
default:
//For ProcessMaker is only allowed flows between: "event -> activity", "event -> gateway", "event -> event"
//any another flow is considered invalid
throw new \LogicException(
"For ProcessMaker is only allowed flows between: \"event -> activity\", \"event -> gateway\", \"event -> event\"" . PHP_EOL .
"Given: bpmnEvent -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]
);
}
}
}
} catch (\Exception $e) {
throw $e;
}
}
public function mapBpmnFlowsToWorkflowRoutes()
{
$this->wp->deleteTaskGatewayToGateway($this->wp->getUid());
//Task - Delete dummies
$this->wp->deleteTaskByArrayType(
$this->wp->getUid(),
array(
$this->arrayTaskAttribute["gateway-to-gateway"]["type"]
)
);
$activities = $this->getActivities();
//Activities
foreach ($this->getActivities() as $value) {
$activity = $value;
foreach ($activities as $activity) {
$flows = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $activity["ACT_UID"],
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $activity["ACT_UID"],
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnActivity"
));
foreach ($flows as $flow) {
foreach ($arrayFlow as $value2) {
$flow = $value2;
switch ($flow->getFloElementDestType()) {
case "bpmnActivity":
// (activity -> activity)
//Activity -> Activity
$this->wp->addRoute($activity["ACT_UID"], $flow->getFloElementDest(), "SEQUENTIAL");
break;
case "bpmnGateway":
// (activity -> gateway)
// we must find the related flows: gateway -> <object>
//Activity -> Gateway
//We must find the related flows: gateway -> <object>
$this->mapBpmnGatewayToWorkflowRoutes($activity["ACT_UID"], $flow->getFloElementDest());
break;
case "bpmnEvent":
//Activity -> Event
$event = \BpmnEventPeer::retrieveByPK($flow->getFloElementDest());
if (!is_null($event)) {
switch ($event->getEvnType()) {
case "START":
throw new \LogicException("Incorrect design" . PHP_EOL . "Given: bpmnActivity -> " . $flow->getFloElementDestType());
break;
case "END":
//$event->getEvnMarker(): EMPTY or MESSAGETHROW
switch ($event->getEvnMarker()) {
case "EMPTY":
//This it's already implemented
break;
case "MESSAGETHROW":
$taskUid = $this->createTaskByElement(
$event->getEvnUid(),
"bpmnEvent",
"end-message-event"
);
$result = $this->wp->addRoute($activity["ACT_UID"], $taskUid, "SEQUENTIAL");
$result = $this->wp->addRoute($taskUid, -1, "SEQUENTIAL");
break;
}
break;
case "INTERMEDIATE":
$this->mapBpmnEventToWorkflowRoutes($activity["ACT_UID"], $flow->getFloElementDest());
break;
}
}
break;
}
}
}
//Events - Message-Event
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
foreach ($this->getEvents() as $value) {
$event = $value;
if (!isset($this->arrayMessageEventTaskRelation[$event["EVN_UID"]]) &&
in_array($event["EVN_TYPE"], $arrayEventType) && in_array($event["EVN_MARKER"], $arrayEventMarker)
) {
switch ($event["EVN_TYPE"]) {
case "START":
$taskUid = $this->createTaskByElement(
$event["EVN_UID"],
"bpmnEvent",
"start-message-event"
);
$this->wp->setStartTask($taskUid);
$this->mapBpmnEventToWorkflowRoutes($taskUid, $event["EVN_UID"]);
break;
case "END":
break;
case "INTERMEDIATE":
break;
}
}
}
@@ -789,6 +1145,27 @@ class BpmnWorkflow extends Project\Bpmn
$bwp->update($projectRecord);
//Array - Set empty
$bwp->arrayMessageEventTaskRelation = array();
//Message-Event-Task-Relation - Get all records
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::EVN_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::TAS_UID);
$criteria->add(\MessageEventTaskRelationPeer::PRJ_UID, $bwp->wp->getUid(), \Criteria::EQUAL);
$rsCriteria = \MessageEventTaskRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Array - Add element
$bwp->arrayMessageEventTaskRelation[$row["EVN_UID"]] = $row["TAS_UID"];
}
/*
* Diagram's Laneset Handling
*/
@@ -1356,5 +1733,33 @@ class BpmnWorkflow extends Project\Bpmn
throw $e;
}
}
public function createMessageEventRelationByBpmnFlow(\BpmnFlow $bpmnFlow)
{
try {
$messageEventRelationUid = "";
if ($bpmnFlow->getFloType() == "MESSAGE" &&
$bpmnFlow->getFloElementOriginType() == "bpmnEvent" && $bpmnFlow->getFloElementDestType() == "bpmnEvent"
) {
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$arrayResult = $messageEventRelation->create(
$bpmnFlow->getPrjUid(),
array(
"EVN_UID_THROW" => $bpmnFlow->getFloElementOrigin(),
"EVN_UID_CATCH" => $bpmnFlow->getFloElementDest()
)
);
$messageEventRelationUid = $arrayResult["MSGER_UID"];
}
//Return
return $messageEventRelationUid;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -625,12 +625,53 @@ class Bpmn extends Handler
}
}
public function throwExceptionFlowIfIsAnInvalidMessageFlow(array $bpmnFlow)
{
try {
if ($bpmnFlow["FLO_TYPE"] == "MESSAGE" &&
$bpmnFlow["FLO_ELEMENT_ORIGIN_TYPE"] == "bpmnEvent" && $bpmnFlow["FLO_ELEMENT_DEST_TYPE"] == "bpmnEvent"
) {
$flagValid = true;
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayAux = array(
array("eventUid" => $bpmnFlow["FLO_ELEMENT_ORIGIN"], "eventMarker" => "MESSAGETHROW"),
array("eventUid" => $bpmnFlow["FLO_ELEMENT_DEST"], "eventMarker" => "MESSAGECATCH")
);
foreach ($arrayAux as $value) {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\BpmnEventPeer::EVN_UID);
$criteria->add(\BpmnEventPeer::EVN_UID, $value["eventUid"], \Criteria::EQUAL);
$criteria->add(\BpmnEventPeer::EVN_TYPE, $arrayEventType, \Criteria::IN);
$criteria->add(\BpmnEventPeer::EVN_MARKER, $value["eventMarker"], \Criteria::EQUAL);
$rsCriteria = \BpmnEventPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
$flagValid = false;
break;
}
}
if (!$flagValid) {
throw new \RuntimeException("Invalid Message Flow.");
}
}
} catch (\Exception $e) {
throw $e;
}
}
public function addFlow($data)
{
self::log("Add Flow with data: ", $data);
// setting defaults
$data['FLO_UID'] = array_key_exists('FLO_UID', $data) ? $data['FLO_UID'] : Common::generateUID();
if (array_key_exists('FLO_STATE', $data)) {
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
}
@@ -680,17 +721,23 @@ class Bpmn extends Handler
));
}
//Check and validate Message Flow
$this->throwExceptionFlowIfIsAnInvalidMessageFlow($data);
//Create
$flow = new Flow();
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
$flow->setPrjUid($this->getUid());
$flow->setDiaUid($this->getDiagram("object")->getDiaUid());
$flow->setFloPosition($this->getFlowNextPosition($data["FLO_UID"], $data["FLO_TYPE"], $data["FLO_ELEMENT_ORIGIN"]));
$flow->save();
self::log("Add Flow Success!");
return $flow->getFloUid();
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
@@ -703,7 +750,12 @@ class Bpmn extends Handler
if (array_key_exists('FLO_STATE', $data)) {
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
}
try {
//Check and validate Message Flow
$this->throwExceptionFlowIfIsAnInvalidMessageFlow($data);
//Update
$flow = FlowPeer::retrieveByPk($floUid);
$flow->fromArray($data);
$flow->save();

View File

@@ -1236,7 +1236,7 @@ class Workflow extends Handler
}
}
public function deleteTaskGatewayToGateway($processUid)
public function deleteTaskByArrayType($processUid, array $arrayTaskType)
{
try {
$task = new \Tasks();
@@ -1245,7 +1245,7 @@ class Workflow extends Handler
$criteria->addSelectColumn(\TaskPeer::TAS_UID);
$criteria->add(\TaskPeer::PRO_UID, $processUid, \Criteria::EQUAL);
$criteria->add(\TaskPeer::TAS_TYPE, "GATEWAYTOGATEWAY", \Criteria::EQUAL);
$criteria->add(\TaskPeer::TAS_TYPE, $arrayTaskType, \Criteria::IN);
$rsCriteria = \TaskPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);

View File

@@ -0,0 +1,134 @@
<?php
namespace ProcessMaker\Services\Api\Project;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Project\MessageEventDefinition Api Controller
*
* @protected
*/
class MessageEventDefinition extends Api
{
private $messageEventDefinition;
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
$this->messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
$this->messageEventDefinition->setFormatFieldNameInUppercase(false);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/message-event-definitions
*
* @param string $prj_uid {@min 32}{@max 32}
*/
public function doGetMessageEventDefinitions($prj_uid)
{
try {
$response = $this->messageEventDefinition->getMessageEventDefinitions($prj_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/message-event-definition/:msged_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $msged_uid {@min 32}{@max 32}
*/
public function doGetMessageEventDefinition($prj_uid, $msged_uid)
{
try {
$response = $this->messageEventDefinition->getMessageEventDefinition($msged_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/message-event-definition/event/:evn_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $evn_uid {@min 32}{@max 32}
*/
public function doGetMessageEventDefinitionEvent($prj_uid, $evn_uid)
{
try {
$response = $this->messageEventDefinition->getMessageEventDefinitionByEvent($prj_uid, $evn_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url POST /:prj_uid/message-event-definition
*
* @param string $prj_uid {@min 32}{@max 32}
* @param array $request_data
*
* @status 201
*/
public function doPostMessageEventDefinition($prj_uid, array $request_data)
{
try {
$arrayData = $this->messageEventDefinition->create($prj_uid, $request_data);
$response = $arrayData;
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url PUT /:prj_uid/message-event-definition/:msged_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $msged_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPutMessageEventDefinition($prj_uid, $msged_uid, array $request_data)
{
try {
$arrayData = $this->messageEventDefinition->update($msged_uid, $request_data);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url DELETE /:prj_uid/message-event-definition/:msged_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $msged_uid {@min 32}{@max 32}
*/
public function doDeleteMessageEventDefinition($prj_uid, $msged_uid)
{
try {
$this->messageEventDefinition->delete($msged_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}

View File

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