Merged in victorsl/processmaker/PM-939 (pull request #1351)

PM-1005 "WebEntry-Event (Endpoints)"
This commit is contained in:
Julio Cesar Laura Avendaño
2015-01-28 15:25:58 -04:00
20 changed files with 3296 additions and 43 deletions

View File

@@ -118,6 +118,24 @@ class WebEntry
return $newName;
}
/**
* Verify if exists the Web Entry
*
* @param string $webEntryUid Unique id of Web Entry
*
* return bool Return true if exists the Web Entry, false otherwise
*/
public function exists($webEntryUid)
{
try {
$obj = \WebEntryPeer::retrieveByPK($webEntryUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the title of a Web Entry
*
@@ -165,19 +183,17 @@ class WebEntry
}
/**
* Verify if does not exist the Web Entry in table WEB_ENTRY
* Verify if does not exists the Web Entry
*
* @param string $webEntryUid Unique id of Web Entry
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exist the Web Entry in table WEB_ENTRY
* return void Throw exception if does not exists the Web Entry
*/
public function throwExceptionIfNotExistsWebEntry($webEntryUid, $fieldNameForException)
{
try {
$obj = \WebEntryPeer::retrieveByPK($webEntryUid);
if (is_null($obj)) {
if (!$this->exists($webEntryUid)) {
throw new \Exception(\G::LoadTranslation("ID_WEB_ENTRY_DOES_NOT_EXIST", array($fieldNameForException, $webEntryUid)));
}
} catch (\Exception $e) {
@@ -601,7 +617,7 @@ class WebEntry
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg);
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
@@ -686,7 +702,7 @@ class WebEntry
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg);
throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();

File diff suppressed because it is too large Load Diff

View File

@@ -369,12 +369,14 @@ abstract class Importer
$this->importWfFiles($arrayWorkflowFiles);
//Update
$workflow = Project\Workflow::load($projectUid);
$workflow = \ProcessMaker\Project\Workflow::load($projectUid);
foreach ($arrayWorkflowTables["tasks"] as $key => $value) {
$arrayTaskData = $value;
$result = $workflow->updateTask($arrayTaskData["TAS_UID"], $arrayTaskData);
if (!in_array($arrayTaskData["TAS_TYPE"], array("GATEWAYTOGATEWAY", "WEBENTRYEVENT"))) {
$result = $workflow->updateTask($arrayTaskData["TAS_UID"], $arrayTaskData);
}
}
unset($arrayWorkflowTables["process"]["PRO_CREATE_USER"]);

View File

@@ -243,6 +243,9 @@ class BpmnWorkflow extends Project\Bpmn
}
$this->updateEventStartObjects($data["FLO_ELEMENT_ORIGIN"], $data["FLO_ELEMENT_DEST"]);
//WebEntry-Event - Update
$this->updateWebEntryEventByEvent($data["FLO_ELEMENT_ORIGIN"], array("ACT_UID" => $data["FLO_ELEMENT_DEST"]));
break;
}
break;
@@ -289,6 +292,9 @@ class BpmnWorkflow extends Project\Bpmn
$this->wp->setStartTask($flowCurrent->getFloElementDest());
$this->updateEventStartObjects($flowCurrent->getFloElementOrigin(), $flowCurrent->getFloElementDest());
//WebEntry-Event - Update
$this->updateWebEntryEventByEvent($flowCurrent->getFloElementOrigin(), array("ACT_UID" => $flowCurrent->getFloElementDest()));
}
}
@@ -342,16 +348,31 @@ class BpmnWorkflow extends Project\Bpmn
if ($flow->getFloElementOriginType() == "bpmnEvent" &&
$flow->getFloElementDestType() == "bpmnActivity"
) {
$event = \BpmnEventPeer::retrieveByPK($flow->getFloElementOrigin());
$bpmnFlow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $flow->getFloElementOrigin(),
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnEvent",
\BpmnFlowPeer::FLO_ELEMENT_DEST => $flow->getFloElementDest(),
\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => "bpmnActivity"
));
if (! is_null($event) && $event->getEvnType() == "START") {
$activity = \BpmnActivityPeer::retrieveByPK($flow->getFloElementDest());
if (! is_null($activity)) {
$this->wp->setStartTask($activity->getActUid(), false);
if (is_null($bpmnFlow)) {
$event = \BpmnEventPeer::retrieveByPK($flow->getFloElementOrigin());
if (!is_null($event) && $event->getEvnType() == "START") {
$activity = \BpmnActivityPeer::retrieveByPK($flow->getFloElementDest());
if (!is_null($activity)) {
$this->wp->setStartTask($activity->getActUid(), false);
}
}
}
$this->updateEventStartObjects($flow->getFloElementOrigin(), "");
//WebEntry-Event - Update
if (is_null($bpmnFlow)) {
$this->updateWebEntryEventByEvent($flow->getFloElementOrigin(), array("WEE_STATUS" => "DISABLED"));
}
} elseif ($flow->getFloElementOriginType() == "bpmnActivity" &&
$flow->getFloElementDestType() == "bpmnEvent") {
// verify case: activity -> event(end)
@@ -403,22 +424,27 @@ class BpmnWorkflow extends Project\Bpmn
return $eventUid;
}
public function removeEvent($data)
public function removeEvent($eventUid)
{
$event = \BpmnEventPeer::retrieveByPK($data);
$event = \BpmnEventPeer::retrieveByPK($eventUid);
// delete case scheduler
if ($event && $event->getEvnMarker() == "TIMER" && $event->getEvnType() == "START") {
$this->wp->removeCaseScheduler($data);
$this->wp->removeCaseScheduler($eventUid);
}
// delete web entry
if ($event && $event->getEvnMarker() == "MESSAGE" && $event->getEvnType() == "START") {
$this->wp->removeWebEntry($data);
if (!is_null($event) && $event->getEvnType() == "START") {
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
if ($webEntryEvent->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayWebEntryEventData = $webEntryEvent->getWebEntryEventByEvent($event->getPrjUid(), $eventUid, true);
$webEntryEvent->delete($arrayWebEntryEventData["WEE_UID"]);
}
}
parent::removeEvent($data);
parent::removeEvent($eventUid);
}
public function updateEventStartObjects($eventUid, $taskUid)
@@ -431,9 +457,9 @@ class BpmnWorkflow extends Project\Bpmn
}
//Update web entry
if (!is_null($event) && $event->getEvnType() == "START" && $event->getEvnMarker() == "MESSAGE") {
$this->wp->updateWebEntry($eventUid, array("TAS_UID" => $taskUid));
}
//if (!is_null($event) && $event->getEvnType() == "START" && $event->getEvnMarker() == "MESSAGE") {
// $this->wp->updateWebEntry($eventUid, array("TAS_UID" => $taskUid));
//}
}
public function mapBpmnGatewayToWorkflowRoutes($activityUid, $gatewayUid)
@@ -1302,5 +1328,27 @@ class BpmnWorkflow extends Project\Bpmn
parent::setDisabled($value);
$this->wp->setDisabled($value);
}
public function updateWebEntryEventByEvent($eventUid, array $arrayData)
{
try {
$bpmnEvent = \BpmnEventPeer::retrieveByPK($eventUid);
if (!is_null($bpmnEvent) && $bpmnEvent->getEvnType() == "START") {
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
if ($webEntryEvent->existsEvent($bpmnEvent->getPrjUid(), $bpmnEvent->getEvnUid())) {
$arrayWebEntryEventData = $webEntryEvent->getWebEntryEventByEvent($bpmnEvent->getPrjUid(), $bpmnEvent->getEvnUid(), true);
$bpmn = \ProcessMaker\Project\Bpmn::load($bpmnEvent->getPrjUid());
$bpmnProject = $bpmn->getProject("object");
$arrayResult = $webEntryEvent->update($arrayWebEntryEventData["WEE_UID"], $bpmnProject->getPrjAuthor(), $arrayData);
}
}
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -764,10 +764,11 @@ class Workflow extends Handler
$oCriteria->add(\CaseTrackerObjectPeer::PRO_UID, $sProcessUID);
\ProcessUserPeer::doDelete($oCriteria);
//Delete Web Entries
//Delete WebEntries
$webEntry = new \ProcessMaker\BusinessModel\WebEntry();
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\WebEntryPeer::WE_UID);
$criteria->add(\WebEntryPeer::PRO_UID, $sProcessUID, \Criteria::EQUAL);
@@ -780,6 +781,23 @@ class Workflow extends Handler
$webEntry->delete($row["WE_UID"]);
}
//Delete WebEntry-Events
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\WebEntryEventPeer::WEE_UID);
$criteria->add(\WebEntryEventPeer::PRJ_UID, $sProcessUID, \Criteria::EQUAL);
$rsCriteria = \WebEntryEventPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$webEntryEvent->delete($row["WEE_UID"]);
}
//Delete the process
try {
$oProcess->remove($sProcessUID);
@@ -1055,7 +1073,27 @@ class Workflow extends Handler
}
}
//Getting templates files
//Get public files to exclude
$arrayPublicFileToExclude = array("wsClient.php");
//WebEntry
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\WebEntryPeer::WE_DATA);
$criteria->add(\WebEntryPeer::PRO_UID, $processUid, \Criteria::EQUAL);
$criteria->add(\WebEntryPeer::WE_METHOD, "WS", \Criteria::EQUAL);
$rsCriteria = \WebEntryPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayPublicFileToExclude[] = $row["WE_DATA"];
$arrayPublicFileToExclude[] = preg_replace("/^(.+)\.php$/", "$1Post.php", $row["WE_DATA"]);
}
//Get templates and public files
$workspaceTargetDirs = array("TEMPLATES" => "mailTemplates", "PUBLIC" => "public");
$workspaceDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP;
@@ -1070,6 +1108,10 @@ class Workflow extends Handler
$filename = basename($templatesFile);
if ($target == "PUBLIC" && in_array($filename, $arrayPublicFileToExclude)) {
continue;
}
$workflowFile[$target][] = array(
"filename" => $filename,
"filepath" => $processUid . PATH_SEP . $filename,
@@ -1095,7 +1137,7 @@ class Workflow extends Handler
$processUidOld = $arrayUid[0]["old_uid"];
$processUid = $arrayUid[0]["new_uid"];
//Update TAS_UID
//Update TASK.TAS_UID
foreach ($arrayWorkflowData["tasks"] as $key => $value) {
$taskUid = $arrayWorkflowData["tasks"][$key]["TAS_UID"];
@@ -1110,6 +1152,20 @@ class Workflow extends Handler
}
}
//Update WEB_ENTRY_EVENT.EVN_UID
foreach ($arrayWorkflowData["webEntryEvent"] as $key => $value) {
$webEntryEventEventUid = $arrayWorkflowData["webEntryEvent"][$key]["EVN_UID"];
foreach ($arrayUid as $value2) {
$arrayItem = $value2;
if ($arrayItem["old_uid"] == $webEntryEventEventUid) {
$arrayWorkflowData["webEntryEvent"][$key]["EVN_UID"] = $arrayItem["new_uid"];
break;
}
}
}
//Workflow tables
$workflowData = (object)($arrayWorkflowData);

View File

@@ -0,0 +1,135 @@
<?php
namespace ProcessMaker\Services\Api\Project;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Project\WebEntryEvent Api Controller
*
* @protected
*/
class WebEntryEvent extends Api
{
private $webEntryEvent;
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
$this->webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
$this->webEntryEvent->setFormatFieldNameInUppercase(false);
$this->webEntryEvent->setArrayFieldNameForException(array("processUid" => "prj_uid"));
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/web-entry-events
*
* @param string $prj_uid {@min 32}{@max 32}
*/
public function doGetWebEntryEvents($prj_uid)
{
try {
$response = $this->webEntryEvent->getWebEntryEvents($prj_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/web-entry-event/:wee_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $wee_uid {@min 32}{@max 32}
*/
public function doGetWebEntryEvent($prj_uid, $wee_uid)
{
try {
$response = $this->webEntryEvent->getWebEntryEvent($wee_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/web-entry-event/event/:evn_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $evn_uid {@min 32}{@max 32}
*/
public function doGetWebEntryEventEvent($prj_uid, $evn_uid)
{
try {
$response = $this->webEntryEvent->getWebEntryEventByEvent($prj_uid, $evn_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url POST /:prj_uid/web-entry-event
*
* @param string $prj_uid {@min 32}{@max 32}
* @param array $request_data
*
* @status 201
*/
public function doPostWebEntryEvent($prj_uid, array $request_data)
{
try {
$arrayData = $this->webEntryEvent->create($prj_uid, $this->getUserId(), $request_data);
$response = $arrayData;
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url PUT /:prj_uid/web-entry-event/:wee_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $wee_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPutWebEntryEvent($prj_uid, $wee_uid, array $request_data)
{
try {
$arrayData = $this->webEntryEvent->update($wee_uid, $this->getUserId(), $request_data);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url DELETE /:prj_uid/web-entry-event/:wee_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $wee_uid {@min 32}{@max 32}
*/
public function doDeleteWebEntryEvent($prj_uid, $wee_uid)
{
try {
$this->webEntryEvent->delete($wee_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}

View File

@@ -37,7 +37,8 @@ debug = 1
trigger-wizard = "ProcessMaker\Services\Api\Project\TriggerWizard"
category = "ProcessMaker\Services\Api\ProcessCategory"
process-variable = "ProcessMaker\Services\Api\Project\Variable"
message = "ProcessMaker\Services\Api\Project\Message"
message = "ProcessMaker\Services\Api\Project\Message"
web-entry-event = "ProcessMaker\Services\Api\Project\WebEntryEvent"
[alias: projects]
project = "ProcessMaker\Services\Api\Project"
@@ -94,3 +95,4 @@ debug = 1
[alias: emails]
email = "ProcessMaker\Services\Api\EmailServer"