From c61a727d7d03e789cbc0669ea748072846055e39 Mon Sep 17 00:00:00 2001 From: "Paula V. Quispe" Date: Thu, 14 Apr 2016 15:51:36 -0400 Subject: [PATCH] HOR-756 --- workflow/engine/classes/class.case.php | 4 +- workflow/engine/classes/class.derivation.php | 11 +++- .../engine/classes/model/AppDelegation.php | 59 ++++++++++++++++++- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/workflow/engine/classes/class.case.php b/workflow/engine/classes/class.case.php index b52037cc9..205da0d28 100755 --- a/workflow/engine/classes/class.case.php +++ b/workflow/engine/classes/class.case.php @@ -1750,12 +1750,12 @@ class Cases * @return void */ - public function newAppDelegation($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sPrevious, $iPriority, $sDelType, $iAppThreadIndex = 1, $nextDel = null) + public function newAppDelegation($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sPrevious, $iPriority, $sDelType, $iAppThreadIndex = 1, $nextDel = null, $flagControl = false) { try { $appDel = new AppDelegation(); $result = $appDel->createAppDelegation( - $sProUid, $sAppUid, $sTasUid, $sUsrUid, $iAppThreadIndex, $iPriority, false, $sPrevious, $nextDel + $sProUid, $sAppUid, $sTasUid, $sUsrUid, $iAppThreadIndex, $iPriority, false, $sPrevious, $nextDel, $flagControl ); //update searchindex if ($this->appSolr != null) { diff --git a/workflow/engine/classes/class.derivation.php b/workflow/engine/classes/class.derivation.php index 2f41ba6df..a125964cc 100755 --- a/workflow/engine/classes/class.derivation.php +++ b/workflow/engine/classes/class.derivation.php @@ -48,6 +48,7 @@ G::LoadClass( "plugin" ); class Derivation { var $case; + protected $flagControl; /** * prepareInformationTask @@ -1134,6 +1135,9 @@ class Derivation $arrayOpenThread = array_merge($arrayOpenThread, $arraySiblings); } $canDerivate = empty($arrayOpenThread); + if($canDerivate){ + $this->flagControl = true; + } break; default: @@ -1184,8 +1188,9 @@ class Derivation break; default: $iNewDelIndex = $this->doDerivation($currentDelegation, $nextDel, $appFields, $aSP); - - $arrayDerivationResult[] = ['DEL_INDEX' => $iNewDelIndex, 'TAS_UID' => $nextDel['TAS_UID'], 'USR_UID' => (isset($nextDel['USR_UID']))? $nextDel['USR_UID'] : '']; + if($iNewDelIndex !== 0){ + $arrayDerivationResult[] = ['DEL_INDEX' => $iNewDelIndex, 'TAS_UID' => $nextDel['TAS_UID'], 'USR_UID' => (isset($nextDel['USR_UID']))? $nextDel['USR_UID'] : '']; + } break; } @@ -1381,7 +1386,7 @@ class Derivation //No Break, need no execute the default ones.... default: // Create new delegation - $iNewDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $nextDel['USR_UID'] ) ? $nextDel['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iAppThreadIndex, $nextDel ); + $iNewDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $nextDel['USR_UID'] ) ? $nextDel['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iAppThreadIndex, $nextDel, $this->flagControl ); break; } diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index d15c30884..cc30a59b4 100755 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -56,7 +56,7 @@ class AppDelegation extends BaseAppDelegation * @param $isSubprocess is a subprocess inside a process? * @return delegation index of the application delegation. */ - public function createAppDelegation ($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null) + public function createAppDelegation ($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null, $flagControl = false) { if (! isset( $sProUid ) || strlen( $sProUid ) == 0) { throw (new Exception( 'Column "PRO_UID" cannot be null.' )); @@ -82,6 +82,7 @@ class AppDelegation extends BaseAppDelegation $criteria = new Criteria("workflow"); $criteria->add(AppDelegationPeer::APP_UID, $sAppUid); $criteria->add(AppDelegationPeer::DEL_LAST_INDEX, 1); + $criteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX); $criteriaIndex = clone $criteria; @@ -112,6 +113,14 @@ class AppDelegation extends BaseAppDelegation $delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1; } } + //Verify successors: parrallel submit in the same time + if($flagControl){ + $nextTaskUid = $sTasUid; + $index = $this->getAllTasksBeforeSecJoin($nextTaskUid, $sAppUid); + if($this->createThread($index, $sAppUid)){ + return 0; + } + } //Update set $criteriaUpdate = new Criteria('workflow'); @@ -156,7 +165,8 @@ class AppDelegation extends BaseAppDelegation try { $res = $this->save(); } catch (PropelException $e) { - throw ($e); + error_log($e->getMessage()); + return; } } else { // Something went wrong. We can now get the validationFailures and handle them. @@ -739,5 +749,50 @@ class AppDelegation extends BaseAppDelegation throw $e; } } + + /** + * Get all task before Join Threads + * + * @param string $nextTaskUid + * @param string $sAppUid + * @return array $index + */ + public static function getAllTasksBeforeSecJoin($nextTaskUid, $sAppUid){ + $criteriaR = new Criteria('workflow'); + $criteriaR->addSelectColumn(AppDelegationPeer::DEL_INDEX); + $criteriaR->addJoin(RoutePeer::TAS_UID, AppDelegationPeer::TAS_UID, Criteria::LEFT_JOIN); + $criteriaR->add(RoutePeer::ROU_NEXT_TASK, $nextTaskUid, Criteria::EQUAL); + $criteriaR->add(RoutePeer::ROU_TYPE, 'SEC-JOIN', Criteria::EQUAL); + $criteriaR->add(AppDelegationPeer::APP_UID, $sAppUid, Criteria::EQUAL); + $rsCriteriaR = RoutePeer::doSelectRS($criteriaR); + $rsCriteriaR->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $index = array(); + $c = 0; + while($rsCriteriaR->next()){ + $row = $rsCriteriaR->getRow(); + $index[$c++] = $row['DEL_INDEX']; + } + return $index; + } + + /** + * Verify if we need to create a new Thread + * + * @param array $index + * @param string $sAppUid + * @return boolean $res + */ + public static function createThread($index, $sAppUid){ + $criteriaDel = new Criteria("workflow"); + $criteriaDel->addSelectColumn(AppDelegationPeer::DEL_INDEX); + $criteriaDel->addSelectColumn(AppDelegationPeer::DEL_PREVIOUS); + $criteriaDel->add(AppDelegationPeer::APP_UID, $sAppUid); + $criteriaDel->add(AppDelegationPeer::DEL_PREVIOUS, $index, Criteria::IN); + $criteriaDel = AppDelegationPeer::doSelectRS($criteriaDel); + $criteriaDel->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $res = $criteriaDel->next(); + return $res; + } + }