From dc894d6857d89b459186bedc16abc58cf5f6a184 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Fri, 23 Apr 2021 17:18:51 -0400 Subject: [PATCH] PMCORE-1220 --- database/factories/ApplicationFactory.php | 8 + database/factories/ConsolidatedFactory.php | 24 ++ .../BusinessModel/Cases/BatchRoutingTest.php | 59 ++++ .../BusinessModel/Cases/CanceledTest.php | 62 ++++ .../BusinessModel/Cases/CasesListTest.php | 60 ++++ .../BusinessModel/Cases/CompletedTest.php | 62 ++++ .../BusinessModel/Cases/DraftTest.php | 1 + .../BusinessModel/Cases/InboxTest.php | 1 + .../BusinessModel/Cases/ParticipatedTest.php | 1 + .../BusinessModel/Cases/PausedTest.php | 1 + .../BusinessModel/Cases/UnassignedTest.php | 1 + .../ProcessMaker/Model/ConsolidatedTest.php | 72 +++++ .../src/ProcessMaker/Model/DelegationTest.php | 266 +++++++++++++++++- .../cases/casesConsolidatedListExtJs.php | 44 +-- .../BusinessModel/Cases/BatchRouting.php | 59 ++++ .../BusinessModel/Cases/Canceled.php | 64 +++++ .../BusinessModel/Cases/CasesList.php | 86 ++++++ .../BusinessModel/Cases/Completed.php | 60 ++++ .../src/ProcessMaker/Model/Consolidated.php | 98 +++++++ .../src/ProcessMaker/Model/Delegation.php | 52 ++-- .../src/ProcessMaker/Services/Api/Light.php | 30 +- .../src/ProcessMaker/Services/Api/System.php | 87 +++--- 22 files changed, 1081 insertions(+), 117 deletions(-) create mode 100644 database/factories/ConsolidatedFactory.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRoutingTest.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CanceledTest.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CompletedTest.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/Model/ConsolidatedTest.php create mode 100644 workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php create mode 100644 workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php create mode 100644 workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php create mode 100644 workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php create mode 100644 workflow/engine/src/ProcessMaker/Model/Consolidated.php diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php index 2688502b8..b227f108e 100644 --- a/database/factories/ApplicationFactory.php +++ b/database/factories/ApplicationFactory.php @@ -100,6 +100,14 @@ $factory->state(\ProcessMaker\Model\Application::class, 'completed', function (F ]; }); +$factory->state(\ProcessMaker\Model\Application::class, 'canceled', function (Faker $faker) { + return [ + 'APP_NUMBER' => $faker->unique()->numberBetween(1000), + 'APP_STATUS_ID' => 4, + 'APP_STATUS' => 'CANCELLED' + ]; +}); + $factory->state(\ProcessMaker\Model\Application::class, 'draft_minor_case', function (Faker $faker) { $caseNumber = $faker->unique()->numberBetween(1, 1000); return [ diff --git a/database/factories/ConsolidatedFactory.php b/database/factories/ConsolidatedFactory.php new file mode 100644 index 000000000..53884b01e --- /dev/null +++ b/database/factories/ConsolidatedFactory.php @@ -0,0 +1,24 @@ +define(\ProcessMaker\Model\Consolidated::class, function (Faker $faker) { + return [ + 'TAS_UID' => G::generateUniqueID(), + 'DYN_UID' => G::generateUniqueID(), + 'REP_TAB_UID' => G::generateUniqueID(), + 'CON_STATUS' => 'ACTIVE', + ]; +}); + +// Create a consolidated task with the foreign keys +$factory->state(\ProcessMaker\Model\Consolidated::class, 'foreign_keys', function (Faker $faker) { + $task = factory(\ProcessMaker\Model\Task::class)->create(); + $dynaform = factory(\ProcessMaker\Model\Dynaform::class)->create(); + return [ + 'TAS_UID' => $task->TAS_UID, + 'DYN_UID' => $dynaform->DYN_UID, + 'REP_TAB_UID' => G::generateUniqueID(), + 'CON_STATUS' => 'ACTIVE', + ]; +}); \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRoutingTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRoutingTest.php new file mode 100644 index 000000000..5df3ceaf9 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRoutingTest.php @@ -0,0 +1,59 @@ +states('foreign_keys')->create(); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'OPEN', + 'TAS_UID' => $consolidated->TAS_UID, + ]); + + return $delegation; + } + + /** + * This checks the counters is working properly in batch routing + * + * @covers \ProcessMaker\BusinessModel\Cases\BatchRouting::getCounter() + * @test + */ + public function it_should_count_cases_consolidated() + { + // Create factories related to the consolidated cases + $cases = $this->createConsolidated(); + // Create new Draft object + $consolidated = new BatchRouting(); + $consolidated->setUserId($cases['USR_ID']); + $consolidated->setUserUid($cases['USR_UID']); + $result = $consolidated->getCounter(); + $this->assertTrue($result > 0); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CanceledTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CanceledTest.php new file mode 100644 index 000000000..1979dd194 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CanceledTest.php @@ -0,0 +1,62 @@ +states('canceled')->create(); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'CLOSED', + 'DEL_INDEX' => 1, + 'USR_UID' => $application->APP_INIT_USER, + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, + ]); + + return $delegation; + } + + /** + * This checks the counters is working properly in canceled + * + * @covers \ProcessMaker\BusinessModel\Cases\Canceled::getCounter() + * @test + */ + public function it_should_count_cases_completed() + { + // Create factories related to the canceled cases + $cases = $this->createCanceled(); + // Create new Canceled object + $canceled = new Canceled(); + $canceled->setUserId($cases['USR_ID']); + $canceled->setUserUid($cases['USR_UID']); + $result = $canceled->getCounter(); + $this->assertTrue($result > 0); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php new file mode 100644 index 000000000..4711632b0 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php @@ -0,0 +1,60 @@ +states('completed')->create(); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'CLOSED', + 'DEL_INDEX' => 1, + 'USR_UID' => $application->APP_INIT_USER, + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, + ]); + + return $delegation; + } + + /** + * This test getAllCounters + * + * @covers \ProcessMaker\BusinessModel\Cases\CasesList::getAllCounters() + * @test + */ + public function it_return_all_counters() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $count = new CasesList(); + $result = $count->getAllCounters($delegation->USR_UID); + $this->assertNotEmpty($result); + $this->assertArrayHasKey('CASES_INBOX', $result); + $this->assertArrayHasKey('CASES_DRAFT', $result); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CompletedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CompletedTest.php new file mode 100644 index 000000000..94c25032d --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CompletedTest.php @@ -0,0 +1,62 @@ +states('completed')->create(); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'CLOSED', + 'DEL_INDEX' => 1, + 'USR_UID' => $application->APP_INIT_USER, + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, + ]); + + return $delegation; + } + + /** + * This checks the counters is working properly in completed + * + * @covers \ProcessMaker\BusinessModel\Cases\Completed::getCounter() + * @test + */ + public function it_should_count_cases_completed() + { + // Create factories related to the completed cases + $cases = $this->createCompleted(); + // Create new Completed object + $completed = new Completed(); + $completed->setUserId($cases['USR_ID']); + $completed->setUserUid($cases['USR_UID']); + $result = $completed->getCounter(); + $this->assertTrue($result > 0); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php index 8a6e82cd3..d8d6940c6 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php @@ -98,6 +98,7 @@ class DraftTest extends TestCase * * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() + * @covers \ProcessMaker\Model\Delegation::scopeDraft() * @test */ public function it_get_result_without_filters() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php index d46f2946e..790adfe81 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php @@ -89,6 +89,7 @@ class InboxTest extends TestCase * * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() + * @covers \ProcessMaker\Model\Delegation::scopeInbox() * @test */ public function it_get_result_without_filters() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php index b024c3b11..7a9f1ea25 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php @@ -89,6 +89,7 @@ class ParticipatedTest extends TestCase * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() + * @covers \ProcessMaker\Model\Delegation::scopeParticipated() * @test */ public function it_get_result_without_filters() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php index 65c755de0..d3184040c 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php @@ -196,6 +196,7 @@ class PausedTest extends TestCase * * @covers \ProcessMaker\BusinessModel\Cases\Paused::getData() * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\Model\Delegation::scopePaused() * @test */ public function it_get_result_without_filters() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php index 2e6133f96..3c849e55d 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php @@ -319,6 +319,7 @@ class UnassignedTest extends TestCase * This ensures get data from self-service-user-assigned without filters * * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getData() + * @covers \ProcessMaker\Model\Delegation::scopeSelfService() * @test */ public function it_test_unassigned_by_user_without_filters() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ConsolidatedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ConsolidatedTest.php new file mode 100644 index 000000000..5938138bc --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ConsolidatedTest.php @@ -0,0 +1,72 @@ +states('foreign_keys')->create(); + $delegation = factory(Delegation::class)->states('foreign_keys')->create([ + 'DEL_THREAD_STATUS' => 'OPEN', + 'TAS_UID' => $consolidated->TAS_UID, + ]); + + return $delegation; + } + + /** + * This checks the counters is working properly in draft + * + * @covers \ProcessMaker\Model\Consolidated::getCounterActive() + * @test + */ + public function it_should_count_cases_consolidated() + { + // Create factories related to the consolidated + $cases = $this->createConsolidated(); + // Create new Consolidated object + $consolidated = new Consolidated(); + $result = $consolidated->getCounterActive(); + $this->assertTrue($result > 0); + } + + /** + * This checks the counters is working properly in consolidated + * + * @covers \ProcessMaker\Model\Consolidated::getCounterActive() + * @test + */ + public function it_should_count_cases() + { + // Create factories related to the consolidated + $cases = $this->createConsolidated(); + // Create new Consolidated object + $consolidated = new Consolidated(); + $result = $consolidated->getConsolidated(); + $this->assertTrue($result > 0); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index a86a42619..4a124c8ab 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use ProcessMaker\Model\AppAssignSelfServiceValue; use ProcessMaker\Model\AppAssignSelfServiceValueGroup; +use ProcessMaker\Model\AppDelay; use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\GroupUser; @@ -218,6 +219,22 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->joinApplication()->caseCompleted()->get()); } + /** + * This test scopeCaseCanceled + * + * @covers \ProcessMaker\Model\Delegation::scopeCaseCanceled() + * @test + */ + public function it_return_scope_case_canceled() + { + $application = factory(Application::class)->states('canceled')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->caseCanceled()->get()); + } + /** * This test scopeStatus * @@ -250,6 +267,70 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->joinApplication()->statusIds([$application->APP_STATUS_ID])->get()); } + /** + * This test scopeStartDateFrom + * + * @covers \ProcessMaker\Model\Delegation::scopeStartDateFrom() + * @test + */ + public function it_return_scope_start_date_from() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->startDateFrom($application->APP_CREATE_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeStartDateTo + * + * @covers \ProcessMaker\Model\Delegation::scopeStartDateTo() + * @test + */ + public function it_return_scope_start_date_to() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->startDateto($application->APP_CREATE_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeFinishCaseFrom + * + * @covers \ProcessMaker\Model\Delegation::scopeFinishCaseFrom() + * @test + */ + public function it_return_scope_finish_case_date_from() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->finishCaseFrom($application->APP_FINISH_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeFinishCaseTo + * + * @covers \ProcessMaker\Model\Delegation::scopeFinishCaseTo() + * @test + */ + public function it_return_scope_finish_case_date_to() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->finishCaseTo($application->APP_FINISH_DATE->format("Y-m-d H:i:s"))->get()); + } + /** * This test scopeDelegateDateFrom * @@ -513,7 +594,7 @@ class DelegationTest extends TestCase public function it_return_scope_exclude_tas_types() { $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(0, $table->excludeTaskTypes(['NORMAL'])->get()); + $this->assertNotEmpty($table->excludeTaskTypes(['ADHOC'])->get()); } /** @@ -546,6 +627,137 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->appStatusId()->get()); } + /** + * This test scopeProcessInList + * + * @covers \ProcessMaker\Model\Delegation::scopeProcessInList() + * @test + */ + public function it_return_scope_process_in_list() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->processInList([$table->PRO_ID])->get()); + } + + /** + * This test scopeJoinCategoryProcess + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinCategoryProcess() + * @test + */ + public function it_return_scope_join_category_process() + { + $category = factory(ProcessCategory::class)->create(); + $process = factory(Process::class)->create([ + 'PRO_CATEGORY' => $category->CATEGORY_UID + ]); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'PRO_ID' => $process->PRO_ID + ]); + $this->assertCount(1, $table->joinCategoryProcess($category->CATEGORY_UID)->get()); + } + + /** + * This test scopeJoinPreviousIndex + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinPreviousIndex() + * @test + */ + public function it_return_scope_join_previous_index() + { + $previous = factory(Delegation::class)->states('foreign_keys')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $previous->APP_NUMBER, + 'DEL_INDEX' => $previous->DEL_INDEX+1, + 'DEL_PREVIOUS' => $previous->DEL_INDEX + ]); + $this->assertNotEmpty($table->joinPreviousIndex()->get()); + } + + /** + * This test scopeJoinProcess + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinProcess() + * @test + */ + public function it_return_scope_join_process() + { + $process = factory(Process::class)->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'PRO_ID' => $process->PRO_ID + ]); + $this->assertCount(1, $table->joinProcess()->get()); + } + + /** + * This test scopeJoinTask + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinTask() + * @test + */ + public function it_return_scope_join_task() + { + $task = factory(Task::class)->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'TAS_ID' => $task->TAS_ID + ]); + $this->assertCount(1, $table->joinTask()->get()); + } + + /** + * This test scopeJoinUser + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinUser() + * @test + */ + public function it_return_scope_join_user() + { + $user = factory(User::class)->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'USR_ID' => $user->USR_ID + ]); + $this->assertCount(1, $table->joinUser()->get()); + } + + /** + * This test scopeJoinApplication + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinApplication() + * @test + */ + public function it_return_scope_join_application() + { + $application = factory(Application::class)->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER + ]); + $this->assertCount(1, $table->joinApplication()->get()); + } + + /** + * This test scopeJoinAppDelay + * + * @covers \ProcessMaker\Model\Delegation::scopeJoinAppDelay() + * @covers \ProcessMaker\Model\Delegation::scopeJoinAppDelayUsers() + * @test + */ + public function it_return_scope_join_app_delay_pause() + { + $user = factory(User::class)->create(); + $delay = factory(AppDelay::class)->create([ + 'APP_TYPE' => 'PAUSE', + 'APP_DISABLE_ACTION_USER' => '0', + 'APP_DELEGATION_USER' => $user->USR_UID, + ]); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'USR_ID' => $user->USR_ID, + 'USR_UID' => $user->USR_UID, + 'APP_NUMBER' => $delay->APP_NUMBER, + 'DEL_INDEX' => $delay->APP_DEL_INDEX + ]); + $this->assertCount(1, $table->joinAppDelay('PAUSE')->joinAppDelayUsers($user->USR_ID)->get()); + } + /** * This checks to make sure pagination is working properly * @@ -2892,6 +3104,58 @@ class DelegationTest extends TestCase $this->assertNotEmpty($result); } + /** + * This check the return of thread info + * + * @covers \ProcessMaker\Model\Delegation::getThreadInfo() + * @test + */ + public function it_get_thread_info() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $result = Delegation::getThreadInfo($delegation->APP_NUMBER, $delegation->DEL_INDEX); + $this->assertNotEmpty($result); + } + + /** + * This check the return of pending threads + * + * @covers \ProcessMaker\Model\Delegation::getPendingThreads() + * @test + */ + public function it_get_threads_pending() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $result = Delegation::getPendingThreads($delegation->APP_NUMBER); + $this->assertNotEmpty($result); + } + + /** + * This check the return of pending task + * + * @covers \ProcessMaker\Model\Delegation::getPendingTask() + * @test + */ + public function it_get_task_pending() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $result = Delegation::getPendingTask($delegation->APP_NUMBER); + $this->assertNotEmpty($result); + } + + /** + * This check the return of last thread + * + * @covers \ProcessMaker\Model\Delegation::getLastThread() + * @test + */ + public function it_get_last_thread() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $result = Delegation::getLastThread($delegation->APP_NUMBER); + $this->assertNotEmpty($result); + } + /** * This tests the getDeltitle() method * diff --git a/workflow/engine/methods/cases/casesConsolidatedListExtJs.php b/workflow/engine/methods/cases/casesConsolidatedListExtJs.php index b8dfee900..d787ed02e 100644 --- a/workflow/engine/methods/cases/casesConsolidatedListExtJs.php +++ b/workflow/engine/methods/cases/casesConsolidatedListExtJs.php @@ -1,13 +1,13 @@ add(CaseConsolidatedCorePeer::CON_STATUS, 'ACTIVE'); -$activeNumRows = CaseConsolidatedCorePeer::doCount($oCriteria); +$consolidated = new Consolidated(); +$activeNumRows = $consolidated->getCounterActive(); $headPublisher = headPublisher::getSingleton(); $usrUid = $_SESSION["USER_LOGGED"]; @@ -17,8 +17,8 @@ try { $confCasesList = $conf->getConfiguration("casesList", $action); $generalConfCasesList = $conf->getConfiguration("ENVIRONMENT_SETTINGS", ""); } catch (Exception $e) { - $confCasesList = array(); - $generalConfCasesList = array(); + $confCasesList = []; + $generalConfCasesList = []; } if (isset($generalConfCasesList["casesListRowNumber"]) && !empty($generalConfCasesList["casesListRowNumber"])) { @@ -27,33 +27,19 @@ if (isset($generalConfCasesList["casesListRowNumber"]) && !empty($generalConfCas $config = getAdditionalFields($action, $confCasesList); $pageSize = intval($config["rowsperpage"]); } +// Get a query +$results = $consolidated->getConsolidated(); -$criteria = new Criteria(); -$criteria->addAsColumn('NUMREC', 'COUNT(' . ListInboxPeer::TAS_UID . ')'); -$criteria->addSelectColumn(ListInboxPeer::PRO_UID); -$criteria->addSelectColumn(ProcessPeer::PRO_TITLE); -$criteria->addSelectColumn(ListInboxPeer::TAS_UID); -$criteria->addSelectColumn(TaskPeer::TAS_TITLE); -$criteria->addSelectColumn(CaseConsolidatedCorePeer::DYN_UID); -$criteria->addJoin(CaseConsolidatedCorePeer::TAS_UID, ListInboxPeer::TAS_UID, Criteria::LEFT_JOIN); -$criteria->addJoin(ListInboxPeer::PRO_UID, ProcessPeer::PRO_UID, Criteria::LEFT_JOIN); -$criteria->addJoin(ListInboxPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN); -$criteria->add(ListInboxPeer::USR_UID, $usrUid, Criteria::EQUAL); -$criteria->add(ListInboxPeer::APP_STATUS, 'TO_DO', Criteria::EQUAL); -$criteria->addGroupByColumn(ListInboxPeer::TAS_UID); -$rsSql = CaseConsolidatedCorePeer::doSelectRS($criteria); -$rsSql->setFetchmode(ResultSet::FETCHMODE_ASSOC); - -while ($rsSql->next()) { - $row = $rsSql->getRow(); - +foreach ($results as $row) { + $casesPerTask = count($row); + $row = head($row); $processUid = $row['PRO_UID']; - $proTitle = $row['PRO_TITLE']; + $proTitle = 'PRO_TITLE'; $taskUid = $row['TAS_UID']; - $taskTitle = $row['TAS_TITLE']; + $taskTitle = 'TAS_TITLE'; $dynaformUid = $row['DYN_UID']; - $tabTitle = $taskTitle . " (" . (($activeNumRows > 0) ? $row["NUMREC"] : 0) . ")"; + $tabTitle = $taskTitle . " (" . (($activeNumRows > 0) ? $casesPerTask : 0) . ")"; $grdTitle = htmlentities($proTitle . " / " . $tabTitle, ENT_QUOTES, "UTF-8"); $tabTitle = htmlentities(substr($proTitle, 0, 25) . ((strlen($proTitle) > 25) ? "..." : null) . " / " . $tabTitle, ENT_QUOTES, "UTF-8"); @@ -117,7 +103,7 @@ if (count($arrayTabItem) > 0) { $headPublisher->assign("urlProxy", $urlProxy); $headPublisher->assign('credentials', $clientToken); - $oHeadPublisher->assign('isIE', Bootstrap::isIE()); + $headPublisher->assign('isIE', Bootstrap::isIE()); $headPublisher->addExtJsScript("app/main", true); $headPublisher->addExtJsScript("cases/casesListConsolidated", false); //Adding a JavaScript file .js diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php new file mode 100644 index 000000000..e095c43a6 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php @@ -0,0 +1,59 @@ +columnsView; + } + + /** + * Scope filters + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function filters($query) + { + // todo, the list for consolidated cases was not defined for the new HOME + } + + /** + * Get the data of consolidated cases + * + * @return array + */ + public function getData() + { + // todo, the list for consolidated cases was not defined for the new HOME + return []; + } + + /** + * Get the number of consolidated cases + * + * @return int + */ + public function getCounter() + { + $query = Consolidated::query()->select(); + // Scope get the pending consolidated task + $query->joinPendingCases(); + // Get only active + $query->active(); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php new file mode 100644 index 000000000..3c69cf2b3 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php @@ -0,0 +1,64 @@ +columnsView; + } + + /** + * Scope filters + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function filters($query) + { + // todo, the list for canceled cases was not defined + } + + /** + * Get the data of canceled cases + * + * @return array + */ + public function getData() + { + // todo, the list for canceled cases was not defined + return []; + } + + /** + * Get the number of canceled cases + * + * @return int + */ + public function getCounter() + { + // Get base query + $query = Delegation::query()->select(); + // Join with application + $query->joinApplication(); + // Scope that sets the queries for Participated + $query->participated($this->getUserId()); + // Scope that search for the CANCELED + $query->caseCanceled(); + // Scope to set the last thread + $query->lastThread(); + // Return the number of rows + return $query->count(['APP_DELEGATION.APP_NUMBER']); + } +} diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php new file mode 100644 index 000000000..44d3ce220 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php @@ -0,0 +1,86 @@ +mapList = [ + /*----------------------------------********---------------------------------*/ + 'batchRouting' => 'CONSOLIDATED_CASES', + /*----------------------------------********---------------------------------*/ + 'canceled' => 'CASES_CANCELLED', + 'completed' => 'CASES_COMPLETED', + 'draft' => 'CASES_DRAFT', + 'inbox' => 'CASES_INBOX', + 'participated' => 'CASES_SENT', + 'paused' => 'CASES_PAUSED', + ]; + + /*----------------------------------********---------------------------------*/ + $this->batchRouting = new BatchRouting(); + /*----------------------------------********---------------------------------*/ + $this->canceled = new Canceled(); + $this->completed = new Completed(); + $this->draft = new Draft(); + $this->inbox = new Inbox(); + $this->participated = new Participated(); + $this->paused = new Paused(); + $this->unassigned = new Unassigned(); + } + + /** + * Count cases by user + * + * @param string $usrUid + * @param bool $format + * + * @return array + */ + public function getAllCounters(string $usrUid, bool $format = false) + { + // Get the usrId key + $usrId = User::getId($usrUid); + // Get the classes + $list = $this->mapList; + $response = []; + foreach ($list as $listObject => $item) { + $this->$listObject->setUserUid($usrUid); + $this->$listObject->setUserId($usrId); + $total = $this->$listObject->getCounter($usrUid); + if ($format) { + array_push($response, (['count' => $total, 'item' => $item])); + } else { + $response[$item] = $total; + } + } + + return $response; + } +} diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php new file mode 100644 index 000000000..ada994487 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php @@ -0,0 +1,60 @@ +columnsView; + } + + /** + * Scope filters + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function filters($query) + { + // todo, the list for completed cases was defined in participated + } + + /** + * Get the data of completed cases + * + * @return array + */ + public function getData() + { + // todo, the list for completed cases was defined in participated + return []; + } + + /** + * Get the number of completed cases + * + * @return int + */ + public function getCounter() + { + // For started by me + $participated = new Participated(); + $participated->setParticipatedStatus('COMPLETED'); + $participated->setUserUid($this->getUserUid()); + $participated->setUserId($this->getUserId()); + $count = $participated->getCounter(); + + return $count; + } +} diff --git a/workflow/engine/src/ProcessMaker/Model/Consolidated.php b/workflow/engine/src/ProcessMaker/Model/Consolidated.php new file mode 100644 index 000000000..a511c15b2 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/Consolidated.php @@ -0,0 +1,98 @@ +belongsTo(Task::class, 'TAS_UID', 'TAS_UID'); + } + + /** + * Scope a query to only include active batch routing + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeActive($query) + { + return $query->where('CON_STATUS', 'ACTIVE'); + } + + /** + * Scope a join for pending cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeJoinPendingCases($query, $statusId = 2) + { + $query->leftJoin('APP_DELEGATION', function ($join) { + $join->on('APP_DELEGATION.TAS_UID', '=', 'CASE_CONSOLIDATED.TAS_UID') + ->where('APP_DELEGATION.DEL_THREAD_STATUS', 'OPEN'); + }); + + return $query; + } + + /** + * Count tasks configured with consolidated + * + * @return int + */ + public function getCounterActive() + { + $query = Consolidated::query()->select(); + // Apply filters + $query->active(); + // Return the number of rows + return $query->count(['CASE_CONSOLIDATED.TAS_UID']); + } + + /** + * Count tasks configured with consolidated + * + * @return int + */ + public function getConsolidated() + { + $query = Consolidated::query()->select([ + 'APP_DELEGATION.APP_NUMBER', + 'APP_DELEGATION.PRO_UID', + 'CASE_CONSOLIDATED.TAS_UID', + 'CASE_CONSOLIDATED.DYN_UID', + ]); + // Scope get the pending consolidated task + $query->joinPendingCases(); + // Get only active + $query->active(); + // Get the rows + $bachPerTask = []; + $results = $query->get(); + $results->each(function ($item, $key) use (&$bachPerTask) { + $res = $item->toArray(); + $bachPerTask[$item->TAS_UID] = []; + $bachPerTask[$item->TAS_UID][] = $res; + }); + // Return + return $bachPerTask; + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 0ecd28fa9..f5a24a243 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -179,6 +179,18 @@ class Delegation extends Model return $query->where('APPLICATION.APP_STATUS_ID', Application::STATUS_COMPLETED); } + /** + * Scope a query to get the canceled by me + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCaseCanceled($query) + { + return $query->where('APPLICATION.APP_STATUS_ID', Application::STATUS_CANCELED); + } + /** * Scope a query to get specific status * @@ -700,23 +712,16 @@ class Delegation extends Model } /** - * Scope a join with APPLICATION with specific app status + * Scope the Process is in list * * @param \Illuminate\Database\Eloquent\Builder $query - * @param string $category + * @param array $processes * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeJoinCategoryProcess($query, $category = '') + public function scopeProcessInList($query, array $processes) { - $query->leftJoin('PROCESS', function ($join) use ($category) { - $join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID'); - if ($category) { - $join->where('PROCESS.PRO_CATEGORY', $category); - } - }); - - return $query; + return $query->whereIn('APP_DELEGATION.PRO_ID', $processes); } /** @@ -835,16 +840,20 @@ class Delegation extends Model } /** - * Scope join with user for get the previous user + * Scope a join with APPLICATION with specific app status * * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $category * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeJoinPreviousUser($query) + public function scopeJoinCategoryProcess($query, $category = '') { - $query->leftJoin('USERS AS PREVIOUS', function ($leftJoin) { - $leftJoin->on('AD.USR_UID', '=', 'PREVIOUS.USR_UID'); + $query->leftJoin('PROCESS', function ($join) use ($category) { + $join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID'); + if ($category) { + $join->where('PROCESS.PRO_CATEGORY', $category); + } }); return $query; @@ -914,19 +923,6 @@ class Delegation extends Model return $query; } - /** - * Scope the Process is in list - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $processes - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeProcessInList($query, array $processes) - { - return $query->whereIn('APP_DELEGATION.PRO_ID', $processes); - } - /** * Scope join with AppDelay * diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Light.php b/workflow/engine/src/ProcessMaker/Services/Api/Light.php index f59ae6bc5..1a06f1c1c 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Light.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Light.php @@ -12,6 +12,7 @@ use Luracast\Restler\RestException; use PmDynaform; use Process as ModelProcess; use ProcessMaker\BusinessModel\Cases as BusinessModelCases; +use ProcessMaker\BusinessModel\Cases\CasesList; use ProcessMaker\BusinessModel\DynaForm as BusinessModelDynaForm; use ProcessMaker\BusinessModel\Light as BusinessModelLight; use ProcessMaker\BusinessModel\Lists; @@ -108,35 +109,20 @@ class Light extends Api /** * Get list counters - * @return array - * - * @copyright Colosa - Bolivia * * @url GET /counters + * @status 200 + * + * @return array */ public function countersCases() { try { - $userId = $this->getUserId(); + $usrUid = $this->getUserId(); + $count = new CasesList(); + $result = $count->getAllCounters($usrUid); + $result = $this->parserCountersCases($result); - /*----------------------------------********---------------------------------*/ - if (true) { - //In enterprise version this block of code should always be executed - //In community version this block of code is deleted and is executed the other - $list = new Lists(); - $arrayListCounter = $list->getCounters($userId); - } else { - /*----------------------------------********---------------------------------*/ - $case = new BusinessModelCases(); - $arrayListCounter = $case->getListCounters( - $userId, - ['to_do', 'draft', 'sent', 'selfservice', 'paused', 'completed', 'cancelled'] - ); - /*----------------------------------********---------------------------------*/ - } - /*----------------------------------********---------------------------------*/ - - $result = $this->parserCountersCases($arrayListCounter); } catch (Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/System.php b/workflow/engine/src/ProcessMaker/Services/Api/System.php index 9b219703e..45dd97079 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/System.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/System.php @@ -1,54 +1,60 @@ - * @copyright Colosa - Bolivia - * - * @url GET /db-engines * @protected */ public function doGetDataBaseEngines() { try { - $oDBConnection = new \ProcessMaker\BusinessModel\DataBaseConnection(); - $response = $oDBConnection->getDbEngines(); + $dbConnection = new DataBaseConnection(); + $response = $dbConnection->getDbEngines(); + return $response; - } catch (\Exception $e) { + } catch (Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } /** - * Get count for all lists + * Get counter for all lists + * + * @url GET /counters-lists + * @status 200 * * @return array * - * @author Brayan Pereyra (Cochalo) - * @copyright Colosa - Bolivia - * - * @url GET /counters-lists * @protected */ public function doGetCountersLists() { try { - $userId = $this->getUserId(); - $lists = new \ProcessMaker\BusinessModel\Lists(); - $response = $lists->getCounters($userId); - return $response; - } catch (\Exception $e) { + $usrUid = $this->getUserId(); + $count = new CasesList(); + $result = $count->getAllCounters($usrUid, true); + + return $result; + } catch (Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } @@ -56,49 +62,54 @@ class System extends Api /** * Get a list of the installed languages. * - * @category HOR-3209,PROD-181 - * @return array * @url GET /languages + * @status 200 + * + * @return array + * * @public + * @category HOR-3209,PROD-181 */ public function doGetLanguages() { try { - $language = new \ProcessMaker\BusinessModel\Language; + $language = new Language; $list = $language->getLanguageList(); + return ["data" => $list]; - } catch (\Exception $e) { + } catch (Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } /** - * @return array - * - * @author Gustavo Cruz - * @copyright Colosa - Bolivia * * @url GET /enabled-features + * @status 200 + * + * @return array + * * @protected */ public function doGetEnabledFeatures() { try { - $enabledFeatures = array(); + $enabledFeatures = []; /*----------------------------------********---------------------------------*/ - $keys = array ('zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=', + $keys = ['zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=', 'oq3S29xemxEZXJpZEIzN01qenJUaStSekY4cTdJVm5vbWtVM0d4S2lJSS9qUT0=', - 'jXsSi94bkRUcVZyRStNVExlTXhEclVadGRRcG9xbjNvTWVFQUF3cklKQVBiVT0='); + 'jXsSi94bkRUcVZyRStNVExlTXhEclVadGRRcG9xbjNvTWVFQUF3cklKQVBiVT0=']; foreach ($keys as $key) { - if (\PMLicensedFeatures + if (PMLicensedFeatures ::getSingleton() ->verifyfeature($key)) { $enabledFeatures[] = $key; } } /*----------------------------------********---------------------------------*/ + return $enabledFeatures; - } catch (\Exception $e) { + } catch (Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } @@ -107,6 +118,8 @@ class System extends Api * Get the list of installed skins. * * @url GET /skins + * @status 200 + * * @return array * @access protected * @class AccessControl {@permission PM_FACTORY} @@ -115,12 +128,12 @@ class System extends Api public function doGetSkins() { try { - $model = new \ProcessMaker\BusinessModel\Skins(); + $model = new Skins(); $response = $model->getSkins(); + return ["data" => $response]; - } catch (\Exception $e) { + } catch (Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } - }