This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-php-gateway.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f7d3b5  AIRAVATA-2995 Require input when file doesn't exist
6f7d3b5 is described below

commit 6f7d3b589e0804aacfd54eb4d8b4c4705bf1cb4f
Author: Marcus Christie <[email protected]>
AuthorDate: Thu Apr 18 16:45:03 2019 -0400

    AIRAVATA-2995 Require input when file doesn't exist
---
 app/libraries/ExperimentUtilities.php          | 56 ++++++++++++++++++++------
 app/views/partials/experiment-inputs.blade.php |  4 +-
 2 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/app/libraries/ExperimentUtilities.php 
b/app/libraries/ExperimentUtilities.php
index 3b92e87..b6295d5 100755
--- a/app/libraries/ExperimentUtilities.php
+++ b/app/libraries/ExperimentUtilities.php
@@ -90,15 +90,8 @@ class ExperimentUtilities
                     if ($input->value === null) {
                         continue;
                     }
-                    if (strpos($input->value, "airavata-dp") === 0) {
-                        $dataProductModel = 
Airavata::getDataProduct(Session::get('authz-token'), $input->value);
-                        $currentInputPath = "";
-                        foreach ($dataProductModel->replicaLocations as $rp) {
-                            if ($rp->replicaLocationCategory == 
ReplicaLocationCategory::GATEWAY_DATA_STORE) {
-                                $currentInputPath = $rp->filePath;
-                                break;
-                            }
-                        }
+                    $currentInputPath = 
ExperimentUtilities::get_data_product_path($input);
+                    if ($currentInputPath) {
                         $fileName = basename($currentInputPath);
                     } else {
                         $fileName = basename($input->value);
@@ -793,15 +786,16 @@ class ExperimentUtilities
     /**
      * Create form inputs to accept the inputs to the given application
      * @param $id
-     * @param $isRequired
+     * @param $experimentInputs
      * @param $allowedFileSize maximum file size in megabytes
      * @internal param $required
      */
-    public static function create_inputs($id, $isRequired, $allowedFileSize)
+    public static function create_inputs($id, $experimentInputs, 
$allowedFileSize)
     {
         $inputs = AppUtilities::get_application_inputs($id);
 
-        $required = $isRequired ? ' required' : '';
+        // require if existing input has no value (check $experimentInputs) or 
file doesn't exist
+        $required = ' required';
 
         //var_dump( $inputs);  echo "<br/>after sort<br/>";
         //arranging inputs in ascending order.
@@ -818,6 +812,21 @@ class ExperimentUtilities
             if($input->isReadOnly)
                 $disabled = "disabled";
 
+            if ($experimentInputs !== null) {
+
+                foreach ($experimentInputs as $experimentInput) {
+                    if ($input->name === $experimentInput->name && 
$experimentInput->value !== null) {
+
+                        if ($experimentInput->type === DataType::URI) {
+                            $path = 
ExperimentUtilities::get_data_product_path($experimentInput);
+                            // Don't require the input file if there is 
already an existing value
+                            if ($path !== null && file_exists($path)) {
+                                $required = '';
+                            }
+                        }
+                    }
+                }
+            }
             switch ($input->type) {
                 case DataType::STRING:
                     echo '<div class="form-group">
@@ -1542,4 +1551,27 @@ class ExperimentUtilities
         GrouperUtilities::shareResourceWithUsers($expId, 
ResourceType::EXPERIMENT, $radd);
         GrouperUtilities::revokeSharingOfResourceFromUsers($expId, 
ResourceType::EXPERIMENT, $rrevoke);
     }
+
+    private static function get_data_product_path($input) {
+
+        if ($input->value === null) {
+            return null;
+        }
+        $currentInputPath = "";
+        if (strpos($input->value, "airavata-dp") === 0) {
+            $dataProductModel = 
Airavata::getDataProduct(Session::get('authz-token'), $input->value);
+            foreach ($dataProductModel->replicaLocations as $rp) {
+                if ($rp->replicaLocationCategory == 
ReplicaLocationCategory::GATEWAY_DATA_STORE) {
+                    $currentInputPath = $rp->filePath;
+                    break;
+                }
+            }
+        }
+
+        if ($currentInputPath !== "") {
+            return parse_url($currentInputPath)['path'];
+        } else {
+            return null;
+        }
+    }
 }
diff --git a/app/views/partials/experiment-inputs.blade.php 
b/app/views/partials/experiment-inputs.blade.php
index eb94ae2..4c48fbd 100644
--- a/app/views/partials/experiment-inputs.blade.php
+++ b/app/views/partials/experiment-inputs.blade.php
@@ -39,9 +39,9 @@
                 {{ 
ExperimentUtilities::list_input_files($expInputs['experiment']->experimentInputs)
 }}
                 <hr/>
             </div>
-            {{ ExperimentUtilities::create_inputs($expInputs['application'], 
false, $expInputs['allowedFileSize']) }}
+            {{ ExperimentUtilities::create_inputs($expInputs['application'], 
$expInputs['experiment']->experimentInputs, $expInputs['allowedFileSize']) }}
             @else
-            {{ ExperimentUtilities::create_inputs($expInputs['application'], 
true, $expInputs['allowedFileSize']) }}
+            {{ ExperimentUtilities::create_inputs($expInputs['application'], 
null, $expInputs['allowedFileSize']) }}
             @endif
         </div>
         <!-- Modal to view file inputs-->

Reply via email to