airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject airavata-php-gateway git commit: AIRAVATA-2041 Display friendly error when exp id doesn't exist
Date Wed, 04 Jan 2017 13:54:28 GMT
Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop 0bb7892b8 -> b7d80b118


AIRAVATA-2041 Display friendly error when exp id doesn't exist


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/b7d80b11
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/b7d80b11
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/b7d80b11

Branch: refs/heads/develop
Commit: b7d80b1186205f9f794db17f1aa403bc8485a497
Parents: 0bb7892
Author: Marcus Christie <machristie@apache.org>
Authored: Wed Jan 4 08:53:37 2017 -0500
Committer: Marcus Christie <machristie@apache.org>
Committed: Wed Jan 4 08:53:37 2017 -0500

----------------------------------------------------------------------
 app/controllers/ExperimentController.php     | 186 +++++++++++-----------
 app/libraries/ExperimentUtilities.php        |   3 +-
 app/views/partials/experiment-info.blade.php |   2 -
 3 files changed, 98 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b7d80b11/app/controllers/ExperimentController.php
----------------------------------------------------------------------
diff --git a/app/controllers/ExperimentController.php b/app/controllers/ExperimentController.php
index fe38a19..08a267e 100755
--- a/app/controllers/ExperimentController.php
+++ b/app/controllers/ExperimentController.php
@@ -1,5 +1,6 @@
 <?php
 
+use Airavata\API\Error\ExperimentNotFoundException;
 use Airavata\Model\Status\JobState;
 use Airavata\Model\Group\ResourceType;
 
@@ -114,111 +115,116 @@ class ExperimentController extends BaseController
 
     public function summary()
     {
-        $experiment = ExperimentUtilities::get_experiment($_GET['expId']);
-        if(isset($_GET['isAutoRefresh']) && $_GET['isAutoRefresh'] == 'true' &&
$experiment != null){
+        $experiment = null;
+        try {
+            $experiment = ExperimentUtilities::get_experiment($_GET['expId']);
+        } catch (ExperimentNotFoundException $enf) {
+
+            Log::error("Experiment wasn't found", array("message" => $enf->getMessage(),
"username" => Session::get("username"), "gateway_id" => Session::get("gateway_id")));
+            if (Input::has("dashboard"))
+                return View::make("partials/experiment-info", array("invalidExperimentId"
=> 1));
+            else
+                return View::make("experiment/summary", array("invalidExperimentId" =>
1));
+        }
+        // Assume that experiment is not null now
+
+        if(isset($_GET['isAutoRefresh']) && $_GET['isAutoRefresh'] == 'true'){
             $autoRefresh = true;
         }else{
             $autoRefresh = false;
         }
-        if ($experiment != null) {
-            //viewing experiments of other gateways is not allowed if user is not super admin
-            if( $experiment->gatewayId != Session::get("gateway_id") && !Session::has("super-admin")){
-                Session::put("permissionDenied", true);
-                CommonUtilities::print_error_message('It seems that you do not have permissions
to view this experiment or it belongs to another gateway.');
-                if (Input::has("dashboard"))
-                    return View::make("partials/experiment-info", array("invalidExperimentId"
=> 1, "users" => json_encode(array())));
-                else
-                    return View::make("experiment/summary", array("invalidExperimentId" =>
1, "users" => json_encode(array())));
-            }
+        //viewing experiments of other gateways is not allowed if user is not super admin
+        if( $experiment->gatewayId != Session::get("gateway_id") && !Session::has("super-admin")){
+            Session::put("permissionDenied", true);
+            CommonUtilities::print_error_message('It seems that you do not have permissions
to view this experiment or it belongs to another gateway.');
+            if (Input::has("dashboard"))
+                return View::make("partials/experiment-info", array("invalidExperimentId"
=> 1, "users" => json_encode(array())));
             else
-                Session::forget("permissionDenied");
+                return View::make("experiment/summary", array("invalidExperimentId" =>
1, "users" => json_encode(array())));
+        }
+        else
+            Session::forget("permissionDenied");
 
 
-            $project = null;
-            if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
-                if (SharingUtilities::userCanRead(Session::get("username"), $experiment->projectId,
ResourceType::PROJECT)) {
-                    $project = ProjectUtilities::get_project($experiment->projectId);
-                }
-            } else {
+        $project = null;
+        if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
+            if (SharingUtilities::userCanRead(Session::get("username"), $experiment->projectId,
ResourceType::PROJECT)) {
                 $project = ProjectUtilities::get_project($experiment->projectId);
             }
-            $expVal = ExperimentUtilities::get_experiment_values($experiment);
-            $jobDetails = ExperimentUtilities::get_job_details($experiment->experimentId);
+        } else {
+            $project = ProjectUtilities::get_project($experiment->projectId);
+        }
+        $expVal = ExperimentUtilities::get_experiment_values($experiment);
+        $jobDetails = ExperimentUtilities::get_job_details($experiment->experimentId);
 //            var_dump( $jobDetails); exit;
-            foreach( $jobDetails as $index => $jobDetail){
-                if(isset($jobDetail->jobStatuses)){
-                      $jobDetails[ $index]->jobStatuses[0]->jobStateName = JobState::$__names[$jobDetail->jobStatuses[0]->jobState];
-                }
-                else{
-                    $jobDetails[ $index]->jobStatuses = [new stdClass()];
-                    $jobDetails[ $index]->jobStatuses[0]->jobStateName = null;
-                }
+        foreach( $jobDetails as $index => $jobDetail){
+            if(isset($jobDetail->jobStatuses)){
+                  $jobDetails[ $index]->jobStatuses[0]->jobStateName = JobState::$__names[$jobDetail->jobStatuses[0]->jobState];
             }
-            $expVal["jobDetails"] = $jobDetails;
-
-            $writeableProjects = ProjectUtilities::get_all_user_writeable_projects(Session::get("gateway_id"),
Session::get("username"));
-
-            $data = array(
-                "expId" => Input::get("expId"),
-                "experiment" => $experiment,
-                "project" => $project,
-                "jobDetails" => $jobDetails,
-                "expVal" => $expVal,
-                "autoRefresh"=> $autoRefresh,
-                "writeableProjects" => $writeableProjects
-            );
-            if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
-                $users = SharingUtilities::getProfilesForSharedUsers(Input::get("expId"),
ResourceType::EXPERIMENT);
-                $sharedExperimentOwner = SharingUtilities::getSharedResourceOwner($experiment->experimentId,
ResourceType::EXPERIMENT);
-                $sharedProjectOwner = SharingUtilities::getSharedResourceOwner($experiment->projectId,
ResourceType::PROJECT);
-
-                $owner = array();
-                $projectOwner = array();
-                if (Session::get("username") !== $sharedExperimentOwner) {
-                    $owner[$sharedExperimentOwner] = $users[$sharedExperimentOwner];
-                }
-                if (Session::get("username") !== $sharedProjectOwner) {
-                    $projectOwner[$sharedProjectOwner] = $users[$sharedProjectOwner];
-                }
-                // Subtract out the owner and project owner from list of users
-                $users = array_diff_key($users, $owner);
-                $users = array_diff_key($users, $projectOwner);
-                // If project owner is the same as owner, just show the owner, not the project
owner
-                $projectOwner = array_diff_key($projectOwner, $owner);
-                // Only allow editing sharing on the summary page if the owner
-                // and the experiment isn't editable. If the experiment is
-                // editable, the sharing can be edited on the edit page.
-                $canEditSharing = (Session::get("username") === $sharedExperimentOwner) &&
!$expVal["editable"];
-                $data['can_write'] = SharingUtilities::userCanWrite(Session::get("username"),
$experiment->experimentId, ResourceType::EXPERIMENT);
-                $data["users"] = json_encode($users);
-                $data["owner"] = json_encode($owner);
-                $data["projectOwner"] = json_encode($projectOwner);
-                $data["canEditSharing"] = $canEditSharing;
-                // The summary page has it's own Update Sharing button
-                $data["updateSharingViaAjax"] = true;
+            else{
+                $jobDetails[ $index]->jobStatuses = [new stdClass()];
+                $jobDetails[ $index]->jobStatuses[0]->jobStateName = null;
             }
-
-            if( Input::has("dashboard"))
-            {
-                $detailedExperiment = ExperimentUtilities::get_detailed_experiment( $_GET['expId']);
-                $data["detailedExperiment"] = $detailedExperiment;
+        }
+        $expVal["jobDetails"] = $jobDetails;
+
+        $writeableProjects = ProjectUtilities::get_all_user_writeable_projects(Session::get("gateway_id"),
Session::get("username"));
+
+        $data = array(
+            "expId" => Input::get("expId"),
+            "experiment" => $experiment,
+            "project" => $project,
+            "jobDetails" => $jobDetails,
+            "expVal" => $expVal,
+            "autoRefresh"=> $autoRefresh,
+            "writeableProjects" => $writeableProjects
+        );
+        if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
+            $users = SharingUtilities::getProfilesForSharedUsers(Input::get("expId"), ResourceType::EXPERIMENT);
+            $sharedExperimentOwner = SharingUtilities::getSharedResourceOwner($experiment->experimentId,
ResourceType::EXPERIMENT);
+            $sharedProjectOwner = SharingUtilities::getSharedResourceOwner($experiment->projectId,
ResourceType::PROJECT);
+
+            $owner = array();
+            $projectOwner = array();
+            if (Session::get("username") !== $sharedExperimentOwner) {
+                $owner[$sharedExperimentOwner] = $users[$sharedExperimentOwner];
             }
-
-            if (Request::ajax()) {
-                //admin wants to see an experiment summary
-                if (Input::has("dashboard")) {
-                    $data["dashboard"] = true;
-                    return View::make("partials/experiment-info", $data);
-                } else
-                    return json_encode($data);
-            } else {
-                return View::make("experiment/summary", $data);
+            if (Session::get("username") !== $sharedProjectOwner) {
+                $projectOwner[$sharedProjectOwner] = $users[$sharedProjectOwner];
             }
+            // Subtract out the owner and project owner from list of users
+            $users = array_diff_key($users, $owner);
+            $users = array_diff_key($users, $projectOwner);
+            // If project owner is the same as owner, just show the owner, not the project
owner
+            $projectOwner = array_diff_key($projectOwner, $owner);
+            // Only allow editing sharing on the summary page if the owner
+            // and the experiment isn't editable. If the experiment is
+            // editable, the sharing can be edited on the edit page.
+            $canEditSharing = (Session::get("username") === $sharedExperimentOwner) &&
!$expVal["editable"];
+            $data['can_write'] = SharingUtilities::userCanWrite(Session::get("username"),
$experiment->experimentId, ResourceType::EXPERIMENT);
+            $data["users"] = json_encode($users);
+            $data["owner"] = json_encode($owner);
+            $data["projectOwner"] = json_encode($projectOwner);
+            $data["canEditSharing"] = $canEditSharing;
+            // The summary page has it's own Update Sharing button
+            $data["updateSharingViaAjax"] = true;
+        }
+
+        if( Input::has("dashboard"))
+        {
+            $detailedExperiment = ExperimentUtilities::get_detailed_experiment( $_GET['expId']);
+            $data["detailedExperiment"] = $detailedExperiment;
+        }
+
+        if (Request::ajax()) {
+            //admin wants to see an experiment summary
+            if (Input::has("dashboard")) {
+                $data["dashboard"] = true;
+                return View::make("partials/experiment-info", $data);
+            } else
+                return json_encode($data);
         } else {
-            if (Input::has("dashboard"))
-                return View::make("partials/experiment-info", array("invalidExperimentId"
=> 1));
-            else
-                return View::make("experiment/summary", array("invalidExperimentId" =>
1));
+            return View::make("experiment/summary", $data);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b7d80b11/app/libraries/ExperimentUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/ExperimentUtilities.php b/app/libraries/ExperimentUtilities.php
index 0db86f1..90193ae 100755
--- a/app/libraries/ExperimentUtilities.php
+++ b/app/libraries/ExperimentUtilities.php
@@ -199,6 +199,7 @@ class ExperimentUtilities
      * Get the experiment with the given ID
      * @param $expId
      * @return null
+     * @throws ExperimentNotFoundException
      */
     public static function get_experiment($expId)
     {
@@ -211,7 +212,7 @@ class ExperimentUtilities
         } catch (InvalidRequestException $ire) {
             CommonUtilities::print_error_message('<p>InvalidRequestException: ' . $ire->getMessage()
. '</p>');
         } catch (ExperimentNotFoundException $enf) {
-            CommonUtilities::print_error_message('<p>ExperimentNotFoundException: '
. $enf->getMessage() . '</p>');
+            throw $enf; // rethrow
         } catch (AiravataClientException $ace) {
             CommonUtilities::print_error_message('AiravataClientException: ' . $ace->getMessage()
. '</p>');
         } catch (AiravataSystemException $ase) {

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b7d80b11/app/views/partials/experiment-info.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/experiment-info.blade.php b/app/views/partials/experiment-info.blade.php
index a0b027e..aa2eaa6 100644
--- a/app/views/partials/experiment-info.blade.php
+++ b/app/views/partials/experiment-info.blade.php
@@ -5,13 +5,11 @@
 }
 </style>
 <div class="container" style="max-width: 750px;">
-    <!--
     @if(isset( $invalidExperimentId ) )
     <div class="alert alert-danger">
         The Experiment ID does not exist. Please go to correct experiment.
     </div>
     @else
-    -->
     @if( Session::has("permissionDenied" ) )
     <div class="alert alert-danger">
         {{Session::forget("permissionDenied") }}


Mime
View raw message