Adding Override Methods to Adapter Bpmn->Workflow Projects
This commit is contained in:
@@ -7,5 +7,66 @@ use ProcessMaker\Util\Hash;
|
|||||||
|
|
||||||
class BpmnWorkflow extends Project\Bpmn
|
class BpmnWorkflow extends Project\Bpmn
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* OVERRIDES
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function create($data)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
parent::create($data);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \RuntimeException(sprintf("Can't create Bpmn Project." . PHP_EOL . $e->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$wpData = array();
|
||||||
|
$wpData["PRO_UID"] = $this->getUid();
|
||||||
|
|
||||||
|
if (array_key_exists("PRJ_NAME", $data)) {
|
||||||
|
$wpData["PRO_TITLE"] = $data["PRJ_NAME"];
|
||||||
|
}
|
||||||
|
if (array_key_exists("PRJ_DESCRIPTION", $data)) {
|
||||||
|
$wpData["PRO_DESCRIPTION"] = $data["PRJ_DESCRIPTION"];
|
||||||
|
}
|
||||||
|
if (array_key_exists("PRJ_AUTHOR", $data)) {
|
||||||
|
$wpData["PRO_CREATE_USER"] = $data["PRJ_AUTHOR"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$wp = new Project\Workflow();
|
||||||
|
$wp->create($wpData);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$prjUid = $this->getUid();
|
||||||
|
$this->remove();
|
||||||
|
|
||||||
|
throw new \RuntimeException(sprintf(
|
||||||
|
"Can't create Bpmn Project with prj_uid: %s, workflow creation fails." . PHP_EOL . $e->getMessage()
|
||||||
|
, $prjUid
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
||||||
|
{
|
||||||
|
$bpmnProjects = parent::getList($start, $limit, $filter, $changeCaseTo);
|
||||||
|
$workflowProjects = Project\Workflow::getList($start, $limit, "", "");
|
||||||
|
|
||||||
|
$workflowProjectsUids = array();
|
||||||
|
|
||||||
|
foreach ($workflowProjects as $workflowProject) {
|
||||||
|
$workflowProjectsUids[] = $workflowProject["PRO_UID"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$prjUidKey = $changeCaseTo == CASE_UPPER ? "PRJ_UID" : "prj_uid";
|
||||||
|
$list = array();
|
||||||
|
|
||||||
|
foreach ($bpmnProjects as $bpmnProject) {
|
||||||
|
if (in_array($bpmnProject[$prjUidKey], $workflowProjectsUids)) {
|
||||||
|
$list[] = $bpmnProject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,11 @@ class Bpmn extends Handler
|
|||||||
$this->prjUid = $this->project->getPrjUid();
|
$this->prjUid = $this->project->getPrjUid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function remove()
|
public function remove()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -100,20 +105,15 @@ class Bpmn extends Handler
|
|||||||
foreach ($activities as $activity) {
|
foreach ($activities as $activity) {
|
||||||
$this->removeActivity($activity["ACT_UID"]);
|
$this->removeActivity($activity["ACT_UID"]);
|
||||||
}
|
}
|
||||||
|
if ($process = $this->getProcess("object")) {
|
||||||
$process = ProcessPeer::retrieveByPK($this->getProcess("object")->getProUid());
|
$process->delete();
|
||||||
$process->delete();
|
}
|
||||||
|
if ($diagram = $this->getDiagram("object")) {
|
||||||
$diagram = DiagramPeer::retrieveByPK($this->getDiagram("object")->getDiaUid());
|
$diagram->delete();
|
||||||
$diagram->delete();
|
}
|
||||||
|
if ($project = $this->getProject("object")) {
|
||||||
$project = ProjectPeer::retrieveByPK($this->getUid());
|
$project->delete();
|
||||||
$project->delete();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
||||||
|
|||||||
@@ -73,9 +73,19 @@ class Workflow extends Handler
|
|||||||
$this->deleteProcess($this->proUid);
|
$this->deleteProcess($this->proUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
||||||
|
{
|
||||||
|
//return Project::getAll($start, $limit, $filter, $changeCaseTo);
|
||||||
|
$process = new Process();
|
||||||
|
$processes = $process->getAllProcesses( $start, $limit, "", "");
|
||||||
|
//$processes = $process->getAll();
|
||||||
|
|
||||||
|
return $processes;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUid()
|
public function getUid()
|
||||||
{
|
{
|
||||||
if (empty($this->project)) {
|
if (empty($this->proUid)) {
|
||||||
throw new \RuntimeException("Error: There is not an initialized project.");
|
throw new \RuntimeException("Error: There is not an initialized project.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ class Project extends Api
|
|||||||
$limit = null;
|
$limit = null;
|
||||||
$filter = "";
|
$filter = "";
|
||||||
|
|
||||||
return \ProcessMaker\Project\Bpmn::getList($start, $limit, $filter, CASE_LOWER);
|
$projects = \ProcessMaker\Project\Adapter\BpmnWorkflow::getList($start, $limit, $filter, CASE_LOWER);
|
||||||
|
|
||||||
|
return $projects;
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -31,7 +34,7 @@ class Project extends Api
|
|||||||
public function get($prjUid)
|
public function get($prjUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$projects = \ProcessMaker\Project\Bpmn::getList();
|
$projects = new \StdClass(); //TODO
|
||||||
|
|
||||||
return $projects;
|
return $projects;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\ProcessMaker\Project\Adapter;
|
||||||
|
|
||||||
|
use \ProcessMaker\Project;
|
||||||
|
|
||||||
|
if (! class_exists("Propel")) {
|
||||||
|
include_once __DIR__ . "/../../../bootstrap.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BpmnWorkflowTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
function testNew()
|
||||||
|
{
|
||||||
|
$data = array(
|
||||||
|
"PRJ_NAME" => "Test BPMN Project #1",
|
||||||
|
"PRJ_DESCRIPTION" => "Description for - Test BPMN Project #1",
|
||||||
|
"PRJ_AUTHOR" => "00000000000000000000000000000001"
|
||||||
|
);
|
||||||
|
|
||||||
|
$bwap = new Project\Adapter\BpmnWorkflow($data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$bp = Project\Bpmn::load($bwap->getUid());
|
||||||
|
} catch (\Exception $e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$wp = Project\Workflow::load($bwap->getUid());
|
||||||
|
} catch (\Exception $e){}
|
||||||
|
|
||||||
|
$this->assertNotEmpty($bp);
|
||||||
|
$this->assertNotEmpty($wp);
|
||||||
|
$this->assertEquals($bp->getUid(), $wp->getUid());
|
||||||
|
|
||||||
|
$project = $bp->getProject();
|
||||||
|
$process = $wp->getProcess();
|
||||||
|
|
||||||
|
$this->assertEquals($project["PRJ_NAME"], $process["PRO_TITLE"]);
|
||||||
|
$this->assertEquals($project["PRJ_DESCRIPTION"], $process["PRO_DESCRIPTION"]);
|
||||||
|
$this->assertEquals($project["PRJ_AUTHOR"], $process["PRO_CREATE_USER"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCreate()
|
||||||
|
{
|
||||||
|
$data = array(
|
||||||
|
"PRJ_NAME" => "Test BPMN Project #2",
|
||||||
|
"PRJ_DESCRIPTION" => "Description for - Test BPMN Project #2",
|
||||||
|
"PRJ_AUTHOR" => "00000000000000000000000000000001"
|
||||||
|
);
|
||||||
|
|
||||||
|
$bwap = new Project\Adapter\BpmnWorkflow();
|
||||||
|
$bwap->create($data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$bp = Project\Bpmn::load($bwap->getUid());
|
||||||
|
} catch (\Exception $e){}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$wp = Project\Workflow::load($bwap->getUid());
|
||||||
|
} catch (\Exception $e){}
|
||||||
|
|
||||||
|
$this->assertNotEmpty($bp);
|
||||||
|
$this->assertNotEmpty($wp);
|
||||||
|
$this->assertEquals($bp->getUid(), $wp->getUid());
|
||||||
|
|
||||||
|
$project = $bp->getProject();
|
||||||
|
$process = $wp->getProcess();
|
||||||
|
|
||||||
|
$this->assertEquals($project["PRJ_NAME"], $process["PRO_TITLE"]);
|
||||||
|
$this->assertEquals($project["PRJ_DESCRIPTION"], $process["PRO_DESCRIPTION"]);
|
||||||
|
$this->assertEquals($project["PRJ_AUTHOR"], $process["PRO_CREATE_USER"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace Tests\ProcessMaker\Project;
|
|||||||
use \ProcessMaker\Project;
|
use \ProcessMaker\Project;
|
||||||
|
|
||||||
if (! class_exists("Propel")) {
|
if (! class_exists("Propel")) {
|
||||||
include_once __DIR__ . "/../bootstrap.php";
|
include_once __DIR__ . "/../../bootstrap.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ class BpmnTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public static function tearDownAfterClass()
|
public static function tearDownAfterClass()
|
||||||
{
|
{
|
||||||
return;
|
//return;
|
||||||
|
|
||||||
//cleaning DB
|
//cleaning DB
|
||||||
foreach (self::$prjUids as $prjUid) {
|
foreach (self::$prjUids as $prjUid) {
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ namespace Tests\ProcessMaker\Project;
|
|||||||
use \ProcessMaker\Project;
|
use \ProcessMaker\Project;
|
||||||
|
|
||||||
if (! class_exists("Propel")) {
|
if (! class_exists("Propel")) {
|
||||||
include_once __DIR__ . "/../bootstrap.php";
|
include_once __DIR__ . "/../../bootstrap.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProcessMakerProjectWorkflowTest extends \PHPUnit_Framework_TestCase
|
class WorkflowTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected static $proUids = array();
|
protected static $proUids = array();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user