Endpoint: POST /project is ready
This commit is contained in:
@@ -152,16 +152,20 @@ class Process extends BaseProcess
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function create ($aData)
|
public function create ($aData, $generateUid = true)
|
||||||
{
|
{
|
||||||
if (! isset( $aData['USR_UID'] )) {
|
if (! isset( $aData['USR_UID'] )) {
|
||||||
throw (new PropelException( 'The process cannot be created. The USR_UID is empty.' ));
|
throw (new PropelException( 'The process cannot be created. The USR_UID is empty.' ));
|
||||||
}
|
}
|
||||||
$con = Propel::getConnection( ProcessPeer::DATABASE_NAME );
|
$con = Propel::getConnection( ProcessPeer::DATABASE_NAME );
|
||||||
try {
|
try {
|
||||||
do {
|
if ($generateUid) {
|
||||||
$sNewProUid = G::generateUniqueID();
|
do {
|
||||||
} while ($this->processExists( $sNewProUid ));
|
$sNewProUid = G::generateUniqueID();
|
||||||
|
} while ($this->processExists( $sNewProUid ));
|
||||||
|
} else {
|
||||||
|
$sNewProUid = $aData['PRO_UID'];
|
||||||
|
}
|
||||||
|
|
||||||
$this->setProUid( $sNewProUid );
|
$this->setProUid( $sNewProUid );
|
||||||
$this->setProParent( $sNewProUid );
|
$this->setProParent( $sNewProUid );
|
||||||
|
|||||||
@@ -356,12 +356,17 @@ class Task extends BaseTask
|
|||||||
* @param array $aData with new values
|
* @param array $aData with new values
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function create($aData)
|
public function create($aData, $generateUid = true)
|
||||||
{
|
{
|
||||||
$con = Propel::getConnection(TaskPeer::DATABASE_NAME);
|
$con = Propel::getConnection(TaskPeer::DATABASE_NAME);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$sTaskUID = G::generateUniqueID();
|
if ($generateUid) {
|
||||||
|
$sTaskUID = G::generateUniqueID();
|
||||||
|
} else {
|
||||||
|
$sTaskUID = $aData['TAS_UID'];
|
||||||
|
}
|
||||||
|
|
||||||
$con->begin();
|
$con->begin();
|
||||||
$this->setProUid($aData['PRO_UID']);
|
$this->setProUid($aData['PRO_UID']);
|
||||||
$this->setTasUid($sTaskUID);
|
$this->setTasUid($sTaskUID);
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ class ProcessProxy extends HttpProxyController
|
|||||||
$this->success = true;
|
$this->success = true;
|
||||||
$this->PRO_UID = $sProUid;
|
$this->PRO_UID = $sProUid;
|
||||||
$this->msg = G::LoadTranslation( 'ID_CREATE_PROCESS_SUCCESS' );
|
$this->msg = G::LoadTranslation( 'ID_CREATE_PROCESS_SUCCESS' );
|
||||||
|
|
||||||
|
//TODO save bpmn project
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class Process
|
|||||||
|
|
||||||
switch ($option) {
|
switch ($option) {
|
||||||
case "CREATE":
|
case "CREATE":
|
||||||
$processUid = $process->create($arrayProcessData);
|
$processUid = $process->create($arrayProcessData, false);
|
||||||
|
|
||||||
//Call plugins
|
//Call plugins
|
||||||
//$arrayData = array(
|
//$arrayData = array(
|
||||||
@@ -155,7 +155,7 @@ class Process
|
|||||||
case "CREATE":
|
case "CREATE":
|
||||||
//Create task
|
//Create task
|
||||||
$arrayDataAux = array(
|
$arrayDataAux = array(
|
||||||
//"TAS_UID" => $arrayData["TAS_UID"],
|
"TAS_UID" => $arrayData["TAS_UID"],
|
||||||
"PRO_UID" => $arrayData["PRO_UID"],
|
"PRO_UID" => $arrayData["PRO_UID"],
|
||||||
"TAS_TITLE" => $arrayData["TAS_TITLE"],
|
"TAS_TITLE" => $arrayData["TAS_TITLE"],
|
||||||
"TAS_DESCRIPTION" => $arrayData["TAS_DESCRIPTION"],
|
"TAS_DESCRIPTION" => $arrayData["TAS_DESCRIPTION"],
|
||||||
@@ -166,7 +166,7 @@ class Process
|
|||||||
|
|
||||||
$task = new \Task();
|
$task = new \Task();
|
||||||
|
|
||||||
$taskUid = $task->create($arrayDataAux);
|
$taskUid = $task->create($arrayDataAux, false);
|
||||||
|
|
||||||
$uidAux = $arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID"];
|
$uidAux = $arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID"];
|
||||||
$arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID"] = $taskUid;
|
$arrayDefineProcessData["process"]["tasks"][$index]["TAS_UID"] = $taskUid;
|
||||||
|
|||||||
@@ -200,6 +200,11 @@ class Model
|
|||||||
foreach($gateways as $gatewayData) {
|
foreach($gateways as $gatewayData) {
|
||||||
$gatewayData = array_change_key_case((array) $gatewayData, CASE_UPPER);
|
$gatewayData = array_change_key_case((array) $gatewayData, CASE_UPPER);
|
||||||
|
|
||||||
|
// fix data
|
||||||
|
if ($gatewayData['GAT_DIRECTION'] === null) {
|
||||||
|
unset($gatewayData['GAT_DIRECTION']);
|
||||||
|
}
|
||||||
|
|
||||||
$gateway = new Gateway();
|
$gateway = new Gateway();
|
||||||
$gateway->fromArray($gatewayData, BasePeer::TYPE_FIELDNAME);
|
$gateway->fromArray($gatewayData, BasePeer::TYPE_FIELDNAME);
|
||||||
$gateway->setGatUid(Hash::generateUID());
|
$gateway->setGatUid(Hash::generateUID());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace ProcessMaker\Adapter;
|
|||||||
use \Process;
|
use \Process;
|
||||||
use \ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
use \ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
||||||
use \ProcessMaker\Util\Hash;
|
use \ProcessMaker\Util\Hash;
|
||||||
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Workflow
|
* Class Workflow
|
||||||
@@ -13,26 +14,8 @@ use \ProcessMaker\Util\Hash;
|
|||||||
*/
|
*/
|
||||||
class Workflow
|
class Workflow
|
||||||
{
|
{
|
||||||
public static $bpmnTypesEquiv = array(
|
public static function loadFromBpmnProject($prjUid)
|
||||||
'event' => array(
|
|
||||||
'START' => 'START' // to define task start
|
|
||||||
),
|
|
||||||
'flow' => array(
|
|
||||||
'SEQUENCE' => 'SEQUENTIAL' // to define task start
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
public function loadFromBpmnProject($prjUid)
|
|
||||||
{
|
{
|
||||||
$bpmnTypesEquiv = array(
|
|
||||||
'event' => array(
|
|
||||||
'start' => 'start' // to define task start
|
|
||||||
),
|
|
||||||
'flow' => array(
|
|
||||||
'SEQUENCE' => 'SEQUENTIAL' // to define task start
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$project = BpmnModel::getBpmnObjectBy('Project', \BpmnProjectPeer::PRJ_UID, $prjUid);
|
$project = BpmnModel::getBpmnObjectBy('Project', \BpmnProjectPeer::PRJ_UID, $prjUid);
|
||||||
|
|
||||||
$process = array();
|
$process = array();
|
||||||
@@ -62,15 +45,6 @@ class Workflow
|
|||||||
$process['routes'] = array_merge($process['routes'], self::getRoutesFromBpmnFlows($prjUid, $activity['ACT_UID']));
|
$process['routes'] = array_merge($process['routes'], self::getRoutesFromBpmnFlows($prjUid, $activity['ACT_UID']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*foreach ($diagram['flows'] as $flow) {
|
|
||||||
$process['routes'][] = array(
|
|
||||||
'ROU_UID' => '',
|
|
||||||
'TAS_UID' => self::getTask($activity['act_uid']),
|
|
||||||
'ROU_NEXT_TASK' => self::getNextTask($activity['act_uid']),
|
|
||||||
'ROU_TYPE' => ''
|
|
||||||
);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return $process;
|
return $process;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,49 +58,69 @@ class Workflow
|
|||||||
|
|
||||||
foreach ($flows as $flow) {
|
foreach ($flows as $flow) {
|
||||||
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
||||||
$type = $flow['FLO_TYPE'];
|
|
||||||
|
|
||||||
switch ($type) {
|
switch ($flow['FLO_TYPE']) {
|
||||||
case 'SEQUENCE':
|
case 'SEQUENCE':
|
||||||
$type = 'SEQUENTIAL';
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
//$elFlow = BpmnModel::getBpmnObjectBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_DEST, $elementUid);
|
default:
|
||||||
|
throw new \LogicException(sprintf(
|
||||||
|
"Unsupported flow type: %s, ProcessMaker only support type '', Given: '%s'",
|
||||||
|
'SEQUENCE', $flow['FLO_TYPE']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
switch ($flow['FLO_ELEMENT_DEST_TYPE']) {
|
switch ($flow['FLO_ELEMENT_DEST_TYPE']) {
|
||||||
case 'bpmnActivity':
|
case 'bpmnActivity':
|
||||||
// the most easy case, when the flow is connecting a activity with another activity
|
// the most easy case, when the flow is connecting a activity with another activity
|
||||||
$routes[] = array(
|
$routes[] = array(
|
||||||
'ROU_UID' => Hash::generateUID(),
|
'ROU_UID' => $flow['FLO_UID'], //Hash::generateUID(),
|
||||||
'PRO_UID' => $prjUid,
|
'PRO_UID' => $prjUid,
|
||||||
'TAS_UID' => $fromUid,
|
'TAS_UID' => $fromUid,
|
||||||
'ROU_NEXT_TASK' => $flow['FLO_ELEMENT_DEST'],
|
'ROU_NEXT_TASK' => $flow['FLO_ELEMENT_DEST'],
|
||||||
'ROU_TYPE' => $type,
|
'ROU_TYPE' => 'SEQUENTIAL',
|
||||||
'_action' => 'CREATE'
|
'_action' => 'CREATE'
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'bpmnGateway':
|
case 'bpmnGateway':
|
||||||
// if it is a gateway it can fork one or more routes
|
|
||||||
$gatUid = $flow['FLO_ELEMENT_DEST'];
|
$gatUid = $flow['FLO_ELEMENT_DEST'];
|
||||||
|
// if it is a gateway it can fork one or more routes
|
||||||
$gatFlows = BpmnModel::getBpmnCollectionBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid);
|
$gatFlows = BpmnModel::getBpmnCollectionBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid);
|
||||||
|
|
||||||
foreach ($gatFlows as $gatFlow) {
|
foreach ($gatFlows as $gatFlow) {
|
||||||
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||||
case 'bpmnActivity':
|
case 'bpmnActivity':
|
||||||
// getting gateway properties
|
// getting gateway properties
|
||||||
$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnFlowPeer::GAT_UID, $gatUid);
|
$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
||||||
|
|
||||||
switch ($gateway['GAT_TYPE']) {
|
switch ($gateway['GAT_TYPE']) {
|
||||||
//TODO we need to know gateways types to match with routes types of processmaker
|
case 'SELECTION':
|
||||||
case '':
|
$routeType = 'SELECT';
|
||||||
$routeType = '';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'EVALUATION':
|
||||||
|
$routeType = 'EVALUATE';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'PARALLEL':
|
||||||
|
$routeType = 'PARALLEL';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'PARALLEL_EVALUATION':
|
||||||
|
$routeType = 'PARALLEL-BY-EVALUATION';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'PARALLEL_JOIN':
|
||||||
|
$routeType = 'SEC-JOIN';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$routes[] = array(
|
$routes[] = array(
|
||||||
'ROU_UID' => Hash::generateUID(),
|
'ROU_UID' => $gatFlow['FLO_UID'], //Hash::generateUID(),
|
||||||
'PRO_UID' => $prjUid,
|
'PRO_UID' => $prjUid,
|
||||||
'TAS_UID' => $fromUid,
|
'TAS_UID' => $fromUid,
|
||||||
'ROU_NEXT_TASK' => $gatFlow['FLO_ELEMENT_DEST'],
|
'ROU_NEXT_TASK' => $gatFlow['FLO_ELEMENT_DEST'],
|
||||||
@@ -137,45 +131,47 @@ class Workflow
|
|||||||
default:
|
default:
|
||||||
// for processmaker is only allowed flows between "gateway -> activity"
|
// for processmaker is only allowed flows between "gateway -> activity"
|
||||||
// any another flow is considered invalid
|
// any another flow is considered invalid
|
||||||
throw new \LogicException("For ProcessMaker is only allowed flows between \"gateway -> activity\"");
|
throw new \LogicException(sprintf(
|
||||||
|
"For ProcessMaker is only allowed flows between \"gateway -> activity\" " . PHP_EOL .
|
||||||
|
"Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE']
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'bpmnEvent':
|
||||||
|
$evnUid = $flow['FLO_ELEMENT_DEST'];
|
||||||
|
$event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $evnUid);
|
||||||
|
|
||||||
|
switch ($event['EVN_TYPE']) {
|
||||||
|
case 'END':
|
||||||
|
$routeType = 'SEQUENTIAL';
|
||||||
|
$routes[] = array(
|
||||||
|
'ROU_UID' => $flow['FLO_UID'], //Hash::generateUID(),
|
||||||
|
'PRO_UID' => $prjUid,
|
||||||
|
'TAS_UID' => $fromUid,
|
||||||
|
'ROU_NEXT_TASK' => '-1',
|
||||||
|
'ROU_TYPE' => $routeType,
|
||||||
|
'_action' => 'CREATE'
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new \LogicException("Invalid connection to Event object type");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $routes;
|
return $routes;
|
||||||
}
|
}
|
||||||
private static function getRoutesFromBpmnFlows2($flows)
|
|
||||||
{
|
|
||||||
// get bpmnActivities on flo_element_origin
|
|
||||||
$flowsOriginActivities = array();
|
|
||||||
|
|
||||||
foreach ($flows as $i => $flow) {
|
|
||||||
if ($flow['flo_element_origin_type'] == 'bpmnActivity') {
|
|
||||||
$flowsOriginActivities[] = $flow;
|
|
||||||
unset($flows[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static function getTask($actUid)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function getNextTask($actUid)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function activityIsStartTask($actUid)
|
private static function activityIsStartTask($actUid)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* 1. find bpmn flows related to target activity
|
* 1. find bpmn flows related to target activity
|
||||||
* 2. verify is the flow_element_origin_type is a BpmnEvent and it have a evn_type = start
|
* 2. verify is the flow_element_origin_type is a BpmnEvent and it have a evn_type=start
|
||||||
*/
|
*/
|
||||||
$selection = BpmnModel::select('*', 'Flow', array(
|
$selection = BpmnModel::select('*', 'Flow', array(
|
||||||
\BpmnFlowPeer::FLO_ELEMENT_DEST => $actUid,
|
\BpmnFlowPeer::FLO_ELEMENT_DEST => $actUid,
|
||||||
@@ -186,7 +182,7 @@ class Workflow
|
|||||||
if ($elementOrigin['FLO_ELEMENT_ORIGIN_TYPE'] == 'bpmnEvent') {
|
if ($elementOrigin['FLO_ELEMENT_ORIGIN_TYPE'] == 'bpmnEvent') {
|
||||||
$event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $elementOrigin['FLO_ELEMENT_ORIGIN']);
|
$event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $elementOrigin['FLO_ELEMENT_ORIGIN']);
|
||||||
|
|
||||||
if ($event['EVN_TYPE'] == self::$bpmnTypesEquiv['event']['START']) {
|
if ($event['EVN_TYPE'] == 'START') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user